-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1038 from matrix-org/element_4050
Support room type (MSC1840)
- Loading branch information
Showing
11 changed files
with
229 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// 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 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, | ||
MXRoomTypeSpace, | ||
// The room type is custom. Refer to the room type string version. | ||
MXRoomTypeCustom | ||
}; | ||
|
||
/// 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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.