From 5da66988b7cfd8f9f7943d6646690cd59caaac66 Mon Sep 17 00:00:00 2001 From: Frank Rotermund Date: Sat, 23 Jul 2022 13:58:34 +0200 Subject: [PATCH] MESSENGER-3152 unignore alert --- Riot/Assets/de.lproj/Vector.strings | 1 + Riot/Assets/en.lproj/Vector.strings | 1 + Riot/Generated/Strings.swift | 4 ++ bwi/IgnoredUsers/IgnoredUser.swift | 3 - bwi/IgnoredUsers/IgnoredUsersView.swift | 84 +++++++++++++++++++++++-- 5 files changed, 84 insertions(+), 9 deletions(-) diff --git a/Riot/Assets/de.lproj/Vector.strings b/Riot/Assets/de.lproj/Vector.strings index 3d1c6eea8..d9ad269ef 100644 --- a/Riot/Assets/de.lproj/Vector.strings +++ b/Riot/Assets/de.lproj/Vector.strings @@ -277,6 +277,7 @@ "settings_night_mode" = "Nachtmodus"; "settings_enable_push_notif" = "Benachrichtigungen auf diesem Gerät"; "settings_unignore_user" = "Alle Nachrichten von %@ anzeigen?"; +"settings_unignore_user_message" = "Diese Aktion kann eine Weile dauern."; "settings_contacts_phonebook_country" = "Land des Telefonbuches"; "settings_labs_e2e_encryption" = "Ende-zu-Ende-Verschlüsselung"; "settings_version" = "Version %@"; diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 771288dc3..e462e9f38 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -665,6 +665,7 @@ Tap the + to start adding people."; "settings_show_url_previews_description" = "Previews will only be shown in unencrypted rooms."; "settings_unignore_user" = "Show all messages from %@?"; +"settings_unignore_user_message" = "This action may take a while."; "settings_contacts_enable_sync" = "Find your contacts"; "settings_contacts_phonebook_country" = "Phonebook country"; diff --git a/Riot/Generated/Strings.swift b/Riot/Generated/Strings.swift index 5b06d86cf..5d8c23f03 100644 --- a/Riot/Generated/Strings.swift +++ b/Riot/Generated/Strings.swift @@ -7515,6 +7515,10 @@ public class VectorL10n: NSObject { public static func settingsUnignoreUser(_ p1: String) -> String { return VectorL10n.tr("Vector", "settings_unignore_user", p1) } + /// This action may take a while. + public static var settingsUnignoreUserMessage: String { + return VectorL10n.tr("Vector", "settings_unignore_user_message") + } /// USER INTERFACE public static var settingsUserInterface: String { return VectorL10n.tr("Vector", "settings_user_interface") diff --git a/bwi/IgnoredUsers/IgnoredUser.swift b/bwi/IgnoredUsers/IgnoredUser.swift index 3cbb56f1c..0ea739ad5 100644 --- a/bwi/IgnoredUsers/IgnoredUser.swift +++ b/bwi/IgnoredUsers/IgnoredUser.swift @@ -28,12 +28,9 @@ class IgnoredUser: ObservableObject, Identifiable { self.displayName = displayName self.matrixId = matrixId self.avatar = avatar - - print("FROT: init \(self.displayName) \(self.matrixId) \(self.avatar)") } func avatarImage() -> UIImage { - print("FROT: \(self.avatar)") if let cachePath = MXMediaManager.thumbnailCachePath(forMatrixContentURI: self.avatar, andType: "image/jpeg", inFolder: nil, toFitViewSize: CGSize(width: 12, height: 12), with: MXThumbnailingMethodCrop) { if let image = MXMediaManager.loadThroughCache(withFilePath: cachePath) { return image diff --git a/bwi/IgnoredUsers/IgnoredUsersView.swift b/bwi/IgnoredUsers/IgnoredUsersView.swift index 7d87b0c9f..f3d722b72 100644 --- a/bwi/IgnoredUsers/IgnoredUsersView.swift +++ b/bwi/IgnoredUsers/IgnoredUsersView.swift @@ -50,7 +50,7 @@ struct IgnoredUsersView: View { var body: some View { List(ignoredUsers) { user in - IgnoredUserView(user: user) + IgnoredUserView(session:session, user: user) } .navigationTitle(NSLocalizedString("bwi_notification_times", tableName: "Bwi", comment: "")) .navigationBarTitleDisplayMode(.inline) @@ -60,7 +60,8 @@ struct IgnoredUsersView: View { fileprivate struct IgnoredUserView: View { @State private var showingAlert = false - var user: IgnoredUser + let session: MXSession? + let user: IgnoredUser var body: some View { Button (action: { @@ -79,10 +80,10 @@ fileprivate struct IgnoredUserView: View { } .alert(isPresented:$showingAlert) { Alert( - title: Text("Are you sure you want to delete this?"), - message: Text("\(self.user.displayName)"), - primaryButton: .destructive(Text("Delete")) { - print("Deleting...") + title: Text(VectorL10n.settingsUnignoreUser(self.user.displayName)), + message: Text(VectorL10n.settingsUnignoreUserMessage), + primaryButton: .default(Text(VectorL10n.yes)) { + unignoreUser(self.session, self.user) }, secondaryButton: .cancel() ) @@ -96,3 +97,74 @@ struct IgnoredUsersView_Previews: PreviewProvider { IgnoredUsersView(session: nil) } } + + +fileprivate func unignoreUser(_ session:MXSession?,_ user:IgnoredUser) { + if let session = session { + session.unIgnore(users: [user.matrixId], completion: { response in + + }) + } +} + +/* + MXSession* session = self.mainSession; + + NSString *ignoredUserId = session.ignoredUsers[row]; + + if (ignoredUserId) + { + [currentAlert dismissViewControllerAnimated:NO completion:nil]; + + __weak typeof(self) weakSelf = self; + + UIAlertController *unignorePrompt = [UIAlertController alertControllerWithTitle:[VectorL10n settingsUnignoreUser:ignoredUserId] message:nil preferredStyle:UIAlertControllerStyleAlert]; + + [unignorePrompt addAction:[UIAlertAction actionWithTitle:[VectorL10n yes] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + + if (weakSelf) + { + typeof(self) self = weakSelf; + self->currentAlert = nil; + + MXSession* session = self.mainSession; + + // Remove the member from the ignored user list + [self startActivityIndicator]; + [session unIgnoreUsers:@[ignoredUserId] success:^{ + + [self stopActivityIndicator]; + + } failure:^(NSError *error) { + + [self stopActivityIndicator]; + + MXLogDebug(@"[SettingsViewController] Unignore %@ failed", ignoredUserId); + + NSString *myUserId = session.myUser.userId; + [[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error userInfo:myUserId ? @{kMXKErrorUserIdKey: myUserId} : nil]; + + }]; + } + + }]]; + + [unignorePrompt addAction:[UIAlertAction actionWithTitle:[VectorL10n no] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + + if (weakSelf) + { + typeof(self) self = weakSelf; + self->currentAlert = nil; + } + + }]]; + + [unignorePrompt mxk_setAccessibilityIdentifier: @"SettingsVCUnignoreAlert"]; + [self presentViewController:unignorePrompt animated:YES completion:nil]; + currentAlert = unignorePrompt; + } + */