From 8144ccaf4609b3294afaa8674da1a261f0d2d4fc Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Tue, 9 Jan 2024 22:36:09 +0000 Subject: [PATCH] fix: use local nickname in chat input link previews (#13168) --- .../chat_section/chat_content/input_area/controller.nim | 7 +++++++ .../chat_section/chat_content/input_area/io_interface.nim | 4 ++++ .../main/chat_section/chat_content/input_area/module.nim | 7 ++++++- .../main/chat_section/chat_content/input_area/view.nim | 7 ++++++- src/app/modules/main/chat_section/chat_content/module.nim | 2 +- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/app/modules/main/chat_section/chat_content/input_area/controller.nim b/src/app/modules/main/chat_section/chat_content/input_area/controller.nim index a9393e4f01..61e6e30cfe 100644 --- a/src/app/modules/main/chat_section/chat_content/input_area/controller.nim +++ b/src/app/modules/main/chat_section/chat_content/input_area/controller.nim @@ -3,6 +3,7 @@ import io_interface, tables, sets import ../../../../../../app_service/service/settings/service as settings_service import ../../../../../../app_service/service/message/service as message_service +import ../../../../../../app_service/service/contacts/service as contact_service import ../../../../../../app_service/service/community/service as community_service import ../../../../../../app_service/service/chat/service as chat_service import ../../../../../../app_service/service/gif/service as gif_service @@ -22,6 +23,7 @@ type chatId: string belongsToCommunity: bool communityService: community_service.Service + contactService: contact_service.Service chatService: chat_service.Service gifService: gif_service.Service messageService: message_service.Service @@ -42,6 +44,7 @@ proc newController*( belongsToCommunity: bool, chatService: chat_service.Service, communityService: community_service.Service, + contactService: contact_service.Service, gifService: gif_service.Service, messageService: message_service.Service, settingsService: settings_service.Service @@ -54,6 +57,7 @@ proc newController*( result.belongsToCommunity = belongsToCommunity result.chatService = chatService result.communityService = communityService + result.contactService = contactService result.gifService = gifService result.messageService = messageService result.settingsService = settingsService @@ -306,3 +310,6 @@ proc setLinkPreviewEnabled*(self: Controller, enabled: bool) = proc onUnfurlingModeChanged(self: Controller, value: UrlUnfurlingMode) = self.linkPreviewPersistentSetting = value self.reloadUnfurlingPlan() + +proc getContactDetails*(self: Controller, contactId: string): ContactDetails = + return self.contactService.getContactDetails(contactId) diff --git a/src/app/modules/main/chat_section/chat_content/input_area/io_interface.nim b/src/app/modules/main/chat_section/chat_content/input_area/io_interface.nim index a03db50845..c4ca48d9bd 100644 --- a/src/app/modules/main/chat_section/chat_content/input_area/io_interface.nim +++ b/src/app/modules/main/chat_section/chat_content/input_area/io_interface.nim @@ -2,6 +2,7 @@ import NimQml, tables import ../../../../../../app_service/service/gif/dto import ../../../../../../app_service/service/message/dto/link_preview +import ../../../../../../app_service/service/contacts/dto/contact_details type AccessInterface* {.pure inheritable.} = ref object of RootObj @@ -134,3 +135,6 @@ method setLinkPreviewEnabledForThisMessage*(self: AccessInterface, enabled: bool method setUrls*(self: AccessInterface, urls: seq[string]) {.base.} = raise newException(ValueError, "No implementation available") + +method getContactDetails*(self: AccessInterface, contactId: string): ContactDetails {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/chat_section/chat_content/input_area/module.nim b/src/app/modules/main/chat_section/chat_content/input_area/module.nim index 980100666f..dd3c869093 100644 --- a/src/app/modules/main/chat_section/chat_content/input_area/module.nim +++ b/src/app/modules/main/chat_section/chat_content/input_area/module.nim @@ -10,6 +10,7 @@ import ../../../../../../app_service/service/message/service as message_service import ../../../../../../app_service/service/message/dto/link_preview import ../../../../../../app_service/service/chat/service as chat_service import ../../../../../../app_service/service/community/service as community_service +import ../../../../../../app_service/service/contacts/service as contact_service import ../../../../../../app_service/service/gif/service as gif_service import ../../../../../../app_service/service/gif/dto @@ -31,6 +32,7 @@ proc newModule*( belongsToCommunity: bool, chatService: chat_service.Service, communityService: community_service.Service, + contactService: contact_service.Service, gifService: gif_service.Service, messageService: message_service.Service, settingsService: settings_service.Service @@ -40,7 +42,7 @@ proc newModule*( result.delegate = delegate result.view = view.newView(result) result.viewVariant = newQVariant(result.view) - result.controller = controller.newController(result, events, sectionId, chatId, belongsToCommunity, chatService, communityService, gifService, messageService, settingsService) + result.controller = controller.newController(result, events, sectionId, chatId, belongsToCommunity, chatService, communityService, contactService, gifService, messageService, settingsService) result.moduleLoaded = false method delete*(self: Module) = @@ -192,3 +194,6 @@ method setLinkPreviewEnabledForThisMessage*(self: Module, value: bool) = method setUrls*(self: Module, urls: seq[string]) = self.view.setUrls(urls) + +method getContactDetails*(self: Module, contactId: string): ContactDetails = + return self.controller.getContactDetails(contactId) diff --git a/src/app/modules/main/chat_section/chat_content/input_area/view.nim b/src/app/modules/main/chat_section/chat_content/input_area/view.nim index c6a979c374..16fb59c7e6 100644 --- a/src/app/modules/main/chat_section/chat_content/input_area/view.nim +++ b/src/app/modules/main/chat_section/chat_content/input_area/view.nim @@ -1,4 +1,4 @@ -import NimQml +import NimQml, sets import ./io_interface import ./gif_column_model import ./preserved_properties @@ -238,6 +238,11 @@ QtObject: proc updateLinkPreviewsFromCache*(self: View, urls: seq[string]) = let linkPreviews = self.delegate.linkPreviewsFromCache(urls) self.linkPreviewModel.updateLinkPreviews(linkPreviews) + + for contactId in self.linkPreviewModel.getContactIds().items: + let contact = self.delegate.getContactDetails(contactId) + if contact.dto.displayName != "": + self.linkPreviewModel.setContactInfo(contact) proc setLinkPreviewUrls*(self: View, urls: seq[string]) = self.linkPreviewModel.setUrls(urls) diff --git a/src/app/modules/main/chat_section/chat_content/module.nim b/src/app/modules/main/chat_section/chat_content/module.nim index 383efc861e..6e0ddfdc2a 100644 --- a/src/app/modules/main/chat_section/chat_content/module.nim +++ b/src/app/modules/main/chat_section/chat_content/module.nim @@ -59,7 +59,7 @@ proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitt result.moduleLoaded = false result.inputAreaModule = input_area_module.newModule(result, events, sectionId, chatId, belongsToCommunity, - chatService, communityService, gifService, messageService, settingsService) + chatService, communityService, contactService, gifService, messageService, settingsService) result.messagesModule = messages_module.newModule(result, events, sectionId, chatId, belongsToCommunity, contactService, communityService, chatService, messageService, mailserversService, sharedUrlsService) result.usersModule = users_module.newModule(events, sectionId, chatId, belongsToCommunity,