diff --git a/Sources/ChatFeature/Controllers/GroupChatController.swift b/Sources/ChatFeature/Controllers/GroupChatController.swift index 2411786865669256bff58b618488bf5fbab36aa4..ae732094cc8cc4304781ad90406b1d151722567f 100644 --- a/Sources/ChatFeature/Controllers/GroupChatController.swift +++ b/Sources/ChatFeature/Controllers/GroupChatController.swift @@ -317,7 +317,7 @@ extension GroupChatController: UICollectionViewDataSource { cellForItemAt indexPath: IndexPath ) -> UICollectionViewCell { - let item = sections[indexPath.section].elements[indexPath.item] + var item = sections[indexPath.section].elements[indexPath.item] let canReply: () -> Bool = { (item.status == .sent || item.status == .received) && item.networkId != nil } @@ -330,7 +330,31 @@ extension GroupChatController: UICollectionViewDataSource { let showRound: (String?) -> Void = viewModel.showRoundFrom(_:) let replyContent: (Data) -> (String, String) = viewModel.getReplyContent(for:) + var isSenderBanned = false + + if let database = try? DependencyInjection.Container.shared.resolve() as Database, + let sender = try? database.fetchContacts(.init(id: [item.senderId])).first { + isSenderBanned = sender.isBanned + } + if item.status == .received { + guard isSenderBanned == false else { + item.text = "This user has been banned" + + let cell: IncomingGroupTextCell = collectionView.dequeueReusableCell(forIndexPath: indexPath) + Bubbler.buildGroup( + bubble: cell.leftView, + with: item, + with: "Banned user" + ) + + cell.canReply = false + cell.performReply = {} + cell.leftView.didTapShowRound = {} + + return cell + } + if let replyMessageId = item.replyMessageId { let cell: IncomingGroupReplyCell = collectionView.dequeueReusableCell(forIndexPath: indexPath) diff --git a/Sources/ChatFeature/Controllers/SingleChatController.swift b/Sources/ChatFeature/Controllers/SingleChatController.swift index ebc780952bfadb1c96b8cb5706f864e90cb19d15..3d2a35d19c39a1b06a703a794e089e6adf196769 100644 --- a/Sources/ChatFeature/Controllers/SingleChatController.swift +++ b/Sources/ChatFeature/Controllers/SingleChatController.swift @@ -456,15 +456,7 @@ public final class SingleChatController: UIViewController { fatalError("[takeAppScreenshot]: Unable to get foreground window scene") } - let keyWindow: UIWindow? - - if #available(iOS 15.0, *) { - keyWindow = foregroundWindowScene.keyWindow - } else { - keyWindow = UIApplication.shared.keyWindow - } - - guard let keyWindow = keyWindow else { + guard let keyWindow = foregroundWindowScene.windows.first(where: \.isKeyWindow) else { fatalError("[takeAppScreenshot]: Unable to get key window") } diff --git a/Sources/Integration/Session/Session.swift b/Sources/Integration/Session/Session.swift index fb14ed89cb8a7a9a2203a166fba55c322dfa84ea..1dec54ded12e24b801769440f3542c769dcba565 100644 --- a/Sources/Integration/Session/Session.swift +++ b/Sources/Integration/Session/Session.swift @@ -442,6 +442,7 @@ public final class Session: SessionType { client.messages .sink { [unowned self] in if var contact = try? dbManager.fetchContacts(.init(id: [$0.senderId])).first { + guard contact.isBanned == false else { return } contact.isRecent = false _ = try? dbManager.saveContact(contact) } diff --git a/Sources/LaunchFeature/LaunchViewModel.swift b/Sources/LaunchFeature/LaunchViewModel.swift index 5d85f07c60490f9ebcf11976d03ae68ef046199d..0f0f7619952b134a90adb1262c792a4f1989dc48 100644 --- a/Sources/LaunchFeature/LaunchViewModel.swift +++ b/Sources/LaunchFeature/LaunchViewModel.swift @@ -87,8 +87,17 @@ final class LaunchViewModel { do { network.writeLogs() - // TODO: Retry inifitely if fails - let _ = try await fetchBannedList() + let bannedUids = try await fetchBannedList() // TODO: Retry inifitely if fails + + if let database = try? DependencyInjection.Container.shared.resolve() as Database { + if let bannedContacts = try? database.fetchContacts(Contact.Query(id: bannedUids, isBanned: false)) { + bannedContacts.forEach { + var contact = $0 + contact.isBanned = true + _ = try? database.saveContact(contact) + } + } + } network.updateNDF { [weak self] in guard let self = self else { return } @@ -211,16 +220,30 @@ final class LaunchViewModel { } } - private func fetchBannedList() async throws -> Data { - let url = URL(string: "https://elixxir-bins.s3.us-west-1.amazonaws.com/client/bannedUsers/banned.csv") + private func fetchBannedList() async throws -> Set<Data> { + let url = URL(string: "https://elixxir-bins.s3.us-west-1.amazonaws.com/client/bannedUsers/bannedTesting.csv") return try await withCheckedThrowingContinuation { continuation in URLSession.shared.dataTask(with: url!) { data, _, error in if let error = error { return continuation.resume(throwing: error) } - guard let data = data else { fatalError("?") } - return continuation.resume(returning: data) + guard let data = data else { + fatalError("No data was downloaded as banned users csv") + } + + guard let csvRaw = String(data: data, encoding: .utf8), + let csv = try? CSV<Enumerated>(string: csvRaw) else { + fatalError("CSV content couldn't be parsed correctly") + } + + guard let bannedUids = csv.columns?[0].rows else { + fatalError("It wasn't possible to get CSV uid array") + } + + return continuation.resume(returning: Set<Data>( + bannedUids.compactMap { $0.data(using: .utf8) } + )) }.resume() } } diff --git a/Sources/PushFeature/PushHandler.swift b/Sources/PushFeature/PushHandler.swift index 2e6dd801c618294f432cadbdea9a70d1d93493d6..9afec9261f1ee12d72eea3b68605ea989124895f 100644 --- a/Sources/PushFeature/PushHandler.swift +++ b/Sources/PushFeature/PushHandler.swift @@ -96,13 +96,6 @@ public final class PushHandler: PushHandling { return } - guard let showSender = defaults.value(forKey: Constants.usernamesSetting) as? Bool, showSender == true else { - pushes.map { ($0.type.unknownSenderContent!, $0) } - .map(contentsBuilder.build) - .forEach { completion($0) } - return - } - let dbPath = FileManager.default .containerURL(forSecurityApplicationGroupIdentifier: "group.elixxir.messenger")! .appendingPathComponent("xxm_database") @@ -119,8 +112,12 @@ public final class PushHandler: PushHandling { return nil } - let name = (contact.nickname ?? contact.username) ?? "" - return ($0.type.knownSenderContent(name)!, $0) + if let showSender = defaults.value(forKey: Constants.usernamesSetting) as? Bool, showSender == true { + let name = (contact.nickname ?? contact.username) ?? "" + return ($0.type.knownSenderContent(name)!, $0) + } else { + return ($0.type.unknownSenderContent!, $0) + } } tuples