feat: request older status updates

This commit is contained in:
Richard Ramos 2021-01-22 15:21:26 -04:00 committed by Iuri Matias
parent bc61aee55e
commit e76e936d2b
5 changed files with 35 additions and 5 deletions

View File

@ -498,6 +498,22 @@ QtObject:
write = setLoadingMessages
notify = loadingMessagesChanged
proc requestMoreTimelineMessages*(self: ChatsView, fetchRange: int) {.slot.} =
self.loadingMessages = true
self.loadingMessagesChanged(true)
var allTopics: seq[string] = @[]
for contact in self.status.contacts.getContacts():
for t in self.status.mailservers.getMailserverTopicsByChatId(getTimelineChatId(contact.id)).map(topic => topic.topic):
allTopics.add(t)
let currentOldestMessageTimestamp = self.oldestMessageTimestamp
self.oldestMessageTimestamp = self.oldestMessageTimestamp - fetchRange
self.status.mailservers.requestMessages(allTopics, self.oldestMessageTimestamp, currentOldestMessageTimestamp, true)
self.oldestMessageTimestampChanged()
self.messagesLoaded();
proc requestMoreMessages*(self: ChatsView, fetchRange: int) {.slot.} =
self.loadingMessages = true
self.loadingMessagesChanged(true)

View File

@ -2,6 +2,7 @@ import NimQml, Tables, std/wrapnils
import ../../../status/[chat/chat, status, ens, accounts]
from ../../../status/libstatus/types import Setting
import ../../../status/libstatus/settings as status_settings
import ../../../status/libstatus/utils as status_utils
import chat_members
@ -111,6 +112,12 @@ QtObject:
QtProperty[QVariant] members:
read = getMembers
proc isTimelineChat*(self: ChatItemView): bool {.slot.} = result = ?.self.chatItem.id == status_utils.getTimelineChatId()
QtProperty[bool] isTimelineChat:
read = isTimelineChat
proc hasMentions*(self: ChatItemView): bool {.slot.} = result = ?.self.chatItem.hasMentions
QtProperty[bool] hasMentions:

View File

@ -68,7 +68,6 @@ QtObject:
proc addFakeMessages*(self: ChatMessageList) =
self.messages.add(self.chatIdentifier(self.id))
self.messages.add(self.fetchMoreMessagesButton())
proc newChatMessageList*(chatId: string, status: Status, addFakeMessages: bool = true): ChatMessageList =
new(result, delete)
@ -76,6 +75,8 @@ QtObject:
result.id = chatId
if addFakeMessages:
result.addFakeMessages()
result.messages.add(result.fetchMoreMessagesButton())
result.messageIndex = initTable[string, int]()
result.timedoutMessages = initHashSet[string]()
result.status = status
@ -242,6 +243,7 @@ QtObject:
self.messages = @[]
if (addFakeMessages):
self.addFakeMessages()
self.messages.add(self.fetchMoreMessagesButton())
self.endResetModel()
proc setMessageReactions*(self: ChatMessageList, messageId: string, newReactions: string)=

View File

@ -131,7 +131,7 @@ Item {
Item {
visible: chatsModel.activeChannel.chatType !== Constants.chatTypePrivateGroupChat || chatsModel.activeChannel.isMember
id: wrapper
height: wrapper.visible ? fetchMoreButton.height + fetchDate.height + 3 + Style.current.smallPadding*2 : 0
height: wrapper.visible ? childrenRect.height + Style.current.smallPadding*2 : 0
anchors.left: parent.left
anchors.right: parent.right
Separator {
@ -152,7 +152,12 @@ Item {
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
onClicked: {
chatsModel.requestMoreMessages(Constants.fetchRangeLast24Hours)
if(chatsModel.activeChannel.isTimelineChat){
chatsModel.requestMoreTimelineMessages(Constants.fetchRangeLast24Hours);
} else {
chatsModel.requestMoreMessages(Constants.fetchRangeLast24Hours);
}
timer.setTimeout(function(){
chatsModel.hideLoadingIndicator()
}, 3000);

View File

@ -14,7 +14,7 @@ ScrollView {
id: root
Layout.fillWidth: true
Layout.fillHeight: true
contentHeight: chatLogView.contentHeight + 40
contentHeight: chatLogView.contentHeight + 140
clip: true
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff