Skip to content

v3 & Harmony diary / thoughts / code snippets

Announcements
  • @DownPW From memory, you should be using a function that looks like this in PROD

    $(window).on('action:ajaxify.end', function (data) {
        function updateUsername() {
            $('.getUsername .username').text(app.user.username);
        }
        if (document.readyState === 'loading') {
            document.addEventListener('DOMContentLoaded', updateUsername);
        } else {
            updateUsername();
        }
        var thehours = new Date().getHours();
    	var themessage;
    	var morning = ('Good morning');
    	var afternoon = ('Good afternoon');
    	var evening = ('Good evening');
        var matched = false;
        $('#getConsent').attr("href", "/user/" + app.user.username + "/consent");
    	if (thehours >= 0 && thehours < 12) {
    		themessage = morning; 
    
    	} else if (thehours >= 12 && thehours < 17) {
    		themessage = afternoon;
    
    	} else if (thehours >= 17 && thehours < 24) {
    		themessage = evening;
    	}
            $('.getUsername').prepend(themessage);
    });
    

    You’ll need the same function in your development environment if you don’t have it already, and will need to add

    $('.topicUsername').text(app.user.username);
    

    Right after line 3, so

    $(window).on('action:ajaxify.end', function(data) {
        function updateUsername() {
            $('.getUsername .username').text(app.user.username);
            $('.topicUsername').text(app.user.username);
        }
        if (document.readyState === 'loading') {
            document.addEventListener('DOMContentLoaded', updateUsername);
        } else {
            updateUsername();
        }
        var thehours = new Date().getHours();
        var themessage;
        var morning = ('Good morning');
        var afternoon = ('Good afternoon');
        var evening = ('Good evening');
        var matched = false;
        $('#getConsent').attr("href", "/user/" + app.user.username + "/consent");
        if (thehours >= 0 && thehours < 12) {
            themessage = morning;
    
        } else if (thehours >= 12 && thehours < 17) {
            themessage = afternoon;
    
        } else if (thehours >= 17 && thehours < 24) {
            themessage = evening;
        }
        if (window.location.href.indexOf("topic") > -1) {
            //console.log("This is a topic, so hide the user welcome message");
            $('#mainbanner').hide();
        } else {
            $('.getUsername').prepend(themessage);
    
        }
    
    
        //	$('.getUsername').prepend(themessage);
    });
    

    Note that your function might look different as I recall you modifying the code I supplied to meet your own needs.

  • @DownPW Ah yes, I can see a case where that would indeed fire, and I’m able to replicate it here

    ce4c965b-5c2c-417e-918b-638ff6315d57-image.png

    Let me adjust the code and get back to you.

    EDIT: Revised widget code here

    <head>
      <style>
        span.topicUsername {
          text-transform: capitalize;
        }
      </style>
    </head>
      {{{ if isSolved }}}
      <div id="resolved">
        <div class="resolved-wrapper">
          <h5 class="resolved-header">Did this solution help you?</h5>
          <div class="resolved-body">
            <div class="resolved-message">Did you find the suggested solution useful? Why not <a href="https://www.buymeacoffee.com/phenomlab" target=_blank>buy me a coffee<a />? It's a nice gesture, and there's <a href="https://sudonix.com/donate">other ways to donate</a> if you wish <span class="heart">💗</span></div>
          </div>
        </div>
      </div>
      <br>
      <script>
        if (!window.jQuery) {
          window.addEventListener('load', function() {
            $(document).ready(function() {
              $("#resolved").insertAfter('.isSolved');
            })
            console.log("Total posts = " + ajaxify.data.postcount)
          })
        } else {
          $(document).ready(function() {
            $("#resolved").insertAfter('.isSolved');
          })
          console.log("Total posts = " + ajaxify.data.postcount)
        }
      </script>
      {{{ end }}}
      {{{ if (uid == loggedInUser.uid) }}}
      {{{ if isQuestion }}}
      {{{ if !isSolved }}}
      {{{ if !unreplied }}}
      <div id="unresolved">
        <div class="unresolved-wrapper">
          <h5 class="unresolved-header">Did you get the answer you needed?</h5>
          <div class="unresolved-body">
            <div class="unresolved-message">Hey <span class="topicUsername"><span class="username"></span></span>. It looks as though there have been one or more replies to your original post. <br>If a provided answer resolved an issue for you, Could you please take a moment, and select "Mark this post as the correct answer" in the corresponding response? <br><br>By doing this, it means that original posters help the rest of the community find answers to previously asked questions by identifying the correct answer. </div>
          </div>
        </div>
      </div>
      <br>
      <script>
        if (!window.jQuery) {
          window.addEventListener('load', function() {
            $(document).ready(function() {
              $("#unresolved").insertBefore('[component="topic/quickreply/container"]');
            })
          })
        } else {
          $(document).ready(function() {
            $("#unresolved").insertBefore('[component="topic/quickreply/container"]');
          })
        }
      </script>
      {{{ end }}}
      {{{ end }}}
      {{{ end }}}
      {{{ end }}}
      {{{ if unreplied }}}
      {{{ if !isSolved }}}
      {{{ if isQuestion }}}
      <div id="unreplied">
        <div class="unreplied-wrapper">
          <h5 class="unreplied-header">No response yet</h5>
          <div class="unreplied-body">
            <div class="unreplied-message">Hey <span class="topicUsername"><span class="username"></span></span>. It looks as though there are no responses yet. Don't panic though, as one will be provided as soon as possible.<br>Please do not "bump" posts. </div>
          </div>
        </div>
      </div>
      <br>
      <script>
        if (!window.jQuery) {
          window.addEventListener('load', function() {
            $(document).ready(function() {
              $("#unreplied").insertBefore('[component="topic/quickreply/container"]');
            })
          })
        } else {
          $(document).ready(function() {
            $("#unreplied").insertBefore('[component="topic/quickreply/container"]');
          })
        }
      </script>
      {{{ end }}}
      {{{ end }}}
      {{{ end }}}
    
  • @phenomlab said in v3 & Harmony diary / thoughts / code snippets:

    @DownPW From memory, you should be using a function that looks like this in PROD

    Ha yes exactly, seems to be forget this lol. 🤣
    With $('.topicUsername').text(app.user.username); it’s perfect 🙂


    @phenomlab said in v3 & Harmony diary / thoughts / code snippets:
    EDIT: Revised widget code here

    yes perfect, definitively better ^^


    Just play with CSS for me but it’s a very good job Mark !
    I love this functionnality a lot, who play which works together with the nodebb-plugin-question-and-answer plugin

  • @DownPW said in v3 & Harmony diary / thoughts / code snippets:

    With $(‘.topicUsername’).text(app.user.username); it’s perfect

    Yes, I need to add that to the documentation above, plus the “missing” function (which I will cut down as the average user won’t need all of it)

    @DownPW said in v3 & Harmony diary / thoughts / code snippets:

    EDIT: Revised widget code here
    yes perfect, definitively better ^^

    Good news

    @DownPW said in v3 & Harmony diary / thoughts / code snippets:

    I love this functionnality a lot, who play which works together with the nodebb-plugin-question-and-answer plugin

    Great ! It was designed primary to work with nodebb-plugin-question-and-answer and in fact won’t work very well without it, so it’s actually a core dependency.

  • I’m a beta tester @phenomlab 😉

    I see other bugs my friends :

    • 1- A user who has not created the topic sees the message intended for the initiator of the topic :
      image.png

    • 2- Same things with solved Post :
      image.png

    –> If the message is only addressed to the initiator of the topic, it’s a bit problematic, isn’t it?

  • @DownPW said in v3 & Harmony diary / thoughts / code snippets:

    1- A user who has not created the topic sees the message intended for the initiator of the topic :

    Ugh. Sorry. Use this widget code (original post updated)

    <head>
      <style>
        span.topicUsername {
          text-transform: capitalize;
        }
      </style>
    </head>
      {{{ if isSolved }}}
      <div id="resolved">
        <div class="resolved-wrapper">
          <h5 class="resolved-header">Did this solution help you?</h5>
          <div class="resolved-body">
            <div class="resolved-message">Did you find the suggested solution useful? Why not <a href="https://www.buymeacoffee.com/phenomlab" target=_blank>buy me a coffee<a />? It's a nice gesture, and there's <a href="https://sudonix.com/donate">other ways to donate</a> if you wish <span class="heart">💗</span></div>
          </div>
        </div>
      </div>
      <br>
      <script>
        if (!window.jQuery) {
          window.addEventListener('load', function() {
            $(document).ready(function() {
              $("#resolved").insertAfter('.isSolved');
            })
            console.log("Total posts = " + ajaxify.data.postcount)
          })
        } else {
          $(document).ready(function() {
            $("#resolved").insertAfter('.isSolved');
          })
          console.log("Total posts = " + ajaxify.data.postcount)
        }
      </script>
      {{{ end }}}
      {{{ if (uid == loggedInUser.uid) }}}
      {{{ if isQuestion }}}
      {{{ if !isSolved }}}
      {{{ if !unreplied }}}
      <div id="unresolved">
        <div class="unresolved-wrapper">
          <h5 class="unresolved-header">Did you get the answer you needed?</h5>
          <div class="unresolved-body">
            <div class="unresolved-message">Hey <span class="topicUsername"><span class="username"></span></span>. It looks as though there have been one or more replies to your original post. <br>If a provided answer resolved an issue for you, Could you please take a moment, and select "Mark this post as the correct answer" in the corresponding response? <br><br>By doing this, it means that original posters help the rest of the community find answers to previously asked questions by identifying the correct answer. </div>
          </div>
        </div>
      </div>
      <br>
      <script>
        if (!window.jQuery) {
          window.addEventListener('load', function() {
            $(document).ready(function() {
              $("#unresolved").insertBefore('[component="topic/quickreply/container"]');
            })
          })
        } else {
          $(document).ready(function() {
            $("#unresolved").insertBefore('[component="topic/quickreply/container"]');
          })
        }
      </script>
      {{{ end }}}
      {{{ end }}}
      {{{ end }}}
      {{{ end }}}
      {{{ if unreplied }}}
      {{{ if !isSolved }}}
      {{{ if isQuestion }}}
      {{{ if (uid == loggedInUser.uid) }}}
      <div id="unreplied">
        <div class="unreplied-wrapper">
          <h5 class="unreplied-header">No response yet</h5>
          <div class="unreplied-body">
            <div class="unreplied-message">Hey <span class="topicUsername"><span class="username"></span></span>. It looks as though there are no responses yet. Don't panic though, as one will be provided as soon as possible.<br>Please do not "bump" posts. </div>
          </div>
        </div>
      </div>
      <br>
      <script>
        if (!window.jQuery) {
          window.addEventListener('load', function() {
            $(document).ready(function() {
              $("#unreplied").insertBefore('[component="topic/quickreply/container"]');
            })
          })
        } else {
          $(document).ready(function() {
            $("#unreplied").insertBefore('[component="topic/quickreply/container"]');
          })
        }
      </script>
      {{{ end }}}
      {{{ end }}}
      {{{ end }}}
      {{{ end }}}
    

    @DownPW said in v3 & Harmony diary / thoughts / code snippets:

    If the message is only addressed to the initiator of the topic, it’s a bit problematic, isn’t it?

    No, not really 🙂 It’s designed to work this way so that anyone else visiting looking for the same answer and finds it has the opportunity to reward you - it’s why it mentions no names 🙂

  • Perfect thats Work on 3;X 😉


    I am testing this code in version 2.X but it seems it is not working properly

    Only the resolution message seems to work in 2.X

    Do you think it is possible to adapt it for 2.X ?

  • @DownPW said in v3 & Harmony diary / thoughts / code snippets:

    I am testing this code in version 2.X but it seems it is not working properly
    Only the resolution message seems to work in 2.X
    Do you think it is possible to adapt it for 2.X ?

    Hmm - I never wrote it to be compatible with v2, but I can’t think of any reason as wo why this would not work. Is there somewhere I can see it ?

  • @phenomlab I pm you

  • @DownPW I see why. The code relies on the existence of

    [component="topic/quickreply/container"]
    

    However, this by definition means that the below has to be enabled

    aeef638f-4188-489d-a9f2-f3a26dbca9d8-image.png

    It will then work

    7fb38631-e0f3-46ef-b652-00929d927b13-image.png

    For some unknown reason, this is hidden in Harmony, and only shows if you select it. In v2, it seems that the <section> is deleted altogether in Persona if “Quick Reply” is disabled, meaning it won’t fire as it can’t locate that specific component.

    The downside is that you might not want the quick reply function, but I think it’s a PITA to scroll up to the top of the post just to reply, so I have it on 🙂


  • Page control arrows for PWA

    Solved Customisation
    27
    25 Votes
    27 Posts
    374 Views

    @crazycells it is, yes - I think I’ll leave it as there is no specific PWA CSS classes I know of. Well, you could use something like the below, but this means multiple CSS files for different operating systems.

    /** * Determine the mobile operating system. * This function returns one of 'iOS', 'Android', 'Windows Phone', or 'unknown'. * * @returns {String} */ function getMobileOperatingSystem() { var userAgent = navigator.userAgent || navigator.vendor || window.opera; // Windows Phone must come first because its UA also contains "Android" if (/windows phone/i.test(userAgent)) { return "Windows Phone"; } if (/android/i.test(userAgent)) { return "Android"; } if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) { return "iOS"; } return "unknown"; // return “Android” - one should either handle the unknown or fallback to a specific platform, let’s say Android }

    Once you’re in that rabbit hole, it’s impossible to get out of it.

  • 6 Votes
    4 Posts
    200 Views

    @cagatay these changes aren’t published anywhere presently, so nothing for you to do.

  • 3 Votes
    2 Posts
    143 Views

    @phenomlab very nice and useful idea

    Bravo Xd GIF

  • Nodebb design

    Solved General
    2
    1 Votes
    2 Posts
    146 Views

    @Panda said in Nodebb design:

    One negative is not being so good for SEO as more Server side rendered forums, if web crawlers dont run the JS to read the forum.

    From recollection, Google and Bing have the capability to read and process JS, although it’s not in the same manner as a physical person will consume content on a page. It will be seen as plain text, but will be indexed. However, it’s important to note that Yandex and Baidu will not render JS, although seeing as Google has a 90% share of the content available on the web in terms of indexing, this isn’t something you’ll likely lose sleep over.

    @Panda said in Nodebb design:

    The “write api” is preferred for server-to-server interactions.

    This is mostly based around overall security - you won’t typically want a client machine changing database elements or altering data. This is why you have “client-side” which could be DOM manipulation etc, and “server-side” which performs more complex operations as it can communicate directly with the database whereas the client cannot (and if it can, then you have a serious security flaw). Reading from the API is perfectly acceptable on the client-side, but not being able to write.

    A paradigm here would be something like SNMP. This protocol exists as a UDP (UDP is very efficient, as it is “fire and forget” and does not wait for a response like TCP does) based service which reads performance data from a remote source, thus enabling an application to parse that data for use in a monitoring application. In all cases, SNMP access should be “RO” (Read Only) and not RW (Read Write). It is completely feasible to assume complete control over a firewall for example by having RW access to SNMP and then exposing it to the entire internet with a weak passphrase.

    You wouldn’t do it (at least, I hope you wouldn’t) and the same ethic applies to server-side rendering and the execution of commands.

  • NodeBB v3 Android Problem

    Solved Configure
    4
    4 Votes
    4 Posts
    189 Views

    thank you fixed.

  • Podcast Share NodeBB

    Solved Configure
    15
    4 Votes
    15 Posts
    483 Views

    @cagatay You could experiment with nodebb-plugin-ns-embed but I expect the x-origin tag on the remote site to prevent playback.

  • 3 Votes
    9 Posts
    411 Views

    The real issue here is that most people consider forums to be “dead” in the sense that nobody uses them anymore, and social media groups have taken their place. Their once dominant stance in the 90’s and early 00’s will never be experienced again, but having said that, there are a number of forums that did in fact survive the social media onslaught, and still enjoy a large user base.

    Forums tend to be niche. One that immediately sticks out is Reddit - despite looking like it was designed in the 80s, it still has an enormous user base. Another is Stack Overflow, which needs no introduction. The key to any forum is the content it offers, and the more people whom contribute in terms of posting , the more popular and widely respected it becomes as a reliable source of information.

    Forums are still intensely popular with gamers, alongside those that offer tips on hacking etc.

  • 1 Votes
    1 Posts
    194 Views
    No one has replied