diff --git a/src/app/modules/main/chat_section/chat_content/chat_details.nim b/src/app/modules/main/chat_section/chat_content/chat_details.nim index 0f4305ab4b..7fed85846d 100644 --- a/src/app/modules/main/chat_section/chat_content/chat_details.nim +++ b/src/app/modules/main/chat_section/chat_content/chat_details.nim @@ -17,6 +17,7 @@ QtObject: notificationsCount: int muted: bool position: int + isMutualContact: bool proc delete*(self: ChatDetails) = self.QObject.delete @@ -26,8 +27,9 @@ QtObject: result.QObject.setup proc setChatDetails*(self: ChatDetails, id: string, `type`: int, belongsToCommunity, - isUsersListAvailable: bool, name, icon: string, color, description, - emoji: string, hasUnreadMessages: bool, notificationsCount: int, muted: bool, position: int) = + isUsersListAvailable: bool, name, icon: string, color, description, + emoji: string, hasUnreadMessages: bool, notificationsCount: int, muted: bool, position: int, + isMutualContact: bool = false) = self.id = id self.`type` = `type` self.belongsToCommunity = belongsToCommunity @@ -41,6 +43,7 @@ QtObject: self.notificationsCount = notificationsCount self.muted = muted self.position = position + self.isMutualContact = isMutualContact proc getId(self: ChatDetails): string {.slot.} = return self.id @@ -160,3 +163,14 @@ QtObject: proc setPotion*(self: ChatDetails, value: int) = # this is not a slot self.position = value self.positionChanged() + + proc isMutualContactChanged(self: ChatDetails) {.signal.} + proc getIsMutualContact(self: ChatDetails): bool {.slot.} = + return self.isMutualContact + QtProperty[bool] isMutualContact: + read = getIsMutualContact + notify = isMutualContactChanged + + proc setIsMutualContact*(self: ChatDetails, value: bool) = # this is not a slot + self.isMutualContact = value + self.isMutualContactChanged() diff --git a/src/app/modules/main/chat_section/chat_content/controller.nim b/src/app/modules/main/chat_section/chat_content/controller.nim index 00c75de0c8..40674036e3 100644 --- a/src/app/modules/main/chat_section/chat_content/controller.nim +++ b/src/app/modules/main/chat_section/chat_content/controller.nim @@ -30,6 +30,9 @@ type communityService: community_service.Service messageService: message_service.Service +# Forward declaration +proc getChatDetails*(self: Controller): ChatDto + proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter, sectionId: string, chatId: string, belongsToCommunity: bool, isUsersListAvailable: bool, settingsService: settings_service.Service, contactService: contact_service.Service, chatService: chat_service.Service, @@ -106,6 +109,30 @@ proc init*(self: Controller) = self.events.on(SIGNAL_CONTACT_UPDATED) do(e: Args): var args = ContactArgs(e) self.delegate.onContactDetailsUpdated(args.contactId) + if (args.contactId == self.chatId): + self.delegate.onMutualContactChanged() + + let chatDto = self.getChatDetails() + if(chatDto.chatType == ChatType.OneToOne): + self.events.on(SIGNAL_CONTACT_ADDED) do(e: Args): + var args = ContactArgs(e) + if (args.contactId == self.chatId): + self.delegate.onMutualContactChanged() + + self.events.on(SIGNAL_CONTACT_REMOVED) do(e: Args): + var args = ContactArgs(e) + if (args.contactId == self.chatId): + self.delegate.onMutualContactChanged() + + self.events.on(SIGNAL_CONTACT_BLOCKED) do(e: Args): + var args = ContactArgs(e) + if (args.contactId == self.chatId): + self.delegate.onMutualContactChanged() + + self.events.on(SIGNAL_CONTACT_UNBLOCKED) do(e: Args): + var args = ContactArgs(e) + if (args.contactId == self.chatId): + self.delegate.onMutualContactChanged() self.events.on(SIGNAL_MESSAGE_DELETION) do(e: Args): let args = MessageDeletedArgs(e) diff --git a/src/app/modules/main/chat_section/chat_content/io_interface.nim b/src/app/modules/main/chat_section/chat_content/io_interface.nim index 95295abdbc..ac7997a3a4 100644 --- a/src/app/modules/main/chat_section/chat_content/io_interface.nim +++ b/src/app/modules/main/chat_section/chat_content/io_interface.nim @@ -111,3 +111,6 @@ method amIChatAdmin*(self: AccessInterface): bool {.base.} = method downloadMessages*(self: AccessInterface, filePath: string) = raise newException(ValueError, "No implementation available") + +method onMutualContactChanged*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") 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 fef1f53ee4..842236ba8e 100644 --- a/src/app/modules/main/chat_section/chat_content/module.nim +++ b/src/app/modules/main/chat_section/chat_content/module.nim @@ -75,13 +75,18 @@ method load*(self: Module) = let notificationsCount = chatDto.unviewedMentionsCount var chatName = chatDto.name var chatImage = chatDto.icon + var isMutualContact = false if(chatDto.chatType == ChatType.OneToOne): - (chatName, chatImage) = self.controller.getOneToOneChatNameAndImage() + let contactDto = self.controller.getContactById(self.controller.getMyChatId()) + chatName = contactDto.userNameOrAlias() + isMutualContact = contactDto.isMutualContact + if(contactDto.image.thumbnail.len > 0): + chatImage = contactDto.image.thumbnail self.view.load(chatDto.id, chatDto.chatType.int, self.controller.belongsToCommunity(), self.controller.isUsersListAvailable(), chatName, chatImage, chatDto.color, chatDto.description, chatDto.emoji, hasNotification, notificationsCount, - chatDto.muted, chatDto.position) + chatDto.muted, chatDto.position, isMutualContact) self.inputAreaModule.load() self.messagesModule.load() @@ -335,3 +340,8 @@ method onChatRenamed*(self: Module, newName: string) = method downloadMessages*(self: Module, filePath: string) = let messages = self.messagesModule.getMessages() self.controller.downloadMessages(messages, filePath) + +method onMutualContactChanged*(self: Module) = + let contactDto = self.controller.getContactById(self.controller.getMyChatId()) + let isMutualContact = contactDto.isMutualContact + self.view.onMutualContactChanged(isMutualContact) diff --git a/src/app/modules/main/chat_section/chat_content/view.nim b/src/app/modules/main/chat_section/chat_content/view.nim index 0a2636c34a..c3ec185d4d 100644 --- a/src/app/modules/main/chat_section/chat_content/view.nim +++ b/src/app/modules/main/chat_section/chat_content/view.nim @@ -31,10 +31,10 @@ QtObject: result.chatDetailsVariant = newQVariant(result.chatDetails) proc load*(self: View, id: string, `type`: int, belongsToCommunity, isUsersListAvailable: bool, - name, icon: string, color, description, emoji: string, - hasUnreadMessages: bool, notificationsCount: int, muted: bool, position: int) = + name, icon: string, color, description, emoji: string, hasUnreadMessages: bool, + notificationsCount: int, muted: bool, position: int, isMutualContact: bool) = self.chatDetails.setChatDetails(id, `type`, belongsToCommunity, isUsersListAvailable, name, icon, - color, description, emoji, hasUnreadMessages, notificationsCount, muted, position) + color, description, emoji, hasUnreadMessages, notificationsCount, muted, position, isMutualContact) self.delegate.viewDidLoad() self.chatDetailsChanged() @@ -123,5 +123,8 @@ QtObject: self.chatDetails.setName(name) self.chatDetailsChanged() + proc onMutualContactChanged*(self: View, value: bool) = + self.chatDetails.setIsMutualContact(value) + proc downloadMessages*(self: View, filePath: string) {.slot.} = self.delegate.downloadMessages(filePath) \ No newline at end of file diff --git a/src/app_service/service/contacts/dto/contacts.nim b/src/app_service/service/contacts/dto/contacts.nim index e6423a7084..5be676f86c 100644 --- a/src/app_service/service/contacts/dto/contacts.nim +++ b/src/app_service/service/contacts/dto/contacts.nim @@ -120,7 +120,7 @@ proc isBlocked*(self: ContactsDto): bool = proc isMutualContact*(self: ContactsDto): bool = # TODO not implemented in `status-go` yet # But for now we consider that contact is mutual contact if I added him and he added me. - return self.hasAddedUs and self.added + return self.hasAddedUs and self.added and not self.removed and not self.blocked proc isContactVerified*(self: ContactsDto): bool = # TODO not implemented in `status-go` yet diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index 6fdea4874b..6b749dfcd6 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -197,9 +197,7 @@ QtObject: elif (group == ContactsGroup.MyMutualContacts): # we need to revise this when we introduce "identity verification" feature return contacts.filter(x => x.id != myPubKey and - x.isMutualContact() and - not x.isContactRemoved() and - not x.isBlocked()) + x.isMutualContact()) elif (group == ContactsGroup.AllKnownContacts): return contacts @@ -322,6 +320,7 @@ QtObject: var contact = self.getContactById(publicKey) contact.added = true + contact.removed = false self.saveContact(contact) self.events.emit(SIGNAL_CONTACT_ADDED, ContactArgs(contactId: contact.id))