Add fetch messages button

This commit adds a fetch messages option in the chat.
If clicked it will re-fetch messages for that chat for 1 month.

It's disabled in production since that's not something we want to go
live with, but it's very helpful for dogfooding/debugging while message
reliability has still some issues.
This commit is contained in:
Andrea Maria Piana 2023-11-29 09:55:03 +00:00
parent e6c8e141e2
commit 94159746ea
No known key found for this signature in database
15 changed files with 63 additions and 58 deletions

View File

@ -8,6 +8,7 @@ import ../../../../../app_service/service/contacts/service as contact_service
import ../../../../../app_service/service/chat/service as chat_service import ../../../../../app_service/service/chat/service as chat_service
import ../../../../../app_service/service/community/service as community_service import ../../../../../app_service/service/community/service as community_service
import ../../../../../app_service/service/message/service as message_service import ../../../../../app_service/service/message/service as message_service
import ../../../../../app_service/service/mailservers/service as mailservers_service
import ../../../../../app_service/service/wallet_account/service as wallet_account_service import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../core/signals/types import ../../../../core/signals/types
@ -26,6 +27,7 @@ type
isUsersListAvailable: bool #users list is not available for 1:1 chat isUsersListAvailable: bool #users list is not available for 1:1 chat
nodeConfigurationService: node_configuration_service.Service nodeConfigurationService: node_configuration_service.Service
settingsService: settings_service.Service settingsService: settings_service.Service
mailserversService: mailservers_service.Service
contactService: contact_service.Service contactService: contact_service.Service
chatService: chat_service.Service chatService: chat_service.Service
communityService: community_service.Service communityService: community_service.Service
@ -221,6 +223,9 @@ proc unblockChat*(self: Controller) =
proc markAllMessagesRead*(self: Controller) = proc markAllMessagesRead*(self: Controller) =
self.messageService.markAllMessagesRead(self.chatId) self.messageService.markAllMessagesRead(self.chatId)
proc requestMoreMessages*(self: Controller) =
self.mailserversService.requestMoreMessages(self.chatId)
proc markMessageRead*(self: Controller, msgID: string) = proc markMessageRead*(self: Controller, msgID: string) =
self.messageService.markCertainMessagesRead(self.chatId, @[msgID]) self.messageService.markCertainMessagesRead(self.chatId, @[msgID])

View File

@ -101,6 +101,9 @@ method unblockChat*(self: AccessInterface) {.base.} =
method markAllMessagesRead*(self: AccessInterface) {.base.} = method markAllMessagesRead*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method requestMoreMessages*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method markMessageRead*(self: AccessInterface, msgID: string) {.base.} = method markMessageRead*(self: AccessInterface, msgID: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -126,9 +126,6 @@ method editMessage*(self: AccessInterface, messageId: string, contentType: int,
method onHistoryCleared*(self: AccessInterface) {.base.} = method onHistoryCleared*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method requestMoreMessages*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method fillGaps*(self: AccessInterface, messageId: string) {.base.} = method fillGaps*(self: AccessInterface, messageId: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
@ -159,6 +156,9 @@ method resetAndScrollToNewMessagesMarker*(self: AccessInterface) {.base.} =
method markAllMessagesRead*(self: AccessInterface) {.base.} = method markAllMessagesRead*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method requestMoreMessages*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method markMessagesAsRead*(self: AccessInterface, messages: seq[string]) {.base.} = method markMessagesAsRead*(self: AccessInterface, messages: seq[string]) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -281,6 +281,9 @@ method unblockChat*(self: Module) =
method markAllMessagesRead*(self: Module) = method markAllMessagesRead*(self: Module) =
self.controller.markAllMessagesRead() self.controller.markAllMessagesRead()
method requestMoreMessages*(self: Module) =
self.controller.requestMoreMessages()
method markMessageRead*(self: Module, msgID: string) = method markMessageRead*(self: Module, msgID: string) =
self.controller.markMessageRead(msgID) self.controller.markMessageRead(msgID)

View File

@ -91,6 +91,9 @@ QtObject:
proc markAllMessagesRead*(self: View) {.slot.} = proc markAllMessagesRead*(self: View) {.slot.} =
self.delegate.markAllMessagesRead() self.delegate.markAllMessagesRead()
proc requestMoreMessages*(self: View) {.slot.} =
self.delegate.requestMoreMessages()
proc markMessageRead*(self: View, msgID: string) {.slot.} = proc markMessageRead*(self: View, msgID: string) {.slot.} =
self.delegate.markMessageRead(msgID) self.delegate.markMessageRead(msgID)

View File

@ -479,6 +479,9 @@ proc unmuteChat*(self: Controller, chatId: string) =
proc markAllMessagesRead*(self: Controller, chatId: string) = proc markAllMessagesRead*(self: Controller, chatId: string) =
self.messageService.markAllMessagesRead(chatId) self.messageService.markAllMessagesRead(chatId)
proc requestMoreMessages*(self: Controller, chatId: string) =
self.mailserversService.requestMoreMessages(chatId)
proc clearChatHistory*(self: Controller, chatId: string) = proc clearChatHistory*(self: Controller, chatId: string) =
self.chatService.clearChatHistory(chatId) self.chatService.clearChatHistory(chatId)

View File

@ -202,6 +202,9 @@ method markAllMessagesRead*(self: AccessInterface, chatId: string) {.base.} =
method clearChatHistory*(self: AccessInterface, chatId: string) {.base.} = method clearChatHistory*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method requestMoreMessages*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method getCurrentFleet*(self: AccessInterface): string {.base.} = method getCurrentFleet*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -902,6 +902,9 @@ method onMarkAllMessagesRead*(self: Module, chat: ChatDto) =
method markAllMessagesRead*(self: Module, chatId: string) = method markAllMessagesRead*(self: Module, chatId: string) =
self.controller.markAllMessagesRead(chatId) self.controller.markAllMessagesRead(chatId)
method requestMoreMessages*(self: Module, chatId: string) =
self.controller.requestMoreMessages(chatId)
method clearChatHistory*(self: Module, chatId: string) = method clearChatHistory*(self: Module, chatId: string) =
self.controller.clearChatHistory(chatId) self.controller.clearChatHistory(chatId)

View File

@ -201,6 +201,9 @@ QtObject:
proc markAllMessagesRead*(self: View, chatId: string) {.slot.} = proc markAllMessagesRead*(self: View, chatId: string) {.slot.} =
self.delegate.markAllMessagesRead(chatId) self.delegate.markAllMessagesRead(chatId)
proc requestMoreMessages*(self: View, chatId: string) {.slot.} =
self.delegate.requestMoreMessages(chatId)
proc clearChatHistory*(self: View, chatId: string) {.slot.} = proc clearChatHistory*(self: View, chatId: string) {.slot.} =
self.delegate.clearChatHistory(chatId) self.delegate.clearChatHistory(chatId)

View File

@ -49,23 +49,20 @@ const requestMoreMessagesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall
let arg = decode[RequestMoreMessagesTaskArg](argEncoded) let arg = decode[RequestMoreMessagesTaskArg](argEncoded)
try: try:
info "Requesting additional message history for chat", chatId=arg.chatId info "Requesting additional message history for chat", chatId=arg.chatId
let response = status_mailservers.syncChatFromSyncedFrom(arg.chatId) let response = status_mailservers.requestMoreMessages(arg.chatId)
if(not response.error.isNil): if(not response.error.isNil):
error "Could not request additional messages due to error", errDescription = response.error.message error "Could not request additional messages due to error", errDescription = response.error.message
arg.finish(%*{"error": response.error.message})
let syncedFrom = response.result.getInt()
if(syncedFrom != 0):
let resultJson = %* {
"chatId": arg.chatId,
"syncedFrom": syncedFrom
}
arg.finish(%resultJson)
else: else:
warn "Syncing mailserver failed", errDescription=arg.chatId info "synced mailserver successfully", chatID=arg.chatId
arg.finish(%*{"error": ""})
except Exception as e: except Exception as e:
warn "Could not request additional messages due to error", errDescription=e.msg warn "Could not request additional messages due to error", errDescription=e.msg
arg.finish(%* {
"error": e.msg
})
const fillGapsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = const fillGapsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[FillGapsTaskArg](argEncoded) let arg = decode[FillGapsTaskArg](argEncoded)
@ -126,20 +123,11 @@ QtObject:
if MAILSERVER_ID != "": if MAILSERVER_ID != "":
discard self.settingsService.pinMailserver(MAILSERVER_ID, fleet) discard self.settingsService.pinMailserver(MAILSERVER_ID, fleet)
proc mailserverSynced*(self: Service, syncInfo: string) {.slot.} =
let syncInfoParsed = parseJson(syncInfo)
let signalData = MailserverSyncedArgs(
chatId: syncInfoParsed["chatId"].getStr(),
syncedFrom: syncInfoParsed["syncedFrom"].getInt()
)
self.events.emit(SIGNAL_MAILSERVER_SYNCED, signalData)
proc requestMoreMessages*(self: Service, chatId: string) = proc requestMoreMessages*(self: Service, chatId: string) =
let arg = RequestMoreMessagesTaskArg( let arg = RequestMoreMessagesTaskArg(
tptr: cast[ByteAddress](requestMoreMessagesTask), tptr: cast[ByteAddress](requestMoreMessagesTask),
vptr: cast[ByteAddress](self.vptr), vptr: cast[ByteAddress](self.vptr),
chatId: chatId, chatId: chatId,
slot: "mailserverSynced"
) )
self.threadpool.start(arg) self.threadpool.start(arg)

View File

@ -33,3 +33,10 @@ proc fillGaps*(chatId: string, messageIds: seq[string]): RpcResponse[JsonNode] {
proc requestAllHistoricMessagesWithRetries*(forceFetchingBackup: bool): RpcResponse[JsonNode] {.raises: [Exception].} = proc requestAllHistoricMessagesWithRetries*(forceFetchingBackup: bool): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %*[forceFetchingBackup] let payload = %*[forceFetchingBackup]
result = core.callPrivateRPC("requestAllHistoricMessagesWithRetries".prefix, payload) result = core.callPrivateRPC("requestAllHistoricMessagesWithRetries".prefix, payload)
proc requestMoreMessages*(chatId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %*[{
"id": chatId
}]
result = core.callPrivateRPC("fetchMessages".prefix, payload)
info "requestMoreMessages", topics="mailserver-interaction", rpc_method="wakuext_fetchMessages", chatId, result

View File

@ -232,7 +232,7 @@ Item {
onAddRemoveGroupMember: { onAddRemoveGroupMember: {
root.addRemoveGroupMember() root.addRemoveGroupMember()
} }
onFetchMoreMessages: { onRequestMoreMessages: {
messageStore.requestMoreMessages(); messageStore.requestMoreMessages();
} }
onLeaveGroup: { onLeaveGroup: {

View File

@ -179,6 +179,10 @@ Item {
root.chatSectionModule.markAllMessagesRead(chatId) root.chatSectionModule.markAllMessagesRead(chatId)
} }
onRequestMoreMessages: {
root.chatSectionModule.requestMoreMessages(chatId)
}
onClearChatHistory: { onClearChatHistory: {
root.chatSectionModule.clearChatHistory(chatId) root.chatSectionModule.clearChatHistory(chatId)
} }

View File

@ -339,6 +339,10 @@ Item {
root.communitySectionModule.markAllMessagesRead(chatId) root.communitySectionModule.markAllMessagesRead(chatId)
} }
onRequestMoreMessages: {
root.communitySectionModule.requestMoreMessages(chatId)
}
onClearChatHistory: { onClearChatHistory: {
root.communitySectionModule.clearChatHistory(chatId) root.communitySectionModule.clearChatHistory(chatId)
} }

View File

@ -42,7 +42,7 @@ StatusMenu {
signal createCommunityChannel(string chatId, string newName, string newDescription, string newEmoji, string newColor) signal createCommunityChannel(string chatId, string newName, string newDescription, string newEmoji, string newColor)
signal editCommunityChannel(string chatId, string newName, string newDescription, string newEmoji, string newColor, string newCategory) signal editCommunityChannel(string chatId, string newName, string newDescription, string newEmoji, string newColor, string newCategory)
signal fetchMoreMessages(int timeFrame) signal requestMoreMessages(string chatId)
signal addRemoveGroupMember() signal addRemoveGroupMember()
width: root.amIChatAdmin && (root.chatType === Constants.chatType.privateGroupChat) ? 207 : implicitWidth width: root.amIChatAdmin && (root.chatType === Constants.chatType.privateGroupChat) ? 207 : implicitWidth
@ -124,39 +124,15 @@ StatusMenu {
} }
} }
//TODO uncomment when implemented StatusAction {
// StatusMenu { objectName: "chatFetchMessagesMenuItem"
// title: qsTr("Fetch messages") text: qsTr("Fetch messages")
// enabled: (root.chatType === Constants.chatType.oneToOne || icon.name: "download"
// root.chatType === Constants.chatType.privateGroupChat) enabled: !production
// StatusAction { onTriggered: {
// text: "Last 24 hours" root.requestMoreMessages(root.chatId)
// onTriggered: { }
// root.fetchMoreMessages(); }
// }
// }
// StatusAction {
// text: "Last 2 days"
// onTriggered: {
// }
// }
// StatusAction {
// text: "Last 3 days"
// onTriggered: {
// }
// }
// StatusAction {
// text: "Last 7 days"
// onTriggered: {
// }
// }
// }
StatusAction { StatusAction {
objectName: "editChannelMenuItem" objectName: "editChannelMenuItem"