Confirm on post

Plugin Development
  • I have one particular post on my forum where lots of members subscribe, but it has several posting rules attached to it.
    Unfortunately members continue to ignore these rules and it makes other members unhappy and I need to go around deleting lots of posts.
    We already have a warning toast when replying and edited the composer box to be red, but it still doesn't make much difference.

    So I'm looking to put up a final confirm dialog on Submit. I can see that I can use bootbox.confirm to bring up the dialog, just not sure what action I need to be watching, and what to call to either stop the message being posted or to let it continue on the callbacks.

  • I am not sure if it will work with bootbox.confirm since the client side hooks are synchronous. You can give it a shot.

    If that doesn't work another option is to add a fake submit button in the composer and hide the real submit button. Once the user confirms the bootbox.confirm trigger a click on the real submit button.

  • @baris thanks for the suggestions, for now I've just replaced the toast on clicking Reply with the confirm dialog and if they cancel it presses the discard button to close the composer.

Suggested Topics

  • 0 Votes
    3 Posts

    Nice, thanks for help!

  • 1 Votes
    1 Posts

    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(, ['truths'], function (err, topicData) { if (err) return console.log(err); var topicTruths = topicData.truths; var parsed = parseColored(; var truthpost = { 'pid':, 'uid':, 'truths': parsed }; if (truthpost.truths) { if (topicTruths && Array.isArray(topicTruths)) { topicTruths.push(truthpost); } else { topicTruths = [truthpost]; } } topics.setTopicFields(, { 'truths': topicTruths }); }); callback(null, payload); } plugin.editPostTruth = function (payload, callback) { posts.getPostFields(, ['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(; var truthpost = { 'pid':, 'uid':, 'truths': parsed }; if (!truthpost.truths) { console.log("checking for pid " +; var i = topicTruths.findIndex(function (o) { return ==; }); 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 " +; var i = topicTruths.findIndex(function (o) { return ==; }); 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(, { '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

    @pichalite thank to your suggest it works I have only topics that aren't "Pin". If I do this:


    The topics show in this way:

    0_1470823128648_Schermata del 2016-08-10 11:45:59.png
    In the image I can see that "primo creato " topic that I have PIN it's the last but I want to become the first.

    I want that when I PIN a topic, this must be the first among the topics (now it is the last).

    In plugin.json I put this hook:

    "hook": "filter:category.topics.prepare", "method": "ordina_zero"

    and in library I do this:

    converter.ordina_zero = function(data, callback) { //Prendo quale element del sorted ha cliccato user.getSettings(data['uid'], function(err, settings) { if (settings.categoryTopicSort === 'zero') { data.reverse = false; data.set = 'cid:' + data.cid + ':tids:posts'; } callback(null, data); }); };

    My purpose is show the PIN topic at the beginning and after show the topics with their order. Can you help me?

  • get all posts

    Plugin Development
    0 Votes
    11 Posts

    @louisemcmahon ,
    You can try the filters unreplied for getting all topics which don't have any reply till.

  • 0 Votes
    3 Posts

    @baris thanks. I realised there's some issues with redactor munging the data.
    When code is insered inside a <pre/> block, switching between HTML and WYSIWYG views will munge the content to HTML entitites.
    You can recreate this issue on this page:

    Switch to code view and add some HTML inside the <pre/> block. I entered:
    Switch to WYSIWYG and back to code and it has been replaced by:


    This breaks the ability to parse that code later with syntax highlighters.

    I've raised it with Imperavi.