Commit 6ea0bb4e authored by Vladimir Baranov's avatar Vladimir Baranov

rref #5392. Don't try to restore scroll position if new messages not loaded

parent d0781023
...@@ -278,6 +278,9 @@ angular.module("ulakbus.messaging") ...@@ -278,6 +278,9 @@ angular.module("ulakbus.messaging")
iScope.selectedChannel = result; iScope.selectedChannel = result;
iScope.selectedChannel.read_only = channel.read_only; iScope.selectedChannel.read_only = channel.read_only;
iScope.selectedChannel.messages = result.last_messages; iScope.selectedChannel.messages = result.last_messages;
if (iScope.selectedChannel.messages.length < 15){
iScope.allMessagesLoaded = true;
}
updateLastMessage(channel.messages); updateLastMessage(channel.messages);
reportLastSeenMessage(); reportLastSeenMessage();
}); });
...@@ -382,6 +385,7 @@ angular.module("ulakbus.messaging") ...@@ -382,6 +385,7 @@ angular.module("ulakbus.messaging")
} }
// prepend loaded messages to current channel messages list // prepend loaded messages to current channel messages list
messages.unshift.apply(messages, result.messages); messages.unshift.apply(messages, result.messages);
return true;
}); });
} }
}; };
...@@ -462,15 +466,18 @@ angular.module("ulakbus.messaging") ...@@ -462,15 +466,18 @@ angular.module("ulakbus.messaging")
var id = elem.find("[id]").first().attr('id'); var id = elem.find("[id]").first().attr('id');
$timeout(function(){iScope.loading = true}); $timeout(function(){iScope.loading = true});
$q.when(iScope.loadMoreCallback()) $q.when(iScope.loadMoreCallback())
.finally(function(){ .finally(function(loaded){
$timeout(function(){ $timeout(function(){
iScope.loading = false; iScope.loading = false;
// if new elements loaded
if (loaded){
// try to restore last scroll position; // try to restore last scroll position;
var lastTopElem = elem.find("#"+id); var lastTopElem = elem.find("#"+id);
if (lastTopElem){ if (lastTopElem){
var top = lastTopElem.offset().top - elem.offset().top - 100; var top = lastTopElem.offset().top - elem.offset().top - 100;
elem.scrollTop(top); elem.scrollTop(top);
} }
}
}); });
}) })
} }
......
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