howto get the new content of edited post?

Solved Plugin Development

Suggested Topics


  • 0 Votes
    6 Posts
    175 Views

    Please open an issue on our github tracker, I am not sure if we should just remove the saving to user settings in the sort dropdown all together and move the sort settings to /user/<slug>/settings like everything else. Then you can change the sort order in every topic without effecting your settings. The setting used in the user page would be the default sort when you enter a topic.

  • 0 Votes
    4 Posts
    320 Views

    @ape the standard way to get nodebb modules is require.main.require

    const Posts = require.main.require('./src/posts'); Posts.getPostData(pid, callback)
  • 1 Votes
    1 Posts
    136 Views

    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." } ] } ],
  • 0 Votes
    3 Posts
    1k Views

    Yep, ended up using posts.isMain function.

  • 0 Votes
    2 Posts
    1k Views

    In your plugins init method you can do

    var helpers = module.parent.require('./routes/helpers'); myPlugin.init = function(params, callback) { helpers.setupPageRoute(params.app, '/', params.middleware, [], myCustomHome); callback(); }; function myCustomHome(req, res, next) { async.parallel({ categories: function(next) { Categories.getAllCategories(); } topics: function(next) { Topics.getLatestTopics(); } }, function(err, results) { res.render('myCustomTemplate', results); }); }

    I left out some of the params for the 2 methods you mentioned. Let me know if you can't figure it out.