chat.js 23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// 名前空間
var CHAT = {};
// test comment
//招待するメンバーを保存する変数
CHAT.globalSelectedUserList = new Array();
CHAT.globalIsInvite = false;

//ログイン中の部屋情報を保存する変数
CHAT.globalLoginParameter;

Lee Munkyeong committed
11 12 13
// fermi coview share
let globalUserInfo = new Object();

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
CHAT.saveRoomInfo = function(roomId, roomName) {
    CHAT.globalLoginParameter.roomId = roomId;
    CHAT.globalLoginParameter.roomName = roomName;
    if (CHAT_UTIL.isIOS()) {
        webkit.messageHandlers.roomInfosaveMessageHandlerId.postMessage({"roomId":roomId, "roomName":roomName});
    } else if (CHAT_UTIL.isAndroid()) {
        if (roomId == undefined && roomName == undefined) {
            android.saveVisitRoomInfo('', '');
        } else {
            android.saveVisitRoomInfo(roomId, roomName);
        }
    }
}

// #36170 画像パスが存在しない場合はデフォルトの画像を返す
// 存在する場合はプロフィール画像取得用APIのURLを生成して返す
CHAT.getProfileImgUrl = function(path) {
    if (path == undefined || path == "") {
        return ASSET_PATH + 'img/noImage.png';
    } else {
Lee Munkyeong committed
34 35 36 37 38 39
        if (path.includes('/mnt')) {
            var userInfo = path.split("/").reverse();
            return CMS_SERVER_URL + '/chatapi/user?profileFileName=' + userInfo[0] + '&profileGetLoginId=' + userInfo[1] + '&sid=' + CHAT.globalLoginParameter.sid + '&cmd=12';
        } else {
            return path;
        }
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    }
}

// Video のサムネイルファイル生成する
CHAT.createVideoThumbnailAndUpload = function(sourceImage, callback) {
    var fileReader = new FileReader();

    fileReader.onload = function() {
        var blob = new Blob([fileReader.result], {type: sourceImage.type});
        var url = URL.createObjectURL(blob);
        var video = document.createElement('video');
        var timeupdate = function() {
            if (snapImage()) {
                video.removeEventListener('timeupdate', timeupdate);
                video.pause();
            }
        };
        video.addEventListener('loadeddata', function() {
            if (snapImage()) {
                video.removeEventListener('timeupdate', timeupdate);
            }
        });
        var snapImage = function() {
            var canvas = document.createElement('canvas');
            canvas.width = video.videoWidth;
            canvas.height = video.videoHeight;
            canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);

            fetch(canvas.toDataURL("image/jpeg"))
                .then(function(res) {
                    return res.arrayBuffer();
                })
                .then(function(buf) {
                    // 回転された画像をFormDataに保存
                    const newFile = new File([buf], sourceImage.name, {type:"image/jpeg"});
                    callback(newFile, true);
                    // ajax End
                }).catch((error) => { // fetch Error catch Block
                        if (error) {
                            console.log(error)
                        }
                });
            return true;
        };
        video.addEventListener('timeupdate', timeupdate);
        video.preload = 'metadata';
        video.src = url;
        // Load video in Safari / IE11
        video.muted = true;
        video.playsInline = true;
90
        video.pause();
91 92 93 94 95 96 97
    };
    fileReader.readAsArrayBuffer(sourceImage);
}

// Ajaxでイメージをアップロードする
CHAT.uploadImage = function(formData) {
    formData.append('roomId', CHAT.globalLoginParameter.roomId);
Lee Munkyeong committed
98
    formData.append('sid', CHAT.globalLoginParameter.sid);
99 100
    jQuery.ajax({
        async: true,
Lee Munkyeong committed
101
        url:    CMS_SERVER_URL+"/chatapi/file/upload",
102 103 104
        type: "post",
        data: formData,
        contentType: false,
105 106 107 108 109
        processData: false,
        error: function () {
            alert("読み込み失敗");
            CHAT_UI.dismissLoadingIndicator();
        }
110
    }).done(function(res) {
Lee Munkyeong committed
111
        var imgPath = CMS_SERVER_URL + '/chatapi/file/getImage?fileName=' + res.fileName + '&roomId=' + CHAT.globalLoginParameter.roomId;
112 113 114 115 116 117 118 119
        var imageName = res.fileName

        // uploadFileの判断
        var extension = imageName.substr(imageName.lastIndexOf('.') + 1).toLowerCase();

        // 画像の処理
        if (res.fileType == "jpeg" || res.fileType == "jpg" || res.fileType == "png") {
            if (res.thumbnailPath && res.thumbnailPath.length > 0) {
Lee Munkyeong committed
120
                imgPath = CMS_SERVER_URL + '/chatapi/file/getImage?fileName=' + res.thumbImageFileName + '&roomId=' + CHAT.globalLoginParameter.roomId;
121 122
                imageName = res.thumbImageFileName;
            }
Lee Munkyeong committed
123
            let downloadPath = CMS_SERVER_URL + '/chatapi/file/download?fileName=' + imageName + '&roomId=' + CHAT.globalLoginParameter.roomId;
124
            // アップロードが終了した後ローディング画面から離れてメッセージをメッセージを転送する
Lee Daehyun committed
125
            const lightbox = $('<a/>', {'data-lightbox':'attachedImages', 'data-title':imageName});
126
            const image = $('<img/>', {src:imgPath, width:'auto', style:'max-width:100%', 'data-toggle':'modal', onclick:'imageModal(this);'});
Lee Daehyun committed
127
            const downloadIcon = $('<a/>', {href:downloadPath, class:'fa fa-download', download:res.fileName});
128 129 130 131 132 133 134 135 136 137 138 139

            lightbox.append(image);
            lightbox.append(downloadIcon);
            let text = lightbox.prop('outerHTML')
            let encodedText
            try {
                encodedText = encodeURIComponent(text)
            } catch(e) {
                encodedText = text;
            }

            socket.emit('createMessage', {
Lee Munkyeong committed
140
                text: encodedText + messageSeperator + messageType.IMAGE
141 142 143 144
            }, 1);

        } else {    // 動画の処理
            if (res.thumbnailPath && res.thumbnailPath.length > 0) {
Lee Munkyeong committed
145
                imgPath = CMS_SERVER_URL + '/chatapi/file/getImage?fileName=' + res.thumbImageFileName + '&roomId=' + CHAT.globalLoginParameter.roomId;
146 147
            }

Lee Munkyeong committed
148
            let downloadPath = CMS_SERVER_URL + '/chatapi/file/download?fileName=' + imageName + '&roomId=' + CHAT.globalLoginParameter.roomId;
149 150 151 152 153

            var videoSrc = CMS_SERVER_URL + '/chatapi/file/getImage?fileName=' + res.fileName + '&roomId=' + CHAT.globalLoginParameter.roomId;
            const totalDiv = $('<div/>', {id:"attachedImages"});
            const videoTag = $('<video/>', {controls:"true", width:'auto', style:'max-width:100%'});
            const source = $('<source/>', {src:videoSrc});
154 155
            const downloadIcon = $('<a/>',{href:downloadPath, class:'fa fa-download', download:res.fileName});

156 157 158
            videoTag.append(source);
            totalDiv.append(videoTag);
            totalDiv.append(downloadIcon);
159

160
            let text = totalDiv.prop('outerHTML');
161 162 163 164 165 166 167 168
            let encodedText
            try {
                encodedText = encodeURIComponent(text)
            } catch(e) {
                encodedText = text;
            }

            socket.emit('createMessage', {
Lee Munkyeong committed
169
                text: encodedText + messageSeperator + messageType.VIDEO
170 171 172 173 174 175 176 177 178
            }, 1);
        }

        $('.overlay').removeClass('active undismissable');
        $('.loader').removeClass('active');
        CHAT_UI.dismissLoadingIndicator();
    })
}

179
CHAT.createGetDataUrl = function(fileName, roomId) {
Lee Munkyeong committed
180
    var filePath = CMS_SERVER_URL + '/chatapi/file/getImage?sid=' + CHAT.globalLoginParameter.sid + '&fileName=' + fileName + '&roomId=' + roomId;
181 182
    return filePath;
}
Lee Munkyeong committed
183

184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
// Thumbnailのファイルを生成する。
CHAT.createThumbnailAndUpload = function(sourceImage, callback) {
    const fileReader = new FileReader();
    const img = new Image();
    fileReader.onloadend = function() {
            img.src = fileReader.result
    }

    img.onload = function() {
        const elem = document.createElement('canvas');
        var rate
        var width = img.width
        var height = img.height
        if ((img.width <= 500) && (img.height <= 500))
        {
            callback(undefined, false)
            return
        }

        if (img.width > img.height)
        {
            rate = 500/img.width
        } else {
            rate = 500/img.height
        }
        elem.width = width * rate;
        elem.height = height * rate;

        const ctx = elem.getContext('2d')

        ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, elem.width, elem.height);
        // ctx.drawImage(img, 0, 0, width, height);

        fetch(elem.toDataURL("image/jpeg"))
        .then(function(res) {
            return res.arrayBuffer();
        })
        .then(function(buf) {
            const newFile = new File([buf], sourceImage.name, {type:"image/jpeg"});

            callback(newFile, true)

        }).catch((error) => { // fetch Error catch Block
                if (error) {
                    console.log(error)
                }
        });
    }

    fileReader.readAsDataURL(sourceImage);
}

// 該当チャットルームに参加するためログイン情報をサーバに渡す
Lee Munkyeong committed
237
getLoginParameter = function(sid, loginId, shopName, roomId = undefined, roomName = undefined, languageCode, shopMemberId) {
238 239 240 241 242 243
    var loginParam = new Object()
    loginParam.sid = sid;
    loginParam.loginId = loginId;
    loginParam.shopName = shopName;
    loginParam.roomId = roomId;
    loginParam.roomName = roomName;
Lee Munkyeong committed
244
    loginParam.shopMemberId = shopMemberId;
245 246 247 248 249 250

    CHAT.globalLoginParameter = loginParam;

    if (!languageCode) {
        languageCode = "en"
    }
Lee Munkyeong committed
251 252 253 254 255 256 257 258 259

    // fermi coview share
    globalUserInfo.sid = sid;
    globalUserInfo.loginId = loginId;
    globalUserInfo.shopName = shopName;
    globalUserInfo.roomId = roomId;
    globalUserInfo.roomName = roomName;
    globalUserInfo.languageCode = languageCode;

Lee Munkyeong committed
260
    CHAT_UI.htmlElementTextInitialize(languageCode);
Lee Munkyeong committed
261
    CHAT_UI.dismissLoadingIndicator();
262 263 264 265 266 267 268
}

CHAT.leaveRoom = function() {
    socket.emit('leaveRoom', function() {
    });
}

藤川諒 committed
269
$(function() {
Lee Munkyeong committed
270 271 272 273 274 275 276 277
    // ルーム名変更イベント
    $('.change_room_name_btn button').click(function(){
        $('form').submit();
    });

    // 検索アイコン押下イベント
    $('.nav_item_wrap .search_menu').click(function(){
        $('.nav_item_wrap').addClass('none');
278
        $('.footer-wrap').addClass('none');
Lee Munkyeong committed
279 280 281 282 283 284
        $('.chat_room_src_form').removeClass('none');
        $('.room_container').addClass('none');
        $('.overlay_src_msg').removeClass('none');
        // フィルタ表示
        $('#filter').removeClass('none');
        $('#user_list').addClass('none');
285 286 287

        $('.chat_room_src_form input[type="search"]').focus();
        $('#searchMessage').addClass('onfocus');
288
        $('.chat_list').removeClass('none');
Lee Munkyeong committed
289 290 291
    });
    $('.chat_room_src_form .cancel').click(function(){
        $('.nav_item_wrap').removeClass('none');
292
        $('.footer-wrap').removeClass('none');
Lee Munkyeong committed
293 294 295 296 297 298 299
        $('.chat_room_src_form').addClass('none');
        $('.chat_room_src_form input').val('');
        $('.room_container').removeClass('none');
        $('.overlay_src_msg').empty();
        // ユーザーリスト表示
        $('#filter').addClass('none');
        $('#user_list').removeClass('none');
300 301 302

        $('.chat_room_src_form input[type="search"]').blur();
        $('#searchMessage').removeClass('onfocus');
303
        $('.chat_list').addClass('none');
304
        CHAT_UI.scrollToBottom();
Lee Munkyeong committed
305 306
    });

307 308 309 310 311 312 313 314 315 316 317 318 319 320
    $('.chat_room_src_form input[type="search"]').click(function() {
        if($('#searchMessage').hasClass('onfocus')) {
            $('#searchMessage').removeClass('onfocus');
            $('#searchMessage').blur();
        } else {
            $('#searchMessage').addClass('onfocus');
            $('#searchMessage').focus();
        }
    })

    $('#searchMessage').blur(function() {
        $('#searchMessage').removeClass('onfocus');
    })

Lee Munkyeong committed
321
    // フィルタ選択イベント
322
    $(document).on('click', '#filter .img_wrap', function(event) {
Lee Munkyeong committed
323 324 325 326 327 328 329 330 331 332 333 334 335 336
        // チェックアイコン追加
        $(this).toggleClass("filter");
    });

    $('#chat .search_form input[type="search"]').click(function(){
        let roomListTitle = getLocalizedString("room_search_placeholder");
        $('#chatTitle').text(roomListTitle);
    });

    $('#chat .search_form .cancel').click(function(){
        let roomListTitle = getLocalizedString("roomListTitle");
        $('#chatTitle').text(roomListTitle);
    });

337 338
    $('#chat_add_user .search_form .cancel').click(function() {
        let roomListTitle = getLocalizedString("inviteUsersSubtitle");
Kang Donghun committed
339
        $('#addUserTitle').text(roomListTitle);
340 341 342 343
    });

    $('#chatMakeRoom .search_form .cancel').click(function() {
        let roomListTitle = getLocalizedString("createRoomTitle");
Kang Donghun committed
344
        $('#makeRoomTitle').text(roomListTitle);
Lee Munkyeong committed
345 346
    });

Lee Munkyeong committed
347
    // チャットメンバー検索
Lee Munkyeong committed
348
    $('#chat .search_form input[type="search"]').keyup(function(e){
Lee Munkyeong committed
349 350 351 352 353 354 355 356 357 358
        var rooms;
        var keyword = $('#chat .search_form input[type="search"]').val();
        if (e.KeyCode == 13 || e.key == "Enter") {
            if (keyword.length != 0 && keyword != '') {
                $('#chat .search_form input[type="search"]').blur();
                return;
            }
        } else if (keyword == '' || keyword.length < 2) {
            $('.overlay_src_msg').empty();
            return;
Lee Munkyeong committed
359
        }
360
        CHAT.searchRoom(keyword, rooms);
Lee Munkyeong committed
361 362 363 364
        if (e.KeyCode == 13 || e.key == "Enter") {
            $('#chat .search_form input[type="search"]').blur();
            return ;
        }
365
    });
366 367 368 369 370 371 372 373
    // iOSキーボード変換検知用
    $('#chat .search_form input[type="search"]').on('compositionend', function(){
        if (CHAT_UTIL.isIOS()) {
            var rooms;
            var keyword = $('#chat .search_form input[type="search"]').val();
            CHAT.searchRoom(keyword, rooms);
        }
    });
藤川諒 committed
374

Lee Munkyeong committed
375 376
    var beforeHeight;
    var beforeScroll;
377
    var footerHeight = $('.footer-wrap').height();
Lee Munkyeong committed
378
    window.addEventListener("resize", function() {
379
        console.log('aaaa');
Lee Munkyeong committed
380 381 382 383 384 385 386 387 388
        var afterHeight = window.innerHeight;
        if (beforeHeight > afterHeight) {
            //キーボード表示時
            var moreScroll = beforeHeight - afterHeight;
            $('.room_container').css('margin-bottom', 0);
            window.scrollTo(0, beforeScroll + moreScroll - $('.footer_content_b').height());

        } else {
            //キーボード非表示
389
            $('.room_container').css('margin-bottom', footerHeight);
Lee Munkyeong committed
390 391 392 393 394 395 396
            window.scrollTo(0, beforeScroll);
        }
    });
    $('#messageInput').focusin(function(e) {
        beforeHeight = window.innerHeight;
        beforeScroll = window.scrollY;
    })
Lee Munkyeong committed
397 398 399

    // チャットルーム
    // メッセージ検索イベント
Lee Munkyeong committed
400
    $('.chat_room_src_form input[type="search"]').keyup(function(e){
401
        let workVal = "";
Lee Munkyeong committed
402
        var keyword = $('.chat_room_src_form input[type="search"]').val();
Lee Munkyeong committed
403
        if (e.key == "Enter" || e.KeyCode == 13) {
Lee Munkyeong committed
404 405 406 407 408 409 410
            if (keyword != '' && keyword.length != 0) {
                $('.chat_room_src_form input[type="search"]').blur();
                return;
            }
        } else if (keyword == '' || keyword.length < 2) {
            $('.overlay_src_msg').empty();
            return;
Lee Munkyeong committed
411
        }
412 413
        
        CHAT.searchMessage(keyword, workVal);
Lee Munkyeong committed
414
        if (e.key == "Enter" || e.KeyCode == 13) {
415
            $('#searchMessage').removeClass('onfocus');
Lee Munkyeong committed
416
            $('.chat_room_src_form input[type="search"]').blur();
Lee Munkyeong committed
417 418
            return;
        }
Lee Munkyeong committed
419
    });
420 421 422 423 424 425 426 427
    // iOSキーボード変換検知用
    $('.chat_room_src_form input[type="search"]').on('compositionend', function(){
        if (CHAT_UTIL.isIOS()) {
            let workVal = "";
            var keyword = $('.chat_room_src_form input[type="search"]').val();
            CHAT.searchMessage(keyword, workVal);
        }
    });
Lee Munkyeong committed
428

429
    $(document).on('click', '.filter_img', function(event) {
Lee Munkyeong committed
430 431 432 433 434 435 436 437
        let workVal = "";
        var keyword = $('.chat_room_src_form input[type="search"]').val();
        $('.overlay_src_msg').empty();
        var checkedUserList = [];
        $('.img_wrap.filter').each(function(user) {
            var selectedUser = $('.img_wrap.filter')[user];
            checkedUserList.push($(selectedUser).data('user-id'));
        })
Lee Munkyeong committed
438
        if (keyword.length == 1) { return; }
Lee Munkyeong committed
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
        var messages = CHAT_DB.searchMessages(keyword, checkedUserList.join(','));
        var userMessageTemplate;
        $.get({ url: "./template/template_user_message.html", async: false }
          , function(text) {
            userMessageTemplate = text;
        });
        var myMessageTemplate;
        $.get({ url: "./template/template_my_message.html", async: false }
          , function(text) {
            myMessageTemplate = text;
        });

        let jQueryMessages = $('.overlay_src_msg');
        messages.forEach(function(message) {
            let template = userMessageTemplate;
            if (message.shopMemberId == CHAT.globalLoginParameter.shopMemberId) {
                 template = myMessageTemplate;
            }
            if (message.messageType == messageType.SYSTEM) {
                template = systemMessageTemplate;
            }
            let messageTime = CHAT_UTIL.formatDate(message.insertDate);
            // ユーザの様式を読み込む

            if (message.profileUrl) {
                message.profileUrl = CHAT.getProfileImgUrl(message.profileUrl)
            } else {
                message.profileUrl = CHAT.getProfileImgUrl("")
            }
             message.message = message.message.toString();
             var replacePath = message.message;
             replacePath = replacePath.replaceAll('?fileName=', '?sid=' + CHAT.globalLoginParameter.sid + '&fileName=');
             message.message = replacePath;

             let html = Mustache.render(template, {
                 text: message.message,
                 from: message.loginId,
                 shopMemberId: message.shopMemberId,
                 profileImage: message.profileUrl,
                 createdAtDay: messageTime.createdAtDay,
                 createdAtTime: messageTime.createdAtTime
             });
             html = message.message.includes('attachedImages') || message.message.includes('attachedVideos') ? CHAT_UTIL.htmlDecode(html) : html;
             workVal = html + workVal;
        })
        jQueryMessages.prepend(workVal);
    });
藤川諒 committed
486
});
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509

// チャットルーム検索
CHAT.searchRoom = function(keyword, rooms) {
    $('.overlay_src_msg').empty();
    rooms = CHAT_DB.getRoomList(chatRoomType.ALL, keyword);
    let roomListTitle = getLocalizedString("room_search_placeholder");
    $('#chatTitle').text(roomListTitle);
    var template;
    $.get({ url: "./template/template_room_list.html", async: false }
        , function(text) {
            template = text;
    });
    rooms.forEach(function(room) {
        room.profileImagePath = ASSET_PATH + 'images/user-profile.png'
        if (room.message) {
            room.message = room.message.toString()
        } else {
            room.message = getLocalizedString("noMessages")
        }
        var displayMsg;
        if (room.messageType == messageType.TEXT || room.messageType == messageType.SYSTEM) displayMsg = room.message;
        if (room.messageType == messageType.IMAGE) displayMsg = getLocalizedString("image");
        if (room.messageType == messageType.VIDEO) displayMsg = getLocalizedString("video");
Lee Munkyeong committed
510 511 512
        if (room.messageType == messageType.TEXT) displayMsg = room.message;
        if (room.messageType == messageType.COMMUNICATIONSTART) displayMsg = getLocalizedString("collaboration_start");
        if (room.messageType == messageType.COMMUNICATIONEND) displayMsg = getLocalizedString("collaboration_end");
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
        var attendUserName = [];
        room.attendUsers.forEach(function(user) {
            user.profileUrl = CHAT.getProfileImgUrl(user.profileUrl);
            attendUserName.push(user.shopMemberName);
        });
        var thumbnailCount = room.attendUsers.length > 4 ? 4 : room.attendUsers.length;
        if (room.chatRoomName == "") {
            room.chatRoomName = attendUserName.join(', ');
        }
        let html = Mustache.render(template, {
            thumbnailCount: thumbnailCount,
            roomName: room.chatRoomName,
            roomId: room.chatRoomId,
            profileImage: room.profileImagePath,
            lastMessage: displayMsg ,
            time: room.insertDate ? CHAT_UTIL.formatDate(room.insertDate).createdAt : '',
            unreadMsgCnt: room.unreadCount == 0 ? '' : room.unreadCount,
            userCnt: room.attendUsers.length + 1,
            attendUsers: room.attendUsers
        });
        // Click event
        let obj = jQuery.parseHTML(html);
        $('.overlay_src_msg').append(obj);
    });
    if (rooms.length == 0) {
        const noResultMsg = $('<div/>',{width:'auto', style:'text-align: center'});
        noResultMsg.append(getLocalizedString("noResult"))
        $('.overlay_src_msg').append(noResultMsg);
    }
};

// メッセージ検索
CHAT.searchMessage = function(keyword, workVal) {
    $('.overlay_src_msg').empty();
    var checkedUserList = [];
    $('.img_wrap.filter').each(function(user) {
        var selectedUser = $('.img_wrap.filter')[user];
        checkedUserList.push($(selectedUser).data('user-id'));
    })
    var messages = CHAT_DB.searchMessages(keyword, checkedUserList.join(','));
    var userMessageTemplate;
    $.get({ url: "./template/template_user_message.html", async: false }
    , function(text) {
        userMessageTemplate = text;
    });
    var myMessageTemplate;
    $.get({ url: "./template/template_my_message.html", async: false }
    , function(text) {
        myMessageTemplate = text;
    });

    let jQueryMessages = $('.overlay_src_msg');
    messages.forEach(function(message) {
        let template = userMessageTemplate;
        if (message.shopMemberId == CHAT.globalLoginParameter.shopMemberId) {
             template = myMessageTemplate;
        }
        if (message.messageType == messageType.SYSTEM) {
            template = systemMessageTemplate;
        }
        let messageTime = CHAT_UTIL.formatDate(message.insertDate);
        if (message.profileUrl) {
            message.profileUrl = CHAT.getProfileImgUrl(message.profileUrl)
        } else {
            message.profileUrl = CHAT.getProfileImgUrl("")
        }
        message.message = message.message.toString();
        var replacePath = message.message;
        replacePath = replacePath.replaceAll('?fileName=', '?sid=' + CHAT.globalLoginParameter.sid + '&fileName=');
        message.message = replacePath;
        let html = Mustache.render(template, {
            text: message.message,
            from: message.loginId,
            shopMemberId: message.shopMemberId,
            profileImage: message.profileUrl,
            createdAtDay: messageTime.createdAtDay,
            createdAtTime: messageTime.createdAtTime
        });
        html = message.message.includes('attachedImages') || message.message.includes('attachedVideos') ? CHAT_UTIL.htmlDecode(html) : html;
        workVal = html + workVal;
    })
    jQueryMessages.prepend(workVal);
    if (messages.length == 0) {
        const noResultMsg = $('<div/>',{width:'auto', style:'text-align: center'});
        noResultMsg.append(getLocalizedString("noResult"))
        jQueryMessages.append(noResultMsg);
    }
};