From 4291b9f7d99339019df5a2fef82200675ed1e7bd Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 11 Feb 2022 18:11:44 +0300 Subject: [PATCH 1/4] Use thread protocols where possible --- .../DataSources/HomeMessagesSearchDataSource.m | 5 +++-- .../Models/Room/MXKRoomBubbleComponent.h | 4 ++-- .../Models/Room/MXKRoomBubbleComponent.m | 15 ++++++++++++--- Riot/Modules/Room/DataSources/RoomDataSource.h | 2 +- Riot/Modules/Room/DataSources/RoomDataSource.m | 3 ++- Riot/Modules/Room/RoomViewController.m | 2 +- .../Search/DataSources/RoomSearchDataSource.m | 5 +++-- .../Views/Threads/Summary/ThreadSummaryView.swift | 10 ++++++---- 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Riot/Modules/GlobalSearch/Messages/DataSources/HomeMessagesSearchDataSource.m b/Riot/Modules/GlobalSearch/Messages/DataSources/HomeMessagesSearchDataSource.m index 14a736b36..b5d03cd4f 100644 --- a/Riot/Modules/GlobalSearch/Messages/DataSources/HomeMessagesSearchDataSource.m +++ b/Riot/Modules/GlobalSearch/Messages/DataSources/HomeMessagesSearchDataSource.m @@ -164,8 +164,9 @@ { if (cellData.hasThreadRoot) { - MXThread *thread = cellData.bubbleComponents.firstObject.thread; - ThreadSummaryView *threadSummaryView = [[ThreadSummaryView alloc] initWithThread:thread]; + id thread = cellData.bubbleComponents.firstObject.thread; + ThreadSummaryView *threadSummaryView = [[ThreadSummaryView alloc] initWithThread:thread + session:self.mxSession]; [bubbleCell.tmpSubviews addObject:threadSummaryView]; threadSummaryView.translatesAutoresizingMaskIntoConstraints = NO; diff --git a/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleComponent.h b/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleComponent.h index b778785e6..6ec53437e 100644 --- a/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleComponent.h +++ b/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleComponent.h @@ -19,7 +19,7 @@ #import "MXKEventFormatter.h" #import "MXKURLPreviewDataProtocol.h" -@class MXThread; +@protocol MXThreadProtocol; /** Flags to indicate if a fix is required at the display time. @@ -108,7 +108,7 @@ typedef enum : NSUInteger { /** Thread for the bubble component. Should only exist for thread root events. */ -@property (nonatomic, readonly) MXThread *thread; +@property (nonatomic, readonly) id thread; /** Create a new `MXKRoomBubbleComponent` object based on a `MXEvent` instance. diff --git a/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleComponent.m b/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleComponent.m index 9a244040e..25560044b 100644 --- a/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleComponent.m +++ b/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleComponent.m @@ -22,7 +22,7 @@ @interface MXKRoomBubbleComponent () -@property (nonatomic, readwrite) MXThread *thread; +@property (nonatomic, readwrite) id thread; @end @@ -69,8 +69,17 @@ _showEncryptionBadge = [self shouldShowWarningBadgeForEvent:event roomState:(MXRoomState*)roomState session:session]; [self updateLinkWithRoomState:roomState]; - - self.thread = [session.threadingService threadWithId:event.eventId]; + + if (event.unsignedData.relations.thread) + { + self.thread = [[MXThreadModel alloc] initWithRootEvent:event + notificationCount:0 + highlightCount:0]; + } + else + { + self.thread = [session.threadingService threadWithId:event.eventId]; + } } return self; } diff --git a/Riot/Modules/Room/DataSources/RoomDataSource.h b/Riot/Modules/Room/DataSources/RoomDataSource.h index 76d55375e..1ce04fc08 100644 --- a/Riot/Modules/Room/DataSources/RoomDataSource.h +++ b/Riot/Modules/Room/DataSources/RoomDataSource.h @@ -130,6 +130,6 @@ @param roomDataSource room data source instance */ - (void)roomDataSource:(RoomDataSource * _Nonnull)roomDataSource - didTapThread:(MXThread * _Nonnull)thread; + didTapThread:(id _Nonnull)thread; @end diff --git a/Riot/Modules/Room/DataSources/RoomDataSource.m b/Riot/Modules/Room/DataSources/RoomDataSource.m index f4561638f..82901062d 100644 --- a/Riot/Modules/Room/DataSources/RoomDataSource.m +++ b/Riot/Modules/Room/DataSources/RoomDataSource.m @@ -466,7 +466,8 @@ const CGFloat kTypingCellHeight = 24; // display thread summary view if the component has a thread in the room timeline if (RiotSettings.shared.enableThreads && component.thread && !self.threadId) { - threadSummaryView = [[ThreadSummaryView alloc] initWithThread:component.thread]; + threadSummaryView = [[ThreadSummaryView alloc] initWithThread:component.thread + session:self.mxSession]; threadSummaryView.delegate = self; threadSummaryView.tag = index; diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 1c0e72410..e8ea422ed 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -4283,7 +4283,7 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; [self updateTitleViewEncryptionDecoration]; } -- (void)roomDataSource:(RoomDataSource *)roomDataSource didTapThread:(MXThread *)thread +- (void)roomDataSource:(RoomDataSource *)roomDataSource didTapThread:(id)thread { [self openThreadWithId:thread.id]; } diff --git a/Riot/Modules/Room/Search/DataSources/RoomSearchDataSource.m b/Riot/Modules/Room/Search/DataSources/RoomSearchDataSource.m index 5b99eea2d..51e283d37 100644 --- a/Riot/Modules/Room/Search/DataSources/RoomSearchDataSource.m +++ b/Riot/Modules/Room/Search/DataSources/RoomSearchDataSource.m @@ -143,8 +143,9 @@ { if (cellData.hasThreadRoot) { - MXThread *thread = cellData.bubbleComponents.firstObject.thread; - ThreadSummaryView *threadSummaryView = [[ThreadSummaryView alloc] initWithThread:thread]; + id thread = cellData.bubbleComponents.firstObject.thread; + ThreadSummaryView *threadSummaryView = [[ThreadSummaryView alloc] initWithThread:thread + session:self.mxSession]; [bubbleCell.tmpSubviews addObject:threadSummaryView]; threadSummaryView.translatesAutoresizingMaskIntoConstraints = NO; diff --git a/Riot/Modules/Room/Views/Threads/Summary/ThreadSummaryView.swift b/Riot/Modules/Room/Views/Threads/Summary/ThreadSummaryView.swift index c1da2d9dd..1a9799b27 100644 --- a/Riot/Modules/Room/Views/Threads/Summary/ThreadSummaryView.swift +++ b/Riot/Modules/Room/Views/Threads/Summary/ThreadSummaryView.swift @@ -38,7 +38,8 @@ class ThreadSummaryView: UIView { @IBOutlet private weak var lastMessageContentLabel: UILabel! private var theme: Theme = ThemeService.shared().theme - private(set) var thread: MXThread? + private(set) var thread: MXThreadProtocol? + private weak var session: MXSession? private lazy var tapGestureRecognizer: UITapGestureRecognizer = { return UITapGestureRecognizer(target: self, action: #selector(tapped(_:))) @@ -48,8 +49,9 @@ class ThreadSummaryView: UIView { // MARK: - Setup - init(withThread thread: MXThread) { + init(withThread thread: MXThreadProtocol, session: MXSession) { self.thread = thread + self.session = session super.init(frame: CGRect(origin: .zero, size: CGSize(width: Constants.viewDefaultWidth, height: RoomBubbleCellLayout.threadSummaryViewHeight))) @@ -59,7 +61,7 @@ class ThreadSummaryView: UIView { translatesAutoresizingMaskIntoConstraints = false } - static func contentViewHeight(forThread thread: MXThread?, fitting maxWidth: CGFloat) -> CGFloat { + static func contentViewHeight(forThread thread: MXThreadProtocol?, fitting maxWidth: CGFloat) -> CGFloat { return RoomBubbleCellLayout.threadSummaryViewHeight } @@ -93,7 +95,7 @@ class ThreadSummaryView: UIView { guard let thread = thread, let lastMessage = thread.lastMessage, - let session = thread.session, + let session = session, let eventFormatter = session.roomSummaryUpdateDelegate as? MXKEventFormatter, let room = session.room(withRoomId: lastMessage.roomId) else { lastMessageAvatarView.avatarImageView.image = nil From e838173159355a0f75d07b14357cbc74ab757fd2 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 11 Feb 2022 18:14:41 +0300 Subject: [PATCH 2/4] Use thread relation if exists when opening search results --- Riot/Modules/GlobalSearch/Files/HomeFilesSearchViewController.m | 2 +- .../GlobalSearch/Messages/HomeMessagesSearchViewController.m | 2 +- Riot/Modules/Room/Search/RoomSearchViewController.m | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Riot/Modules/GlobalSearch/Files/HomeFilesSearchViewController.m b/Riot/Modules/GlobalSearch/Files/HomeFilesSearchViewController.m index 5ec57f136..d51cfaa64 100644 --- a/Riot/Modules/GlobalSearch/Files/HomeFilesSearchViewController.m +++ b/Riot/Modules/GlobalSearch/Files/HomeFilesSearchViewController.m @@ -160,7 +160,7 @@ threadParameters = [[ThreadParameters alloc] initWithThreadId:event.threadId stackRoomScreen:NO]; } - else if ([self.mainSession.threadingService isEventThreadRoot:event]) + else if (event.unsignedData.relations.thread || [self.mainSession.threadingService isEventThreadRoot:event]) { threadParameters = [[ThreadParameters alloc] initWithThreadId:event.eventId stackRoomScreen:NO]; diff --git a/Riot/Modules/GlobalSearch/Messages/HomeMessagesSearchViewController.m b/Riot/Modules/GlobalSearch/Messages/HomeMessagesSearchViewController.m index b8ba693be..8ba3d8241 100644 --- a/Riot/Modules/GlobalSearch/Messages/HomeMessagesSearchViewController.m +++ b/Riot/Modules/GlobalSearch/Messages/HomeMessagesSearchViewController.m @@ -167,7 +167,7 @@ threadParameters = [[ThreadParameters alloc] initWithThreadId:event.threadId stackRoomScreen:NO]; } - else if ([self.mainSession.threadingService isEventThreadRoot:event]) + else if (event.unsignedData.relations.thread || [self.mainSession.threadingService isEventThreadRoot:event]) { threadParameters = [[ThreadParameters alloc] initWithThreadId:event.eventId stackRoomScreen:NO]; diff --git a/Riot/Modules/Room/Search/RoomSearchViewController.m b/Riot/Modules/Room/Search/RoomSearchViewController.m index 8097ca2b0..214f3f497 100644 --- a/Riot/Modules/Room/Search/RoomSearchViewController.m +++ b/Riot/Modules/Room/Search/RoomSearchViewController.m @@ -165,7 +165,7 @@ threadParameters = [[ThreadParameters alloc] initWithThreadId:event.threadId stackRoomScreen:NO]; } - else if ([self.mainSession.threadingService isEventThreadRoot:event]) + else if (event.unsignedData.relations.thread || [self.mainSession.threadingService isEventThreadRoot:event]) { threadParameters = [[ThreadParameters alloc] initWithThreadId:event.eventId stackRoomScreen:NO]; From c1050515f079729d9ddef95bd5686dcc08f60f47 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 11 Feb 2022 18:15:23 +0300 Subject: [PATCH 3/4] Avoid redundant live timeline loading if thread relation exists --- .../Messages/DataSources/HomeMessagesSearchDataSource.m | 4 ++++ Riot/Modules/Room/Search/DataSources/RoomSearchDataSource.m | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Riot/Modules/GlobalSearch/Messages/DataSources/HomeMessagesSearchDataSource.m b/Riot/Modules/GlobalSearch/Messages/DataSources/HomeMessagesSearchDataSource.m index b5d03cd4f..b136c9af4 100644 --- a/Riot/Modules/GlobalSearch/Messages/DataSources/HomeMessagesSearchDataSource.m +++ b/Riot/Modules/GlobalSearch/Messages/DataSources/HomeMessagesSearchDataSource.m @@ -89,6 +89,10 @@ { continueBlock(); } + else if (result.result.unsignedData.relations.thread) + { + continueBlock(); + } else if (room) { [room liveTimeline:^(id liveTimeline) { diff --git a/Riot/Modules/Room/Search/DataSources/RoomSearchDataSource.m b/Riot/Modules/Room/Search/DataSources/RoomSearchDataSource.m index 51e283d37..dd33c86cb 100644 --- a/Riot/Modules/Room/Search/DataSources/RoomSearchDataSource.m +++ b/Riot/Modules/Room/Search/DataSources/RoomSearchDataSource.m @@ -96,6 +96,10 @@ { continueBlock(); } + else if (result.result.unsignedData.relations.thread) + { + continueBlock(); + } else { [roomDataSource.room liveTimeline:^(id liveTimeline) { From d8450ff2ef8adbc4788f5ade13654d304c26ebe9 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 11 Feb 2022 18:16:37 +0300 Subject: [PATCH 4/4] Add changelog --- changelog.d/5562.change | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5562.change diff --git a/changelog.d/5562.change b/changelog.d/5562.change new file mode 100644 index 000000000..729c93acc --- /dev/null +++ b/changelog.d/5562.change @@ -0,0 +1 @@ +Search: Use bundled aggregations if provided.