src/main/ChatController.js
/**
 * When user presses Intro and there is text, a new message is shown and sent.
 */
When user presses Intro and there is text, a new message is shown and sent.
When user presses Intro and there is text a new message is shown and sent .
async function checkKey(e) {
    e = e || window.event;
    if (e.keyCode == "13" && $("#write-chat").val() != "") {
        const username = $("#user-name").text();
        const message = $("#write-chat").val();
        var dateFormat = require("date-fns");
        var now = new Date();
        const ttime = "21" + dateFormat.format(now, "yy-MM-dd") + "T" + dateFormat.format(now, "HH-mm-ss");
        if (currentChat.interlocutorWebId.includes("Group"))
            await messageService.storeMessage(userDataUrl, currentChat.interlocutorWebId.split("profile/").pop() + "/" + username, userWebId, ttime, message, interlocWebId, true, currentChat.members);
        else
            await messageService.storeMessage(userDataUrl, username, userWebId, ttime, message, interlocWebId, true, null);
        $("#write-chat").val("");
        var index = contactsWithChat.indexOf(currentChat.interlocutorWebId.replace("Group/", ""));
        if (index == -1)
            index = contactsWithChat.indexOf(currentChat.interlocutorWebId);
        $("#chatwindow" + index).remove();
        semanticChats[index].loadMessage({
            messagetext: message,
            url: null,
            author: username,
            time: ttime
        });
        const parsedmessage = message.replace(/\:(.*?)\:/g, "<img src='main/resources/static/img/$1.gif' alt='$1'></img>");
        $(".chat").append("<div class='chat-bubble me'><div class='my-mouth'></div><div class='content'>" +
            parsedmessage + "</div><div class='time'>" +
            ttime.substring(11, 16).replace("\-", "\:") + "</div></div>");
        toScrollDown();
        if (!showingContacts) {
            var html = "<div style='cursor: pointer;' class='contact' id='chatwindow" + index + "'><img src='" + semanticChats[index].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'>" + semanticChats[index].interlocutorName +
                "</h1><p class='font-preview' id='lastMsg" + index + "'>" +
                parsedmessage + "</p></div></div><div class='contact-time'><p>" +
                semanticChats[index].getHourOfMessage(semanticChats[index].getNumberOfMsgs() - 1); +
            "</p></div></div>";
            $(".contact-list").prepend(html);
            document.getElementById("chatwindow" + index).addEventListener("click", loadMessagesToWindow, false);
        }
    }
}
async function checkKey ( e ) { e = e || window . event ; if ( e . keyCode == "13" && $ ( "#write-chat" ) . val ( ) != "" ) { const username = $ ( "#user-name" ) . text ( ) ; const message = $ ( "#write-chat" ) . val ( ) ; var dateFormat = require ( "date-fns" ) ; var now = new Date ( ) ; const ttime = "21" + dateFormat . format ( now , "yy-MM-dd" ) + "T" + dateFormat . format ( now , "HH-mm-ss" ) ; if ( currentChat . interlocutorWebId . includes ( "Group" ) ) await messageService . storeMessage ( userDataUrl , currentChat . interlocutorWebId . split ( "profile/" ) . pop ( ) + "/" + username , userWebId , ttime , message , interlocWebId , true , currentChat . members ) ; else await messageService . storeMessage ( userDataUrl , username , userWebId , ttime , message , interlocWebId , true , null ) ; $ ( "#write-chat" ) . val ( "" ) ; var index = contactsWithChat . indexOf ( currentChat . interlocutorWebId . replace ( "Group/" , "" ) ) ; if ( index == - 1 ) index = contactsWithChat . indexOf ( currentChat . interlocutorWebId ) ; $ ( "#chatwindow" + index ) . remove ( ) ; semanticChats [ index ] . loadMessage ( { messagetext : message , url : null , author : username , time : ttime } ) ; const parsedmessage = message . replace ( / \:(.*?)\: / g , "<img src='main/resources/static/img/$1.gif' alt='$1'></img>" ) ; $ ( ".chat" ) . append ( "<div class='chat-bubble me'><div class='my-mouth'></div><div class='content'>" + parsedmessage + "</div><div class='time'>" + ttime . substring ( 11 , 16 ) . replace ( "\-" , "\:" ) + "</div></div>" ) ; toScrollDown ( ) ; if ( ! showingContacts ) { var html = "<div style='cursor: pointer;' class='contact' id='chatwindow" + index + "'><img src='" + semanticChats [ index ] . 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'>" + semanticChats [ index ] . interlocutorName + "</h1><p class='font-preview' id='lastMsg" + index + "'>" + parsedmessage + "</p></div></div><div class='contact-time'><p>" + semanticChats [ index ] . getHourOfMessage ( semanticChats [ index ] . getNumberOfMsgs ( ) - 1 ) ; + "</p></div></div>" ; $ ( ".contact-list" ) . prepend ( html ) ; document . getElementById ( "chatwindow" + index ) . addEventListener ( "click" , loadMessagesToWindow , false ) ; } } }
When user presses Intro and there is text, a new message is shown and sent.
When user presses Intro and there is text a new message is shown and sent .