Hide 'show more history' button if there are no more messages

This commit is contained in:
Pavel Djundik 2018-07-10 19:51:45 +03:00 committed by Pavel Djundik
parent 0654a4373f
commit 30bdfe9d3f
5 changed files with 8 additions and 7 deletions

View file

@ -57,7 +57,7 @@
ref="chat" ref="chat"
class="chat" class="chat"
> >
<div class="show-more"> <div :class="['show-more', { show: channel.moreHistoryAvailable }]">
<button <button
ref="loadMoreButton" ref="loadMoreButton"
:disabled="channel.historyLoading || !$root.connected" :disabled="channel.historyLoading || !$root.connected"

View file

@ -1080,6 +1080,7 @@ background on hover (unless active) */
padding-top: 15px; padding-top: 15px;
padding-bottom: 0; padding-bottom: 0;
width: 100%; width: 100%;
display: none;
} }
#chat .show-more .btn { #chat .show-more .btn {

View file

@ -18,6 +18,7 @@ socket.on("more", function(data) {
return; return;
} }
channel.channel.moreHistoryAvailable = data.moreHistoryAvailable;
channel.channel.messages.unshift(...data.messages); channel.channel.messages.unshift(...data.messages);
channel.channel.historyLoading = false; channel.channel.historyLoading = false;
@ -26,8 +27,4 @@ socket.on("more", function(data) {
const position = chan.height() - heightOld; const position = chan.height() - heightOld;
scrollable.finish().scrollTop(position); scrollable.finish().scrollTop(position);
}); });
if (data.messages.length !== 100) {
scrollable.find(".show-more").removeClass("show");
}
}); });

View file

@ -400,6 +400,7 @@ Client.prototype.more = function(data) {
return { return {
chan: chan.id, chan: chan.id,
messages: messages, messages: messages,
moreHistoryAvailable: index > 100,
}; };
}; };

View file

@ -178,12 +178,14 @@ Chan.prototype.getFilteredClone = function(lastActiveChannel, lastMessage) {
newChannel[prop] = this[prop] newChannel[prop] = this[prop]
.filter((m) => m.id > lastMessage) .filter((m) => m.id > lastMessage)
.slice(-100); .slice(-100);
newChannel.moreHistoryAvailable = this[prop].length > 100;
} else { } else {
// If channel is active, send up to 100 last messages, for all others send just 1 // If channel is active, send up to 100 last messages, for all others send just 1
// Client will automatically load more messages whenever needed based on last seen messages // Client will automatically load more messages whenever needed based on last seen messages
const messagesToSend = lastActiveChannel === true || this.id === lastActiveChannel ? -100 : -1; const messagesToSend = lastActiveChannel === true || this.id === lastActiveChannel ? 100 : 1;
newChannel[prop] = this[prop].slice(messagesToSend); newChannel[prop] = this[prop].slice(-messagesToSend);
newChannel.moreHistoryAvailable = this[prop].length > messagesToSend;
} }
} else { } else {
newChannel[prop] = this[prop]; newChannel[prop] = this[prop];