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:
parent
e35086f448
commit
3e3c9e7bdf
|
@ -153,6 +153,9 @@ method resendChatMessage*(self: AccessInterface, messageId: string): string =
|
||||||
method resetNewMessagesMarker*(self: AccessInterface) =
|
method resetNewMessagesMarker*(self: AccessInterface) =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method resetAndScrollToNewMessagesMarker*(self: AccessInterface) =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method markAllMessagesRead*(self: AccessInterface) =
|
method markAllMessagesRead*(self: AccessInterface) =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ type
|
||||||
viewVariant: QVariant
|
viewVariant: QVariant
|
||||||
controller: Controller
|
controller: Controller
|
||||||
moduleLoaded: bool
|
moduleLoaded: bool
|
||||||
|
scrollToFirstUnseenMessageWhenLoaded: bool
|
||||||
|
|
||||||
proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitter, sectionId: string, chatId: string,
|
proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitter, sectionId: string, chatId: string,
|
||||||
belongsToCommunity: bool, contactService: contact_service.Service, communityService: community_service.Service,
|
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,
|
result.controller = controller.newController(result, events, sectionId, chatId, belongsToCommunity, contactService,
|
||||||
communityService, chatService, messageService, mailserversService)
|
communityService, chatService, messageService, mailserversService)
|
||||||
result.moduleLoaded = false
|
result.moduleLoaded = false
|
||||||
|
result.scrollToFirstUnseenMessageWhenLoaded = true
|
||||||
|
|
||||||
# Forward declaration
|
# Forward declaration
|
||||||
proc createChatIdentifierItem(self: Module): Item
|
proc createChatIdentifierItem(self: Module): Item
|
||||||
|
@ -682,6 +684,12 @@ method resendChatMessage*(self: Module, messageId: string): string =
|
||||||
return self.controller.resendChatMessage(messageId)
|
return self.controller.resendChatMessage(messageId)
|
||||||
|
|
||||||
method resetNewMessagesMarker*(self: Module) =
|
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.view.setFirstUnseenMessageLoaded(false)
|
||||||
self.controller.getAsyncFirstUnseenMessageId()
|
self.controller.getAsyncFirstUnseenMessageId()
|
||||||
|
|
||||||
|
@ -723,7 +731,6 @@ proc updateItemsByAlbum(self: Module, items: var seq[Item], message: MessageDto)
|
||||||
method onFirstUnseenMessageLoaded*(self: Module, messageId: string) =
|
method onFirstUnseenMessageLoaded*(self: Module, messageId: string) =
|
||||||
self.view.model().setFirstUnseenMessageId(messageId)
|
self.view.model().setFirstUnseenMessageId(messageId)
|
||||||
self.view.model().resetNewMessagesMarker()
|
self.view.model().resetNewMessagesMarker()
|
||||||
let index = self.view.model().findIndexForMessageId(messageId)
|
if self.scrollToFirstUnseenMessageWhenLoaded:
|
||||||
if (index != -1):
|
self.scrollToMessage(messageId)
|
||||||
self.view.emitScrollToFirstUnreadMessageSignal(index)
|
|
||||||
self.view.setFirstUnseenMessageLoaded(true)
|
self.view.setFirstUnseenMessageLoaded(true)
|
||||||
|
|
|
@ -246,7 +246,3 @@ QtObject:
|
||||||
QtProperty[bool] firstUnseenMessageLoaded:
|
QtProperty[bool] firstUnseenMessageLoaded:
|
||||||
read = getFirstUnseenMessageLoaded
|
read = getFirstUnseenMessageLoaded
|
||||||
notify = firstUnseenMessageLoadedChanged
|
notify = firstUnseenMessageLoadedChanged
|
||||||
|
|
||||||
proc scrollToFirstUnreadMessage(self: View, messageIndex: int) {.signal.}
|
|
||||||
proc emitScrollToFirstUnreadMessageSignal*(self: View, messageIndex: int) =
|
|
||||||
self.scrollToFirstUnreadMessage(messageIndex)
|
|
|
@ -387,7 +387,7 @@ method contactTrustStatusChanged*(self: Module, publicKey: string, isUntrustwort
|
||||||
self.view.updateTrustStatus(isUntrustworthy)
|
self.view.updateTrustStatus(isUntrustworthy)
|
||||||
|
|
||||||
method onMadeActive*(self: Module) =
|
method onMadeActive*(self: Module) =
|
||||||
self.messagesModule.resetNewMessagesMarker()
|
self.messagesModule.resetAndScrollToNewMessagesMarker()
|
||||||
self.view.setActive()
|
self.view.setActive()
|
||||||
|
|
||||||
method onMadeInactive*(self: Module) =
|
method onMadeInactive*(self: Module) =
|
||||||
|
|
|
@ -87,12 +87,6 @@ Item {
|
||||||
function onScrollToMessage(messageIndex) {
|
function onScrollToMessage(messageIndex) {
|
||||||
d.goToMessage(messageIndex)
|
d.goToMessage(messageIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
function onScrollToFirstUnreadMessage(messageIndex) {
|
|
||||||
if (d.isMostRecentMessageInViewport) {
|
|
||||||
d.goToMessage(messageIndex)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
|
|
Loading…
Reference in New Issue