From 824db1fab34985fbe8c7ad1e1540ca54331de6ee Mon Sep 17 00:00:00 2001 From: manuroe Date: Mon, 20 May 2019 17:31:25 +0200 Subject: [PATCH] Reactions: Add a labs setting #2441 --- Riot/Assets/en.lproj/Vector.strings | 1 + Riot/Generated/Strings.swift | 4 +++ Riot/Managers/Settings/RiotSettings.swift | 9 ++++++ .../Modules/Room/DataSources/RoomDataSource.m | 1 + Riot/Modules/Room/RoomViewController.m | 2 +- .../Modules/Settings/SettingsViewController.m | 32 ++++++++++++++++++- 6 files changed, 47 insertions(+), 2 deletions(-) diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 13db82f5c..31ca8d5bf 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -406,6 +406,7 @@ "settings_labs_room_members_lazy_loading" = "Lazy load rooms members"; "settings_labs_room_members_lazy_loading_error_message" = "Your homeserver does not support lazy loading of room members yet. Try later."; "settings_labs_create_conference_with_jitsi" = "Create conference calls with jitsi"; +"settings_labs_message_reaction" = "React to messages with emoji"; "settings_version" = "Version %@"; "settings_olm_version" = "Olm Version %@"; diff --git a/Riot/Generated/Strings.swift b/Riot/Generated/Strings.swift index 44c885e30..6bfea7cf9 100644 --- a/Riot/Generated/Strings.swift +++ b/Riot/Generated/Strings.swift @@ -2474,6 +2474,10 @@ internal enum VectorL10n { internal static var settingsLabsE2eEncryptionPromptMessage: String { return VectorL10n.tr("Vector", "settings_labs_e2e_encryption_prompt_message") } + /// React to messages with emoji + internal static var settingsLabsMessageReaction: String { + return VectorL10n.tr("Vector", "settings_labs_message_reaction") + } /// Lazy load rooms members internal static var settingsLabsRoomMembersLazyLoading: String { return VectorL10n.tr("Vector", "settings_labs_room_members_lazy_loading") diff --git a/Riot/Managers/Settings/RiotSettings.swift b/Riot/Managers/Settings/RiotSettings.swift index 6db8ec7b3..09d5220ff 100644 --- a/Riot/Managers/Settings/RiotSettings.swift +++ b/Riot/Managers/Settings/RiotSettings.swift @@ -26,6 +26,7 @@ final class RiotSettings: NSObject { static let enableCrashReport = "enableCrashReport" static let enableRageShake = "enableRageShake" static let createConferenceCallsWithJitsi = "createConferenceCallsWithJitsi" + static let messageReaction = "messageReaction" static let userInterfaceTheme = "userInterfaceTheme" static let notificationsShowDecryptedContent = "showDecryptedContent" static let pinRoomsWithMissedNotifications = "pinRoomsWithMissedNotif" @@ -119,4 +120,12 @@ final class RiotSettings: NSObject { UserDefaults.standard.set(newValue, forKey: UserDefaultsKeys.createConferenceCallsWithJitsi) } } + + var messageReaction: Bool { + get { + return UserDefaults.standard.bool(forKey: UserDefaultsKeys.messageReaction) + } set { + UserDefaults.standard.set(newValue, forKey: UserDefaultsKeys.messageReaction) + } + } } diff --git a/Riot/Modules/Room/DataSources/RoomDataSource.m b/Riot/Modules/Room/DataSources/RoomDataSource.m index 1dee9902f..02858a7aa 100644 --- a/Riot/Modules/Room/DataSources/RoomDataSource.m +++ b/Riot/Modules/Room/DataSources/RoomDataSource.m @@ -59,6 +59,7 @@ self.markTimelineInitialEvent = NO; self.showBubbleDateTimeOnSelection = YES; + self.showReactions = RiotSettings.shared.messageReaction; // Observe user interface theme change. kThemeServiceDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kThemeServiceDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 6278e9523..fa8320696 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -5077,7 +5077,7 @@ [self contextualMenuAnimationCompletionAfterBeingShown:YES]; }]; - if ([cell isKindOfClass:MXKRoomBubbleTableViewCell.class]) + if (RiotSettings.shared.messageReaction && [cell isKindOfClass:MXKRoomBubbleTableViewCell.class]) { // Note: For the moment, we use the frame of the cell instead of the component // From UI perpective, that means the menu will be around a paragraph instead of a message diff --git a/Riot/Modules/Settings/SettingsViewController.m b/Riot/Modules/Settings/SettingsViewController.m index cbda06f84..b397757e1 100644 --- a/Riot/Modules/Settings/SettingsViewController.m +++ b/Riot/Modules/Settings/SettingsViewController.m @@ -119,7 +119,8 @@ enum enum { LABS_USE_ROOM_MEMBERS_LAZY_LOADING_INDEX = 0, - LABS_USE_JITSI_WIDGET_INDEX = 0, + LABS_USE_JITSI_WIDGET_INDEX, + LABS_USE_MESSAGE_REACTION_INDEX, LABS_CRYPTO_INDEX, LABS_COUNT }; @@ -2136,6 +2137,19 @@ SignOutAlertPresenterDelegate> cell = labelAndSwitchCell; } + else if (row == LABS_USE_MESSAGE_REACTION_INDEX) + { + MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath]; + + labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_labs_message_reaction", @"Vector", nil); + labelAndSwitchCell.mxkSwitch.on = RiotSettings.shared.messageReaction; + labelAndSwitchCell.mxkSwitch.onTintColor = ThemeService.shared.theme.tintColor; + labelAndSwitchCell.mxkSwitch.enabled = YES; + + [labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleMessageReaction:) forControlEvents:UIControlEventTouchUpInside]; + + cell = labelAndSwitchCell; + } else if (row == LABS_CRYPTO_INDEX) { MXSession* session = [AppDelegate theDelegate].mxSessions[0]; @@ -3035,6 +3049,22 @@ SignOutAlertPresenterDelegate> } } +- (void)toggleMessageReaction:(id)sender +{ + if (sender && [sender isKindOfClass:UISwitch.class]) + { + UISwitch *switchButton = (UISwitch*)sender; + + RiotSettings.shared.messageReaction = switchButton.isOn; + + // Reset cached room data sources + MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:self.mainSession]; + [roomDataSourceManager reset]; + + [self.tableView reloadData]; + } +} + - (void)toggleLabsEndToEndEncryption:(id)sender { if (sender && [sender isKindOfClass:UISwitch.class])