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 write = setLoadingMessages
notify = loadingMessagesChanged 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.} = proc requestMoreMessages*(self: ChatsView, fetchRange: int) {.slot.} =
self.loadingMessages = true self.loadingMessages = true
self.loadingMessagesChanged(true) self.loadingMessagesChanged(true)

View File

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

View File

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

View File

@ -131,7 +131,7 @@ Item {
Item { Item {
visible: chatsModel.activeChannel.chatType !== Constants.chatTypePrivateGroupChat || chatsModel.activeChannel.isMember visible: chatsModel.activeChannel.chatType !== Constants.chatTypePrivateGroupChat || chatsModel.activeChannel.isMember
id: wrapper 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.left: parent.left
anchors.right: parent.right anchors.right: parent.right
Separator { Separator {
@ -152,7 +152,12 @@ Item {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
chatsModel.requestMoreMessages(Constants.fetchRangeLast24Hours) if(chatsModel.activeChannel.isTimelineChat){
chatsModel.requestMoreTimelineMessages(Constants.fetchRangeLast24Hours);
} else {
chatsModel.requestMoreMessages(Constants.fetchRangeLast24Hours);
}
timer.setTimeout(function(){ timer.setTimeout(function(){
chatsModel.hideLoadingIndicator() chatsModel.hideLoadingIndicator()
}, 3000); }, 3000);

View File

@ -14,10 +14,10 @@ ScrollView {
id: root id: root
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
contentHeight: chatLogView.contentHeight + 40 contentHeight: chatLogView.contentHeight + 140
clip: true clip: true
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
property var onActivated: function () { property var onActivated: function () {
chatsModel.setActiveChannelToTimeline() chatsModel.setActiveChannelToTimeline()
statusUpdateInput.textInput.forceActiveFocus(Qt.MouseFocusReason) statusUpdateInput.textInput.forceActiveFocus(Qt.MouseFocusReason)