src/main/ChatController.js
/**
 * If user has a chat already with selected contact, such chat is opened.
 * If not, a new chat is created with said contact.
 */
If user has a chat already with selected contact, such chat is opened.
If not, a new chat is created with said contact.
If user has a chat already with selected contact such chat is opened . If not a new chat is created with said contact .
async function openContact() {
    $(".chat").html("");
    var intWebId = this.getAttribute("id").replace("openchatwindow", "");
    var index = contactsWithChat.indexOf(intWebId);
    if (index != -1) {
        loadMessages(index);
    } else {
        const dataUrl = baseService.getDefaultDataUrl(userWebId);
        if (await baseService.writePermission(dataUrl)) {
            interlocWebId = intWebId;
            userDataUrl = dataUrl;
            var semanticChat = await createService.setUpNewChat(userDataUrl, userWebId, interlocWebId);
            const friendName = await baseService.getFormattedName(interlocWebId);
            var friendPhoto = await baseService.getPhoto(interlocWebId);
            if (!friendPhoto) {
                friendPhoto = baseService.getDefaultFriendPhoto();
            }
            semanticChat.interlocutorName = friendName;
            semanticChat.photo = friendPhoto;
            semanticChats.push(semanticChat);
            index = semanticChats.indexOf(semanticChat);
            contactsWithChat.splice(index, 0, intWebId);
            loadMessages(index);
        } else {
            $("#write-permission-url").text(dataUrl);
            $("#write-permission").modal("show");
        }
    }
}
async function openContact ( ) { $ ( ".chat" ) . html ( "" ) ; var intWebId = this . getAttribute ( "id" ) . replace ( "openchatwindow" , "" ) ; var index = contactsWithChat . indexOf ( intWebId ) ; if ( index != - 1 ) { loadMessages ( index ) ; } else { const dataUrl = baseService . getDefaultDataUrl ( userWebId ) ; if ( await baseService . writePermission ( dataUrl ) ) { interlocWebId = intWebId ; userDataUrl = dataUrl ; var semanticChat = await createService . setUpNewChat ( userDataUrl , userWebId , interlocWebId ) ; const friendName = await baseService . getFormattedName ( interlocWebId ) ; var friendPhoto = await baseService . getPhoto ( interlocWebId ) ; if ( ! friendPhoto ) { friendPhoto = baseService . getDefaultFriendPhoto ( ) ; } semanticChat . interlocutorName = friendName ; semanticChat . photo = friendPhoto ; semanticChats . push ( semanticChat ) ; index = semanticChats . indexOf ( semanticChat ) ; contactsWithChat . splice ( index , 0 , intWebId ) ; loadMessages ( index ) ; } else { $ ( "#write-permission-url" ) . text ( dataUrl ) ; $ ( "#write-permission" ) . modal ( "show" ) ; } } }
If user has a chat already with selected contact, such chat is opened.
If user has a chat already with selected contact such chat is opened .