Re: Re: Re: Reply as topic creates empty quote

  • @loopback0 said in Re: Re: Reply as topic creates empty quote:

    @RaceProUK said in Re: Reply as topic creates empty quote:

    @wharrgarbl said in Reply as topic creates empty quote:

    @wharrgarbl said in A single long group name broke autocomplete on mobile:

    As demonstrated above.

    Cannot reproduce: this worked perfectly fine.

    It doesn't fail every time, just some times.

    I wrote the code in question.

    I'm guessing that it's a race condition.

    The problem is, there's no "open composer to create new topic, and add this quote to it" function (or if there is, I'm not aware of it). Neither is there an "open composer to create new topic, and call this callback function when done" function. I did find functions for:

    • "open composer to create new post"
    • "open composer to create new post, and add this quote to it"
    • "open composer to create new topic"
    • "add this quote to the currently-open composer"

    The composer for new topics is different from the composer for new posts (the topic composer includes the dropdown for category and field to add tags).

    So the only way to create a topic and add a quote to it is to call the function to open the composer for a new topic, wait some unspecified amount of time, and then call the function to add a quote to it. If it takes longer than expected to open the composer, the function that adds a quote can fire before it finishes opening, and the quote it adds gets erased.

    I think I remember putting some code in there that's supposed to detect whether the composer finished opening before it calls the code to add the function, and if not, it's supposed to wait longer. That's probably what isn't working all of the time; I bet it's hitting a condition that satisfies the logic I used to think the composer is ready when it's actually not quite ready.

    Another difference is, the functions to create posts can include a PID-in-reply-to, but the function to create a topic does not. That's why "reply as topic" topics don't include the undefined icon with a reference to the parent post, and they don't show up as a reply in its list of replies. (Replies that are moved by a mod into a new topic do have the parent post reference, so it's not a limitation in the database; it's just the functions didn't allow me to specify any.)

  • I found the same problem. I solved it by using the translator to create a callback.

  • Here's the code...


  • @NedFodder I actually like what you did; I didn't dig deep enough into NodeBB's core to figure out how to add a "reply-as-topic-with-quote" function, like you did.

    Could your 'action:composer.replyAsTopic' function be modified to include the PID-in-reply-to? If so, then it'd probably be good to just replace my function with yours...

  • @anotherusername said in Re: Re: Re: Reply as topic creates empty quote:


    I don't know what that is. Searching for that string on github is pretty much impossible. Can you show me teh codez?

  • @NedFodder it's the thing that makes the "undefined" on the post.

    For instance, I started this post by entering this:

    $(window).trigger('', {
        pid: 1140559,
        text: ''

  • You'll note, that post appears to be a reply to itself, because I used its PID as the pid_in_reply_to.

    I don't know what it's called on the other side of $(window).trigger, but it's what I call it.

  • @NedFodder Wait, I figured it out. I'm calling composer.newTopic which calls which doesn't take a pid parameter. You'd have to call something (???) that calls posts.reply (which takes a toPid parameter) to get the undefined thingy. Or something. I don't have time to dig farther than that...

  • @NedFodder oh... yeah, that sounds about right. The client side can't do it at all because the socket.emit events don't allow it in a new topic.

  • @anotherusername

    For one thing, it looks like it uses a relative post index instead of a permalink.

    Lol, permalinks didn't exist when I wrote it!

    It'd need a few changes, but by and large I like the way it works

    Sorry I don't have a ton of time to help. Good luck...

  • @anotherusername Another bug in your script: Replying to the Wondows 10 Craters' Pupdate topic creates a new topic called Re: Wondows 10 Craters' Pupdate. My version doesn't do that. That could be NodeBB's fault maybe, I dunno...

  • kills Dumbledore

  • @anotherusername I'm almost certain that the only way to get the undefined thingy would be to make two changes to the composer (the pid needs to be passed down here and here). So assuming we're not going to do that, I propose we do this:

    function replyAsTopic(event) {
        var e = $('li[component="post"]').get(0);
        var pid = e.getAttribute('data-pid');
        socket.emit('posts.getRawPost', pid, function(err, text) {
            if(err) {
                return app.alertError(err.message);
            require(['composer', 'translator'], function(composer, translator) {
                var title =;
                var username = e.getAttribute('data-username');
                var escapedTitle = (title || '').replace(/([\\`*_{}\[\]()#+\-.!])/g, '\\$1').replace(/\[/g, '[').replace(/\]/g, ']').replace(/%/g, '%').replace(/,/g, ',');
                if (text) {
                    text = '> ' + text.replace(/\n/g, '\n> ') + '\n\n';
                if (title) {
                    var link = '[' + escapedTitle + '](' + config.relative_path + '/post/' + (pid) + ')';
                    translator.translate('[[modules:composer.user_said_in, ' + username + ', ' + link + ']]\n', config.defaultLang, onTranslated);
                } else {
                    translator.translate('[[modules:composer.user_said, ' + username + ']]\n', config.defaultLang, onTranslated);
                function onTranslated(translated) {
                        title: 'Re: ' + (title || ''),
                        body: translated + text
                    setTimeout(function () {
                        document.querySelector('.composer textarea.write').focus();
                    }, 100);                

    This should solve the race condition and the escaped title. Thoughts?

Log in to reply

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.