From c8830349fcc1b34e2485103ba8426ed4db75782b Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 18 Mar 2022 02:41:33 +0300 Subject: [PATCH 1/7] Use constant for enableThreads setting --- Riot/Managers/Settings/RiotSettings.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Riot/Managers/Settings/RiotSettings.swift b/Riot/Managers/Settings/RiotSettings.swift index 71f44b1d85..98da99ce50 100644 --- a/Riot/Managers/Settings/RiotSettings.swift +++ b/Riot/Managers/Settings/RiotSettings.swift @@ -30,6 +30,7 @@ final class RiotSettings: NSObject { static let pinRoomsWithMissedNotificationsOnHome = "pinRoomsWithMissedNotif" static let pinRoomsWithUnreadMessagesOnHome = "pinRoomsWithUnread" static let showAllRoomsInHomeSpace = "showAllRoomsInHomeSpace" + static let enableThreads = "enableThreads" } static let shared = RiotSettings() @@ -143,7 +144,7 @@ final class RiotSettings: NSObject { var enableRingingForGroupCalls /// Indicates if threads enabled in the timeline. - @UserDefault(key: "enableThreads", defaultValue: false, storage: defaults) + @UserDefault(key: UserDefaultsKeys.enableThreads, defaultValue: true, storage: defaults) var enableThreads // MARK: Calls From 3685722a51045a76d10fa01934f254f12f99be68 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 18 Mar 2022 02:43:39 +0300 Subject: [PATCH 2/7] Turn on threads for users who had not set it before --- Riot/Managers/Settings/RiotSettings.swift | 5 +++++ Riot/Modules/Application/LegacyAppDelegate.m | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Riot/Managers/Settings/RiotSettings.swift b/Riot/Managers/Settings/RiotSettings.swift index 98da99ce50..42092753b0 100644 --- a/Riot/Managers/Settings/RiotSettings.swift +++ b/Riot/Managers/Settings/RiotSettings.swift @@ -147,6 +147,11 @@ final class RiotSettings: NSObject { @UserDefault(key: UserDefaultsKeys.enableThreads, defaultValue: true, storage: defaults) var enableThreads + /// Indicates if `enableThreads` setting has been set once. + var isThreadsEnabledHasBeenSetOnce: Bool { + return RiotSettings.defaults.object(forKey: UserDefaultsKeys.enableThreads) != nil + } + // MARK: Calls /// Indicate if `allowStunServerFallback` settings has been set once. diff --git a/Riot/Modules/Application/LegacyAppDelegate.m b/Riot/Modules/Application/LegacyAppDelegate.m index f7c2dff3b5..ff75528db0 100644 --- a/Riot/Modules/Application/LegacyAppDelegate.m +++ b/Riot/Modules/Application/LegacyAppDelegate.m @@ -4461,6 +4461,11 @@ - (void)setupUserDefaults { RiotSettings.shared.showDecryptedContentInNotifications = BuildSettings.decryptNotificationsByDefault; } + + if (!RiotSettings.shared.isThreadsEnabledHasBeenSetOnce) + { + RiotSettings.shared.enableThreads = YES; + } } #pragma mark - App version management From b428dfd36ddcea3eaa344caf47c51256687453e2 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 18 Mar 2022 15:35:31 +0300 Subject: [PATCH 3/7] Remove RiotSettings.shared.enableThreads everywhere --- Config/CommonConfiguration.swift | 3 - Riot/Assets/en.lproj/Vector.strings | 1 - Riot/Generated/Strings.swift | 4 - .../PushNotificationService.m | 2 +- Riot/Managers/Settings/RiotSettings.swift | 10 -- Riot/Modules/Application/LegacyAppDelegate.m | 26 ++- .../Files/HomeFilesSearchViewController.m | 19 +-- .../HomeMessagesSearchDataSource.m | 152 ++++++++---------- .../HomeMessagesSearchViewController.m | 19 +-- .../Utils/EventFormatter/MXKEventFormatter.m | 6 +- .../Room/CellData/RoomBubbleCellData.m | 16 -- .../Modules/Room/DataSources/RoomDataSource.m | 4 +- Riot/Modules/Room/RoomViewController.m | 39 ++--- .../Search/DataSources/RoomSearchDataSource.m | 148 ++++++++--------- .../Room/Search/RoomSearchViewController.m | 19 +-- Riot/Utils/EventFormatter.m | 2 +- 16 files changed, 197 insertions(+), 273 deletions(-) diff --git a/Config/CommonConfiguration.swift b/Config/CommonConfiguration.swift index 5802f8d778..0dc31f2fbe 100644 --- a/Config/CommonConfiguration.swift +++ b/Config/CommonConfiguration.swift @@ -72,9 +72,6 @@ class CommonConfiguration: NSObject, Configurable { // Disable key backup on common sdkOptions.enableKeyBackupWhenStartingMXCrypto = false - // Pass threading option to the SDK - sdkOptions.enableThreads = RiotSettings.shared.enableThreads - sdkOptions.clientPermalinkBaseUrl = BuildSettings.clientPermalinkBaseUrl sdkOptions.authEnableRefreshTokens = BuildSettings.authEnableRefreshTokens diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index af5aa32bea..f970dab62b 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -628,7 +628,6 @@ Tap the + to start adding people."; "settings_labs_message_reaction" = "React to messages with emoji"; "settings_labs_enable_ringing_for_group_calls" = "Ring for group calls"; "settings_labs_enabled_polls" = "Polls"; -"settings_labs_enable_threads" = "Threaded messaging"; "settings_labs_use_only_latest_user_avatar_and_name" = "Show latest avatar and name for users in message history"; "settings_version" = "Version %@"; diff --git a/Riot/Generated/Strings.swift b/Riot/Generated/Strings.swift index ca1a6125a1..bcf2feceeb 100644 --- a/Riot/Generated/Strings.swift +++ b/Riot/Generated/Strings.swift @@ -6671,10 +6671,6 @@ public class VectorL10n: NSObject { public static var settingsLabsEnableRingingForGroupCalls: String { return VectorL10n.tr("Vector", "settings_labs_enable_ringing_for_group_calls") } - /// Threaded messaging - public static var settingsLabsEnableThreads: String { - return VectorL10n.tr("Vector", "settings_labs_enable_threads") - } /// Polls public static var settingsLabsEnabledPolls: String { return VectorL10n.tr("Vector", "settings_labs_enabled_polls") diff --git a/Riot/Managers/PushNotification/PushNotificationService.m b/Riot/Managers/PushNotification/PushNotificationService.m index e48a3acfa4..854a9bb66a 100644 --- a/Riot/Managers/PushNotification/PushNotificationService.m +++ b/Riot/Managers/PushNotification/PushNotificationService.m @@ -484,7 +484,7 @@ - (void)handleNotificationInlineReplyForRoomId:(NSString*)roomId // initialize data source for a thread or a room __block MXKRoomDataSource *dataSource; dispatch_group_t dispatchGroupDataSource = dispatch_group_create(); - if (RiotSettings.shared.enableThreads && threadId) + if (threadId) { dispatch_group_enter(dispatchGroupDataSource); [ThreadDataSource loadRoomDataSourceWithRoomId:roomId diff --git a/Riot/Managers/Settings/RiotSettings.swift b/Riot/Managers/Settings/RiotSettings.swift index 42092753b0..53b23f6182 100644 --- a/Riot/Managers/Settings/RiotSettings.swift +++ b/Riot/Managers/Settings/RiotSettings.swift @@ -30,7 +30,6 @@ final class RiotSettings: NSObject { static let pinRoomsWithMissedNotificationsOnHome = "pinRoomsWithMissedNotif" static let pinRoomsWithUnreadMessagesOnHome = "pinRoomsWithUnread" static let showAllRoomsInHomeSpace = "showAllRoomsInHomeSpace" - static let enableThreads = "enableThreads" } static let shared = RiotSettings() @@ -143,15 +142,6 @@ final class RiotSettings: NSObject { @UserDefault(key: "enableRingingForGroupCalls", defaultValue: false, storage: defaults) var enableRingingForGroupCalls - /// Indicates if threads enabled in the timeline. - @UserDefault(key: UserDefaultsKeys.enableThreads, defaultValue: true, storage: defaults) - var enableThreads - - /// Indicates if `enableThreads` setting has been set once. - var isThreadsEnabledHasBeenSetOnce: Bool { - return RiotSettings.defaults.object(forKey: UserDefaultsKeys.enableThreads) != nil - } - // MARK: Calls /// Indicate if `allowStunServerFallback` settings has been set once. diff --git a/Riot/Modules/Application/LegacyAppDelegate.m b/Riot/Modules/Application/LegacyAppDelegate.m index ff75528db0..b2c9f62f5d 100644 --- a/Riot/Modules/Application/LegacyAppDelegate.m +++ b/Riot/Modules/Application/LegacyAppDelegate.m @@ -1415,18 +1415,15 @@ - (BOOL)handleUniversalLinkWithParameters:(UniversalLinkParameters*)universalLin } ThreadParameters *threadParameters = nil; - if (RiotSettings.shared.enableThreads) + if (event.threadId) { - if (event.threadId) - { - threadParameters = [[ThreadParameters alloc] initWithThreadId:event.threadId - stackRoomScreen:NO]; - } - else if ([account.mxSession.threadingService threadWithId:eventId]) - { - threadParameters = [[ThreadParameters alloc] initWithThreadId:eventId - stackRoomScreen:NO]; - } + threadParameters = [[ThreadParameters alloc] initWithThreadId:event.threadId + stackRoomScreen:NO]; + } + else if ([account.mxSession.threadingService threadWithId:eventId]) + { + threadParameters = [[ThreadParameters alloc] initWithThreadId:eventId + stackRoomScreen:NO]; } RoomNavigationParameters *parameters = [[RoomNavigationParameters alloc] initWithRoomId:roomId @@ -3011,7 +3008,7 @@ - (void)showRoom:(NSString*)roomId threadId:(NSString*)threadId andEventId:(NSSt ScreenPresentationParameters *presentationParameters = [[ScreenPresentationParameters alloc] initWithRestoreInitialDisplay:YES]; ThreadParameters *threadParameters = nil; - if (RiotSettings.shared.enableThreads && threadId) + if (threadId) { threadParameters = [[ThreadParameters alloc] initWithThreadId:threadId stackRoomScreen:NO]; } @@ -4461,11 +4458,6 @@ - (void)setupUserDefaults { RiotSettings.shared.showDecryptedContentInNotifications = BuildSettings.decryptNotificationsByDefault; } - - if (!RiotSettings.shared.isThreadsEnabledHasBeenSetOnce) - { - RiotSettings.shared.enableThreads = YES; - } } #pragma mark - App version management diff --git a/Riot/Modules/GlobalSearch/Files/HomeFilesSearchViewController.m b/Riot/Modules/GlobalSearch/Files/HomeFilesSearchViewController.m index 04297d759d..95b50c9e70 100644 --- a/Riot/Modules/GlobalSearch/Files/HomeFilesSearchViewController.m +++ b/Riot/Modules/GlobalSearch/Files/HomeFilesSearchViewController.m @@ -143,18 +143,15 @@ - (void)showRoomWithId:(NSString*)roomId inMatrixSession:(MXSession*)session { ThreadParameters *threadParameters = nil; - if (RiotSettings.shared.enableThreads) + if (event.threadId) { - if (event.threadId) - { - threadParameters = [[ThreadParameters alloc] initWithThreadId:event.threadId - stackRoomScreen:NO]; - } - else if (event.unsignedData.relations.thread || [self.mainSession.threadingService isEventThreadRoot:event]) - { - threadParameters = [[ThreadParameters alloc] initWithThreadId:event.eventId - stackRoomScreen:NO]; - } + threadParameters = [[ThreadParameters alloc] initWithThreadId:event.threadId + stackRoomScreen:NO]; + } + else if (event.unsignedData.relations.thread || [self.mainSession.threadingService isEventThreadRoot:event]) + { + threadParameters = [[ThreadParameters alloc] initWithThreadId:event.eventId + stackRoomScreen:NO]; } ScreenPresentationParameters *presentationParameters = [[ScreenPresentationParameters alloc] initWithRestoreInitialDisplay:NO stackAboveVisibleViews:NO]; diff --git a/Riot/Modules/GlobalSearch/Messages/DataSources/HomeMessagesSearchDataSource.m b/Riot/Modules/GlobalSearch/Messages/DataSources/HomeMessagesSearchDataSource.m index f2f2cd4064..919cf122a0 100644 --- a/Riot/Modules/GlobalSearch/Messages/DataSources/HomeMessagesSearchDataSource.m +++ b/Riot/Modules/GlobalSearch/Messages/DataSources/HomeMessagesSearchDataSource.m @@ -83,34 +83,27 @@ - (void)convertHomeserverResultsIntoCells:(MXSearchRoomEventResults *)roomEventR dispatch_group_leave(group); }; - if (RiotSettings.shared.enableThreads) + if (result.result.isInThread) { - if (result.result.isInThread) - { - continueBlock(); - } - else if (result.result.unsignedData.relations.thread) - { - continueBlock(); - } - else if (room) - { - [room liveTimeline:^(id liveTimeline) { - [liveTimeline paginate:NSUIntegerMax - direction:MXTimelineDirectionBackwards - onlyFromStore:YES - complete:^{ - [liveTimeline resetPagination]; - continueBlock(); - } failure:^(NSError * _Nonnull error) { - continueBlock(); - }]; + continueBlock(); + } + else if (result.result.unsignedData.relations.thread) + { + continueBlock(); + } + else if (room) + { + [room liveTimeline:^(id liveTimeline) { + [liveTimeline paginate:NSUIntegerMax + direction:MXTimelineDirectionBackwards + onlyFromStore:YES + complete:^{ + [liveTimeline resetPagination]; + continueBlock(); + } failure:^(NSError * _Nonnull error) { + continueBlock(); }]; - } - else - { - continueBlock(); - } + }]; } else { @@ -159,63 +152,60 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N // Display date for each message [bubbleCell addDateLabel]; - if (RiotSettings.shared.enableThreads) - { - RoomBubbleCellData *cellData = (RoomBubbleCellData*)[self cellDataAtIndex:indexPath.row]; - MXEvent *event = cellData.events.firstObject; + RoomBubbleCellData *cellData = (RoomBubbleCellData*)[self cellDataAtIndex:indexPath.row]; + MXEvent *event = cellData.events.firstObject; - if (event) + if (event) + { + if (cellData.hasThreadRoot) { - if (cellData.hasThreadRoot) - { - id thread = cellData.bubbleComponents.firstObject.thread; - ThreadSummaryView *threadSummaryView = [[ThreadSummaryView alloc] initWithThread:thread - session:self.mxSession]; - [bubbleCell.tmpSubviews addObject:threadSummaryView]; - - threadSummaryView.translatesAutoresizingMaskIntoConstraints = NO; - [bubbleCell.contentView addSubview:threadSummaryView]; - - CGFloat leftMargin = PlainRoomCellLayoutConstants.reactionsViewLeftMargin; - CGFloat height = [ThreadSummaryView contentViewHeightForThread:thread fitting:cellData.maxTextViewWidth]; - - CGRect bubbleComponentFrame = [bubbleCell componentFrameInContentViewForIndex:0]; - CGFloat bottomPositionY = bubbleComponentFrame.origin.y + bubbleComponentFrame.size.height; - - // Set constraints for the summary view - [NSLayoutConstraint activateConstraints: @[ - [threadSummaryView.leadingAnchor constraintEqualToAnchor:threadSummaryView.superview.leadingAnchor - constant:leftMargin], - [threadSummaryView.topAnchor constraintEqualToAnchor:threadSummaryView.superview.topAnchor - constant:bottomPositionY + PlainRoomCellLayoutConstants.threadSummaryViewTopMargin], - [threadSummaryView.heightAnchor constraintEqualToConstant:height], - [threadSummaryView.trailingAnchor constraintLessThanOrEqualToAnchor:threadSummaryView.superview.trailingAnchor constant:-PlainRoomCellLayoutConstants.reactionsViewRightMargin] - ]]; - } - else if (event.isInThread) - { - FromAThreadView *fromAThreadView = [FromAThreadView instantiate]; - [bubbleCell.tmpSubviews addObject:fromAThreadView]; - - fromAThreadView.translatesAutoresizingMaskIntoConstraints = NO; - [bubbleCell.contentView addSubview:fromAThreadView]; - - CGFloat leftMargin = PlainRoomCellLayoutConstants.reactionsViewLeftMargin; - CGFloat height = [FromAThreadView contentViewHeightForEvent:event fitting:cellData.maxTextViewWidth]; - - CGRect bubbleComponentFrame = [bubbleCell componentFrameInContentViewForIndex:0]; - CGFloat bottomPositionY = bubbleComponentFrame.origin.y + bubbleComponentFrame.size.height; - - // Set constraints for the summary view - [NSLayoutConstraint activateConstraints: @[ - [fromAThreadView.leadingAnchor constraintEqualToAnchor:fromAThreadView.superview.leadingAnchor - constant:leftMargin], - [fromAThreadView.topAnchor constraintEqualToAnchor:fromAThreadView.superview.topAnchor - constant:bottomPositionY + PlainRoomCellLayoutConstants.fromAThreadViewTopMargin], - [fromAThreadView.heightAnchor constraintEqualToConstant:height], - [fromAThreadView.trailingAnchor constraintLessThanOrEqualToAnchor:fromAThreadView.superview.trailingAnchor constant:-PlainRoomCellLayoutConstants.reactionsViewRightMargin] - ]]; - } + id thread = cellData.bubbleComponents.firstObject.thread; + ThreadSummaryView *threadSummaryView = [[ThreadSummaryView alloc] initWithThread:thread + session:self.mxSession]; + [bubbleCell.tmpSubviews addObject:threadSummaryView]; + + threadSummaryView.translatesAutoresizingMaskIntoConstraints = NO; + [bubbleCell.contentView addSubview:threadSummaryView]; + + CGFloat leftMargin = PlainRoomCellLayoutConstants.reactionsViewLeftMargin; + CGFloat height = [ThreadSummaryView contentViewHeightForThread:thread fitting:cellData.maxTextViewWidth]; + + CGRect bubbleComponentFrame = [bubbleCell componentFrameInContentViewForIndex:0]; + CGFloat bottomPositionY = bubbleComponentFrame.origin.y + bubbleComponentFrame.size.height; + + // Set constraints for the summary view + [NSLayoutConstraint activateConstraints: @[ + [threadSummaryView.leadingAnchor constraintEqualToAnchor:threadSummaryView.superview.leadingAnchor + constant:leftMargin], + [threadSummaryView.topAnchor constraintEqualToAnchor:threadSummaryView.superview.topAnchor + constant:bottomPositionY + PlainRoomCellLayoutConstants.threadSummaryViewTopMargin], + [threadSummaryView.heightAnchor constraintEqualToConstant:height], + [threadSummaryView.trailingAnchor constraintLessThanOrEqualToAnchor:threadSummaryView.superview.trailingAnchor constant:-PlainRoomCellLayoutConstants.reactionsViewRightMargin] + ]]; + } + else if (event.isInThread) + { + FromAThreadView *fromAThreadView = [FromAThreadView instantiate]; + [bubbleCell.tmpSubviews addObject:fromAThreadView]; + + fromAThreadView.translatesAutoresizingMaskIntoConstraints = NO; + [bubbleCell.contentView addSubview:fromAThreadView]; + + CGFloat leftMargin = PlainRoomCellLayoutConstants.reactionsViewLeftMargin; + CGFloat height = [FromAThreadView contentViewHeightForEvent:event fitting:cellData.maxTextViewWidth]; + + CGRect bubbleComponentFrame = [bubbleCell componentFrameInContentViewForIndex:0]; + CGFloat bottomPositionY = bubbleComponentFrame.origin.y + bubbleComponentFrame.size.height; + + // Set constraints for the summary view + [NSLayoutConstraint activateConstraints: @[ + [fromAThreadView.leadingAnchor constraintEqualToAnchor:fromAThreadView.superview.leadingAnchor + constant:leftMargin], + [fromAThreadView.topAnchor constraintEqualToAnchor:fromAThreadView.superview.topAnchor + constant:bottomPositionY + PlainRoomCellLayoutConstants.fromAThreadViewTopMargin], + [fromAThreadView.heightAnchor constraintEqualToConstant:height], + [fromAThreadView.trailingAnchor constraintLessThanOrEqualToAnchor:fromAThreadView.superview.trailingAnchor constant:-PlainRoomCellLayoutConstants.reactionsViewRightMargin] + ]]; } } } diff --git a/Riot/Modules/GlobalSearch/Messages/HomeMessagesSearchViewController.m b/Riot/Modules/GlobalSearch/Messages/HomeMessagesSearchViewController.m index ea0c6a2f3b..26608cf9ab 100644 --- a/Riot/Modules/GlobalSearch/Messages/HomeMessagesSearchViewController.m +++ b/Riot/Modules/GlobalSearch/Messages/HomeMessagesSearchViewController.m @@ -150,18 +150,15 @@ - (void)showRoomWithId:(NSString*)roomId inMatrixSession:(MXSession*)session { ThreadParameters *threadParameters = nil; - if (RiotSettings.shared.enableThreads) + if (event.threadId) { - if (event.threadId) - { - threadParameters = [[ThreadParameters alloc] initWithThreadId:event.threadId - stackRoomScreen:NO]; - } - else if (event.unsignedData.relations.thread || [self.mainSession.threadingService isEventThreadRoot:event]) - { - threadParameters = [[ThreadParameters alloc] initWithThreadId:event.eventId - stackRoomScreen:NO]; - } + threadParameters = [[ThreadParameters alloc] initWithThreadId:event.threadId + stackRoomScreen:NO]; + } + else if (event.unsignedData.relations.thread || [self.mainSession.threadingService isEventThreadRoot:event]) + { + threadParameters = [[ThreadParameters alloc] initWithThreadId:event.eventId + stackRoomScreen:NO]; } ScreenPresentationParameters *screenParameters = [[ScreenPresentationParameters alloc] initWithRestoreInitialDisplay:NO stackAboveVisibleViews:NO]; diff --git a/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m b/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m index 2e196bc59e..b5fde76249 100644 --- a/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m +++ b/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m @@ -329,7 +329,7 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent *)event withRoomState if (isRedacted) { // Check whether the event is a thread root or redacted information is required - if ((RiotSettings.shared.enableThreads && [mxSession.threadingService isEventThreadRoot:event]) + if (([mxSession.threadingService isEventThreadRoot:event]) || _settings.showRedactionsInRoomHistory) { MXLogDebug(@"[MXKEventFormatter] Redacted event %@ (%@)", event.description, event.redactedBecause); @@ -1374,7 +1374,7 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent *)event withRoomState // For replies, look for the end of the parent message // This helps us insert the emote prefix in the right place - if (event.relatesTo.inReplyTo || (!RiotSettings.shared.enableThreads && event.isInThread)) + if (event.relatesTo.inReplyTo) { [attributedDisplayText enumerateAttribute:kMXKToolsBlockquoteMarkAttribute inRange:NSMakeRange(0, attributedDisplayText.length) @@ -1754,7 +1754,7 @@ - (NSAttributedString*)renderHTMLString:(NSString*)htmlString forEvent:(MXEvent* NSString *html = htmlString; // Special treatment for "In reply to" message - if (event.isReplyEvent || (!RiotSettings.shared.enableThreads && event.isInThread)) + if (event.isReplyEvent) { html = [self renderReplyTo:html withRoomState:roomState]; } diff --git a/Riot/Modules/Room/CellData/RoomBubbleCellData.m b/Riot/Modules/Room/CellData/RoomBubbleCellData.m index 70ad44a482..dbb05d3312 100644 --- a/Riot/Modules/Room/CellData/RoomBubbleCellData.m +++ b/Riot/Modules/Room/CellData/RoomBubbleCellData.m @@ -284,12 +284,6 @@ - (BOOL)hasNoDisplay - (BOOL)hasThreadRoot { - if (!RiotSettings.shared.enableThreads) - { - // do not consider this cell data if threads not enabled in the timeline - return NO; - } - if (roomDataSource.threadId) { // do not consider this cell data if in a thread view @@ -680,11 +674,6 @@ - (void)setNeedsUpdateAdditionalContentHeight - (CGFloat)threadSummaryViewHeightForEventId:(NSString*)eventId { - if (!RiotSettings.shared.enableThreads) - { - // do not show thread summary view if threads not enabled in the timeline - return 0; - } if (roomDataSource.threadId) { // do not show thread summary view on threads @@ -707,11 +696,6 @@ - (CGFloat)threadSummaryViewHeightForEventId:(NSString*)eventId - (CGFloat)fromAThreadViewHeightForEventId:(NSString*)eventId { - if (!RiotSettings.shared.enableThreads) - { - // do not show from a thread view if threads not enabled - return 0; - } if (roomDataSource.threadId) { // do not show from a thread view on threads diff --git a/Riot/Modules/Room/DataSources/RoomDataSource.m b/Riot/Modules/Room/DataSources/RoomDataSource.m index 5e91b0d51a..9d7fe1004f 100644 --- a/Riot/Modules/Room/DataSources/RoomDataSource.m +++ b/Riot/Modules/Room/DataSources/RoomDataSource.m @@ -261,7 +261,7 @@ - (BOOL)shouldQueueEventForProcessing:(MXEvent *)event roomState:(MXRoomState *) } } } - else if (RiotSettings.shared.enableThreads) + else { // if not in a thread, ignore all threaded events if (event.isInThread) @@ -455,7 +455,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N ThreadSummaryView *threadSummaryView; // display thread summary view if the component has a thread in the room timeline - if (RiotSettings.shared.enableThreads && component.thread && !self.threadId) + if (component.thread && !self.threadId) { threadSummaryView = [[ThreadSummaryView alloc] initWithThread:component.thread session:self.mxSession]; diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 544d5ca058..f1ecb4cd65 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -1775,27 +1775,24 @@ - (void)refreshRoomTitle } [self refreshMissedDiscussionsCount:YES]; - - if (RiotSettings.shared.enableThreads) + + if (self.roomDataSource.threadId) { - if (self.roomDataSource.threadId) + // in a thread + if (rightBarButtonItems == nil) { - // in a thread - if (rightBarButtonItems == nil) - { - rightBarButtonItems = [NSMutableArray new]; - } - UIBarButtonItem *itemThreadMore = [self threadMoreBarButtonItem]; - [rightBarButtonItems insertObject:itemThreadMore atIndex:0]; - } - else - { - // in a regular timeline - UIBarButtonItem *itemThreadList = [self threadListBarButtonItem]; - [self updateThreadListBarButtonItem:itemThreadList - with:self.mainSession.threadingService]; - [rightBarButtonItems insertObject:itemThreadList atIndex:0]; + rightBarButtonItems = [NSMutableArray new]; } + UIBarButtonItem *itemThreadMore = [self threadMoreBarButtonItem]; + [rightBarButtonItems insertObject:itemThreadMore atIndex:0]; + } + else + { + // in a regular timeline + UIBarButtonItem *itemThreadList = [self threadListBarButtonItem]; + [self updateThreadListBarButtonItem:itemThreadList + with:self.mainSession.threadingService]; + [rightBarButtonItems insertObject:itemThreadList atIndex:0]; } } @@ -3445,9 +3442,7 @@ - (void)showAdditionalActionsMenuForEvent:(MXEvent*)selectedEvent inCell:(id *items = [NSMutableArray arrayWithCapacity:5]; diff --git a/Riot/Modules/Room/Search/DataSources/RoomSearchDataSource.m b/Riot/Modules/Room/Search/DataSources/RoomSearchDataSource.m index 9c0530a7ba..e4a6926912 100644 --- a/Riot/Modules/Room/Search/DataSources/RoomSearchDataSource.m +++ b/Riot/Modules/Room/Search/DataSources/RoomSearchDataSource.m @@ -90,35 +90,28 @@ - (void)convertHomeserverResultsIntoCells:(MXSearchRoomEventResults *)roomEventR dispatch_group_leave(group); }; - if (RiotSettings.shared.enableThreads) + if (result.result.isInThread) { - if (result.result.isInThread) - { - continueBlock(); - } - else if (result.result.unsignedData.relations.thread) - { - continueBlock(); - } - else - { - [roomDataSource.room liveTimeline:^(id liveTimeline) { - [liveTimeline paginate:NSUIntegerMax - direction:MXTimelineDirectionBackwards - onlyFromStore:YES - complete:^{ - [liveTimeline resetPagination]; - continueBlock(); - } failure:^(NSError * _Nonnull error) { - continueBlock(); - }]; - }]; - } + continueBlock(); } - else + else if (result.result.unsignedData.relations.thread) { continueBlock(); } + else + { + [roomDataSource.room liveTimeline:^(id liveTimeline) { + [liveTimeline paginate:NSUIntegerMax + direction:MXTimelineDirectionBackwards + onlyFromStore:YES + complete:^{ + [liveTimeline resetPagination]; + continueBlock(); + } failure:^(NSError * _Nonnull error) { + continueBlock(); + }]; + }]; + } } dispatch_group_notify(group, dispatch_get_main_queue(), ^{ @@ -138,63 +131,60 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N // Display date for each message [bubbleCell addDateLabel]; - if (RiotSettings.shared.enableThreads) + RoomBubbleCellData *cellData = (RoomBubbleCellData*)[self cellDataAtIndex:indexPath.row]; + MXEvent *event = cellData.events.firstObject; + + if (event) { - RoomBubbleCellData *cellData = (RoomBubbleCellData*)[self cellDataAtIndex:indexPath.row]; - MXEvent *event = cellData.events.firstObject; - - if (event) + if (cellData.hasThreadRoot) + { + id thread = cellData.bubbleComponents.firstObject.thread; + ThreadSummaryView *threadSummaryView = [[ThreadSummaryView alloc] initWithThread:thread + session:self.mxSession]; + [bubbleCell.tmpSubviews addObject:threadSummaryView]; + + threadSummaryView.translatesAutoresizingMaskIntoConstraints = NO; + [bubbleCell.contentView addSubview:threadSummaryView]; + + CGFloat leftMargin = PlainRoomCellLayoutConstants.reactionsViewLeftMargin; + CGFloat height = [ThreadSummaryView contentViewHeightForThread:thread fitting:cellData.maxTextViewWidth]; + + CGRect bubbleComponentFrame = [bubbleCell componentFrameInContentViewForIndex:0]; + CGFloat bottomPositionY = bubbleComponentFrame.origin.y + bubbleComponentFrame.size.height; + + // Set constraints for the summary view + [NSLayoutConstraint activateConstraints: @[ + [threadSummaryView.leadingAnchor constraintEqualToAnchor:threadSummaryView.superview.leadingAnchor + constant:leftMargin], + [threadSummaryView.topAnchor constraintEqualToAnchor:threadSummaryView.superview.topAnchor + constant:bottomPositionY + PlainRoomCellLayoutConstants.threadSummaryViewTopMargin], + [threadSummaryView.heightAnchor constraintEqualToConstant:height], + [threadSummaryView.trailingAnchor constraintLessThanOrEqualToAnchor:threadSummaryView.superview.trailingAnchor constant:-PlainRoomCellLayoutConstants.reactionsViewRightMargin] + ]]; + } + else if (event.isInThread) { - if (cellData.hasThreadRoot) - { - id thread = cellData.bubbleComponents.firstObject.thread; - ThreadSummaryView *threadSummaryView = [[ThreadSummaryView alloc] initWithThread:thread - session:self.mxSession]; - [bubbleCell.tmpSubviews addObject:threadSummaryView]; - - threadSummaryView.translatesAutoresizingMaskIntoConstraints = NO; - [bubbleCell.contentView addSubview:threadSummaryView]; - - CGFloat leftMargin = PlainRoomCellLayoutConstants.reactionsViewLeftMargin; - CGFloat height = [ThreadSummaryView contentViewHeightForThread:thread fitting:cellData.maxTextViewWidth]; - - CGRect bubbleComponentFrame = [bubbleCell componentFrameInContentViewForIndex:0]; - CGFloat bottomPositionY = bubbleComponentFrame.origin.y + bubbleComponentFrame.size.height; - - // Set constraints for the summary view - [NSLayoutConstraint activateConstraints: @[ - [threadSummaryView.leadingAnchor constraintEqualToAnchor:threadSummaryView.superview.leadingAnchor - constant:leftMargin], - [threadSummaryView.topAnchor constraintEqualToAnchor:threadSummaryView.superview.topAnchor - constant:bottomPositionY + PlainRoomCellLayoutConstants.threadSummaryViewTopMargin], - [threadSummaryView.heightAnchor constraintEqualToConstant:height], - [threadSummaryView.trailingAnchor constraintLessThanOrEqualToAnchor:threadSummaryView.superview.trailingAnchor constant:-PlainRoomCellLayoutConstants.reactionsViewRightMargin] - ]]; - } - else if (event.isInThread) - { - FromAThreadView *fromAThreadView = [FromAThreadView instantiate]; - [bubbleCell.tmpSubviews addObject:fromAThreadView]; - - fromAThreadView.translatesAutoresizingMaskIntoConstraints = NO; - [bubbleCell.contentView addSubview:fromAThreadView]; - - CGFloat leftMargin = PlainRoomCellLayoutConstants.reactionsViewLeftMargin; - CGFloat height = [FromAThreadView contentViewHeightForEvent:event fitting:cellData.maxTextViewWidth]; - - CGRect bubbleComponentFrame = [bubbleCell componentFrameInContentViewForIndex:0]; - CGFloat bottomPositionY = bubbleComponentFrame.origin.y + bubbleComponentFrame.size.height; - - // Set constraints for the summary view - [NSLayoutConstraint activateConstraints: @[ - [fromAThreadView.leadingAnchor constraintEqualToAnchor:fromAThreadView.superview.leadingAnchor - constant:leftMargin], - [fromAThreadView.topAnchor constraintEqualToAnchor:fromAThreadView.superview.topAnchor - constant:bottomPositionY + PlainRoomCellLayoutConstants.fromAThreadViewTopMargin], - [fromAThreadView.heightAnchor constraintEqualToConstant:height], - [fromAThreadView.trailingAnchor constraintLessThanOrEqualToAnchor:fromAThreadView.superview.trailingAnchor constant:-PlainRoomCellLayoutConstants.reactionsViewRightMargin] - ]]; - } + FromAThreadView *fromAThreadView = [FromAThreadView instantiate]; + [bubbleCell.tmpSubviews addObject:fromAThreadView]; + + fromAThreadView.translatesAutoresizingMaskIntoConstraints = NO; + [bubbleCell.contentView addSubview:fromAThreadView]; + + CGFloat leftMargin = PlainRoomCellLayoutConstants.reactionsViewLeftMargin; + CGFloat height = [FromAThreadView contentViewHeightForEvent:event fitting:cellData.maxTextViewWidth]; + + CGRect bubbleComponentFrame = [bubbleCell componentFrameInContentViewForIndex:0]; + CGFloat bottomPositionY = bubbleComponentFrame.origin.y + bubbleComponentFrame.size.height; + + // Set constraints for the summary view + [NSLayoutConstraint activateConstraints: @[ + [fromAThreadView.leadingAnchor constraintEqualToAnchor:fromAThreadView.superview.leadingAnchor + constant:leftMargin], + [fromAThreadView.topAnchor constraintEqualToAnchor:fromAThreadView.superview.topAnchor + constant:bottomPositionY + PlainRoomCellLayoutConstants.fromAThreadViewTopMargin], + [fromAThreadView.heightAnchor constraintEqualToConstant:height], + [fromAThreadView.trailingAnchor constraintLessThanOrEqualToAnchor:fromAThreadView.superview.trailingAnchor constant:-PlainRoomCellLayoutConstants.reactionsViewRightMargin] + ]]; } } } diff --git a/Riot/Modules/Room/Search/RoomSearchViewController.m b/Riot/Modules/Room/Search/RoomSearchViewController.m index 235d89798e..da4b3053c3 100644 --- a/Riot/Modules/Room/Search/RoomSearchViewController.m +++ b/Riot/Modules/Room/Search/RoomSearchViewController.m @@ -142,18 +142,15 @@ - (UIStatusBarStyle)preferredStatusBarStyle - (void)selectEvent:(MXEvent *)event { ThreadParameters *threadParameters = nil; - if (RiotSettings.shared.enableThreads) + if (event.threadId) { - if (event.threadId) - { - threadParameters = [[ThreadParameters alloc] initWithThreadId:event.threadId - stackRoomScreen:NO]; - } - else if (event.unsignedData.relations.thread || [self.mainSession.threadingService isEventThreadRoot:event]) - { - threadParameters = [[ThreadParameters alloc] initWithThreadId:event.eventId - stackRoomScreen:NO]; - } + threadParameters = [[ThreadParameters alloc] initWithThreadId:event.threadId + stackRoomScreen:NO]; + } + else if (event.unsignedData.relations.thread || [self.mainSession.threadingService isEventThreadRoot:event]) + { + threadParameters = [[ThreadParameters alloc] initWithThreadId:event.eventId + stackRoomScreen:NO]; } ScreenPresentationParameters *screenParameters = [[ScreenPresentationParameters alloc] initWithRestoreInitialDisplay:NO diff --git a/Riot/Utils/EventFormatter.m b/Riot/Utils/EventFormatter.m index 64bd0f5d54..35b24b7cb9 100644 --- a/Riot/Utils/EventFormatter.m +++ b/Riot/Utils/EventFormatter.m @@ -103,7 +103,7 @@ - (NSAttributedString *)unsafeAttributedStringFromEvent:(MXEvent *)event withRoo if (event.isRedactedEvent) { // Check whether the event is a thread root or redacted information is required - if ((RiotSettings.shared.enableThreads && [mxSession.threadingService isEventThreadRoot:event]) + if ([mxSession.threadingService isEventThreadRoot:event] || self.settings.showRedactionsInRoomHistory) { UIFont *font = self.defaultTextFont; From 5f9f92cbbc3a224f4f725ec63122584a195a066f Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 18 Mar 2022 16:17:13 +0300 Subject: [PATCH 4/7] Remove reply fallback for thread events --- .../Utils/EventFormatter/MXKEventFormatter.m | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m b/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m index b5fde76249..1d3c26ba98 100644 --- a/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m +++ b/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m @@ -1266,31 +1266,12 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent *)event withRoomState NSString *body; BOOL isHTML = NO; - NSString *eventThreadId = event.threadId; // Use the HTML formatted string if provided if ([contentToUse[@"format"] isEqualToString:kMXRoomMessageFormatHTML]) { - isHTML =YES; - MXJSONModelSetString(body, contentToUse[@"formatted_body"]); - } - else if (event.isReplyEvent || (eventThreadId && !RiotSettings.shared.enableThreads)) - { - NSString *repliedEventId = event.relatesTo.inReplyTo.eventId ?: eventThreadId; isHTML = YES; - MXJSONModelSetString(body, contentToUse[kMXMessageBodyKey]); - MXEvent *repliedEvent = [mxSession.store eventWithEventId:repliedEventId - inRoom:event.roomId]; - - NSString *repliedEventContent; - MXJSONModelSetString(repliedEventContent, repliedEvent.content[kMXMessageBodyKey]); - body = [NSString stringWithFormat:@"
In reply to %@
%@
%@", - [MXTools permalinkToEvent:repliedEventId inRoom:event.roomId], - [MXTools permalinkToUserWithUserId:repliedEvent.sender], - repliedEvent.sender, - repliedEventContent, - body]; - + MXJSONModelSetString(body, contentToUse[@"formatted_body"]); } else { From 72aef5b705074a994bfbd0a35c68a748b928bc2f Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 18 Mar 2022 16:17:34 +0300 Subject: [PATCH 5/7] Remove labs setting for threads --- .../Modules/Settings/SettingsViewController.m | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/Riot/Modules/Settings/SettingsViewController.m b/Riot/Modules/Settings/SettingsViewController.m index 0d72d28032..f87d2b9483 100644 --- a/Riot/Modules/Settings/SettingsViewController.m +++ b/Riot/Modules/Settings/SettingsViewController.m @@ -158,7 +158,6 @@ typedef NS_ENUM(NSUInteger, ABOUT) typedef NS_ENUM(NSUInteger, LABS_ENABLE) { LABS_ENABLE_RINGING_FOR_GROUP_CALLS_INDEX = 0, - LABS_ENABLE_THREADS_INDEX, LABS_ENABLE_MESSAGE_BUBBLES_INDEX, LABS_USE_ONLY_LATEST_USER_AVATAR_AND_NAME_INDEX }; @@ -571,7 +570,6 @@ - (void)updateSections { Section *sectionLabs = [Section sectionWithTag:SECTION_TAG_LABS]; [sectionLabs addRowWithTag:LABS_ENABLE_RINGING_FOR_GROUP_CALLS_INDEX]; - [sectionLabs addRowWithTag:LABS_ENABLE_THREADS_INDEX]; [sectionLabs addRowWithTag:LABS_ENABLE_MESSAGE_BUBBLES_INDEX]; [sectionLabs addRowWithTag:LABS_USE_ONLY_LATEST_USER_AVATAR_AND_NAME_INDEX]; sectionLabs.headerTitle = [VectorL10n settingsLabs]; @@ -2442,18 +2440,6 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell = labelAndSwitchCell; } - else if (row == LABS_ENABLE_THREADS_INDEX) - { - MXKTableViewCellWithLabelAndSwitch *labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath]; - - labelAndSwitchCell.mxkLabel.text = [VectorL10n settingsLabsEnableThreads]; - labelAndSwitchCell.mxkSwitch.on = RiotSettings.shared.enableThreads; - labelAndSwitchCell.mxkSwitch.onTintColor = ThemeService.shared.theme.tintColor; - - [labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleEnableThreads:) forControlEvents:UIControlEventTouchUpInside]; - - cell = labelAndSwitchCell; - } else if (row == LABS_ENABLE_MESSAGE_BUBBLES_INDEX) { cell = [self buildMessageBubblesCellForTableView:tableView atIndexPath:indexPath]; @@ -3197,14 +3183,6 @@ - (void)toggleEnableRingingForGroupCalls:(UISwitch *)sender RiotSettings.shared.enableRingingForGroupCalls = sender.isOn; } -- (void)toggleEnableThreads:(UISwitch *)sender -{ - RiotSettings.shared.enableThreads = sender.isOn; - MXSDKOptions.sharedInstance.enableThreads = sender.isOn; - [[MXKRoomDataSourceManager sharedManagerForMatrixSession:self.mainSession] reset]; - [[AppDelegate theDelegate] restoreEmptyDetailsViewController]; -} - - (void)togglePinRoomsWithMissedNotif:(UISwitch *)sender { RiotSettings.shared.pinRoomsWithMissedNotificationsOnHome = sender.isOn; From bb7333ac50fbb3aae79b0069d4b78ec1970f9b43 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 18 Mar 2022 16:21:05 +0300 Subject: [PATCH 6/7] Add changelog --- changelog.d/5799.change | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5799.change diff --git a/changelog.d/5799.change b/changelog.d/5799.change new file mode 100644 index 0000000000..71ad6f2b6a --- /dev/null +++ b/changelog.d/5799.change @@ -0,0 +1 @@ +Threads: Enable threads everywhere & remove labs setting. From 5f83d361b717796409de58d9bc53386858bd5fa0 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 18 Mar 2022 16:31:12 +0300 Subject: [PATCH 7/7] Remove threads setting to display notice --- Riot/Modules/Room/RoomViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 90e790f245..d2e3cc7d91 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -643,7 +643,7 @@ - (void)viewDidAppear:(BOOL)animated self.showSettingsInitially = NO; - if (!RiotSettings.shared.threadsNoticeDisplayed && RiotSettings.shared.enableThreads) + if (!RiotSettings.shared.threadsNoticeDisplayed) { [self showThreadsNotice]; }