From 65afb30fc037b188167ef680cd30d2b96488b66c Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 4 Mar 2021 16:10:10 +0100 Subject: [PATCH 01/16] MXRoomCreateContent: Add room type property (MSC1840). --- MatrixSDK/JSONModels/MXRoomCreateContent.h | 5 +++++ MatrixSDK/JSONModels/MXRoomCreateContent.m | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/MatrixSDK/JSONModels/MXRoomCreateContent.h b/MatrixSDK/JSONModels/MXRoomCreateContent.h index 2299148ef6..2b97e3bb0a 100644 --- a/MatrixSDK/JSONModels/MXRoomCreateContent.h +++ b/MatrixSDK/JSONModels/MXRoomCreateContent.h @@ -41,4 +41,9 @@ */ @property (nonatomic, readonly) BOOL isFederated; +/** + The room type as described in MSC1840 (https://github.com/matrix-org/matrix-doc/pull/1840). + */ +@property (nonatomic, readonly, nullable) NSString *roomType; + @end diff --git a/MatrixSDK/JSONModels/MXRoomCreateContent.m b/MatrixSDK/JSONModels/MXRoomCreateContent.m index 5fadbbd56f..1389750e86 100644 --- a/MatrixSDK/JSONModels/MXRoomCreateContent.m +++ b/MatrixSDK/JSONModels/MXRoomCreateContent.m @@ -22,6 +22,8 @@ static NSString* const kRoomCreateContentPredecessorInfoJSONKey = @"predecessor"; static NSString* const kRoomCreateContentRoomVersionJSONKey = @"room_version"; static NSString* const kRoomCreateContentFederateJSONKey = @"m.federate"; +static NSString* const kRoomCreateContentRoomTypeJSONKey = @"m.room.type"; +static NSString* const kRoomCreateContentRoomTypeMSC1772JSONKey = @"org.matrix.msc1772.type"; #pragma mark - Private Interface @@ -31,6 +33,7 @@ @interface MXRoomCreateContent() @property (nonatomic, strong, readwrite, nullable) MXRoomPredecessorInfo *roomPredecessorInfo; @property (nonatomic, copy, readwrite, nullable) NSString *roomVersion; @property (nonatomic, readwrite) BOOL isFederated; +@property (nonatomic, readwrite, nullable) NSString *roomType; @end @@ -48,6 +51,12 @@ + (id)modelFromJSON:(NSDictionary *)jsonDictionary MXJSONModelSetMXJSONModel(roomCreateContent.roomPredecessorInfo, MXRoomPredecessorInfo, jsonDictionary[kRoomCreateContentPredecessorInfoJSONKey]); MXJSONModelSetString(roomCreateContent.roomVersion, jsonDictionary[kRoomCreateContentRoomVersionJSONKey]); MXJSONModelSetBoolean(roomCreateContent.isFederated, jsonDictionary[kRoomCreateContentFederateJSONKey]) + + NSString *roomType; + + MXJSONModelSetString(roomType, jsonDictionary[kRoomCreateContentRoomTypeMSC1772JSONKey]); + + roomCreateContent.roomType = roomType; } return roomCreateContent; @@ -74,6 +83,11 @@ - (NSDictionary *)JSONDictionary jsonDictionary[kRoomCreateContentFederateJSONKey] = @(self.isFederated); + if (self.roomType) + { + jsonDictionary[kRoomCreateContentRoomTypeMSC1772JSONKey] = self.roomType; + } + return jsonDictionary; } From 6cc9322759218aa9e27dcf07b5cf391118976970 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 4 Mar 2021 16:13:32 +0100 Subject: [PATCH 02/16] MXRoomSummary: Add room type property. --- MatrixSDK/Data/MXRoomSummary.h | 5 +++++ MatrixSDK/Data/MXRoomSummaryUpdater.m | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/MatrixSDK/Data/MXRoomSummary.h b/MatrixSDK/Data/MXRoomSummary.h index 1bc0cc5fa2..539e62b2f0 100644 --- a/MatrixSDK/Data/MXRoomSummary.h +++ b/MatrixSDK/Data/MXRoomSummary.h @@ -91,6 +91,11 @@ FOUNDATION_EXPORT NSString *const kMXRoomSummaryDidChangeNotification; */ @property (nonatomic, readonly) MXRoom *room; +/** + Shortcut to the corresponding room type. + */ +@property (nonatomic) NSString *roomType; + /** Create a `MXRoomSummary` instance. diff --git a/MatrixSDK/Data/MXRoomSummaryUpdater.m b/MatrixSDK/Data/MXRoomSummaryUpdater.m index e92d5a2ec0..1c2bd1983d 100644 --- a/MatrixSDK/Data/MXRoomSummaryUpdater.m +++ b/MatrixSDK/Data/MXRoomSummaryUpdater.m @@ -170,9 +170,13 @@ - (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary } case MXEventTypeRoomCreate: + { + MXRoomCreateContent *createContent = [MXRoomCreateContent modelFromJSON:event.content]; summary.creatorUserId = roomState.creatorUserId; - updated = YES; - [self checkRoomCreateStateEventPredecessorAndUpdateObsoleteRoomSummaryIfNeededWithCreateEvent:event summary:summary session:session roomState:roomState]; + summary.roomType = createContent.roomType; + updated = YES; + [self checkRoomCreateStateEventPredecessorAndUpdateObsoleteRoomSummaryIfNeededWithCreateContent:createContent summary:summary session:session roomState:roomState]; + } break; default: @@ -247,10 +251,8 @@ - (BOOL)checkForTombStoneStateEventAndUpdateRoomSummaryIfNeeded:(MXRoomSummary*) // Hide tombstoned room predecessor from user only if the user joined the current room // Important: Room predecessor summary could not be present in memory when making this process, // in this case it should be processed when checking the room predecessor in `checkForTombStoneStateEventAndUpdateRoomSummaryIfNeeded:session:room:`. -- (void)checkRoomCreateStateEventPredecessorAndUpdateObsoleteRoomSummaryIfNeededWithCreateEvent:(MXEvent*)createEvent summary:(MXRoomSummary*)summary session:(MXSession*)session roomState:(MXRoomState*)roomState +- (void)checkRoomCreateStateEventPredecessorAndUpdateObsoleteRoomSummaryIfNeededWithCreateContent:(MXRoomCreateContent*)createContent summary:(MXRoomSummary*)summary session:(MXSession*)session roomState:(MXRoomState*)roomState { - MXRoomCreateContent *createContent = [MXRoomCreateContent modelFromJSON:createEvent.content]; - if (createContent.roomPredecessorInfo) { MXRoomSummary *obsoleteRoomSummary = [session roomSummaryWithRoomId:createContent.roomPredecessorInfo.roomId]; From d4b2f00203ba208006ec1fe2fb84fb1d7aca5549 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 4 Mar 2021 16:14:26 +0100 Subject: [PATCH 03/16] Add known room types constants. --- MatrixSDK.xcodeproj/project.pbxproj | 6 ++++++ MatrixSDK/Data/MXRoomType.h | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 MatrixSDK/Data/MXRoomType.h diff --git a/MatrixSDK.xcodeproj/project.pbxproj b/MatrixSDK.xcodeproj/project.pbxproj index 751664dccd..6e45f3873a 100644 --- a/MatrixSDK.xcodeproj/project.pbxproj +++ b/MatrixSDK.xcodeproj/project.pbxproj @@ -1142,6 +1142,8 @@ B19A30D724042F2700FB6F35 /* MXSelfVerifyingMasterKeyNotTrustedQRCodeData.m in Sources */ = {isa = PBXBuildFile; fileRef = B19A30D324042F2700FB6F35 /* MXSelfVerifyingMasterKeyNotTrustedQRCodeData.m */; }; B19A30D82404335D00FB6F35 /* MXQRCodeDataTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B19A30AE240425D000FB6F35 /* MXQRCodeDataTests.m */; }; B19A30D92404335D00FB6F35 /* MXQRCodeDataTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B19A30AE240425D000FB6F35 /* MXQRCodeDataTests.m */; }; + B1C854EE25E7B497005867D0 /* MXRoomType.h in Headers */ = {isa = PBXBuildFile; fileRef = B1C854ED25E7B492005867D0 /* MXRoomType.h */; settings = {ATTRIBUTES = (Public, ); }; }; + B1C854EF25E7B498005867D0 /* MXRoomType.h in Headers */ = {isa = PBXBuildFile; fileRef = B1C854ED25E7B492005867D0 /* MXRoomType.h */; settings = {ATTRIBUTES = (Public, ); }; }; B1DDC9D62418098200D208E3 /* MXIncomingSASTransaction_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = B1DDC9D52418098200D208E3 /* MXIncomingSASTransaction_Private.h */; settings = {ATTRIBUTES = (Public, ); }; }; B1DDC9D72418098200D208E3 /* MXIncomingSASTransaction_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = B1DDC9D52418098200D208E3 /* MXIncomingSASTransaction_Private.h */; }; B1E09A132397FA950057C069 /* MatrixSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B14EF36B2397E90400758AF0 /* MatrixSDK.framework */; }; @@ -1977,6 +1979,7 @@ B19A30CD24042F0800FB6F35 /* MXSelfVerifyingMasterKeyTrustedQRCodeData.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXSelfVerifyingMasterKeyTrustedQRCodeData.m; sourceTree = ""; }; B19A30D224042F2700FB6F35 /* MXSelfVerifyingMasterKeyNotTrustedQRCodeData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXSelfVerifyingMasterKeyNotTrustedQRCodeData.h; sourceTree = ""; }; B19A30D324042F2700FB6F35 /* MXSelfVerifyingMasterKeyNotTrustedQRCodeData.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXSelfVerifyingMasterKeyNotTrustedQRCodeData.m; sourceTree = ""; }; + B1C854ED25E7B492005867D0 /* MXRoomType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXRoomType.h; sourceTree = ""; }; B1DDC9D52418098200D208E3 /* MXIncomingSASTransaction_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXIncomingSASTransaction_Private.h; sourceTree = ""; }; B1E09A0E2397FA950057C069 /* MatrixSDKTests-macOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "MatrixSDKTests-macOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; B57EF0A39A7649D55CA1208A /* libPods-MatrixSDK-MatrixSDK-iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-MatrixSDK-MatrixSDK-iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -2205,6 +2208,7 @@ 323547DB2226FC5700F15F94 /* MXCredentials.m */, F0173EAA1FCF0E8800B5F6A3 /* MXGroup.h */, F0173EAB1FCF0E8900B5F6A3 /* MXGroup.m */, + B1C854ED25E7B492005867D0 /* MXRoomType.h */, 320DFDCA19DD99B60068622A /* MXRoom.h */, 320DFDCB19DD99B60068622A /* MXRoom.m */, 32C235701F827F3800E38FC5 /* MXRoomOperation.h */, @@ -3816,6 +3820,7 @@ 32792BD42295A86600F4FC9D /* MXAggregatedReactionsUpdater.h in Headers */, B146D4D621A5A44E00D8C2C6 /* MXScanRealmInMemoryProvider.h in Headers */, B19A30C42404268600FB6F35 /* MXVerifyingAnotherUserQRCodeData.h in Headers */, + B1C854EE25E7B497005867D0 /* MXRoomType.h in Headers */, B11BD45422CB583E0064D8B0 /* MXReplyEventBodyParts.h in Headers */, 32549AF923F2E2790002576B /* MXKeyVerificationReady.h in Headers */, B17285792100C8EA0052C51E /* MXSendReplyEventStringsLocalizable.h in Headers */, @@ -4071,6 +4076,7 @@ B14EF2D42397E90400758AF0 /* MatrixSDK.h in Headers */, B14EF2D52397E90400758AF0 /* MXReactionOperation.h in Headers */, B19A30D524042F2700FB6F35 /* MXSelfVerifyingMasterKeyNotTrustedQRCodeData.h in Headers */, + B1C854EF25E7B498005867D0 /* MXRoomType.h in Headers */, B124BBCD256453C90028996D /* MXMembershipTransitionState.h in Headers */, B14EF2D72397E90400758AF0 /* MXAggregationsStore.h in Headers */, B14EF2D82397E90400758AF0 /* MXCredentials.h in Headers */, diff --git a/MatrixSDK/Data/MXRoomType.h b/MatrixSDK/Data/MXRoomType.h new file mode 100644 index 0000000000..d3ed444c70 --- /dev/null +++ b/MatrixSDK/Data/MXRoomType.h @@ -0,0 +1,23 @@ +// +// Copyright 2021 The Matrix.org Foundation C.I.C +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/// MXRoomType identifies the type of room as decribed in MSC1840 (see https://github.com/matrix-org/matrix-doc/pull/1840). +typedef NSString *const MXRoomType NS_TYPED_EXTENSIBLE_ENUM; + +static MXRoomType const MXRoomTypeRoomMSC1840 = @"org.matrix.msc1840.messaging"; +static MXRoomType const MXRoomTypeRoom = @"m.message"; +static MXRoomType const MXRoomTypeSpaceMSC1772 = @"org.matrix.msc1772.space"; +static MXRoomType const MXRoomTypeSpace = @"m.space"; From 5381bc703332393b714f4c6f9016447531f18b02 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 4 Mar 2021 16:16:34 +0100 Subject: [PATCH 04/16] Update changes --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index a915877510..d0359a69ce 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,7 @@ Changes to be released in next version * 🙌 Improvements - * + * Support room type as descirbed in MSC1840 (/vector-im/element-ios/issues/4050). 🐛 Bugfix * From 4fbb89fe36b8dbe2a045b842db0ae9faab37f360 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 4 Mar 2021 17:02:22 +0100 Subject: [PATCH 05/16] Update CHANGES.rst Co-authored-by: ismailgulek --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index d0359a69ce..b86ee83986 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,7 @@ Changes to be released in next version * 🙌 Improvements - * Support room type as descirbed in MSC1840 (/vector-im/element-ios/issues/4050). + * Support room type as described in MSC1840 (vector-im/element-ios/issues/4050). 🐛 Bugfix * From 4cd40a7890a3bdf5b6670c0e16e0accd0743aac6 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 11 Mar 2021 09:15:30 +0100 Subject: [PATCH 06/16] Add MXRoomType enum with known string values MXRoomTypeString. --- MatrixSDK/Data/MXRoomType.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/MatrixSDK/Data/MXRoomType.h b/MatrixSDK/Data/MXRoomType.h index d3ed444c70..63d0ab9e84 100644 --- a/MatrixSDK/Data/MXRoomType.h +++ b/MatrixSDK/Data/MXRoomType.h @@ -15,9 +15,17 @@ // /// MXRoomType identifies the type of room as decribed in MSC1840 (see https://github.com/matrix-org/matrix-doc/pull/1840). -typedef NSString *const MXRoomType NS_TYPED_EXTENSIBLE_ENUM; +typedef NS_ENUM(NSUInteger, MXRoomType) { + MXRoomTypeRoom, + MXRoomTypeSpace, + // The room type is custom. Refer to the room type string version. + MXRoomTypeCustom +}; -static MXRoomType const MXRoomTypeRoomMSC1840 = @"org.matrix.msc1840.messaging"; -static MXRoomType const MXRoomTypeRoom = @"m.message"; -static MXRoomType const MXRoomTypeSpaceMSC1772 = @"org.matrix.msc1772.space"; -static MXRoomType const MXRoomTypeSpace = @"m.space"; +/// MXRoomTypeString identifies the known room type string values +typedef NSString *const MXRoomTypeString NS_TYPED_EXTENSIBLE_ENUM; + +static MXRoomTypeString const MXRoomTypeStringRoomMSC1840 = @"org.matrix.msc1840.messaging"; +static MXRoomTypeString const MXRoomTypeStringRoom = @"m.message"; +static MXRoomTypeString const MXRoomTypeStringSpaceMSC1772 = @"org.matrix.msc1772.space"; +static MXRoomTypeString const MXRoomTypeStringSpace = @"m.space"; From 81957f324af287d594236a0056af2ecd11894a42 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 11 Mar 2021 09:16:00 +0100 Subject: [PATCH 07/16] Add MXRoomTypeMapper to get the corresponding room type from a room type string. --- MatrixSDK/Data/MXRoomTypeMapper.swift | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 MatrixSDK/Data/MXRoomTypeMapper.swift diff --git a/MatrixSDK/Data/MXRoomTypeMapper.swift b/MatrixSDK/Data/MXRoomTypeMapper.swift new file mode 100644 index 0000000000..988c24dcd4 --- /dev/null +++ b/MatrixSDK/Data/MXRoomTypeMapper.swift @@ -0,0 +1,59 @@ +// +// Copyright 2021 The Matrix.org Foundation C.I.C +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import Foundation + +/// MXRoomTypeMapper enables to get the corresponding room type from a room type string +@objcMembers +public class MXRoomTypeMapper: NSObject { + + // MARK: - Properties + + /// Default room type used when the given room type string is nil or empty + public var defaultRoomType: MXRoomType + + // MARK: - Setup + + public init(defaultRoomType: MXRoomType) { + self.defaultRoomType = defaultRoomType + super.init() + } + + // MARK: - Public + + public func roomType(from roomTypeString: String?) -> MXRoomType { + guard let roomTypeString = roomTypeString?.trimmingCharacters(in: .whitespacesAndNewlines) else { + return self.defaultRoomType + } + + let roomType: MXRoomType + + switch roomTypeString { + case MXRoomTypeString.room.rawValue, MXRoomTypeString.roomMSC1840.rawValue: + roomType = .room + case MXRoomTypeString.space.rawValue, MXRoomTypeString.spaceMSC1772.rawValue: + roomType = .space + case "": + // Use default room type when the value is empty + roomType = self.defaultRoomType + default: + roomType = .custom + } + + return roomType + } + +} From adfdd14a71f19e2debd05a2e75f415a06c1c3e1b Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 11 Mar 2021 09:17:02 +0100 Subject: [PATCH 08/16] MXRoomSummaryUpdater: Add options to filter room type strings and hide a room if needed. --- MatrixSDK/Data/MXRoomSummaryUpdater.h | 22 ++++++++++ MatrixSDK/Data/MXRoomSummaryUpdater.m | 62 ++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/MatrixSDK/Data/MXRoomSummaryUpdater.h b/MatrixSDK/Data/MXRoomSummaryUpdater.h index 8c78a30d4f..5016818d8c 100644 --- a/MatrixSDK/Data/MXRoomSummaryUpdater.h +++ b/MatrixSDK/Data/MXRoomSummaryUpdater.h @@ -66,4 +66,26 @@ */ @property id roomNameStringLocalizations; +/** + Indicate YES to handle room types with nil or empty value. + If YES `defaultRoomType` will be used to define the default room type to use in this case. + + YES by default. +*/ +@property (nonatomic) BOOL supportNilOrEmptyRoomType; + +/** + Room type used when the room type of a room is not defined (null or empty). + + MXRoomTypeRoom by default. +*/ +@property (nonatomic) MXRoomType defaultRoomType; + +/** + List of supported room type strings. Unsupported room types will be hidden (see MXRoomSummary.hiddenFromUser). It's not necessary to add empty or nil values, this case is handled by `supportNilOrEmptyRoomType` property. + + Nil by default. +*/ +@property (nonatomic) NSArray *supportedRoomTypeStrings; + @end diff --git a/MatrixSDK/Data/MXRoomSummaryUpdater.m b/MatrixSDK/Data/MXRoomSummaryUpdater.m index 1c2bd1983d..942c45b0b2 100644 --- a/MatrixSDK/Data/MXRoomSummaryUpdater.m +++ b/MatrixSDK/Data/MXRoomSummaryUpdater.m @@ -26,8 +26,18 @@ #import "NSArray+MatrixSDK.h" +#import "MatrixSDKSwiftHeader.h" + +@interface MXRoomSummaryUpdater() + +@property (nonatomic) MXRoomTypeMapper *roomTypeMapper; + +@end + @implementation MXRoomSummaryUpdater +#pragma mark - Setup + + (instancetype)roomSummaryUpdaterForSession:(MXSession *)mxSession { static NSMapTable *updaterPerSession; @@ -47,6 +57,29 @@ + (instancetype)roomSummaryUpdaterForSession:(MXSession *)mxSession return updater; } +- (instancetype)init +{ + self = [super init]; + if (self) + { + _supportNilOrEmptyRoomType = YES; + _defaultRoomType = MXRoomTypeRoom; + _roomTypeMapper = [[MXRoomTypeMapper alloc] initWithDefaultRoomType:_defaultRoomType]; + } + return self; +} + +#pragma mark - Properties + +- (void)setDefaultRoomType:(MXRoomType)defaultRoomType +{ + if (_defaultRoomType != defaultRoomType) + { + _defaultRoomType = defaultRoomType; + + self.roomTypeMapper.defaultRoomType = defaultRoomType; + } +} #pragma mark - MXRoomSummaryUpdating @@ -173,7 +206,13 @@ - (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary { MXRoomCreateContent *createContent = [MXRoomCreateContent modelFromJSON:event.content]; summary.creatorUserId = roomState.creatorUserId; - summary.roomType = createContent.roomType; + + NSString *roomTypeString = [createContent.roomType stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + summary.roomTypeString = createContent.roomType; + summary.roomType = [self.roomTypeMapper roomTypeFrom:roomTypeString]; + summary.hiddenFromUser = [self shouldHideRoomWithRoomTypeString:roomTypeString]; + updated = YES; [self checkRoomCreateStateEventPredecessorAndUpdateObsoleteRoomSummaryIfNeededWithCreateContent:createContent summary:summary session:session roomState:roomState]; } @@ -567,4 +606,25 @@ - (BOOL)updateSummaryMemberCount:(MXRoomSummary *)summary session:(MXSession *)s return otherMembers; } +- (BOOL)shouldHideRoomWithRoomTypeString:(NSString*)roomTypeString +{ + BOOL hiddenFromUser = NO; + + if (!roomTypeString.length) + { + hiddenFromUser = !self.supportNilOrEmptyRoomType; + } + else if (self.supportedRoomTypeStrings.count) + { + hiddenFromUser = NO == [self.supportedRoomTypeStrings containsObject:roomTypeString]; + } + else + { + hiddenFromUser = YES; + } + + return hiddenFromUser; +} + + @end From b91dd8e3e977729370e28358b352454655476cab Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 11 Mar 2021 09:17:45 +0100 Subject: [PATCH 09/16] MXRoomSummary: Add a room type string property along a room type property. --- MatrixSDK/Data/MXRoomSummary.h | 16 +++++++++++----- MatrixSDK/Data/MXRoomSummary.m | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/MatrixSDK/Data/MXRoomSummary.h b/MatrixSDK/Data/MXRoomSummary.h index 539e62b2f0..a3623ef10e 100644 --- a/MatrixSDK/Data/MXRoomSummary.h +++ b/MatrixSDK/Data/MXRoomSummary.h @@ -24,6 +24,7 @@ #import "MXEnumConstants.h" #import "MXUsersTrustLevelSummary.h" #import "MXMembershipTransitionState.h" +#import "MXRoomType.h" @class MXSession, MXRoom, MXRoomState, MXEvent; @protocol MXStore; @@ -91,11 +92,6 @@ FOUNDATION_EXPORT NSString *const kMXRoomSummaryDidChangeNotification; */ @property (nonatomic, readonly) MXRoom *room; -/** - Shortcut to the corresponding room type. - */ -@property (nonatomic) NSString *roomType; - /** Create a `MXRoomSummary` instance. @@ -142,6 +138,16 @@ FOUNDATION_EXPORT NSString *const kMXRoomSummaryDidChangeNotification; #pragma mark - Data related to room state +/** + The room type string value. Can be nil. + */ +@property (nonatomic) NSString *roomTypeString; + +/** + The computed room type. + */ +@property (nonatomic) MXRoomType roomType; + /** The Matrix content URI of the room avatar. */ diff --git a/MatrixSDK/Data/MXRoomSummary.m b/MatrixSDK/Data/MXRoomSummary.m index 2a9a22bf3e..9ce0bc2137 100644 --- a/MatrixSDK/Data/MXRoomSummary.m +++ b/MatrixSDK/Data/MXRoomSummary.m @@ -819,6 +819,7 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder { _roomId = [aDecoder decodeObjectForKey:@"roomId"]; + _roomTypeString = [aDecoder decodeObjectForKey:@"roomTypeString"]; _avatar = [aDecoder decodeObjectForKey:@"avatar"]; _displayname = [aDecoder decodeObjectForKey:@"displayname"]; _topic = [aDecoder decodeObjectForKey:@"topic"]; @@ -876,6 +877,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeObject:_roomId forKey:@"roomId"]; + [aCoder encodeObject:_roomTypeString forKey:@"roomTypeString"]; [aCoder encodeObject:_avatar forKey:@"avatar"]; [aCoder encodeObject:_displayname forKey:@"displayname"]; [aCoder encodeObject:_topic forKey:@"topic"]; From cb7da182ebd4380c44d53f5c8d366a4c5735b926 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 11 Mar 2021 09:18:00 +0100 Subject: [PATCH 10/16] Update pbxproj --- MatrixSDK.xcodeproj/project.pbxproj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MatrixSDK.xcodeproj/project.pbxproj b/MatrixSDK.xcodeproj/project.pbxproj index 6e45f3873a..fadc375d0b 100644 --- a/MatrixSDK.xcodeproj/project.pbxproj +++ b/MatrixSDK.xcodeproj/project.pbxproj @@ -1077,6 +1077,8 @@ B14EF3652397E90400758AF0 /* MXServiceTerms.h in Headers */ = {isa = PBXBuildFile; fileRef = 3294FD9C22F321B0007F1E60 /* MXServiceTerms.h */; settings = {ATTRIBUTES = (Public, ); }; }; B165B81125C3307E003CF7F7 /* MXLoginSSOIdentityProviderBrand.h in Headers */ = {isa = PBXBuildFile; fileRef = B165B81025C3307E003CF7F7 /* MXLoginSSOIdentityProviderBrand.h */; settings = {ATTRIBUTES = (Public, ); }; }; B165B81225C3307E003CF7F7 /* MXLoginSSOIdentityProviderBrand.h in Headers */ = {isa = PBXBuildFile; fileRef = B165B81025C3307E003CF7F7 /* MXLoginSSOIdentityProviderBrand.h */; settings = {ATTRIBUTES = (Public, ); }; }; + B16F35A225F916A00029AE98 /* MXRoomTypeMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B16F35A125F9169F0029AE98 /* MXRoomTypeMapper.swift */; }; + B16F35A325F916A00029AE98 /* MXRoomTypeMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B16F35A125F9169F0029AE98 /* MXRoomTypeMapper.swift */; }; B17285792100C8EA0052C51E /* MXSendReplyEventStringsLocalizable.h in Headers */ = {isa = PBXBuildFile; fileRef = B17285782100C88A0052C51E /* MXSendReplyEventStringsLocalizable.h */; settings = {ATTRIBUTES = (Public, ); }; }; B172857C2100D4F60052C51E /* MXSendReplyEventDefaultStringLocalizations.h in Headers */ = {isa = PBXBuildFile; fileRef = B172857A2100D4F60052C51E /* MXSendReplyEventDefaultStringLocalizations.h */; settings = {ATTRIBUTES = (Public, ); }; }; B172857D2100D4F60052C51E /* MXSendReplyEventDefaultStringLocalizations.m in Sources */ = {isa = PBXBuildFile; fileRef = B172857B2100D4F60052C51E /* MXSendReplyEventDefaultStringLocalizations.m */; }; @@ -1938,6 +1940,7 @@ B14EECED2578FE3F00448735 /* MXAuthenticationSessionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXAuthenticationSessionTests.swift; sourceTree = ""; }; B14EF36B2397E90400758AF0 /* MatrixSDK.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MatrixSDK.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B165B81025C3307E003CF7F7 /* MXLoginSSOIdentityProviderBrand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXLoginSSOIdentityProviderBrand.h; sourceTree = ""; }; + B16F35A125F9169F0029AE98 /* MXRoomTypeMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXRoomTypeMapper.swift; sourceTree = ""; }; B17285782100C88A0052C51E /* MXSendReplyEventStringsLocalizable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MXSendReplyEventStringsLocalizable.h; path = ../MXSendReplyEventStringsLocalizable.h; sourceTree = ""; }; B172857A2100D4F60052C51E /* MXSendReplyEventDefaultStringLocalizations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MXSendReplyEventDefaultStringLocalizations.h; path = ../MXSendReplyEventDefaultStringLocalizations.h; sourceTree = ""; }; B172857B2100D4F60052C51E /* MXSendReplyEventDefaultStringLocalizations.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = MXSendReplyEventDefaultStringLocalizations.m; path = ../MXSendReplyEventDefaultStringLocalizations.m; sourceTree = ""; }; @@ -2209,6 +2212,7 @@ F0173EAA1FCF0E8800B5F6A3 /* MXGroup.h */, F0173EAB1FCF0E8900B5F6A3 /* MXGroup.m */, B1C854ED25E7B492005867D0 /* MXRoomType.h */, + B16F35A125F9169F0029AE98 /* MXRoomTypeMapper.swift */, 320DFDCA19DD99B60068622A /* MXRoom.h */, 320DFDCB19DD99B60068622A /* MXRoom.m */, 32C235701F827F3800E38FC5 /* MXRoomOperation.h */, @@ -4762,6 +4766,7 @@ ECB5D98C2552C9B4000AD89C /* MXStopwatch.swift in Sources */, B1136964230AC9D900E2B2FA /* MXIdentityServerRestClient.m in Sources */, F0C34CBB1C18C93700C36F09 /* MXSDKOptions.m in Sources */, + B16F35A225F916A00029AE98 /* MXRoomTypeMapper.swift in Sources */, 320BBF441D6C81550079890E /* MXEventsEnumeratorOnArray.m in Sources */, 32618E7220ED2DF500E1D2EA /* MXFilterJSONModel.m in Sources */, 323F8865212D4E480001C73C /* MXMatrixVersions.m in Sources */, @@ -4953,6 +4958,7 @@ B14EF1F42397E90400758AF0 /* MXMemoryStore.m in Sources */, B14EF1F52397E90400758AF0 /* MXAggregationPaginatedResponse.m in Sources */, B14EF1F62397E90400758AF0 /* MXEventReplace.m in Sources */, + B16F35A325F916A00029AE98 /* MXRoomTypeMapper.swift in Sources */, B14EF1F72397E90400758AF0 /* MXLoginTerms.m in Sources */, B14EF1F82397E90400758AF0 /* MXReplyEventParts.m in Sources */, 3A108A8125810C96005EEBE9 /* MXKeyData.m in Sources */, From e177b3a444ade3bc9f2a561b96b61d7a1c22f760 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 11 Mar 2021 10:52:33 +0100 Subject: [PATCH 11/16] Update MXRoomSummary and MXRoomSummaryUpdater with Manu's remarks. --- MatrixSDK/Data/MXRoomSummary.h | 4 ++-- MatrixSDK/Data/MXRoomSummaryUpdater.h | 6 +++--- MatrixSDK/Data/MXRoomSummaryUpdater.m | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/MatrixSDK/Data/MXRoomSummary.h b/MatrixSDK/Data/MXRoomSummary.h index a3623ef10e..26292d3900 100644 --- a/MatrixSDK/Data/MXRoomSummary.h +++ b/MatrixSDK/Data/MXRoomSummary.h @@ -139,12 +139,12 @@ FOUNDATION_EXPORT NSString *const kMXRoomSummaryDidChangeNotification; #pragma mark - Data related to room state /** - The room type string value. Can be nil. + The room type string value as provided by the server. Can be nil. */ @property (nonatomic) NSString *roomTypeString; /** - The computed room type. + The locally computed room type derivated from `roomTypeString`. */ @property (nonatomic) MXRoomType roomType; diff --git a/MatrixSDK/Data/MXRoomSummaryUpdater.h b/MatrixSDK/Data/MXRoomSummaryUpdater.h index 5016818d8c..660c48db15 100644 --- a/MatrixSDK/Data/MXRoomSummaryUpdater.h +++ b/MatrixSDK/Data/MXRoomSummaryUpdater.h @@ -72,7 +72,7 @@ YES by default. */ -@property (nonatomic) BOOL supportNilOrEmptyRoomType; +@property (nonatomic) BOOL showNilOrEmptyRoomType; /** Room type used when the room type of a room is not defined (null or empty). @@ -82,10 +82,10 @@ @property (nonatomic) MXRoomType defaultRoomType; /** - List of supported room type strings. Unsupported room types will be hidden (see MXRoomSummary.hiddenFromUser). It's not necessary to add empty or nil values, this case is handled by `supportNilOrEmptyRoomType` property. + List of supported room type strings to show to the user. Other room types will be hidden (see MXRoomSummary.hiddenFromUser). It's not necessary to add empty or nil values, this case is handled by `showNilOrEmptyRoomType` property. Nil by default. */ -@property (nonatomic) NSArray *supportedRoomTypeStrings; +@property (nonatomic) NSArray *showRoomTypeStrings; @end diff --git a/MatrixSDK/Data/MXRoomSummaryUpdater.m b/MatrixSDK/Data/MXRoomSummaryUpdater.m index 942c45b0b2..8c43c2082a 100644 --- a/MatrixSDK/Data/MXRoomSummaryUpdater.m +++ b/MatrixSDK/Data/MXRoomSummaryUpdater.m @@ -62,7 +62,7 @@ - (instancetype)init self = [super init]; if (self) { - _supportNilOrEmptyRoomType = YES; + _showNilOrEmptyRoomType = YES; _defaultRoomType = MXRoomTypeRoom; _roomTypeMapper = [[MXRoomTypeMapper alloc] initWithDefaultRoomType:_defaultRoomType]; } @@ -612,11 +612,11 @@ - (BOOL)shouldHideRoomWithRoomTypeString:(NSString*)roomTypeString if (!roomTypeString.length) { - hiddenFromUser = !self.supportNilOrEmptyRoomType; + hiddenFromUser = !self.showNilOrEmptyRoomType; } - else if (self.supportedRoomTypeStrings.count) + else if (self.showRoomTypeStrings.count) { - hiddenFromUser = NO == [self.supportedRoomTypeStrings containsObject:roomTypeString]; + hiddenFromUser = NO == [self.showRoomTypeStrings containsObject:roomTypeString]; } else { From 8accef1e078a59b2b69e98cd98f35deb0843f26a Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 11 Mar 2021 11:18:50 +0100 Subject: [PATCH 12/16] MXRoomType: Add MXRoomTypeNone case. --- MatrixSDK/Data/MXRoomType.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MatrixSDK/Data/MXRoomType.h b/MatrixSDK/Data/MXRoomType.h index 63d0ab9e84..3ae026ab93 100644 --- a/MatrixSDK/Data/MXRoomType.h +++ b/MatrixSDK/Data/MXRoomType.h @@ -16,6 +16,8 @@ /// MXRoomType identifies the type of room as decribed in MSC1840 (see https://github.com/matrix-org/matrix-doc/pull/1840). typedef NS_ENUM(NSUInteger, MXRoomType) { + // The MXRoomTypeNone can be used when the value of the room type is nil or empty and you do not want to associate a room type for this case (See MXRoomSummaryUpdater.defaultRoomType). + MXRoomTypeNone, MXRoomTypeRoom, MXRoomTypeSpace, // The room type is custom. Refer to the room type string version. From 52081b690fb88dbe7975c0d26b3916195038122e Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 11 Mar 2021 11:28:46 +0100 Subject: [PATCH 13/16] Increase MXFileStore version. --- MatrixSDK/Data/Store/MXFileStore/MXFileStore.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MatrixSDK/Data/Store/MXFileStore/MXFileStore.m b/MatrixSDK/Data/Store/MXFileStore/MXFileStore.m index f2edf1a8b2..662863667b 100644 --- a/MatrixSDK/Data/Store/MXFileStore/MXFileStore.m +++ b/MatrixSDK/Data/Store/MXFileStore/MXFileStore.m @@ -26,7 +26,7 @@ #import "MXSDKOptions.h" #import "MXTools.h" -static NSUInteger const kMXFileVersion = 68; +static NSUInteger const kMXFileVersion = 69; static NSString *const kMXFileStoreFolder = @"MXFileStore"; static NSString *const kMXFileStoreMedaDataFile = @"MXFileStore"; From 69a7d107d1691dbd6309b34ed8e6f3bf231e9ada Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 11 Mar 2021 20:19:15 +0100 Subject: [PATCH 14/16] MXRoomSummary: Handle NSCoding for roomType property. --- MatrixSDK/Data/MXRoomSummary.m | 2 ++ MatrixSDK/Data/MXRoomType.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/MatrixSDK/Data/MXRoomSummary.m b/MatrixSDK/Data/MXRoomSummary.m index 9ce0bc2137..502496d2b4 100644 --- a/MatrixSDK/Data/MXRoomSummary.m +++ b/MatrixSDK/Data/MXRoomSummary.m @@ -820,6 +820,7 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder _roomId = [aDecoder decodeObjectForKey:@"roomId"]; _roomTypeString = [aDecoder decodeObjectForKey:@"roomTypeString"]; + _roomType = (MXRoomType)[aDecoder decodeObjectForKey:@"roomType"]; _avatar = [aDecoder decodeObjectForKey:@"avatar"]; _displayname = [aDecoder decodeObjectForKey:@"displayname"]; _topic = [aDecoder decodeObjectForKey:@"topic"]; @@ -878,6 +879,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder [aCoder encodeObject:_roomId forKey:@"roomId"]; [aCoder encodeObject:_roomTypeString forKey:@"roomTypeString"]; + [aCoder encodeInteger:_roomType forKey:@"roomType"]; [aCoder encodeObject:_avatar forKey:@"avatar"]; [aCoder encodeObject:_displayname forKey:@"displayname"]; [aCoder encodeObject:_topic forKey:@"topic"]; diff --git a/MatrixSDK/Data/MXRoomType.h b/MatrixSDK/Data/MXRoomType.h index 3ae026ab93..b843a53902 100644 --- a/MatrixSDK/Data/MXRoomType.h +++ b/MatrixSDK/Data/MXRoomType.h @@ -15,7 +15,7 @@ // /// MXRoomType identifies the type of room as decribed in MSC1840 (see https://github.com/matrix-org/matrix-doc/pull/1840). -typedef NS_ENUM(NSUInteger, MXRoomType) { +typedef NS_ENUM(NSInteger, MXRoomType) { // The MXRoomTypeNone can be used when the value of the room type is nil or empty and you do not want to associate a room type for this case (See MXRoomSummaryUpdater.defaultRoomType). MXRoomTypeNone, MXRoomTypeRoom, From e79b654bbe079b538247d05e1f333c9c2dd35c26 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Fri, 12 Mar 2021 14:40:47 +0100 Subject: [PATCH 15/16] MXRoomSummaryUpdater: Do not trim room type string. --- MatrixSDK/Data/MXRoomSummaryUpdater.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MatrixSDK/Data/MXRoomSummaryUpdater.m b/MatrixSDK/Data/MXRoomSummaryUpdater.m index 8c43c2082a..f3582cd1e8 100644 --- a/MatrixSDK/Data/MXRoomSummaryUpdater.m +++ b/MatrixSDK/Data/MXRoomSummaryUpdater.m @@ -207,7 +207,7 @@ - (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary MXRoomCreateContent *createContent = [MXRoomCreateContent modelFromJSON:event.content]; summary.creatorUserId = roomState.creatorUserId; - NSString *roomTypeString = [createContent.roomType stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + NSString *roomTypeString = createContent.roomType; summary.roomTypeString = createContent.roomType; summary.roomType = [self.roomTypeMapper roomTypeFrom:roomTypeString]; From bb7bca75959e9ab5ba0e9f362e04f1fcf3c6b2ea Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Fri, 12 Mar 2021 14:59:45 +0100 Subject: [PATCH 16/16] MXRoomSummaryUpdater: Remove useless whitespace. --- MatrixSDK/Data/MXRoomSummaryUpdater.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MatrixSDK/Data/MXRoomSummaryUpdater.m b/MatrixSDK/Data/MXRoomSummaryUpdater.m index f3582cd1e8..7be7303b78 100644 --- a/MatrixSDK/Data/MXRoomSummaryUpdater.m +++ b/MatrixSDK/Data/MXRoomSummaryUpdater.m @@ -207,7 +207,7 @@ - (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary MXRoomCreateContent *createContent = [MXRoomCreateContent modelFromJSON:event.content]; summary.creatorUserId = roomState.creatorUserId; - NSString *roomTypeString = createContent.roomType; + NSString *roomTypeString = createContent.roomType; summary.roomTypeString = createContent.roomType; summary.roomType = [self.roomTypeMapper roomTypeFrom:roomTypeString];