src/main/ChatController.js
/**
 * Creates new message for each video sent, showing, storing and sending it.
 */
Creates new message for each video sent, showing, storing and sending it.
Creates new message for each video sent showing storing and sending it .
function videosToSend(input, userDataUrl, username, userWebId, interlocWebId, currentChat, semanticChats) {
    if (input.files) {
        var filesAmount = input.files.length;
        var i = 0;
        var index = contactsWithChat.indexOf(currentChat.interlocutorWebId.replace("Group/", ""));
        if (index == -1)
            index = contactsWithChat.indexOf(currentChat.interlocutorWebId);
        for (i = 0; i < filesAmount; i++) {
            var reader = new FileReader();
            reader.onload = async function(event) {
                var now = new Date();
                var dateFormat = require("date-fns");
                const ttime = "21" + dateFormat.format(now, "yy-MM-dd") + "T" + dateFormat.format(now, "HH-mm-ss");
                var video = "<video width='200' height='200' controls> <source src= '" + event.target.result +
                    "'> Your browser does not support HTML5 video. </video>";
                if (currentChat.interlocutorWebId.includes("Group"))
                    await messageService.storeMessage(userDataUrl, currentChat.interlocutorWebId.split("profile/").pop() + "/" + username, userWebId, ttime, event.target.result, interlocWebId, true, currentChat.members);
                else
                    await messageService.storeMessage(userDataUrl, username, userWebId, ttime, event.target.result, interlocWebId, true, null);
                $("#chatwindow" + index).remove();
                semanticChats[index].loadMessage({
                    messagetext: event.target.result,
                    url: null,
                    author: username,
                    time: ttime
                });
                $(".chat").append("<div class='chat-bubble me'><div class='my-mouth'></div><div class='content'>" + video + "</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 + "'>" + "<video width='20' height='20'> <source src= '" + event.target.result + "'> Your browser does not support HTML5 video. </video>" +
                        "</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);
                }
            }
            reader.readAsDataURL(input.files[i]);
        }
    }
}
function videosToSend ( input , userDataUrl , username , userWebId , interlocWebId , currentChat , semanticChats ) { if ( input . files ) { var filesAmount = input . files . length ; var i = 0 ; var index = contactsWithChat . indexOf ( currentChat . interlocutorWebId . replace ( "Group/" , "" ) ) ; if ( index == - 1 ) index = contactsWithChat . indexOf ( currentChat . interlocutorWebId ) ; for ( i = 0 ; i < filesAmount ; i ++ ) { var reader = new FileReader ( ) ; reader . onload = async function ( event ) { var now = new Date ( ) ; var dateFormat = require ( "date-fns" ) ; const ttime = "21" + dateFormat . format ( now , "yy-MM-dd" ) + "T" + dateFormat . format ( now , "HH-mm-ss" ) ; var video = "<video width='200' height='200' controls> <source src= '" + event . target . result + "'> Your browser does not support HTML5 video. </video>" ; if ( currentChat . interlocutorWebId . includes ( "Group" ) ) await messageService . storeMessage ( userDataUrl , currentChat . interlocutorWebId . split ( "profile/" ) . pop ( ) + "/" + username , userWebId , ttime , event . target . result , interlocWebId , true , currentChat . members ) ; else await messageService . storeMessage ( userDataUrl , username , userWebId , ttime , event . target . result , interlocWebId , true , null ) ; $ ( "#chatwindow" + index ) . remove ( ) ; semanticChats [ index ] . loadMessage ( { messagetext : event . target . result , url : null , author : username , time : ttime } ) ; $ ( ".chat" ) . append ( "<div class='chat-bubble me'><div class='my-mouth'></div><div class='content'>" + video + "</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 + "'>" + "<video width='20' height='20'> <source src= '" + event . target . result + "'> Your browser does not support HTML5 video. </video>" + "</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 ) ; } } reader . readAsDataURL ( input . files [ i ] ) ; } } }
Creates new message for each video sent, showing, storing and sending it.
Creates new message for each video sent showing storing and sending it .
/* SENDING MESSAGE */