Commit 71bcbbc2 by Kim Peace

Fixed chat room loading indicator timing

parent 1de8bd84
...@@ -78,6 +78,9 @@ document.addEventListener("readystatechange", () => { ...@@ -78,6 +78,9 @@ document.addEventListener("readystatechange", () => {
case "interactive": case "interactive":
break; break;
case "complete": case "complete":
if (typeof initialLoading != "undefined" && initialLoading) {
break;
}
Common.dismissLoadingIndicator(); Common.dismissLoadingIndicator();
break; break;
} }
......
...@@ -388,9 +388,9 @@ ReverseDelegate.leaveRoom = function () { ...@@ -388,9 +388,9 @@ ReverseDelegate.leaveRoom = function () {
}; };
// for android call // for android call
ReverseDelegate.displayExistRoom = function (roomId) { ReverseDelegate.displayExistRoom = function (roomID) {
if (confirm("error_already_exist_same_user")) { if (confirm("error_already_exist_same_user")) {
NativeBridgeDelegate.joinRoom(roomId); NativeBridgeDelegate.joinRoom(roomID);
} }
return; return;
}; };
...@@ -2,6 +2,7 @@ var beforeHeight = window.innerHeight; ...@@ -2,6 +2,7 @@ var beforeHeight = window.innerHeight;
var beforeWidth = window.innerWidth; var beforeWidth = window.innerWidth;
var beforeScroll; var beforeScroll;
var roomName = ""; var roomName = "";
var initialLoading = true;
var ChatRoom = {}; var ChatRoom = {};
window.onscroll = function () { window.onscroll = function () {
...@@ -13,23 +14,25 @@ window.onscroll = function () { ...@@ -13,23 +14,25 @@ window.onscroll = function () {
messageCount = $(".chat_message").length; messageCount = $(".chat_message").length;
// TODO: peacekim :: check this condition // TODO: peacekim :: check this condition
if ($(this).scrollTop() === 0 && messageCount >= PagingSize.MESSAGE) { if ($(this).scrollTop() === 0 && messageCount >= PagingSize.MESSAGE) {
if (!$("#chatLoader").is(":visible")) { setTimeout(function () {
// display loading indicator in chat message if (!$("#chatLoader").is(":visible")) {
let loader = $( // display loading indicator in chat message
'<div id="chatLoader" class="text-center"><div class="spinner-grow spinner-grow-sm" role="status" /></div>' let loader = $(
); '<div id="chatLoader" class="text-center"><div class="spinner-grow spinner-grow-sm" role="status" /></div>'
$("#messages").append(loader); );
// get lastest message id and update message from server via native $("#messages").append(loader);
const messageID = $($(".chat_message").get(0)).data("messageid"); // get lastest message id and update message from server via native
NativeBridgeDelegate.updatePreMessage(messageID); const messageID = $($(".chat_message").last()).data("messageid");
let messages = NativeBridgeDataSource.getMessagesByMessageID(messageID); NativeBridgeDelegate.updatePreMessage(messageID);
// prepend message let messages = NativeBridgeDataSource.getMessagesByMessageID(messageID);
ChatRoom.prependMessage(messages); // prepend message
// hide loading indicator ChatRoom.prependMessage(messages);
loader.remove(); // hide loading indicator
var afterHeight = $(".room_container").height(); loader.remove();
window.scroll(0, afterHeight - beforeHeight); var afterHeight = $(".room_container").height();
} window.scroll(0, afterHeight - beforeHeight);
}
}, 0);
} }
}; };
...@@ -176,7 +179,11 @@ ChatRoom.scrollToBottom = function (animated = true) { ...@@ -176,7 +179,11 @@ ChatRoom.scrollToBottom = function (animated = true) {
{ {
scrollTop: scrollHeight, scrollTop: scrollHeight,
}, },
animated ? 100 : 0 animated ? 100 : 0,
function () {
initialLoading = false;
Common.dismissLoadingIndicator();
}
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment