From 2c63e40cd23472a8cdb93286f90ee5a531874c12 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 18 Mar 2022 16:13:24 +0300 Subject: [PATCH 1/3] Remove sdk option to enable/disable threads --- MatrixSDK/Data/MXRoom.m | 67 +++++++++++----------- MatrixSDK/MXSDKOptions.h | 7 --- MatrixSDK/MXSDKOptions.m | 1 - MatrixSDK/Threads/MXThreadingService.swift | 5 -- 4 files changed, 32 insertions(+), 48 deletions(-) diff --git a/MatrixSDK/Data/MXRoom.m b/MatrixSDK/Data/MXRoom.m index 883a621718..12a1f675db 100644 --- a/MatrixSDK/Data/MXRoom.m +++ b/MatrixSDK/Data/MXRoom.m @@ -787,50 +787,47 @@ - (MXHTTPOperation*)_sendEventOfType:(MXEventTypeString)eventTypeString BOOL startsThread = NO; BOOL isReply = content[kMXEventRelationRelatesToKey][kMXEventContentRelatesToKeyInReplyTo][kMXEventContentRelatesToKeyEventId] != nil; BOOL isEditing = [content[kMXEventRelationRelatesToKey][kMXEventContentRelatesToKeyRelationType] isEqualToString:MXEventRelationTypeReplace]; - if (MXSDKOptions.sharedInstance.enableThreads) + if (threadId) { - if (threadId) + inThread = YES; + NSMutableDictionary *mutableContent = [newContent mutableDeepCopy]; + if (isReply) { - inThread = YES; - NSMutableDictionary *mutableContent = [newContent mutableDeepCopy]; - if (isReply) + // this will be a real in-thread reply + mutableContent[kMXEventRelationRelatesToKey][kMXEventContentRelatesToKeyIsReplyFallback] = @(NO); + } + else + { + // this will look like a reply, but only an in-thread event + NSString *lastEventId = [mxSession.threadingService threadWithId:threadId].lastMessage.eventId; + startsThread = lastEventId == nil; + NSString *replyToEventId = lastEventId ?: threadId; + + if (mutableContent[kMXEventRelationRelatesToKey]) { - // this will be a real in-thread reply - mutableContent[kMXEventRelationRelatesToKey][kMXEventContentRelatesToKeyIsReplyFallback] = @(NO); + mutableContent[kMXEventRelationRelatesToKey][kMXEventContentRelatesToKeyInReplyTo] = @{ + kMXEventContentRelatesToKeyEventId: replyToEventId + }; + mutableContent[kMXEventRelationRelatesToKey][kMXEventContentRelatesToKeyIsReplyFallback] = @(YES); } else { - // this will look like a reply, but only an in-thread event - NSString *lastEventId = [mxSession.threadingService threadWithId:threadId].lastMessage.eventId; - startsThread = lastEventId == nil; - NSString *replyToEventId = lastEventId ?: threadId; - - if (mutableContent[kMXEventRelationRelatesToKey]) - { - mutableContent[kMXEventRelationRelatesToKey][kMXEventContentRelatesToKeyInReplyTo] = @{ + mutableContent[kMXEventRelationRelatesToKey] = @{ + kMXEventContentRelatesToKeyIsReplyFallback: @(YES), + kMXEventContentRelatesToKeyInReplyTo: @{ kMXEventContentRelatesToKeyEventId: replyToEventId - }; - mutableContent[kMXEventRelationRelatesToKey][kMXEventContentRelatesToKeyIsReplyFallback] = @(YES); - } - else - { - mutableContent[kMXEventRelationRelatesToKey] = @{ - kMXEventContentRelatesToKeyIsReplyFallback: @(YES), - kMXEventContentRelatesToKeyInReplyTo: @{ - kMXEventContentRelatesToKeyEventId: replyToEventId - } - }; - } + } + }; } - newContent = mutableContent; - } - else if (isEditing) - { - // detect in-thread edits - NSString *editedEventId = content[kMXEventRelationRelatesToKey][kMXEventContentRelatesToKeyEventId]; - MXEvent *editedEvent = [self.mxSession.store eventWithEventId:editedEventId inRoom:self.roomId]; - inThread = editedEvent.isInThread; } + newContent = mutableContent; + } + else if (isEditing) + { + // detect in-thread edits + NSString *editedEventId = content[kMXEventRelationRelatesToKey][kMXEventContentRelatesToKeyEventId]; + MXEvent *editedEvent = [self.mxSession.store eventWithEventId:editedEventId inRoom:self.roomId]; + inThread = editedEvent.isInThread; } return [mxSession.matrixRestClient sendEventToRoom:self.roomId threadId:threadId eventType:eventTypeString content:newContent txnId:txnId success:^(NSString *eventId) { diff --git a/MatrixSDK/MXSDKOptions.h b/MatrixSDK/MXSDKOptions.h index 780569b1f3..636941c9c0 100644 --- a/MatrixSDK/MXSDKOptions.h +++ b/MatrixSDK/MXSDKOptions.h @@ -189,13 +189,6 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, assign) BOOL authEnableRefreshTokens; -/** - Enable threading module and thread-specific replies to events. - - @remark NO by default. - */ -@property (nonatomic) BOOL enableThreads; - @end NS_ASSUME_NONNULL_END diff --git a/MatrixSDK/MXSDKOptions.m b/MatrixSDK/MXSDKOptions.m index dd3385aa8a..3134cee842 100644 --- a/MatrixSDK/MXSDKOptions.m +++ b/MatrixSDK/MXSDKOptions.m @@ -52,7 +52,6 @@ - (instancetype)init self.roomListDataManagerClass = [MXCoreDataRoomListDataManager class]; _clientPermalinkBaseUrl = nil; _authEnableRefreshTokens = NO; - _enableThreads = NO; } return self; diff --git a/MatrixSDK/Threads/MXThreadingService.swift b/MatrixSDK/Threads/MXThreadingService.swift index 8458984c42..f9b7bba01b 100644 --- a/MatrixSDK/Threads/MXThreadingService.swift +++ b/MatrixSDK/Threads/MXThreadingService.swift @@ -96,11 +96,6 @@ public class MXThreadingService: NSObject { /// - direction: direction of the event /// - completion: Completion block containing the flag indicating that the event is handled public func handleEvent(_ event: MXEvent, direction: MXTimelineDirection, completion: ((Bool) -> Void)?) { - guard MXSDKOptions.sharedInstance().enableThreads else { - // threads disabled in the SDK - completion?(false) - return - } guard let session = session else { // session closed completion?(false) From 861f931a3258f639999199c94a98a94e9f1c5024 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 18 Mar 2022 16:15:17 +0300 Subject: [PATCH 2/3] 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..a12a640062 --- /dev/null +++ b/changelog.d/5799.change @@ -0,0 +1 @@ +MXSDKOptions: Remove `enableThreads` options, which is true by default now. From fb1dab59033268f975705f5a2cd1088c6ab90510 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 18 Mar 2022 16:29:10 +0300 Subject: [PATCH 3/3] Fix tests --- MatrixSDKTests/MXThreadEventTimelineUnitTests.swift | 1 - MatrixSDKTests/MXThreadingServiceTests.swift | 1 - MatrixSDKTests/MXThreadingServiceUnitTests.swift | 1 - 3 files changed, 3 deletions(-) diff --git a/MatrixSDKTests/MXThreadEventTimelineUnitTests.swift b/MatrixSDKTests/MXThreadEventTimelineUnitTests.swift index 396a031f31..85774bc776 100644 --- a/MatrixSDKTests/MXThreadEventTimelineUnitTests.swift +++ b/MatrixSDKTests/MXThreadEventTimelineUnitTests.swift @@ -30,7 +30,6 @@ class MXThreadEventTimelineUnitTests: XCTestCase { override class func setUp() { MXRealmCryptoStore.deleteAllStores() - MXSDKOptions.sharedInstance().enableThreads = true } func testLiveTimelineProperties() { diff --git a/MatrixSDKTests/MXThreadingServiceTests.swift b/MatrixSDKTests/MXThreadingServiceTests.swift index 9b306c630a..7e404318fb 100644 --- a/MatrixSDKTests/MXThreadingServiceTests.swift +++ b/MatrixSDKTests/MXThreadingServiceTests.swift @@ -22,7 +22,6 @@ class MXThreadingServiceTests: XCTestCase { override func setUp() { testData = MatrixSDKTestsData() - MXSDKOptions.sharedInstance().enableThreads = true } override func tearDown() { diff --git a/MatrixSDKTests/MXThreadingServiceUnitTests.swift b/MatrixSDKTests/MXThreadingServiceUnitTests.swift index 85688e3128..42aef463cf 100644 --- a/MatrixSDKTests/MXThreadingServiceUnitTests.swift +++ b/MatrixSDKTests/MXThreadingServiceUnitTests.swift @@ -32,7 +32,6 @@ class MXThreadingServiceUnitTests: XCTestCase { override class func setUp() { MXRealmCryptoStore.deleteAllStores() - MXSDKOptions.sharedInstance().enableThreads = true } func testInitialization() {