fix(chat): use `scrollTo` mechanism for `firstUnseenMessage`

- it ensures enough messages are loaded when `firstUnseenMessage` is not
  within the range of initially loaded messages

fixes: #10197
This commit is contained in:
Patryk Osmaczko 2023-04-06 19:16:56 +02:00 committed by osmaczko
parent e35086f448
commit 3e3c9e7bdf
5 changed files with 14 additions and 14 deletions

View File

@ -153,6 +153,9 @@ method resendChatMessage*(self: AccessInterface, messageId: string): string =
method resetNewMessagesMarker*(self: AccessInterface) =
raise newException(ValueError, "No implementation available")
method resetAndScrollToNewMessagesMarker*(self: AccessInterface) =
raise newException(ValueError, "No implementation available")
method markAllMessagesRead*(self: AccessInterface) =
raise newException(ValueError, "No implementation available")

View File

@ -32,6 +32,7 @@ type
viewVariant: QVariant
controller: Controller
moduleLoaded: bool
scrollToFirstUnseenMessageWhenLoaded: bool
proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitter, sectionId: string, chatId: string,
belongsToCommunity: bool, contactService: contact_service.Service, communityService: community_service.Service,
@ -44,6 +45,7 @@ proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitt
result.controller = controller.newController(result, events, sectionId, chatId, belongsToCommunity, contactService,
communityService, chatService, messageService, mailserversService)
result.moduleLoaded = false
result.scrollToFirstUnseenMessageWhenLoaded = true
# Forward declaration
proc createChatIdentifierItem(self: Module): Item
@ -682,6 +684,12 @@ method resendChatMessage*(self: Module, messageId: string): string =
return self.controller.resendChatMessage(messageId)
method resetNewMessagesMarker*(self: Module) =
self.scrollToFirstUnseenMessageWhenLoaded = false
self.view.setFirstUnseenMessageLoaded(false)
self.controller.getAsyncFirstUnseenMessageId()
method resetAndScrollToNewMessagesMarker*(self: Module) =
self.scrollToFirstUnseenMessageWhenLoaded = true
self.view.setFirstUnseenMessageLoaded(false)
self.controller.getAsyncFirstUnseenMessageId()
@ -723,7 +731,6 @@ proc updateItemsByAlbum(self: Module, items: var seq[Item], message: MessageDto)
method onFirstUnseenMessageLoaded*(self: Module, messageId: string) =
self.view.model().setFirstUnseenMessageId(messageId)
self.view.model().resetNewMessagesMarker()
let index = self.view.model().findIndexForMessageId(messageId)
if (index != -1):
self.view.emitScrollToFirstUnreadMessageSignal(index)
if self.scrollToFirstUnseenMessageWhenLoaded:
self.scrollToMessage(messageId)
self.view.setFirstUnseenMessageLoaded(true)

View File

@ -246,7 +246,3 @@ QtObject:
QtProperty[bool] firstUnseenMessageLoaded:
read = getFirstUnseenMessageLoaded
notify = firstUnseenMessageLoadedChanged
proc scrollToFirstUnreadMessage(self: View, messageIndex: int) {.signal.}
proc emitScrollToFirstUnreadMessageSignal*(self: View, messageIndex: int) =
self.scrollToFirstUnreadMessage(messageIndex)

View File

@ -387,7 +387,7 @@ method contactTrustStatusChanged*(self: Module, publicKey: string, isUntrustwort
self.view.updateTrustStatus(isUntrustworthy)
method onMadeActive*(self: Module) =
self.messagesModule.resetNewMessagesMarker()
self.messagesModule.resetAndScrollToNewMessagesMarker()
self.view.setActive()
method onMadeInactive*(self: Module) =

View File

@ -87,12 +87,6 @@ Item {
function onScrollToMessage(messageIndex) {
d.goToMessage(messageIndex)
}
function onScrollToFirstUnreadMessage(messageIndex) {
if (d.isMostRecentMessageInViewport) {
d.goToMessage(messageIndex)
}
}
}
Connections {