Skip to content
Snippets Groups Projects
Commit a6aa22bd authored by Bruno Muniz's avatar Bruno Muniz :apple:
Browse files

Implemented missing requirements except for APi reporting

parent b26c12d6
No related branches found
No related tags found
3 merge requests!71Releasing v1.1.5 (214),!69Implemented filtering for banned/blocked users and reporting,!67v1.1.5 b(203)
...@@ -317,7 +317,7 @@ extension GroupChatController: UICollectionViewDataSource { ...@@ -317,7 +317,7 @@ extension GroupChatController: UICollectionViewDataSource {
cellForItemAt indexPath: IndexPath cellForItemAt indexPath: IndexPath
) -> UICollectionViewCell { ) -> UICollectionViewCell {
let item = sections[indexPath.section].elements[indexPath.item] var item = sections[indexPath.section].elements[indexPath.item]
let canReply: () -> Bool = { let canReply: () -> Bool = {
(item.status == .sent || item.status == .received) && item.networkId != nil (item.status == .sent || item.status == .received) && item.networkId != nil
} }
...@@ -330,7 +330,31 @@ extension GroupChatController: UICollectionViewDataSource { ...@@ -330,7 +330,31 @@ extension GroupChatController: UICollectionViewDataSource {
let showRound: (String?) -> Void = viewModel.showRoundFrom(_:) let showRound: (String?) -> Void = viewModel.showRoundFrom(_:)
let replyContent: (Data) -> (String, String) = viewModel.getReplyContent(for:) 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 { 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 { if let replyMessageId = item.replyMessageId {
let cell: IncomingGroupReplyCell = collectionView.dequeueReusableCell(forIndexPath: indexPath) let cell: IncomingGroupReplyCell = collectionView.dequeueReusableCell(forIndexPath: indexPath)
......
...@@ -456,15 +456,7 @@ public final class SingleChatController: UIViewController { ...@@ -456,15 +456,7 @@ public final class SingleChatController: UIViewController {
fatalError("[takeAppScreenshot]: Unable to get foreground window scene") fatalError("[takeAppScreenshot]: Unable to get foreground window scene")
} }
let keyWindow: UIWindow? guard let keyWindow = foregroundWindowScene.windows.first(where: \.isKeyWindow) else {
if #available(iOS 15.0, *) {
keyWindow = foregroundWindowScene.keyWindow
} else {
keyWindow = UIApplication.shared.keyWindow
}
guard let keyWindow = keyWindow else {
fatalError("[takeAppScreenshot]: Unable to get key window") fatalError("[takeAppScreenshot]: Unable to get key window")
} }
......
...@@ -442,6 +442,7 @@ public final class Session: SessionType { ...@@ -442,6 +442,7 @@ public final class Session: SessionType {
client.messages client.messages
.sink { [unowned self] in .sink { [unowned self] in
if var contact = try? dbManager.fetchContacts(.init(id: [$0.senderId])).first { if var contact = try? dbManager.fetchContacts(.init(id: [$0.senderId])).first {
guard contact.isBanned == false else { return }
contact.isRecent = false contact.isRecent = false
_ = try? dbManager.saveContact(contact) _ = try? dbManager.saveContact(contact)
} }
......
...@@ -87,8 +87,17 @@ final class LaunchViewModel { ...@@ -87,8 +87,17 @@ final class LaunchViewModel {
do { do {
network.writeLogs() network.writeLogs()
// TODO: Retry inifitely if fails let bannedUids = try await fetchBannedList() // TODO: Retry inifitely if fails
let _ = try await fetchBannedList()
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 network.updateNDF { [weak self] in
guard let self = self else { return } guard let self = self else { return }
...@@ -211,16 +220,30 @@ final class LaunchViewModel { ...@@ -211,16 +220,30 @@ final class LaunchViewModel {
} }
} }
private func fetchBannedList() async throws -> Data { private func fetchBannedList() async throws -> Set<Data> {
let url = URL(string: "https://elixxir-bins.s3.us-west-1.amazonaws.com/client/bannedUsers/banned.csv") let url = URL(string: "https://elixxir-bins.s3.us-west-1.amazonaws.com/client/bannedUsers/bannedTesting.csv")
return try await withCheckedThrowingContinuation { continuation in return try await withCheckedThrowingContinuation { continuation in
URLSession.shared.dataTask(with: url!) { data, _, error in URLSession.shared.dataTask(with: url!) { data, _, error in
if let error = error { if let error = error {
return continuation.resume(throwing: error) return continuation.resume(throwing: error)
} }
guard let data = data else { fatalError("?") } guard let data = data else {
return continuation.resume(returning: data) 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() }.resume()
} }
} }
......
...@@ -96,13 +96,6 @@ public final class PushHandler: PushHandling { ...@@ -96,13 +96,6 @@ public final class PushHandler: PushHandling {
return 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 let dbPath = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: "group.elixxir.messenger")! .containerURL(forSecurityApplicationGroupIdentifier: "group.elixxir.messenger")!
.appendingPathComponent("xxm_database") .appendingPathComponent("xxm_database")
...@@ -119,8 +112,12 @@ public final class PushHandler: PushHandling { ...@@ -119,8 +112,12 @@ public final class PushHandler: PushHandling {
return nil return nil
} }
let name = (contact.nickname ?? contact.username) ?? "" if let showSender = defaults.value(forKey: Constants.usernamesSetting) as? Bool, showSender == true {
return ($0.type.knownSenderContent(name)!, $0) let name = (contact.nickname ?? contact.username) ?? ""
return ($0.type.knownSenderContent(name)!, $0)
} else {
return ($0.type.unknownSenderContent!, $0)
}
} }
tuples tuples
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment