src/main/ChatController.js
/**
 * Displays a certain message in main panel.
 * If author is current user, it is displayed to the right.
 * If author is anyone else, it is displayed to the left.
 * May be displayed as an image, video or document according to format.
 */
Displays a certain message in main panel.
If author is current user, it is displayed to the right.
If author is anyone else, it is displayed to the left.
May be displayed as an image, video or document according to format.
Displays a certain message in main panel . If author is current user it is displayed to the right . If author is anyone else it is displayed to the left . May be displayed as an image video or document according to format .
function showMessage(message) {
    var msgToBeShown;
    if (message.messagetext.includes("data:image")) {
        msgToBeShown = "<img alt = 'uploaded' style='height:200px; width:200px;' src = '" + message.messagetext + "' />";
    } else if (message.messagetext.includes("data:video")) {
        msgToBeShown = "<video width='200' height='200' controls> <source src= '" +
            message.messagetext + "'> Your browser does not support HTML5 video. </video>";
    } else if (message.messagetext.includes("data:text")) {
        msgToBeShown = "<a target='_blank' href='" + message.messagetext +
            "' style='padding: 10px;margin : 5px;background-color: darkgrey;color : white;  border-radius: 15px;' >" +
            "Click to view text file</a>";
    } else {
        msgToBeShown = message.messagetext.replace(/\:(.*?)\:/g, "<img src='main/resources/static/img/$1.gif' alt='$1'></img>");
    }
    if (message.author.split("/").pop().replace(/U\+0020/g, " ") === $("#user-name").text()) {
        $(".chat").append("<div class='chat-bubble me'><div class='my-mouth'></div><div class='content'>" +
            msgToBeShown + "</div><div class='time'>" +
            message.time.substring(11, 16).replace("\-", "\:") + "</div></div>");
    } else {
        if (currentChat.interlocutorWebId.includes("Group")) {
            $(".chat").append("<div class='chat-bubble you'><div class='your-mouth'></div><h4>" +
                message.author.split("/").pop().replace(/U\+0020/g, " ") + "</h4><div class='content'>" +
                msgToBeShown + "</div><div class='time'>" +
                message.time.substring(11, 16).replace("\-", "\:") + "</div></div>");
        } else {
            $(".chat").append("<div class='chat-bubble you'><div class='your-mouth'></div><div class='content'>" +
                msgToBeShown + "</div><div class='time'>" +
                message.time.substring(11, 16).replace("\-", "\:") + "</div></div>");
        }
    }
    $(".fa fa-bars fa-lg").removeClass("hidden");
    toScrollDown();
}
function showMessage ( message ) { var msgToBeShown ; if ( message . messagetext . includes ( "data:image" ) ) { msgToBeShown = "<img alt = 'uploaded' style='height:200px; width:200px;' src = '" + message . messagetext + "' />" ; } else if ( message . messagetext . includes ( "data:video" ) ) { msgToBeShown = "<video width='200' height='200' controls> <source src= '" + message . messagetext + "'> Your browser does not support HTML5 video. </video>" ; } else if ( message . messagetext . includes ( "data:text" ) ) { msgToBeShown = "<a target='_blank' href='" + message . messagetext + "' style='padding: 10px;margin : 5px;background-color: darkgrey;color : white;  border-radius: 15px;' >" + "Click to view text file</a>" ; } else { msgToBeShown = message . messagetext . replace ( / \:(.*?)\: / g , "<img src='main/resources/static/img/$1.gif' alt='$1'></img>" ) ; } if ( message . author . split ( "/" ) . pop ( ) . replace ( / U\+0020 / g , " " ) === $ ( "#user-name" ) . text ( ) ) { $ ( ".chat" ) . append ( "<div class='chat-bubble me'><div class='my-mouth'></div><div class='content'>" + msgToBeShown + "</div><div class='time'>" + message . time . substring ( 11 , 16 ) . replace ( "\-" , "\:" ) + "</div></div>" ) ; } else { if ( currentChat . interlocutorWebId . includes ( "Group" ) ) { $ ( ".chat" ) . append ( "<div class='chat-bubble you'><div class='your-mouth'></div><h4>" + message . author . split ( "/" ) . pop ( ) . replace ( / U\+0020 / g , " " ) + "</h4><div class='content'>" + msgToBeShown + "</div><div class='time'>" + message . time . substring ( 11 , 16 ) . replace ( "\-" , "\:" ) + "</div></div>" ) ; } else { $ ( ".chat" ) . append ( "<div class='chat-bubble you'><div class='your-mouth'></div><div class='content'>" + msgToBeShown + "</div><div class='time'>" + message . time . substring ( 11 , 16 ) . replace ( "\-" , "\:" ) + "</div></div>" ) ; } } $ ( ".fa fa-bars fa-lg" ) . removeClass ( "hidden" ) ; toScrollDown ( ) ; }
Displays a certain message in main panel.
Displays a certain message in main panel .