src/main/ChatController.js
/**
 * Shows open chats at left panel.
 */
Shows open chats at left panel.
Shows open chats at left panel .
async function showChats() {
    $(".contact-list").html("");
    chatCounter = 0;
    semanticChats.forEach(async chat => {
        var lastMsg = chat.getLastMessage().messagetext;
        var lastHr = "";
        if (!lastMsg) {
            lastMsg = "Sin mensajes";
        } else {
            if (lastMsg.includes("data:image")) {
                lastMsg = "<img alt = 'uploaded' src = '" + lastMsg + "'" + "/>";
            } else if (lastMsg.includes("data:video")) {
                lastMsg = "<video width='20' height='20'> <source src= '" + lastMsg + "'> Your browser does not support HTML5 video. </video>";
            } else if (lastMsg.includes("data:text")) {
                lastMsg = "<a class='disable' href='" + lastMsg + "'>" +
                    "Text File</a>";
            } else {
                lastMsg = lastMsg.replace(/\:(.*?)\:/g, "<img src='main/resources/static/img/$1.gif' alt='$1'></img>");
            }
            lastHr = chat.getHourOfMessage(chat.getMessages().length - 1);
        }
        const newmsg = 0;
        if (newmsg === 0) {
            var html;
            var html = "<div style='cursor: pointer;' class='contact' id='chatwindow" + chatCounter + "'><img src='" + chat.photo +
                "' alt='!' onerror='this.onerror=null;this.src='http://www.philosophica.info/voces/aquino/Aquino.jpg';'><div class='contact-preview'><div class='contact-text'><h1 class='font-name'>" +
                chat.interlocutorName + "</h1><p class='font-preview' id='lastMsg" +
                chatCounter + "'>" +
                lastMsg +
                "</p></div></div><div class='contact-time'><p>" + lastHr + "</p></div></div>";
        } else {
            var html = $("<div style='cursor: pointer;' class='contact new-message-contact' id='chatwindow" +
                chatCounter + "'><img src='" + chat.photo +
                "' alt='!' onerror='this.onerror=null;this.src='http://www.philosophica.info/voces/aquino/Aquino.jpg';'><div class='contact-preview'><div class='contact-text'><h1 class='font-name'>" +
                chat.interlocutorName + "</h1><p class='font-preview' id='lastMsg" + chatCounter + "'>" +
                lastMsg +
                "</p></div></div><div class='contact-time'><p>" + "?" + "</p><div class='new-message' id='nm" +
                lastHr + "'><p>" + "1" + "</p></div></div></div>");
        }
        $(".contact-list").prepend(html);
        document.getElementById("chatwindow" + chatCounter).addEventListener("click", loadMessagesToWindow, false);
        chatCounter += 1;
    });
}
async function showChats ( ) { $ ( ".contact-list" ) . html ( "" ) ; chatCounter = 0 ; semanticChats . forEach ( async chat => { var lastMsg = chat . getLastMessage ( ) . messagetext ; var lastHr = "" ; if ( ! lastMsg ) { lastMsg = "Sin mensajes" ; } else { if ( lastMsg . includes ( "data:image" ) ) { lastMsg = "<img alt = 'uploaded' src = '" + lastMsg + "'" + "/>" ; } else if ( lastMsg . includes ( "data:video" ) ) { lastMsg = "<video width='20' height='20'> <source src= '" + lastMsg + "'> Your browser does not support HTML5 video. </video>" ; } else if ( lastMsg . includes ( "data:text" ) ) { lastMsg = "<a class='disable' href='" + lastMsg + "'>" + "Text File</a>" ; } else { lastMsg = lastMsg . replace ( / \:(.*?)\: / g , "<img src='main/resources/static/img/$1.gif' alt='$1'></img>" ) ; } lastHr = chat . getHourOfMessage ( chat . getMessages ( ) . length - 1 ) ; } const newmsg = 0 ; if ( newmsg === 0 ) { var html ; var html = "<div style='cursor: pointer;' class='contact' id='chatwindow" + chatCounter + "'><img src='" + chat . photo + "' alt='!' onerror='this.onerror=null;this.src='http://www.philosophica.info/voces/aquino/Aquino.jpg';'><div class='contact-preview'><div class='contact-text'><h1 class='font-name'>" + chat . interlocutorName + "</h1><p class='font-preview' id='lastMsg" + chatCounter + "'>" + lastMsg + "</p></div></div><div class='contact-time'><p>" + lastHr + "</p></div></div>" ; } else { var html = $ ( "<div style='cursor: pointer;' class='contact new-message-contact' id='chatwindow" + chatCounter + "'><img src='" + chat . photo + "' alt='!' onerror='this.onerror=null;this.src='http://www.philosophica.info/voces/aquino/Aquino.jpg';'><div class='contact-preview'><div class='contact-text'><h1 class='font-name'>" + chat . interlocutorName + "</h1><p class='font-preview' id='lastMsg" + chatCounter + "'>" + lastMsg + "</p></div></div><div class='contact-time'><p>" + "?" + "</p><div class='new-message' id='nm" + lastHr + "'><p>" + "1" + "</p></div></div></div>" ) ; } $ ( ".contact-list" ) . prepend ( html ) ; document . getElementById ( "chatwindow" + chatCounter ) . addEventListener ( "click" , loadMessagesToWindow , false ) ; chatCounter += 1 ; } ) ; }
Shows open chats at left panel.
Shows open chats at left panel .