-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spaces: Add support for spaces Summary API #1072
Changes from 8 commits
5893503
0cd1e85
f8499b5
d851212
dd1b700
fc61243
9e4d190
2198378
94bc509
088d3b6
428f16e
352918d
5beb2ab
997ed77
bd97741
32a76f4
5c9111e
4ff8593
374fd22
8180db9
ecfc55d
0bd5431
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,13 +18,18 @@ | |
|
||
@implementation MXSpaceChildSummaryResponse | ||
|
||
+ (id)modelFromJSON:(NSDictionary *)JSONDictionary | ||
+ (instancetype)modelFromJSON:(NSDictionary *)JSONDictionary | ||
{ | ||
MXSpaceChildSummaryResponse *spaceChildSummaryResponse = [MXSpaceChildSummaryResponse new]; | ||
|
||
NSString *roomId; | ||
|
||
if (spaceChildSummaryResponse) | ||
MXJSONModelSetString(roomId, JSONDictionary[@"room_id"]); | ||
|
||
if (spaceChildSummaryResponse && roomId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should return nil if there is no |
||
{ | ||
MXJSONModelSetString(spaceChildSummaryResponse.roomId, JSONDictionary[@"room_id"]); | ||
spaceChildSummaryResponse.roomId = roomId; | ||
|
||
MXJSONModelSetString(spaceChildSummaryResponse.roomType, JSONDictionary[@"room_type"]); | ||
MXJSONModelSetString(spaceChildSummaryResponse.name, JSONDictionary[@"name"]); | ||
MXJSONModelSetString(spaceChildSummaryResponse.topic, JSONDictionary[@"topic"]); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,11 +48,16 @@ public class MXSpaceService: NSObject { | |
|
||
private let roomTypeMapper: MXRoomTypeMapper | ||
|
||
private let processingQueue: DispatchQueue | ||
private let completionQueue: DispatchQueue | ||
|
||
// MARK: - Setup | ||
|
||
public init(session: MXSession) { | ||
self.session = session | ||
self.roomTypeMapper = MXRoomTypeMapper(defaultRoomType: .room) | ||
self.processingQueue = DispatchQueue(label: "org.matrix.sdk.MXSpaceService.processingQueue", attributes: .concurrent) | ||
self.completionQueue = DispatchQueue.main | ||
} | ||
|
||
// MARK: - Public | ||
|
@@ -122,29 +127,41 @@ public class MXSpaceService: NSObject { | |
return self.session.matrixRestClient.getSpaceChildrenForSpace(withId: spaceId, parameters: parameters) { (response) in | ||
switch response { | ||
case .success(let spaceChildrenResponse): | ||
guard let rooms = spaceChildrenResponse.rooms else { | ||
// We should have at least one room for the requested space | ||
completion(.failure(MXSpaceServiceError.spaceNotFound)) | ||
return | ||
} | ||
self.processingQueue.async { [weak self] in | ||
guard let self = self else { | ||
return | ||
} | ||
|
||
guard let rooms = spaceChildrenResponse.rooms else { | ||
// We should have at least one room for the requested space | ||
self.completionQueue.async { | ||
completion(.failure(MXSpaceServiceError.spaceNotFound)) | ||
} | ||
return | ||
} | ||
|
||
guard let rootSpaceChildSummaryResponse = rooms.first(where: { spaceResponse -> Bool in | ||
return spaceResponse.roomId == spaceId | ||
}) else { | ||
// Fail to find root child. We should have at least one room for the requested space | ||
completion(.failure(MXSpaceServiceError.spaceNotFound)) | ||
return | ||
} | ||
guard let rootSpaceChildSummaryResponse = rooms.first(where: { spaceResponse -> Bool in | ||
return spaceResponse.roomId == spaceId | ||
}) else { | ||
// Fail to find root child. We should have at least one room for the requested space | ||
self.completionQueue.async { | ||
completion(.failure(MXSpaceServiceError.spaceNotFound)) | ||
} | ||
return | ||
} | ||
|
||
// Build the queried space summary | ||
let spaceSummary = self.createRoomSummary(with: rootSpaceChildSummaryResponse) | ||
// Build the queried space summary | ||
let spaceSummary = self.createRoomSummary(with: rootSpaceChildSummaryResponse) | ||
|
||
// Build the child summaries of the queried space | ||
let childInfos = self.spaceChildInfos(from: spaceChildrenResponse, excludedSpaceId: spaceId) | ||
// Build the child summaries of the queried space | ||
let childInfos = self.spaceChildInfos(from: spaceChildrenResponse, excludedSpaceId: spaceId) | ||
|
||
let spaceChildrenSummary = MXSpaceChildrenSummary(spaceSummary: spaceSummary, childInfos: childInfos) | ||
let spaceChildrenSummary = MXSpaceChildrenSummary(spaceSummary: spaceSummary, childInfos: childInfos) | ||
|
||
completion(.success(spaceChildrenSummary)) | ||
self.completionQueue.async { | ||
completion(.success(spaceChildrenSummary)) | ||
} | ||
} | ||
case .failure(let error): | ||
completion(.failure(error)) | ||
} | ||
|
@@ -162,8 +179,12 @@ public class MXSpaceService: NSObject { | |
roomSummary.roomTypeString = roomTypeString | ||
roomSummary.roomType = self.roomTypeMapper.roomType(from: roomTypeString) | ||
|
||
let joinedMembersCount = UInt(spaceChildSummaryResponse.numJoinedMembers) | ||
|
||
let membersCount = MXRoomMembersCount() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about |
||
membersCount.joined = UInt(spaceChildSummaryResponse.numJoinedMembers) | ||
membersCount.joined = joinedMembersCount | ||
membersCount.members = joinedMembersCount | ||
|
||
roomSummary.membersCount = membersCount | ||
roomSummary.displayname = spaceChildSummaryResponse.name | ||
roomSummary.topic = spaceChildSummaryResponse.topic | ||
|
@@ -204,9 +225,13 @@ public class MXSpaceService: NSObject { | |
spaceChildContent = MXSpaceChildContent(fromJSON: stateEventContent) | ||
} | ||
|
||
let roomTypeString = spaceChildSummaryResponse.roomType | ||
let roomType = self.roomTypeMapper.roomType(from: roomTypeString) | ||
|
||
return MXSpaceChildInfo(childRoomId: spaceChildSummaryResponse.roomId, | ||
isKnown: true, | ||
roomType: spaceChildSummaryResponse.roomType, | ||
roomTypeString: roomTypeString, | ||
roomType: roomType, | ||
name: spaceChildSummaryResponse.name, | ||
topic: spaceChildSummaryResponse.topic, | ||
avatarUrl: spaceChildSummaryResponse.avatarUrl, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if can have nil as default value. We are in full swift here, no?