Skip to content

Adding a banner to chat messages

Tips
38 3 17.4k 1
  • wrote on last edited by DownPW
    #11

    Ok so there is a problem on my side. Sorry, test it again

  • Ok so there is a problem on my side. Sorry, test it again

    wrote on last edited by
    #12

    @DownPW let me know how you get on.

  • wrote on last edited by DownPW
    #13

    Work now with empty chat room, Thank you 🙂
    But they appear at the very bottom of the chat :

    98e475da-fa86-410d-ac8f-a752be0ba7b3-image.png

    Just see that the banner is displayed even after a system event :

    component="chat/system-message"

    02c5edc5-89b5-4f9f-a342-449ab1371155-image.png

    System events should be considered as a separate message for thebanner message to be displayed below.

  • Work now with empty chat room, Thank you 🙂
    But they appear at the very bottom of the chat :

    98e475da-fa86-410d-ac8f-a752be0ba7b3-image.png

    Just see that the banner is displayed even after a system event :

    component="chat/system-message"

    02c5edc5-89b5-4f9f-a342-449ab1371155-image.png

    System events should be considered as a separate message for thebanner message to be displayed below.

    wrote on last edited by
    #14

    @DownPW did the chat banner work in the way you expected here?

  • @DownPW did the chat banner work in the way you expected here?

    wrote on last edited by
    #15

    @phenomlab said in Adding a banner to chat messages:

    @DownPW did the chat banner work in the way you expected here

    A little bit. See hère:

    @DownPW said in Adding a banner to chat messages:

    Work now with empty chat room, Thank you 🙂
    But they appear at the very bottom of the chat :

    98e475da-fa86-410d-ac8f-a752be0ba7b3-image.png

    Just see that the banner is displayed even after a system event :

    component="chat/system-message"

    02c5edc5-89b5-4f9f-a342-449ab1371155-image.png

    System events should be considered as a separate message for thebanner message to be displayed below.

  • @phenomlab said in Adding a banner to chat messages:

    @DownPW did the chat banner work in the way you expected here

    A little bit. See hère:

    @DownPW said in Adding a banner to chat messages:

    Work now with empty chat room, Thank you 🙂
    But they appear at the very bottom of the chat :

    98e475da-fa86-410d-ac8f-a752be0ba7b3-image.png

    Just see that the banner is displayed even after a system event :

    component="chat/system-message"

    02c5edc5-89b5-4f9f-a342-449ab1371155-image.png

    System events should be considered as a separate message for thebanner message to be displayed below.

    wrote on last edited by phenomlab
    #16

    @DownPW I think this is what you want - let me know

    a1670323-e770-4717-b63e-759832e1b012-image.png

    in this case, the code has to be modified so it looks like the below

    // Chat message banner
    function chatBanner() {
        var roomName = $("h5[component='chat/header/title']").text().trim();
        var bannerContent;
        if (roomName === "Testing 3") {
            bannerContent = '<div id="chatbanner">This message will fire for chat rooms with the title of "Testing 3"</div>';
        } else {
            bannerContent = '<div id="chatbanner">This session is for <strong>private discussion only</strong> between the chosen participants. Please do <strong>not</strong> place support requests here and create a <a href="#" onclick="app.newTopic();">new topic</a> instead.</div>';
        }
        var chatMessagesContainer = $('[component="chat/system-message"]:last-of-type');
        var existingMessages = $('[component="chat/message"]');
    
        if (existingMessages.length === 0) {
            // If there are no messages, append the banner to the messages container
            chatMessagesContainer.first().after(bannerContent);
        } else {
            // If there are messages, add the banner after the last message
            existingMessages.last().after(bannerContent);
        }
    }
    
    $(window).on('action:chat.loaded', function(data) {
        $(document).ready(function() {
            chatBanner()
        });
    });
    

    This will place the banner after the last system message and before any of the messages themselves. If there are existing messages in the room, the banner will be placed at the footer of the last message so it is seen each time.

    484a7ebb-8246-4a44-8227-b0ab0f42ae56-image.png

  • wrote on last edited by
    #17

    Thanks Mark, you are a champion 🙂

    Test this code ASAP

  • wrote on last edited by DownPW
    #18

    I have tested now this last code, It’s clearly better, Thnks you again.
    Just one things mark @phenomlab, the banner don’t appear if there is empty (no message) :

    f7d5e292-9139-4efa-a3b4-f13e60171e48-image.png

  • I have tested now this last code, It’s clearly better, Thnks you again.
    Just one things mark @phenomlab, the banner don’t appear if there is empty (no message) :

    f7d5e292-9139-4efa-a3b4-f13e60171e48-image.png

    wrote on last edited by
    #19

    @DownPW Does it appear if you reload the page?

  • wrote on last edited by
    #20

    @phenomlab nope 🙂

  • wrote on last edited by
    #21

    @DownPW Very odd - I see this on your DEV server

    3d34b97b-f793-400f-9f36-e37438c43ea3-image.png

  • wrote on last edited by DownPW
    #22

    It’s because you have joined the public chat and so we have a system message. (Phenomlab as joined the room…)

    If you are the creator of the room, no joined her and 0 message (user and system message), banner don’t appear but it’s not very serious

    image.png

  • It’s because you have joined the public chat and so we have a system message. (Phenomlab as joined the room…)

    If you are the creator of the room, no joined her and 0 message (user and system message), banner don’t appear but it’s not very serious

    image.png

    wrote on last edited by
    #23

    @DownPW Can you create another ? I should be able to get this to work…

  • wrote on last edited by
    #24

    ok, I recreated the "“Support” lounge

  • ok, I recreated the "“Support” lounge

    wrote on last edited by
    #25

    @DownPW Can you create a new room? There are events in the old one which will trigger the message

  • wrote on last edited by
    #26

    ok, no problem

  • ok, no problem

    wrote on last edited by
    #27

    @DownPW I can’t replicate this issue. Each time I access the room, it will add a system event which causes the JS to trigger

    b9c530f9-7d93-4d11-9ae0-66938e5776e0-image.png

  • wrote on last edited by
    #28

    hmm I think because you have not create the room like me but like I said, it’s not very serious

  • hmm I think because you have not create the room like me but like I said, it’s not very serious

    wrote on last edited by
    #29

    @DownPW Nope. I get the same if I create the room

    323977da-f3c4-4506-9104-531fd6d4f228-image.png

  • wrote on last edited by phenomlab
    #30

    Here’s a small modification to the chatBanner function that will place the message just above the composer/reply component meaning it is pinned at the bottom and always in view as a reminder. I’ve made this change to support the threadedChat I’m currently developing

    // Chat message banner
    function chatBanner() {
        var roomName = $("h5[component='chat/header/title']").text().trim();
        var bannerContent;
        if (roomName === "Testing 3") {
            bannerContent = '<div id="chatbanner">This message will fire for chat rooms with the title of "Testing 3"</div>';
        } else {
            bannerContent = '<div id="chatbanner">This session is for <strong>private discussion only</strong> between the chosen participants. Please do <strong>not</strong> place support requests here and create a <a href="#" onclick="app.newTopic();">new topic</a> instead.</div>';
        }
        var chatMessagesContainer = $('[component="chat/system-message"]:last-of-type');
        //var existingMessages = $('[component="chat/message"]');
        var existingMessages = $('[component="chat/composer"]');   
        if (existingMessages.length === 0) {
            // If there are no messages, append the banner to the messages container
            chatMessagesContainer.first().after(bannerContent);
        } else {
            // If there are messages, add the banner after the last message
           // existingMessages.last().after(bannerContent);
           existingMessages.before(bannerContent);
        }
    }
    

    There are only two changes here:

    var existingMessages = $('[component="chat/message"]');
    

    becomes

    var existingMessages = $('[component="chat/composer"]');
    

    and

    existingMessages.last().after(bannerContent);
    

    becomes

    existingMessages.before(bannerContent);
    
  • phenomlab phenomlab referenced this topic on
  • phenomlab phenomlab referenced this topic on

Related Topics
  • Rename videos in bulk - linux commands

    Unsolved Tips gopro linux commands
    12
    4 Votes
    12 Posts
    4k Views
    phenomlab
    @Hari Yes, that’s one (of many) I would recommend. It’s going to be easier to do this under Windows and the fact that you are already connected using SMB is a huge plus.
  • Google slow to crawl website (Search Console)

    Tips seo crawl google
    6
    1
    3 Votes
    6 Posts
    2k Views
    phenomlab
    Seems like Google is finally crawling this site. And, “crawling” in the sense that it’s still extremely slow …
  • 2 Votes
    2 Posts
    1k Views
    phenomlab
    As an aside to this, there is also the command of tasklist which will provide a list of processes running on your machine, or a remote machine you are looking to query. [image: 000a408c-cc7e-450f-8e5e-bed9a4238a05-image.png] There is also a useful list of switches below, plus the ability to format into a table, or CSV. https://ss64.com/nt/tasklist.html
  • Killing Linux Zombie Processes

    Tips zombie linux
    3
    7
    2 Votes
    3 Posts
    2k Views
    phenomlab
    @DownPW odd indeed. Looks like it’s spawning, immediately dying, then spawning again.
  • Google Authenticator for 2FA

    Tips tips 2fa
    7
    6 Votes
    7 Posts
    3k Views
    phenomlab
    @crazycells yes, this is something I see on a daily basis and despite how shockingly simple it is to conduct SIM jacking, it seems that several of the USA based banks are reluctant to switch to at least TOTP in the same sense as the USA has been extremely slow to adopt chip and pin - something Europe has been making use of for years. And they wonder why cheque and wire fraud is rife in America.
  • [NodeBB] Custom fields plugin

    Unsolved Customisation nodebb plugins javascript custom
    5
    0 Votes
    5 Posts
    3k Views
    phenomlab
    @pwsincd hi. Just following up on this thread (I know it’s old) but was curious to understand if it’s still an issue or not ?
  • Invalid CSRF on dev install

    Moved Solved Tips csrf
    10
    5 Votes
    10 Posts
    8k Views
    phenomlab
    @DownPW which version of MongoDB are you using?
  • [NodeBB] Import custom Font

    Solved Customisation custom fonts nodebb css
    12
    3 Votes
    12 Posts
    5k Views
    phenomlab
    @cagatay you’ll need to define this in the body tag (or another element if you want greater or more granular targets) - for example body { font-family: "Poppins"; font-size: 16px; } Essentially, you use the font-size CSS directive.