fix(@desktop/app-search): loading messages improvements
This commit is contained in:
parent
25f7544b41
commit
0a9aad7b03
|
@ -38,7 +38,7 @@ type
|
|||
searchLocation: string
|
||||
searchSubLocation: string
|
||||
searchTerm: string
|
||||
resultItems: Table[string, ResultItemDetails] # [resuiltItemId, ResultItemDetails]
|
||||
resultItems: Table[string, ResultItemDetails] # [resultItemId, ResultItemDetails]
|
||||
|
||||
proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter, contactsService: contact_service.Service,
|
||||
chatService: chat_service.Service, communityService: community_service.Service,
|
||||
|
|
|
@ -23,6 +23,7 @@ type
|
|||
chatId: string
|
||||
belongsToCommunity: bool
|
||||
searchedMessageId: string
|
||||
loadingMessagesPerPageFactor: int
|
||||
contactService: contact_service.Service
|
||||
communityService: community_service.Service
|
||||
chatService: chat_service.Service
|
||||
|
@ -37,6 +38,7 @@ proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter
|
|||
result.events = events
|
||||
result.sectionId = sectionId
|
||||
result.chatId = chatId
|
||||
result.loadingMessagesPerPageFactor = 1
|
||||
result.belongsToCommunity = belongsToCommunity
|
||||
result.contactService = contactService
|
||||
result.communityService = communityService
|
||||
|
@ -145,7 +147,7 @@ method init*(self: Controller) =
|
|||
var args = ActiveSectionChatArgs(e)
|
||||
if(self.sectionId != args.sectionId or self.chatId != args.chatId):
|
||||
return
|
||||
self.delegate.switchToMessage(args.messageId)
|
||||
self.delegate.scrollToMessage(args.messageId)
|
||||
|
||||
method getMySectionId*(self: Controller): string =
|
||||
return self.sectionId
|
||||
|
@ -166,7 +168,8 @@ method belongsToCommunity*(self: Controller): bool =
|
|||
return self.belongsToCommunity
|
||||
|
||||
method loadMoreMessages*(self: Controller) =
|
||||
self.messageService.asyncLoadMoreMessagesForChat(self.chatId)
|
||||
let limit = self.loadingMessagesPerPageFactor * MESSAGES_PER_PAGE
|
||||
self.messageService.asyncLoadMoreMessagesForChat(self.chatId, limit)
|
||||
|
||||
method addReaction*(self: Controller, messageId: string, emojiId: int) =
|
||||
self.messageService.addReaction(self.chatId, messageId, emojiId)
|
||||
|
@ -212,4 +215,13 @@ method setSearchedMessageId*(self: Controller, searchedMessageId: string) =
|
|||
self.searchedMessageId = searchedMessageId
|
||||
|
||||
method clearSearchedMessageId*(self: Controller) =
|
||||
self.setSearchedMessageId("")
|
||||
self.setSearchedMessageId("")
|
||||
|
||||
method getLoadingMessagesPerPageFactor*(self: Controller): int =
|
||||
return self.loadingMessagesPerPageFactor
|
||||
|
||||
method increaseLoadingMessagesPerPageFactor*(self: Controller) =
|
||||
self.loadingMessagesPerPageFactor = self.loadingMessagesPerPageFactor + 1
|
||||
|
||||
method resetLoadingMessagesPerPageFactor*(self: Controller) =
|
||||
self.loadingMessagesPerPageFactor = 1
|
|
@ -79,4 +79,13 @@ method setSearchedMessageId*(self: AccessInterface, searchedMessageId: string) {
|
|||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method clearSearchedMessageId*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getLoadingMessagesPerPageFactor*(self: AccessInterface): int {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method increaseLoadingMessagesPerPageFactor*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method resetLoadingMessagesPerPageFactor*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
|
@ -94,6 +94,19 @@ proc createChatIdentifierItem(self: Module): Item =
|
|||
@[],
|
||||
)
|
||||
|
||||
proc checkIfMessageLoadedAndScrollToItIfItIs(self: Module): bool =
|
||||
let searchedMessageId = self.controller.getSearchedMessageId()
|
||||
if(searchedMessageId.len > 0):
|
||||
self.view.emitScrollMessagesUpSignal()
|
||||
let index = self.view.model().findIndexForMessageId(searchedMessageId)
|
||||
self.controller.increaseLoadingMessagesPerPageFactor()
|
||||
if(index != -1):
|
||||
self.controller.clearSearchedMessageId()
|
||||
self.controller.resetLoadingMessagesPerPageFactor()
|
||||
self.view.emitScrollToMessageSignal(index)
|
||||
return true
|
||||
return false
|
||||
|
||||
method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: seq[ReactionDto],
|
||||
pinnedMessages: seq[PinnedMessageDto]) =
|
||||
var viewItems: seq[Item]
|
||||
|
@ -157,10 +170,10 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
|
|||
if(not self.view.getInitialMessagesLoaded()):
|
||||
self.view.initialMessagesAreLoaded()
|
||||
|
||||
self.setLoadingHistoryMessagesInProgress(false)
|
||||
|
||||
# check if this loading was caused by the click on a messages from the app search result
|
||||
let searchedMessageId = self.controller.getSearchedMessageId()
|
||||
if(searchedMessageId.len > 0):
|
||||
self.switchToMessage(searchedMessageId)
|
||||
discard self.checkIfMessageLoadedAndScrollToItIfItIs()
|
||||
|
||||
method messageAdded*(self: Module, message: MessageDto) =
|
||||
let sender = self.controller.getContactDetails(message.`from`)
|
||||
|
@ -198,6 +211,7 @@ method onSendingMessageError*(self: Module) =
|
|||
self.view.emitSendingMessageErrorSignal()
|
||||
|
||||
method loadMoreMessages*(self: Module) =
|
||||
self.setLoadingHistoryMessagesInProgress(true)
|
||||
self.controller.loadMoreMessages()
|
||||
|
||||
method toggleReaction*(self: Module, messageId: string, emojiId: int) =
|
||||
|
@ -330,4 +344,8 @@ method switchToMessage*(self: Module, messageId: string) =
|
|||
self.view.emitSwitchToMessageSignal(index)
|
||||
else:
|
||||
self.controller.setSearchedMessageId(messageId)
|
||||
|
||||
method scrollToMessage*(self: Module, messageId: string) =
|
||||
self.controller.setSearchedMessageId(messageId)
|
||||
if(not self.checkIfMessageLoadedAndScrollToItIfItIs()):
|
||||
self.loadMoreMessages()
|
|
@ -38,5 +38,5 @@ method onMessageEdited*(self: AccessInterface, message: MessageDto) {.base.} =
|
|||
method setLoadingHistoryMessagesInProgress*(self: AccessInterface, isLoading: bool) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method switchToMessage*(self: AccessInterface, messageId: string) {.base.} =
|
||||
method scrollToMessage*(self: AccessInterface, messageId: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
|
@ -133,4 +133,12 @@ QtObject:
|
|||
|
||||
proc switchToMessage(self: View, messageIndex: int) {.signal.}
|
||||
proc emitSwitchToMessageSignal*(self: View, messageIndex: int) =
|
||||
self.switchToMessage(messageIndex)
|
||||
self.switchToMessage(messageIndex)
|
||||
|
||||
proc scrollToMessage(self: View, messageIndex: int) {.signal.}
|
||||
proc emitScrollToMessageSignal*(self: View, messageIndex: int) =
|
||||
self.scrollToMessage(messageIndex)
|
||||
|
||||
proc scrollMessagesUp(self: View) {.signal.}
|
||||
proc emitScrollMessagesUpSignal*(self: View) =
|
||||
self.scrollMessagesUp()
|
|
@ -20,7 +20,8 @@ logScope:
|
|||
topics = "messages-service"
|
||||
|
||||
let NEW_LINE = re"\n|\r" #must be defined as let, not const
|
||||
const MESSAGES_PER_PAGE = 20
|
||||
const MESSAGES_PER_PAGE* = 20
|
||||
const MESSAGES_PER_PAGE_MAX* = 300
|
||||
const CURSOR_VALUE_IGNORE = "ignore"
|
||||
|
||||
# Signals which may be emitted by this service:
|
||||
|
@ -271,7 +272,7 @@ QtObject:
|
|||
self.events.emit(SIGNAL_MESSAGES_LOADED, data)
|
||||
|
||||
|
||||
proc asyncLoadMoreMessagesForChat*(self: Service, chatId: string) =
|
||||
proc asyncLoadMoreMessagesForChat*(self: Service, chatId: string, limit = MESSAGES_PER_PAGE) =
|
||||
if (chatId.len == 0):
|
||||
error "empty chat id", methodName="asyncLoadMoreMessagesForChat"
|
||||
return
|
||||
|
@ -297,7 +298,7 @@ QtObject:
|
|||
chatId: chatId,
|
||||
msgCursor: msgCursor,
|
||||
pinnedMsgCursor: pinnedMsgCursor,
|
||||
limit: MESSAGES_PER_PAGE
|
||||
limit: if(limit <= MESSAGES_PER_PAGE_MAX): limit else: MESSAGES_PER_PAGE_MAX
|
||||
)
|
||||
|
||||
self.threadpool.start(arg)
|
||||
|
|
|
@ -48,7 +48,11 @@ Item {
|
|||
sendingMsgFailedPopup.open();
|
||||
}
|
||||
|
||||
onSwitchToMessage: {
|
||||
onScrollMessagesUp: {
|
||||
chatLogView.positionViewAtEnd()
|
||||
}
|
||||
|
||||
onScrollToMessage: {
|
||||
chatLogView.positionViewAtIndex(messageIndex, ListView.Center);
|
||||
chatLogView.itemAtIndex(messageIndex).startMessageFoundAnimation();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue