Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(block): remove chat and messages when blocking a contact #16889

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/app/modules/main/chat_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ method onCategoryNameChanged*(self: Module, category: Category) =
self.view.chatsModel().renameCategory(category.id, category.name)

method onCommunityChannelDeletedOrChatLeft*(self: Module, chatId: string) =
if(not self.chatContentModules.contains(chatId)):
if not self.chatContentModules.contains(chatId):
return
self.view.chatsModel().removeItemById(chatId)
self.removeSubmodule(chatId)
Expand Down Expand Up @@ -1197,6 +1197,7 @@ method blockContact*(self: Module, publicKey: string) =
method onContactBlocked*(self: Module, publicKey: string) =
self.view.contactRequestsModel().removeItemById(publicKey)
self.view.chatsModel().changeBlockedOnItemById(publicKey, blocked=true)
self.onCommunityChannelDeletedOrChatLeft(publicKey)

method onContactUnblocked*(self: Module, publicKey: string) =
self.view.chatsModel().changeBlockedOnItemById(publicKey, blocked=false)
Expand Down
8 changes: 0 additions & 8 deletions src/app_service/service/chat/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ type
role*: MemberRole
joined*: bool

RpcResponseArgs* = ref object of Args
response*: RpcResponse[JsonNode]

CheckChannelPermissionsResponseArgs* = ref object of Args
communityId*: string
chatId*: string
Expand Down Expand Up @@ -120,7 +117,6 @@ const SIGNAL_CHAT_MEMBER_UPDATED* = "chatMemberUpdated"
const SIGNAL_CHAT_SWITCH_TO_OR_CREATE_1_1_CHAT* = "switchToOrCreateOneToOneChat"
const SIGNAL_CHAT_ADDED_OR_UPDATED* = "chatAddedOrUpdated"
const SIGNAL_CHAT_CREATED* = "chatCreated"
const SIGNAL_CHAT_REQUEST_UPDATE_AFTER_SEND* = "chatRequestUpdateAfterSend"
const SIGNAL_CHECK_CHANNEL_PERMISSIONS_RESPONSE* = "checkChannelPermissionsResponse"
const SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_RESPONSE* = "checkAllChannelsPermissionsResponse"
const SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_FAILED* = "checkAllChannelsPermissionsFailed"
Expand Down Expand Up @@ -183,10 +179,6 @@ QtObject:
for clearedHistoryDto in receivedData.clearedHistories:
self.events.emit(SIGNAL_CHAT_HISTORY_CLEARED, ChatArgs(chatId: clearedHistoryDto.chatId))

self.events.on(SIGNAL_CHAT_REQUEST_UPDATE_AFTER_SEND) do(e: Args):
var args = RpcResponseArgs(e)
discard self.processMessengerResponse(args.response)

proc asyncGetActiveChats*(self: Service) =
let arg = AsyncGetActiveChatsTaskArg(
tptr: asyncGetActiveChatsTask,
Expand Down
9 changes: 3 additions & 6 deletions src/app_service/service/contacts/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ type
publicKey*: string
ok*: bool

RpcResponseArgs* = ref object of Args
response*: RpcResponse[JsonNode]

AppendChatMessagesArgs* = ref object of Args
chatId*: string
messages*: JsonNode
Expand Down Expand Up @@ -395,9 +392,9 @@ QtObject:
if self.contacts.hasKey(publicKey):
if self.contacts[publicKey].dto.added and not self.contacts[publicKey].dto.removed and contact.added and not contact.removed:
signal = SIGNAL_CONTACT_UPDATED
if contact.removed:
singletonInstance.globalEvents.showContactRemoved("Contact removed", fmt "You removed {contact.displayName} as a contact", contact.id)
signal = SIGNAL_CONTACT_REMOVED
if contact.removed and not self.contacts[publicKey].dto.removed:
caybro marked this conversation as resolved.
Show resolved Hide resolved
singletonInstance.globalEvents.showContactRemoved("Contact removed", fmt "You removed {contact.displayName} as a contact", contact.id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to do the notification here at all; we do those (in the correct format) in Popups.qml already. There are different permutations, depending on what other actions the user takes via the popups (like marking as untrosted, blocking, etc). All of these are processed at once, so that you don't get a single notification for each action.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also (not a big deal atm) this is not translatable at all

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. I guess we have a couple of stray notifications in Nim. I don't know if we have already an issue to refactor those to move them to QML

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there was some initial effort by Noelia (see ToastsManager.qml) but never finished actually; I guess here's one of those (many) still done on the NIM side

signal = SIGNAL_CONTACT_REMOVED

self.contacts[publicKey] = self.constructContactDetails(contact)
self.events.emit(signal, ContactArgs(contactId: publicKey))
Expand Down
2 changes: 1 addition & 1 deletion src/backend/contacts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ proc getContacts*(): RpcResponse[JsonNode] =
result = callPrivateRPC("contacts".prefix, payload)

proc blockContact*(id: string): RpcResponse[JsonNode] =
result = callPrivateRPC("blockContactDesktop".prefix, %* [id])
result = callPrivateRPC("blockContact".prefix, %* [id])

proc unblockContact*(id: string): RpcResponse[JsonNode] =
result = callPrivateRPC("unblockContact".prefix, %* [id])
Expand Down