diff --git a/src/app/modules/main/app_search/controller.nim b/src/app/modules/main/app_search/controller.nim index bcbc3c103e..ca8c3b1e5d 100644 --- a/src/app/modules/main/app_search/controller.nim +++ b/src/app/modules/main/app_search/controller.nim @@ -1,4 +1,4 @@ -import controller_interface +import Tables, controller_interface, chronicles import io_interface import ../../../global/app_sections_config as conf @@ -12,6 +12,19 @@ import ../../../core/eventemitter export controller_interface +logScope: + topics = "app-search-module-controller" + +type ResultItemDetails = object + sectionId*: string + channelId*: string + messageId*: string + +method isEmpty(self: ResultItemDetails): bool = + self.sectionId.len == 0 and + self.channelId.len == 0 and + self.messageId.len == 0 + type Controller* = ref object of controller_interface.AccessInterface delegate: io_interface.AccessInterface @@ -25,6 +38,7 @@ type searchLocation: string searchSubLocation: string searchTerm: string + resultItems: Table[string, ResultItemDetails] # [resuiltItemId, ResultItemDetails] proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter, contactsService: contact_service.Service, chatService: chat_service.Service, communityService: community_service.Service, @@ -36,9 +50,10 @@ proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter result.chatService = chatService result.communityService = communityService result.messageService = messageService + result.resultItems = initTable[string, ResultItemDetails]() method delete*(self: Controller) = - discard + self.resultItems.clear method init*(self: Controller) = self.events.on(SIGNAL_SEARCH_MESSAGES_LOADED) do(e:Args): @@ -87,6 +102,7 @@ method getChatDetails*(self: Controller, communityId, chatId: string): ChatDto = return self.chatService.getChatById(fullId) method searchMessages*(self: Controller, searchTerm: string) = + self.resultItems.clear self.searchTerm = searchTerm var chats: seq[string] @@ -122,4 +138,16 @@ method getOneToOneChatNameAndImage*(self: Controller, chatId: string): method getContactNameAndImage*(self: Controller, contactId: string): tuple[name: string, image: string, isIdenticon: bool] = - return self.contactsService.getContactNameAndImage(contactId) \ No newline at end of file + return self.contactsService.getContactNameAndImage(contactId) + +method addResultItemDetails*(self: Controller, itemId: string, sectionId = "", channelId = "", messageId = "") = + self.resultItems.add(itemId, ResultItemDetails(sectionId: sectionId, channelId: channelId, messageId: messageId)) + +method resultItemClicked*(self: Controller, itemId: string) = + let itemDetails = self.resultItems.getOrDefault(itemId) + if(itemDetails.isEmpty()): + # we shouldn't be here ever + info "important: we don't have stored details for a searched result item with id: ", itemId + return + + self.messageService.switchTo(itemDetails.sectionId, itemDetails.channelId, itemDetails.messageId) \ No newline at end of file diff --git a/src/app/modules/main/app_search/controller_interface.nim b/src/app/modules/main/app_search/controller_interface.nim index 8e33212dc7..0569cbe02f 100644 --- a/src/app/modules/main/app_search/controller_interface.nim +++ b/src/app/modules/main/app_search/controller_interface.nim @@ -57,4 +57,11 @@ method getOneToOneChatNameAndImage*(self: AccessInterface, chatId: string): method getContactNameAndImage*(self: AccessInterface, contactId: string): tuple[name: string, image: string, isIdenticon: bool] {.base.} = + raise newException(ValueError, "No implementation available") + +method addResultItemDetails*(self: AccessInterface, itemId: string, sectionId = "", channelId = "", messageId = "") + {.base.} = + raise newException(ValueError, "No implementation available") + +method resultItemClicked*(self: AccessInterface, itemId: string) {.base.} = raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/app_search/module.nim b/src/app/modules/main/app_search/module.nim index bbdadd6142..d2dddf20df 100644 --- a/src/app/modules/main/app_search/module.nim +++ b/src/app/modules/main/app_search/module.nim @@ -158,6 +158,7 @@ method onSearchMessagesDone*(self: Module, messages: seq[MessageDto]) = let item = result_item.initItem(co.id, "", "", co.id, co.name, SEARCH_RESULT_COMMUNITIES_SECTION_NAME, co.images.thumbnail, co.color, "", "", co.images.thumbnail, co.color, false) + self.controller.addResultItemDetails(co.id, co.id) items.add(item) # Add channels @@ -170,6 +171,7 @@ method onSearchMessagesDone*(self: Module, messages: seq[MessageDto]) = SEARCH_RESULT_CHANNELS_SECTION_NAME, chatDto.identicon, chatDto.color, "", "", chatDto.identicon, chatDto.color, false) + self.controller.addResultItemDetails(chatDto.id, co.id, chatDto.id) channels.add(item) # Add chats @@ -193,6 +195,7 @@ method onSearchMessagesDone*(self: Module, messages: seq[MessageDto]) = let item = result_item.initItem(c.id, "", "", c.id, chatName, SEARCH_RESULT_CHATS_SECTION_NAME, chatImage, c.color, "", "", chatImage, c.color, isIdenticon) + self.controller.addResultItemDetails(c.id, conf.CHAT_SECTION_ID, c.id) items.add(item) # Add channels in order as requested by the design @@ -218,6 +221,7 @@ method onSearchMessagesDone*(self: Module, messages: seq[MessageDto]) = let item = result_item.initItem(m.id, m.text, $m.timestamp, m.`from`, senderName, SEARCH_RESULT_MESSAGES_SECTION_NAME, senderImage, "", chatName, "", chatImage, chatDto.color, isIdenticon) + self.controller.addResultItemDetails(m.id, conf.CHAT_SECTION_ID, chatDto.id, m.id) items.add(item) else: let community = self.controller.getCommunityById(chatDto.communityId) @@ -227,6 +231,11 @@ method onSearchMessagesDone*(self: Module, messages: seq[MessageDto]) = SEARCH_RESULT_MESSAGES_SECTION_NAME, senderImage, "", community.name, channelName, community.images.thumbnail, community.color, false) + self.controller.addResultItemDetails(m.id, chatDto.communityId, chatDto.id, m.id) items.add(item) self.view.searchResultModel().set(items) + self.view.emitAppSearchCompletedSignal() + +method resultItemClicked*(self: Module, itemId: string) = + self.controller.resultItemClicked(itemId) diff --git a/src/app/modules/main/app_search/private_interfaces/module_view_delegate_interface.nim b/src/app/modules/main/app_search/private_interfaces/module_view_delegate_interface.nim index 647fcbbc97..9d50476626 100644 --- a/src/app/modules/main/app_search/private_interfaces/module_view_delegate_interface.nim +++ b/src/app/modules/main/app_search/private_interfaces/module_view_delegate_interface.nim @@ -11,4 +11,7 @@ method getSearchLocationObject*(self: AccessInterface): string {.base.} = raise newException(ValueError, "No implementation available") method searchMessages*(self: AccessInterface, searchTerm: string) {.base.} = + raise newException(ValueError, "No implementation available") + +method resultItemClicked*(self: AccessInterface, itemId: string) {.base.} = raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/app_search/result_model.nim b/src/app/modules/main/app_search/result_model.nim index 02d5eab49c..5d4c99f6c2 100644 --- a/src/app/modules/main/app_search/result_model.nim +++ b/src/app/modules/main/app_search/result_model.nim @@ -1,4 +1,4 @@ -import NimQml, Tables, strutils +import NimQml, Tables, strutils, strformat import result_item @@ -33,15 +33,15 @@ QtObject: new(result, delete) result.setup() - ################################################# - # Properties - ################################################# + proc `$`*(self: Model): string = + for i in 0 ..< self.resultList.len: + result &= fmt"""SearchResultMessageModel: + [{i}]:({$self.resultList[i]}) + """ proc countChanged*(self: Model) {.signal.} - proc count*(self: Model): int {.slot.} = self.resultList.len - QtProperty[int] count: read = count notify = countChanged diff --git a/src/app/modules/main/app_search/view.nim b/src/app/modules/main/app_search/view.nim index 704b372a59..1e383bfd20 100644 --- a/src/app/modules/main/app_search/view.nim +++ b/src/app/modules/main/app_search/view.nim @@ -58,4 +58,11 @@ QtObject: self.delegate.getSearchLocationObject() proc searchMessages*(self: View, searchTerm: string) {.slot.} = - self.delegate.searchMessages(searchTerm) \ No newline at end of file + self.delegate.searchMessages(searchTerm) + + proc resultItemClicked*(self: View, itemId: string) {.slot.} = + self.delegate.resultItemClicked(itemId) + + proc appSearchCompleted(self: View) {.signal.} + proc emitAppSearchCompletedSignal*(self: View) = + self.appSearchCompleted() \ No newline at end of file diff --git a/src/app/modules/main/chat_section/chat_content/messages/controller.nim b/src/app/modules/main/chat_section/chat_content/messages/controller.nim index ccdcc1b18b..16c133ec64 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/controller.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/controller.nim @@ -22,6 +22,7 @@ type sectionId: string chatId: string belongsToCommunity: bool + searchedMessageId: string contactService: contact_service.Service communityService: community_service.Service chatService: chat_service.Service @@ -140,6 +141,12 @@ method init*(self: Controller) = let args = LinkPreviewDataArgs(e) self.delegate.onPreviewDataLoaded(args.response) + self.events.on(SIGNAL_MAKE_SECTION_CHAT_ACTIVE) do(e: Args): + var args = ActiveSectionChatArgs(e) + if(self.sectionId != args.sectionId or self.chatId != args.chatId): + return + self.delegate.switchToMessage(args.messageId) + method getMySectionId*(self: Controller): string = return self.sectionId @@ -196,4 +203,13 @@ method editMessage*(self: Controller, messageId: string, updatedMsg: string) = self.messageService.editMessage(messageId, updatedMsg) method getLinkPreviewData*(self: Controller, link: string, uuid: string): string = - self.messageService.asyncGetLinkPreviewData(link, uuid) \ No newline at end of file + self.messageService.asyncGetLinkPreviewData(link, uuid) + +method getSearchedMessageId*(self: Controller): string = + return self.searchedMessageId + +method setSearchedMessageId*(self: Controller, searchedMessageId: string) = + self.searchedMessageId = searchedMessageId + +method clearSearchedMessageId*(self: Controller) = + self.setSearchedMessageId("") \ No newline at end of file diff --git a/src/app/modules/main/chat_section/chat_content/messages/controller_interface.nim b/src/app/modules/main/chat_section/chat_content/messages/controller_interface.nim index 2ec2472175..184a5366fb 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/controller_interface.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/controller_interface.nim @@ -71,3 +71,12 @@ method editMessage*(self: AccessInterface, messageId: string, updatedMsg: string method getLinkPreviewData*(self: AccessInterface, link: string, uuid: string): string {.base.} = raise newException(ValueError, "No implementation available") + +method getSearchedMessageId*(self: AccessInterface): string {.base.} = + raise newException(ValueError, "No implementation available") + +method setSearchedMessageId*(self: AccessInterface, searchedMessageId: string) {.base.} = + raise newException(ValueError, "No implementation available") + +method clearSearchedMessageId*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/chat_section/chat_content/messages/module.nim b/src/app/modules/main/chat_section/chat_content/messages/module.nim index b807ef3260..962067227c 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/module.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/module.nim @@ -156,6 +156,11 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se if(not self.view.getInitialMessagesLoaded()): self.view.initialMessagesAreLoaded() + + # 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) method messageAdded*(self: Module, message: MessageDto) = let sender = self.controller.getContactDetails(message.`from`) @@ -317,3 +322,12 @@ method getLinkPreviewData*(self: Module, link: string, uuid: string): string = method onPreviewDataLoaded*(self: Module, previewData: string) = self.view.onPreviewDataLoaded(previewData) + +method switchToMessage*(self: Module, messageId: string) = + let index = self.view.model().findIndexForMessageId(messageId) + if(index != -1): + self.controller.clearSearchedMessageId() + self.view.emitSwitchToMessageSignal(index) + else: + self.controller.setSearchedMessageId(messageId) + self.loadMoreMessages() \ No newline at end of file diff --git a/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_controller_delegate_interface.nim b/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_controller_delegate_interface.nim index a177edeb2a..36943a8958 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_controller_delegate_interface.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_controller_delegate_interface.nim @@ -36,4 +36,7 @@ method onMessageEdited*(self: AccessInterface, message: MessageDto) {.base.} = raise newException(ValueError, "No implementation available") method setLoadingHistoryMessagesInProgress*(self: AccessInterface, isLoading: bool) {.base.} = + raise newException(ValueError, "No implementation available") + +method switchToMessage*(self: AccessInterface, messageId: string) {.base.} = raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/chat_section/chat_content/messages/view.nim b/src/app/modules/main/chat_section/chat_content/messages/view.nim index dc322b8cd4..11e918e1ab 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/view.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/view.nim @@ -103,7 +103,6 @@ QtObject: self.delegate.loadMoreMessages() proc messageSuccessfullySent*(self: View) {.signal.} - proc emitSendingMessageSuccessSignal*(self: View) = self.messageSuccessfullySent() @@ -130,4 +129,8 @@ QtObject: proc linkPreviewDataWasReceived*(self: View, previewData: string) {.signal.} proc onPreviewDataLoaded*(self: View, previewData: string) {.slot.} = - self.linkPreviewDataWasReceived(previewData) \ No newline at end of file + self.linkPreviewDataWasReceived(previewData) + + proc switchToMessage(self: View, messageIndex: int) {.signal.} + proc emitSwitchToMessageSignal*(self: View, messageIndex: int) = + self.switchToMessage(messageIndex) \ No newline at end of file diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index b30ff2556c..bc9dd2786d 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -130,6 +130,12 @@ method init*(self: Controller) = var args = ChatRenameArgs(e) self.delegate.onChatRenamed(args.id, args.newName) + self.events.on(SIGNAL_MAKE_SECTION_CHAT_ACTIVE) do(e: Args): + var args = ActiveSectionChatArgs(e) + if (self.sectionId != args.sectionId): + return + self.delegate.makeChatWithIdActive(args.chatId) + method getMySectionId*(self: Controller): string = return self.sectionId diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index 987b388934..7fc781d305 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -1,7 +1,7 @@ import NimQml, Tables, chronicles, json, sequtils import io_interface import ../io_interface as delegate_interface -import view, controller, item, sub_item, model, sub_model +import view, controller, item, sub_item, model, sub_model, base_item import ../../shared_models/contacts_item as contacts_item import ../../shared_models/contacts_model as contacts_model @@ -275,11 +275,31 @@ method chatContentDidLoad*(self: Module) = method setActiveItemSubItem*(self: Module, itemId: string, subItemId: string) = self.controller.setActiveItemSubItem(itemId, subItemId) +method makeChatWithIdActive*(self: Module, chatId: string) = + var item = self.view.chatsModel().getItemById(chatId) + var subItemId: string + if(item.isNil): + let subItem = self.view.chatsModel().getSubItemById(chatId) + if(subItem.isNil): + # Should never be here + error "trying to make chat/channel active for an unexisting id ", chatId, methodName="makeChatWithIdActive" + return + + subItemId = subItem.BaseItem.id + item = self.view.chatsModel().getItemById(subItem.parentId()) + if(item.isNil): + # Should never be here + error "unexisting parent item with id ", subItemId, methodName="makeChatWithIdActive" + return + + # here, in this step we have appropriate item and subitem assigned + self.setActiveItemSubItem(item.BaseItem.id, subItemId) + method activeItemSubItemSet*(self: Module, itemId: string, subItemId: string) = let item = self.view.chatsModel().getItemById(itemId) if(item.isNil): # Should never be here - error "chat-view unexisting item id: ", itemId + error "chat-view unexisting item id: ", itemId, methodName="activeItemSubItemSet" return # Chats from Chat section and chats from Community section which don't belong @@ -299,7 +319,7 @@ method getModuleAsVariant*(self: Module): QVariant = method getChatContentModule*(self: Module, chatId: string): QVariant = if(not self.chatContentModules.contains(chatId)): - error "unexisting chat key: ", chatId + error "unexisting chat key: ", chatId, methodName="getChatContentModule" return return self.chatContentModules[chatId].getModuleAsVariant() @@ -312,11 +332,11 @@ method onActiveSectionChange*(self: Module, sectionId: string) = method createPublicChat*(self: Module, chatId: string) = if(self.controller.isCommunity()): - debug "creating public chat is not allowed for community, most likely it's an error in qml" + debug "creating public chat is not allowed for community, most likely it's an error in qml", methodName="createPublicChat" return if(self.chatContentModules.hasKey(chatId)): - error "error: public chat is already added", chatId + error "error: public chat is already added", chatId, methodName="createPublicChat" return self.controller.createPublicChat(chatId) @@ -386,7 +406,7 @@ method onCommunityChannelEdited*(self: Module, chat: ChatDto) = method createOneToOneChat*(self: Module, chatId: string, ensName: string) = if(self.controller.isCommunity()): - debug "creating an one to one chat is not allowed for community, most likely it's an error in qml" + debug "creating an one to one chat is not allowed for community, most likely it's an error in qml", methodName="createOneToOneChat" return if(self.chatContentModules.hasKey(chatId)): diff --git a/src/app/modules/main/chat_section/private_interfaces/module_controller_delegate_interface.nim b/src/app/modules/main/chat_section/private_interfaces/module_controller_delegate_interface.nim index f64c3df964..d1e6622237 100644 --- a/src/app/modules/main/chat_section/private_interfaces/module_controller_delegate_interface.nim +++ b/src/app/modules/main/chat_section/private_interfaces/module_controller_delegate_interface.nim @@ -1,6 +1,9 @@ method activeItemSubItemSet*(self: AccessInterface, itemId: string, subItemId: string) {.base.} = raise newException(ValueError, "No implementation available") +method makeChatWithIdActive*(self: AccessInterface, chatId: string) {.base.} = + raise newException(ValueError, "No implementation available") + method addNewChat*(self: AccessInterface, chatDto: ChatDto, belongsToCommunity: bool, events: EventEmitter, settingsService: settings_service.ServiceInterface, contactService: contact_service.Service, chatService: chat_service.Service, communityService: community_service.Service, diff --git a/src/app/modules/main/controller.nim b/src/app/modules/main/controller.nim index a3958ce5c5..93cc2825ae 100644 --- a/src/app/modules/main/controller.nim +++ b/src/app/modules/main/controller.nim @@ -1,4 +1,5 @@ import ../shared_models/section_item, controller_interface, io_interface, chronicles +import ../../global/app_sections_config as conf import ../../global/global_singleton import ../../global/app_signals import ../../core/signals/types @@ -141,6 +142,11 @@ method init*(self: Controller) = self.events.on(SIGNAL_MNEMONIC_REMOVAL) do(e: Args): self.delegate.mnemonicBackedUp() + self.events.on(SIGNAL_MAKE_SECTION_CHAT_ACTIVE) do(e: Args): + var args = ActiveSectionChatArgs(e) + let sectionType = if args.sectionId == conf.CHAT_SECTION_ID: SectionType.Chat else: SectionType.Community + self.setActiveSection(args.sectionId, sectionType) + method getJoinedCommunities*(self: Controller): seq[CommunityDto] = return self.communityService.getJoinedCommunities() diff --git a/src/app/modules/shared_models/message_model.nim b/src/app/modules/shared_models/message_model.nim index a43f698ac5..8e03b3373e 100644 --- a/src/app/modules/shared_models/message_model.nim +++ b/src/app/modules/shared_models/message_model.nim @@ -49,8 +49,9 @@ QtObject: result.setup proc `$`*(self: Model): string = + result = "MessageModel:\n" for i in 0 ..< self.items.len: - result &= fmt"""MessageModel: + result &= fmt""" [{i}]:({$self.items[i]}) """ @@ -158,7 +159,7 @@ QtObject: of ModelRole.Links: result = newQVariant(item.links.join(" ")) - proc findIndexForMessageId(self: Model, messageId: string): int = + proc findIndexForMessageId*(self: Model, messageId: string): int = for i in 0 ..< self.items.len: if(self.items[i].id == messageId): return i diff --git a/src/app_service/service/chat/service.nim b/src/app_service/service/chat/service.nim index 709f9909cf..19d63a2775 100644 --- a/src/app_service/service/chat/service.nim +++ b/src/app_service/service/chat/service.nim @@ -157,7 +157,7 @@ QtObject: proc getChatById*(self: Service, chatId: string): ChatDto = if(not self.chats.contains(chatId)): - error "trying to get chat data for an unexisting chat id" + error "trying to get chat data for an unexisting chat id", chatId return return self.chats[chatId] diff --git a/src/app_service/service/message/service.nim b/src/app_service/service/message/service.nim index 6b904c95b2..ede4e57de8 100644 --- a/src/app_service/service/message/service.nim +++ b/src/app_service/service/message/service.nim @@ -36,6 +36,7 @@ const SIGNAL_MESSAGE_REACTION_FROM_OTHERS* = "messageReactionFromOthers" const SIGNAL_MESSAGE_DELETION* = "messageDeleted" const SIGNAL_MESSAGE_EDITED* = "messageEdited" const SIGNAL_MESSAGE_LINK_PREVIEW_DATA_LOADED* = "messageLinkPreviewDataLoaded" +const SIGNAL_MAKE_SECTION_CHAT_ACTIVE* = "makeSectionChatActive" include async_tasks @@ -81,6 +82,11 @@ type LinkPreviewDataArgs* = ref object of Args response*: string + ActiveSectionChatArgs* = ref object of Args + sectionId*: string + chatId*: string + messageId*: string + QtObject: type Service* = ref object of QObject events: EventEmitter @@ -652,4 +658,13 @@ proc editMessage*(self: Service, messageId: string, updatedMsg: string) = self.events.emit(SIGNAL_MESSAGE_EDITED, data) except Exception as e: - error "error: ", methodName="editMessage", errName = e.name, errDesription = e.msg \ No newline at end of file + error "error: ", methodName="editMessage", errName = e.name, errDesription = e.msg + +proc switchTo*(self: Service, sectionId: string, chatId: string, messageId: string) = + ## Calling this proc the app will switch to passed `sectionId`, after that if `chatId` is set + ## it will make that chat an active one and at the end if `messageId` is set it will point to + ## that message. + ## We should use this proc (or just emit a signal bellow) when we want to switch to certain + ## section and/or chat and/or message + let data = ActiveSectionChatArgs(sectionId: sectionId, chatId: chatId, messageId: messageId) + self.events.emit(SIGNAL_MAKE_SECTION_CHAT_ACTIVE, data) \ No newline at end of file diff --git a/ui/app/AppLayouts/Chat/views/ActivityCenterMessageComponentView.qml b/ui/app/AppLayouts/Chat/views/ActivityCenterMessageComponentView.qml index 9da44063ec..90bcaa3f96 100644 --- a/ui/app/AppLayouts/Chat/views/ActivityCenterMessageComponentView.qml +++ b/ui/app/AppLayouts/Chat/views/ActivityCenterMessageComponentView.qml @@ -145,7 +145,12 @@ Item { // } // root.chatSectionModule.setActiveChannel(model.chatId); - positionAtMessage(model.id); + + // To position to appropriate message check how it's done in AppSearch module, + // similar may be done here, corresponding module for activity center just need to + // use the mechanism done there, send the signal form message service and + // and the rest is already handled. +// positionAtMessage(model.id); } prevMessageIndex: root.previousNotificationIndex prevMsgTimestamp: root.previousNotificationTimestamp diff --git a/ui/app/AppLayouts/Chat/views/ChatColumnView.qml b/ui/app/AppLayouts/Chat/views/ChatColumnView.qml index f3cf805cb7..aebc9a3d30 100644 --- a/ui/app/AppLayouts/Chat/views/ChatColumnView.qml +++ b/ui/app/AppLayouts/Chat/views/ChatColumnView.qml @@ -117,11 +117,6 @@ Item { Global.applicationWindow.requestActivate() } - function positionAtMessage(messageId, isSearch = false) { - // Not Refactored Yet -// stackLayoutChatMessages.children[stackLayoutChatMessages.currentIndex].message.scrollToMessage(messageId, isSearch); - } - Timer { interval: 60000; // 1 min running: true @@ -341,10 +336,6 @@ Item { // Connections { // target: root.rootStore.chatsModelInst.messageView -// onSearchedMessageLoaded: { -// positionAtMessage(messageId, true); -// } - // onMessageNotificationPushed: function(messageId, communityId, chatId, msg, contentType, chatType, timestamp, identicon, username, hasMention, isAddedContact, channelName) { // if (localAccountSensitiveSettings.notificationSetting == Constants.notifyAllMessages || // (localAccountSensitiveSettings.notificationSetting == Constants.notifyJustMentions && hasMention)) { diff --git a/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml b/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml index 440c18a3ab..f41ae67cd7 100644 --- a/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml +++ b/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml @@ -27,7 +27,6 @@ Item { property bool stickersLoaded: false property alias chatLogView: chatLogView - property alias scrollToMessage: chatLogView.scrollToMessage property var messageContextMenuInst @@ -38,6 +37,30 @@ Item { signal openStickerPackPopup(string stickerPackId) signal showReplyArea(string messageId, string author) + Connections { + target: root.messageStore.messageModule + + onMessageSuccessfullySent: { + chatLogView.scrollToBottom(true) + } + + onSendingMessageFailed: { + sendingMsgFailedPopup.open(); + } + + onSwitchToMessage: { + chatLogView.positionViewAtIndex(messageIndex, ListView.Center); + chatLogView.itemAtIndex(messageIndex).startMessageFoundAnimation(); + } + + // Not Refactored Yet +// onNewMessagePushed: { +// if (!chatLogView.scrollToBottom()) { +// newMessages++ +// } +// } + } + Item { id: loadingMessagesIndicator visible: messageStore.messageModule? messageStore.messageModule.loadingHistoryMessagesInProgress : false @@ -90,34 +113,6 @@ Item { } } - property var scrollToMessage: function (messageId, isSearch = false) { - // Not Refactored Yet -// delayPositioningViewTimer.msgId = messageId; -// delayPositioningViewTimer.isSearch = isSearch; -// delayPositioningViewTimer.restart(); - } - -// Timer { -// id: delayPositioningViewTimer -// interval: 1000 -// property string msgId -// property bool isSearch -// onTriggered: { -// let item -// for (let i = 0; i < messages.rowCount(); i++) { -// item = messageListDelegate.items.get(i); -// if (item.model.messageId === msgId) { -// chatLogView.positionViewAtIndex(i, ListView.Beginning); -// if (isSearch) { -// chatLogView.itemAtIndex(i).startMessageFoundAnimation(); -// } -// } -// } -// msgId = ""; -// isSearch = false; -// } -// } - ScrollBar.vertical: ScrollBar { visible: chatLogView.visibleArea.heightRatio < 1 } @@ -223,25 +218,6 @@ Item { // } // } - Connections { - target: messageStore.messageModule - - onMessageSuccessfullySent: { - chatLogView.scrollToBottom(true) - } - - onSendingMessageFailed: { - sendingMsgFailedPopup.open(); - } - - // Not Refactored Yet -// onNewMessagePushed: { -// if (!chatLogView.scrollToBottom()) { -// newMessages++ -// } -// } - } - // Connections { // Not Refactored Yet // target: root.store.chatsModelInst.communities diff --git a/ui/app/AppLayouts/stores/AppSearchStore.qml b/ui/app/AppLayouts/stores/AppSearchStore.qml new file mode 100644 index 0000000000..d166bdcb2e --- /dev/null +++ b/ui/app/AppLayouts/stores/AppSearchStore.qml @@ -0,0 +1,40 @@ +import QtQuick 2.13 + +QtObject { + id: root + + property var appSearchModule + + property var locationMenuModel: root.appSearchModule.locationMenuModel + property var resultModel: root.appSearchModule.resultModel + + function searchMessages(searchTerm) { + if(!root.appSearchModule) + return + root.appSearchModule.searchMessages(searchTerm) + } + + function setSearchLocation(location, subLocation) { + if(!root.appSearchModule) + return + root.appSearchModule.setSearchLocation(location, subLocation) + } + + function prepareLocationMenuModel() { + if(!root.appSearchModule) + return + root.appSearchModule.prepareLocationMenuModel() + } + + function getSearchLocationObject() { + if(!root.appSearchModule) + return "" + root.appSearchModule.getSearchLocationObject() + } + + function resultItemClicked(itemId) { + if(!root.appSearchModule) + return + root.appSearchModule.resultItemClicked(itemId) + } +} diff --git a/ui/app/AppLayouts/stores/RootStore.qml b/ui/app/AppLayouts/stores/RootStore.qml index dd47716cce..2b554c7038 100644 --- a/ui/app/AppLayouts/stores/RootStore.qml +++ b/ui/app/AppLayouts/stores/RootStore.qml @@ -9,6 +9,10 @@ QtObject { property var communitiesModuleInst: communitiesModule property var observedCommunity: communitiesModuleInst.observedCommunity + property AppSearchStore appSearchStore: AppSearchStore { + appSearchModule: root.mainModuleInst.appSearchModule + } + property ProfileSectionStore profileSectionStore: ProfileSectionStore { } diff --git a/ui/app/AppMain.qml b/ui/app/AppMain.qml index c52737cd4a..5e4c2aaf32 100644 --- a/ui/app/AppMain.qml +++ b/ui/app/AppMain.qml @@ -189,7 +189,7 @@ Item { AppSearch{ id: appSearch - store: mainModule.appSearchModule + store: appMain.rootStore.appSearchStore } StatusAppLayout { diff --git a/ui/app/AppSearch.qml b/ui/app/AppSearch.qml index 7cbb6d9710..4b0c4d04e9 100644 --- a/ui/app/AppSearch.qml +++ b/ui/app/AppSearch.qml @@ -9,7 +9,7 @@ Item { property var store readonly property var searchMessages: Backpressure.debounce(searchPopup, 400, function (value) { - store.searchMessages(value) + appSearch.store.searchMessages(value) }) function openSearchPopup(){ @@ -17,7 +17,7 @@ Item { } Connections { - target: store.locationMenuModel + target: appSearch.store.locationMenuModel onModelAboutToBeReset: { for (var i = 2; i <= searchPopupMenu.count; i++) { //clear menu @@ -28,13 +28,18 @@ Item { } } + Connections { + target: appSearch.store.appSearchModule + onAppSearchCompleted: searchPopup.loading = false + } + StatusSearchLocationMenu { id: searchPopupMenu searchPopup: searchPopup - locationModel: store.locationMenuModel + locationModel: appSearch.store.locationMenuModel onItemClicked: { - store.setSearchLocation(firstLevelItemValue, secondLevelItemValue) + appSearch.store.setSearchLocation(firstLevelItemValue, secondLevelItemValue) if(searchPopup.searchText !== "") searchMessages(searchPopup.searchText) } @@ -47,13 +52,14 @@ Item { defaultSearchLocationText: qsTr("Anywhere") searchOptionsPopupMenu: searchPopupMenu - searchResults: store.resultModel + searchResults: appSearch.store.resultModel formatTimestampFn: function (ts) { return new Date(parseInt(ts, 10)).toLocaleString(Qt.locale(localAppSettings.locale)) } onSearchTextChanged: { + searchPopup.loading = true searchMessages(searchPopup.searchText); } onAboutToHide: { @@ -67,9 +73,9 @@ Item { onOpened: { searchPopup.resetSearchSelection(); searchPopup.forceActiveFocus() - store.prepareLocationMenuModel() + appSearch.store.prepareLocationMenuModel() - const jsonObj = store.getSearchLocationObject() + const jsonObj = appSearch.store.getSearchLocationObject() if (!jsonObj) { return @@ -78,7 +84,7 @@ Item { let obj = JSON.parse(jsonObj) if (obj.location === "") { if(obj.subLocation === "") { - store.setSearchLocation("", "") + appSearch.store.setSearchLocation("", "") } else { searchPopup.setSearchSelection(obj.subLocation.text, @@ -88,7 +94,7 @@ Item { obj.subLocation.iconName, obj.subLocation.identiconColor) - store.setSearchLocation("", obj.subLocation.value) + appSearch.store.setSearchLocation("", obj.subLocation.value) } } else { @@ -100,7 +106,7 @@ Item { obj.subLocation.iconName, obj.subLocation.identiconColor) - store.setSearchLocation(obj.location.value, obj.subLocation.value) + appSearch.store.setSearchLocation(obj.location.value, obj.subLocation.value) } else { searchPopup.setSearchSelection(obj.location.title, @@ -110,15 +116,13 @@ Item { obj.location.iconName, obj.location.identiconColor) - store.setSearchLocation(obj.location.value, obj.subLocation.value) + appSearch.store.setSearchLocation(obj.location.value, obj.subLocation.value) } } } onResultItemClicked: { searchPopup.close() - - // Not Refactored - //root.rootStore.chatsModelInst.switchToSearchedItem(itemId) + appSearch.store.resultItemClicked(itemId) } onResultItemTitleClicked: { diff --git a/ui/imports/shared/views/chat/MessageView.qml b/ui/imports/shared/views/chat/MessageView.qml index 68d61de886..6e3dec109e 100644 --- a/ui/imports/shared/views/chat/MessageView.qml +++ b/ui/imports/shared/views/chat/MessageView.qml @@ -193,9 +193,9 @@ Column { // return root.rootStore.showReactionAuthors(fromAccounts, emojiId) // } -// function startMessageFoundAnimation() { -// messageLoader.item.startMessageFoundAnimation(); -// } + function startMessageFoundAnimation() { + messageLoader.item.startMessageFoundAnimation(); + } /////////////////////////////////////////////