diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index fae1bcdc6a..723271d221 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -487,12 +487,12 @@ QtObject: read = isLoadingMessages notify = loadingMessagesChanged - proc requestMoreMessages*(self: ChatsView) {.slot.} = + proc requestMoreMessages*(self: ChatsView, fetchRange: int) {.slot.} = self.loadingMessages = true self.loadingMessagesChanged() let topics = self.status.mailservers.getMailserverTopicsByChatId(self.activeChannel.id).map(topic => topic.topic) let currentOldestMessageTimestamp = self.oldestMessageTimestamp - self.oldestMessageTimestamp = self.oldestMessageTimestamp - 86400 + self.oldestMessageTimestamp = self.oldestMessageTimestamp - fetchRange self.status.mailservers.requestMessages(topics, self.oldestMessageTimestamp, currentOldestMessageTimestamp, true) self.oldestMessageTimestampChanged() diff --git a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml index bfcafedebb..484c589151 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml @@ -130,7 +130,7 @@ Item { cursorShape: Qt.PointingHandCursor anchors.fill: parent onClicked: { - chatsModel.requestMoreMessages() + chatsModel.requestMoreMessages(Constants.fetchRangeLast24Hours) timer.setTimeout(function(){ chatsModel.hideLoadingIndicator() }, 3000); diff --git a/ui/app/AppLayouts/Chat/ContactsColumn/ChannelList.qml b/ui/app/AppLayouts/Chat/ContactsColumn/ChannelList.qml index d98b7626ad..b2dcdd0f23 100644 --- a/ui/app/AppLayouts/Chat/ContactsColumn/ChannelList.qml +++ b/ui/app/AppLayouts/Chat/ContactsColumn/ChannelList.qml @@ -16,6 +16,11 @@ ScrollView { contentHeight: channelListContent.height + Style.current.padding clip: true + Timer { + id: timer + } + + Item { id: channelListContent Layout.fillHeight: true @@ -198,13 +203,49 @@ ScrollView { // TODO call fetch for the wanted duration //% "Last 24 hours" - Action { text: qsTrId("last-24-hours"); icon.width: 0; } + Action { + text: qsTrId("last-24-hours"); + icon.width: 0; + onTriggered: { + chatsModel.requestMoreMessages(Constants.fetchRangeLast24Hours) + timer.setTimeout(function(){ + chatsModel.hideLoadingIndicator() + }, 3000); + } + } //% "Last 2 days" - Action { text: qsTrId("last-2-days"); icon.width: 0; } + Action { + text: qsTrId("last-2-days"); + icon.width: 0; + onTriggered: { + chatsModel.requestMoreMessages(Constants.fetchRangeLast2Days) + timer.setTimeout(function(){ + chatsModel.hideLoadingIndicator() + }, 4000); + } + } //% "Last 3 days" - Action { text: qsTrId("last-3-days"); icon.width: 0; } + Action { + text: qsTrId("last-3-days"); + icon.width: 0; + onTriggered: { + chatsModel.requestMoreMessages(Constants.fetchRangeLast3Days) + timer.setTimeout(function(){ + chatsModel.hideLoadingIndicator() + }, 5000); + } + } //% "Last 7 days" - Action { text: qsTrId("last-7-days"); icon.width: 0; } + Action { + text: qsTrId("last-7-days"); + icon.width: 0; + onTriggered: { + chatsModel.requestMoreMessages(Constants.fetchRangeLast7Days) + timer.setTimeout(function(){ + chatsModel.hideLoadingIndicator() + }, 7000); + } + } } Action { //% "Clear History" diff --git a/ui/imports/Constants.qml b/ui/imports/Constants.qml index 7d5d321879..f5807e2a99 100644 --- a/ui/imports/Constants.qml +++ b/ui/imports/Constants.qml @@ -7,6 +7,11 @@ QtObject { readonly property int chatTypePublic: 2 readonly property int chatTypePrivateGroupChat: 3 + readonly property int fetchRangeLast24Hours: 86400 + readonly property int fetchRangeLast2Days: 172800 + readonly property int fetchRangeLast3Days: 259200 + readonly property int fetchRangeLast7Days: 604800 + readonly property int limitLongChatText: 500 readonly property int limitLongChatTextCompactMode: 1000