src/main/ChatController.js
/**
 * Shows and stores those messages received whose chat is being displayed.
 */
Shows and stores those messages received whose chat is being displayed.
Shows and stores those messages received whose chat is being displayed .
async function showAndStoreMessages() {
    var i = 0;
    while (i < interlocutorMessages.length) {
        var nameThroughUrl;
        console.log(interlocutorMessages[i].author);
        if (!interlocutorMessages[i].author.includes("Group"))
            nameThroughUrl = interlocutorMessages[i].author.split("/").pop();
        else
            nameThroughUrl = interlocutorMessages[i].author.split("/")[1];
        if (nameThroughUrl === $("#interlocutorw-name").text()) {
            showMessage(interlocutorMessages[i]);
            await messageService.storeMessage(userDataUrl, interlocutorMessages[i].author.split("/").pop(), userWebId, interlocutorMessages[i].time, interlocutorMessages[i].messagetext, interlocWebId, false);
            var index = contactsWithChat.indexOf(interlocWebId);
            if (index == -1)
                index = contactsWithChat.indexOf(interlocWebId.replace("Group/", ""));
            semanticChats[index].loadMessage({
                messagetext: interlocutorMessages[i].messagetext,
                url: null,
                author: interlocutorMessages[i].author.split("/").pop(),
                time: interlocutorMessages[i].time
            });
            baseService.deleteFileForUser(interlocutorMessages[i].inboxUrl);
            $("#chatwindow" + index).remove();
            var msgToShow;
            if (interlocutorMessages[i].messagetext.includes("data:image")) {
                msgToShow = "<img alt = 'uploaded' src = '" + interlocutorMessages[i].messagetext + "'" + "/>";
            } else if (interlocutorMessages[i].messagetext.includes("data:video")) {
                msgToShow = "<video controls> <source src= '" + interlocutorMessages[i].messagetext + "'> Your browser does not support HTML5 video. </video>";
            } else if (interlocutorMessages[i].messagetext.includes("data:text")) {
                msgToShow = "<a class='disable' href='" + interlocutorMessages[i].messagetext + "'>" + "Click to view text file</a>";
            } else {
                msgToShow = interlocutorMessages[i].messagetext.replace(/\:(.*?)\:/g, "<img src='main/resources/static/img/$1.gif' alt='$1'></img>");
            }
            const parsedmessage = msgToShow;
            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].numberOfMessages - 1) + "</p></div></div>";
            $(".contact-list").prepend(html);
            document.getElementById("chatwindow" + index).addEventListener("click", loadMessagesToWindow, false);
            interlocutorMessages[i] = "D";
        }
        i++;
    }
    i = interlocutorMessages.length;
    while (i--) {
        if (interlocutorMessages[i] == "D") {
            interlocutorMessages.splice(i, 1);
        }
    }
}
async function showAndStoreMessages ( ) { var i = 0 ; while ( i < interlocutorMessages . length ) { var nameThroughUrl ; console . log ( interlocutorMessages [ i ] . author ) ; if ( ! interlocutorMessages [ i ] . author . includes ( "Group" ) ) nameThroughUrl = interlocutorMessages [ i ] . author . split ( "/" ) . pop ( ) ; else nameThroughUrl = interlocutorMessages [ i ] . author . split ( "/" ) [ 1 ] ; if ( nameThroughUrl === $ ( "#interlocutorw-name" ) . text ( ) ) { showMessage ( interlocutorMessages [ i ] ) ; await messageService . storeMessage ( userDataUrl , interlocutorMessages [ i ] . author . split ( "/" ) . pop ( ) , userWebId , interlocutorMessages [ i ] . time , interlocutorMessages [ i ] . messagetext , interlocWebId , false ) ; var index = contactsWithChat . indexOf ( interlocWebId ) ; if ( index == - 1 ) index = contactsWithChat . indexOf ( interlocWebId . replace ( "Group/" , "" ) ) ; semanticChats [ index ] . loadMessage ( { messagetext : interlocutorMessages [ i ] . messagetext , url : null , author : interlocutorMessages [ i ] . author . split ( "/" ) . pop ( ) , time : interlocutorMessages [ i ] . time } ) ; baseService . deleteFileForUser ( interlocutorMessages [ i ] . inboxUrl ) ; $ ( "#chatwindow" + index ) . remove ( ) ; var msgToShow ; if ( interlocutorMessages [ i ] . messagetext . includes ( "data:image" ) ) { msgToShow = "<img alt = 'uploaded' src = '" + interlocutorMessages [ i ] . messagetext + "'" + "/>" ; } else if ( interlocutorMessages [ i ] . messagetext . includes ( "data:video" ) ) { msgToShow = "<video controls> <source src= '" + interlocutorMessages [ i ] . messagetext + "'> Your browser does not support HTML5 video. </video>" ; } else if ( interlocutorMessages [ i ] . messagetext . includes ( "data:text" ) ) { msgToShow = "<a class='disable' href='" + interlocutorMessages [ i ] . messagetext + "'>" + "Click to view text file</a>" ; } else { msgToShow = interlocutorMessages [ i ] . messagetext . replace ( / \:(.*?)\: / g , "<img src='main/resources/static/img/$1.gif' alt='$1'></img>" ) ; } const parsedmessage = msgToShow ; 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 ] . numberOfMessages - 1 ) + "</p></div></div>" ; $ ( ".contact-list" ) . prepend ( html ) ; document . getElementById ( "chatwindow" + index ) . addEventListener ( "click" , loadMessagesToWindow , false ) ; interlocutorMessages [ i ] = "D" ; } i ++ ; } i = interlocutorMessages . length ; while ( i -- ) { if ( interlocutorMessages [ i ] == "D" ) { interlocutorMessages . splice ( i , 1 ) ; } } }
Shows and stores those messages received whose chat is being displayed.
Shows and stores those messages received whose chat is being displayed .
/* After processing it, we mark it for Deletion. */