From 8bc4ea6d478ff4ec7488862c848e5acec20e0147 Mon Sep 17 00:00:00 2001 From: Bruno Muniz Azevedo Filho <bruno@elixxir.io> Date: Fri, 12 Aug 2022 02:07:02 -0300 Subject: [PATCH] Rejecting notifications from banned/blocked users and not allowing to scan those --- .../ChatFeature/ViewModels/GroupChatViewModel.swift | 8 +++++++- .../ChatListFeature/ViewModel/ChatListViewModel.swift | 8 ++++++-- Sources/LaunchFeature/LaunchViewModel.swift | 4 +++- Sources/PushFeature/PushHandler.swift | 4 ++++ .../ViewModels/SearchRightViewModel.swift | 10 ++++++++++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Sources/ChatFeature/ViewModels/GroupChatViewModel.swift b/Sources/ChatFeature/ViewModels/GroupChatViewModel.swift index aa1dbefc..fc7a30d4 100644 --- a/Sources/ChatFeature/ViewModels/GroupChatViewModel.swift +++ b/Sources/ChatFeature/ViewModels/GroupChatViewModel.swift @@ -103,7 +103,13 @@ final class GroupChatViewModel { return "[DELETED]" } - return (contact.nickname ?? contact.username) ?? "Fetching username..." + var name = (contact.nickname ?? contact.username) ?? "Fetching username..." + + if contact.isBlocked { + name = "\(name) (Blocked)" + } + + return name } func didRequestReply(_ message: Message) { diff --git a/Sources/ChatListFeature/ViewModel/ChatListViewModel.swift b/Sources/ChatListFeature/ViewModel/ChatListViewModel.swift index 470e9cf3..1b094ffa 100644 --- a/Sources/ChatListFeature/ViewModel/ChatListViewModel.swift +++ b/Sources/ChatListFeature/ViewModel/ChatListViewModel.swift @@ -135,11 +135,15 @@ final class ChatListViewModel { isBanned: false ), groupChatInfoQuery: GroupChatInfo.Query( - authStatus: [.participating] + authStatus: [.participating], + isLeaderBlocked: false, + isLeaderBanned: false ), groupQuery: Group.Query( withMessages: false, - authStatus: [.participating] + authStatus: [.participating], + isLeaderBlocked: false, + isLeaderBanned: false ) )) .assertNoFailure() diff --git a/Sources/LaunchFeature/LaunchViewModel.swift b/Sources/LaunchFeature/LaunchViewModel.swift index 68f3fab8..5d85f07c 100644 --- a/Sources/LaunchFeature/LaunchViewModel.swift +++ b/Sources/LaunchFeature/LaunchViewModel.swift @@ -137,8 +137,10 @@ final class LaunchViewModel { } func getContactWith(userId: Data) -> Contact? { + let query = Contact.Query(id: [userId], isBlocked: false, isBanned: false) + guard let session = try? DependencyInjection.Container.shared.resolve() as SessionType, - let contact = try? session.dbManager.fetchContacts(.init(id: [userId])).first else { + let contact = try? session.dbManager.fetchContacts(query).first else { return nil } diff --git a/Sources/PushFeature/PushHandler.swift b/Sources/PushFeature/PushHandler.swift index f750c575..2e6dd801 100644 --- a/Sources/PushFeature/PushHandler.swift +++ b/Sources/PushFeature/PushHandler.swift @@ -115,6 +115,10 @@ public final class PushHandler: PushHandling { return ($0.type.unknownSenderContent!, $0) } + if contact.isBlocked || contact.isBanned { + return nil + } + let name = (contact.nickname ?? contact.username) ?? "" return ($0.type.knownSenderContent(name)!, $0) } diff --git a/Sources/SearchFeature/ViewModels/SearchRightViewModel.swift b/Sources/SearchFeature/ViewModels/SearchRightViewModel.swift index 5cfe38db..148db4ca 100644 --- a/Sources/SearchFeature/ViewModels/SearchRightViewModel.swift +++ b/Sources/SearchFeature/ViewModels/SearchRightViewModel.swift @@ -78,6 +78,16 @@ final class SearchRightViewModel { /// that we already have /// if let alreadyContact = try? session.dbManager.fetchContacts(.init(id: [userId])).first { + if alreadyContact.isBlocked { + statusSubject.send(.failed(.unknown("You previously blocked this user."))) + return + } + + if alreadyContact.isBanned { + statusSubject.send(.failed(.unknown("This user was banned."))) + return + } + /// Show error accordingly to the auth status /// if alreadyContact.authStatus == .friend { -- GitLab