Skip to content

Plugin Development

Have a question about building a plugin? Ask here
444 Topics 1.9k Posts
  • filter:post.edit, setTopicFields keeps forgetting data on restart

    1
    1 Votes
    1 Posts
    256 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
    942 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
    705 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...
  • Async error while running Ethereum Smart Contracts tests ?

    2
    0 Votes
    2 Posts
    266 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.
  • Problem with shoutbox plugin after 1.12.2 -> 1.13.0 nodebb upgrade

    6
    0 Votes
    6 Posts
    882 Views
    Ne HoN
    @fais3000 I have this issue with the original on version v1.13.3. (Shoutbox.base is undefined)
  • Does anybody know where all the alert messages are to customize them.

    2
    0 Votes
    2 Posts
    380 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
    980 Views
    G
    @baris i love u
  • i need get the fields of an authorized user

    1
    0 Votes
    1 Posts
    311 Views
    G
    i need get the fields of an authorized user
  • 0 Votes
    7 Posts
    957 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
    376 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
    461 Views
    barisB
    https://github.com/NodeBB/NodeBB/issues/8120
  • Use method from library.js in main.js ( static js file )

    2
    0 Votes
    2 Posts
    534 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
    347 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
    352 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
    869 Views
    Q
    @jzbg This feature is something I've always wanted too...
  • plugin for getting user notifications?

    3
    0 Votes
    3 Posts
    610 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
  • Problem with socket in plugin after 1.12.2 -> 1.13.0 upgrade

    7
    0 Votes
    7 Posts
    941 Views
    A
    @baris OK. I changed this and it works now. Thanks!
  • Adding custom fields to edit.tpl

    1
    0 Votes
    1 Posts
    254 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!
  • Customize forum collection information

    4
    0 Votes
    4 Posts
    448 Views
    PitaJP
    @waldhay yes, you're supposed to rebuild and restart after installing plugins or changing themes.