Skip to content

Plugin Development

Have a question about building a plugin? Ask here
425 Topics 1.9k Posts
  • Client script cannot be available in both main and admin?

    Solved
    6
    0 Votes
    6 Posts
    613 Views
    magnusvhendinM

    Thanks for the clarification @PitaJ! I did a lot of experimenting but I guess I didn't get the right combination. I think I never tried naming the module with its extension. That might have been it. For anyone who might be interested in the actual solution, here it is:

    In file-explorer.js:

    define('azure/file-explorer', ['components'], function (components) { const FileExplorer = {}; FileExplorer.init = function () { // Init stuff here }); return FileExplorer; });

    In plugin.json:

    "modules": { "azure/file-explorer.js": "static/lib/file-explorer.js" },

    In admin.js:

    define('admin/plugins/azure', ['settings', 'azure/file-explorer'], function (settings, fileExplorer) { fileExplorer.init(); });

    In main.js:

    $(document).ready(function () { require(['azure/file-explorer'], (fileExplorer) => { fileExplorer.init(); }); });
  • 1 Votes
    1 Posts
    195 Views
    selkkieS

    I'm having a frustrating time with setTopicFields, but only on filter:post.edit. filter:post.create works fine, and the code is pretty similar so I'm not sure what I'm missing. At first, it looks like it works properly, but when I restart NodeBB the data reverts back to how it was on post.create.

    The post data works correctly, but it creates a discrepancy where the post content says the right thing and the custom topicField says something out of date.

    plugin.createPostTruth = function (payload, callback) { topics.getTopicFields(payload.data.tid, ['truths'], function (err, topicData) { if (err) return console.log(err); var topicTruths = topicData.truths; var parsed = parseColored(payload.post.content); var truthpost = { 'pid': payload.post.pid, 'uid': payload.post.uid, 'truths': parsed }; if (truthpost.truths) { if (topicTruths && Array.isArray(topicTruths)) { topicTruths.push(truthpost); } else { topicTruths = [truthpost]; } } topics.setTopicFields(payload.data.tid, { 'truths': topicTruths }); }); callback(null, payload); } plugin.editPostTruth = function (payload, callback) { posts.getPostFields(payload.data.pid, ['tid'], function (err, postData) { topics.getTopicFields(postData.tid, ['truths'], function (err, topicData) { if (err) return console.log(err); var topicTruths = topicData.truths; var parsed = parseColored(payload.post.content); var truthpost = { 'pid': payload.post.pid, 'uid': payload.post.uid, 'truths': parsed }; if (!truthpost.truths) { console.log("checking for pid " + truthpost.pid); var i = topicTruths.findIndex(function (o) { return o.pid == truthpost.pid; }); if (i >= 0) { console.log("removing truths"); topicTruths.splice(i, 1); } //else return payload; } else { if (topicTruths && Array.isArray(topicTruths)) { console.log("checking to find pid " + truthpost.pid); var i = topicTruths.findIndex(function (o) { return o.pid == truthpost.pid; }); if (i >= 0) { console.log("Found pid. splicing truth"); topicTruths.splice(i, 1, truthpost); } else { topicTruths.push(truthpost); console.log("No pid found. adding truth to bottom of stack."); } } else { topicTruths = [truthpost]; console.log("There were no truths at all. making this the first truth..."); } } topics.setTopicFields(payload.data.tid, { 'truths': topicTruths }); }); }); callback(null, payload); }

    The topic json before edit, and after restart:

    "title": "Example Topic", "uid": 1, "viewcount": 1, "truths": [ { "pid": 136, "uid": 1, "truths": [ { "type": "red", "text": "This is a red." } ] }, { "pid": 137, "uid": 1, "truths": [ { "type": "blue", "text": "This is a blue." } ] } ],

    The topic json just after edit, and what it should look like:

    "title": "Example Topic", "uid": 1, "viewcount": 1, "truths": [ { "pid": 136, "uid": 1, "truths": [ { "type": "red", "text": "This is a red." } ] }, { "pid": 137, "uid": 1, "truths": [ { "type": "gold", "text": "This is not a blue." } ] } ],
  • Plugin For Read/Unread in Groups?

    10
    0 Votes
    10 Posts
    637 Views
    barisB

    topics.getUnreadData doesn't take an array of pids. You should use Topics.hasReadTopics(tids, uid);

  • Hook for modifying session cookie

    3
    0 Votes
    3 Posts
    561 Views
    gotwfG

    @julian said in Hook for modifying session cookie:

    Hi @asdrubalivan! That's an interesting conundrum you've got there...
    ...
    However, it seems last last year, @oplik0 used sameSite: 'Strict' for API routes, or at least, those requiring the CSRF token.

    Not a dev so don't follow most of this but my eyes did pick out the cross site and strict, and yes, necessary for CSRF. Seems trying to work around that would be less than advisable? I guess it ultimately depends on your security stance and cost/benefit but I'd be wary of circumventing. It's a freakin' war zone out there. And an election year for U.S. so expect community and blogger sites to be targeted vigorously and relentlessly.

    My $0.02. We now return you to your regularly scheduled programming... 😜

  • 0 Votes
    2 Posts
    219 Views
    PitaJP

    This is the community forum for NodeBB, the node.js based forum software. It's not meant to be for general node.js questions.

    You're free to ask here but you're unlikely to get an answer.

  • 0 Votes
    6 Posts
    684 Views
    Ne HoN

    @fais3000 I have this issue with the original on version v1.13.3. (Shoutbox.base is undefined)

  • 0 Votes
    2 Posts
    319 Views
    PitaJP

    You want to use nodebb-plugin-customize

  • get all posts

    11
    0 Votes
    11 Posts
    5k Views
    S

    @louisemcmahon ,
    You can try the filters unreplied for getting all topics which don't have any reply till.
    https://community.nodebb.org/recent?filter=unreplied

  • write widget

    9
    0 Votes
    9 Posts
    771 Views
    G

    @baris i love u

  • 0 Votes
    1 Posts
    246 Views
    G

    i need get the fields of an authorized user

  • 0 Votes
    7 Posts
    726 Views
    E

    @baris Your solution was confirmed working for my plugin. Thank you Sir.

  • NodeBB not applying new post.tpl on edit

    1
    0 Votes
    1 Posts
    281 Views
    Jovan IvanovićJ

    Hello, I modified the post.tpl to my liking and added some more elements and stuff.

    When I use composer to make a new post in a topic, it works just fine, I get the post.tpl I modified, but when I try to edit any of the posts in the topic, it looks like the default post.tpl file.

    What am I doing wrong here?

  • Static hooks

    3
    1 Votes
    3 Posts
    349 Views
    barisB

    Link Preview Image Throwing an error in a static hook doesn't propagate to caller · Issue #8120 · NodeBB/NodeBB

    NodeBB version: 1.13.1 NodeBB git hash: d1e0672 Installed NodeBB Plugins: N/A Database type: N/A Database version: N/A Exact steps to cause this issue: I am trying to handle static:messaging.canMessageUser with custom logic to block cert...

    favicon

    GitHub (github.com)

  • 0 Votes
    2 Posts
    426 Views
    magnusvhendinM

    I don't believe you can do that since what you're asking for is using server side code on the client. To do that, the entire stack would need to be available on the client and everything it does. Basically running NodeBB on the client.

    What you could do is set up your own socket and return the desired data that way.

    In your library.js file:

    const pluginSockets = require.main.require('./src/socket.io/plugins'); // This will add to the sockets object used by NodeBB core pluginSockets.customFunc = ((socket, dataDoToFetch, done) => { const response = 'This response is only a string but it can be whatever you want'; done(null, response); });

    Then client side:

    socket.emit('plugins.customFunc', dataDoToFetch, (err, data) => { if (err) console.log('My socket customFunc', err, data); else console.log('Do stuff with this', data); });

    I cannot guarantee that this will work out of the box since my setup involves a bit more complexity, but this is the basic idea. Give it a shot!

  • Cached scripts

    1
    1 Votes
    1 Posts
    289 Views
    magnusvhendinM

    Hi all!
    I've run into an issue that when I deploy a new version of my theme/plugin, most users don't get any changes done until they do a hard refresh. This only seems to affect the client side Javascript, so everything looks updated, but in reality functionality gets lost.

    Has anyone stumbled upon something similar? Is there a better way to release code?

    The background in this is that I have forked Persona and built upon it, so all changes to the platform is basically in the theme. Is there a way to make sure all clients receive all updates?

    Thanks!

  • Hooks on build

    1
    0 Votes
    1 Posts
    265 Views
    asdrubalivanA

    Hello! I've been reading the code of NodeBB since I'm developing a plugin for it. Right now I have some ES6 code that needs to be transpiled to ES5 and I'm looking for a way to transpile it in the build process. Are there any hooks that can help me with this process?

    Thanks in advance

  • 0 Votes
    6 Posts
    657 Views
    Q

    @jzbg

    This feature is something I've always wanted too...

  • plugin for getting user notifications?

    3
    0 Votes
    3 Posts
    451 Views
    Nick HarmonN

    @julian Thanks for getting back to me quickly. Other priorities pulled me away from this, but after looking at your response, it seems like what I'm actually after are "unread" counts, not just notifications. The simple GET solution returned notifications, but not every "unread". Our app is using the session sharing plugin, and we are associating NodeBB accounts with our app accounts. Would I be able to leverage some of the session sharing functionality to get an unread count for users on our app based on their NodeBB account? Thanks

  • 0 Votes
    7 Posts
    716 Views
    A

    @baris OK. I changed this and it works now. Thanks!

  • Adding custom fields to edit.tpl

    1
    0 Votes
    1 Posts
    195 Views
    magnusvhendinM

    Hi all!
    I was wondering if there's a simple way to add my custom fields (from the ns-custom-fields plugin) to the regular edit.tpl. I'm making a private forum aimed at professionals and would really love it if I could have everything in one place.

    What I'm currently looking to add is Company, Title and possible some more in the future.

    An idea I have is to just put them in the available form and then using the custom-fields "API" in the backend (on save) to store them separately.

    Any ideas are welcome.

    Sorry to tag you (@Nicolas, the creator) but I believe you can answer this question quite easily.

    Thanks!