Skip to content
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

Avoid calling SDK synchroniously in spaces classes #4999 #1260

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions MatrixSDK/Space/MXSpaceNotificationCounter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,31 @@ public class MXSpaceNotificationCounter: NSObject {
self.processingQueue.async {

let roomId = roomIds[index]
var _roomInfo: RoomInfo?

self.sdkProcessingQueue.sync {
guard let room = self.session.room(withRoomId: roomId), let summary = room.summary, summary.roomType != .space else {
return
self.sdkProcessingQueue.async {
var _roomInfo: RoomInfo?
var isMentionOnly: Bool = false

if let room = self.session.room(withRoomId: roomId), let summary = room.summary, summary.roomType != .space {
let roomInto = RoomInfo(with: room)
_roomInfo = roomInto
isMentionOnly = self.isRoomMentionsOnly(roomInto)
}

_roomInfo = RoomInfo(with: room)
self.computeNotificationCount(for: spaceIds, with: roomIds, at: index, output: output, ancestorsPerRoomId: ancestorsPerRoomId, roomInfo: _roomInfo, isMentionOnly: isMentionOnly, completion: completion)
}

}
}

private func computeNotificationCount(for spaceIds:[String], with roomIds:[String], at index: Int, output: ComputeDataResult, ancestorsPerRoomId: [String: Set<String>], roomInfo _roomInfo: RoomInfo?, isMentionOnly: Bool, completion: @escaping (_ result: ComputeDataResult) -> Void) {

self.processingQueue.async {
guard let roomInfo = _roomInfo else {
self.computeNotificationCount(for: spaceIds, with: roomIds, at: index + 1, output: output, ancestorsPerRoomId: ancestorsPerRoomId, completion: completion)
return
}

let notificationState = self.notificationState(for: roomInfo)
let notificationState = self.notificationState(for: roomInfo, isMentionOnly: isMentionOnly)

output.homeNotificationState += notificationState
for spaceId in spaceIds {
Expand All @@ -174,15 +183,9 @@ public class MXSpaceNotificationCounter: NSObject {
}
}

private func notificationState(for roomInfo: RoomInfo) -> MXSpaceNotificationState {
private func notificationState(for roomInfo: RoomInfo, isMentionOnly: Bool) -> MXSpaceNotificationState {
let notificationState = MXSpaceNotificationState()

var isMentionOnly: Bool = false

self.sdkProcessingQueue.sync {
isMentionOnly = self.isRoomMentionsOnly(roomInfo)
}

let notificationCount = isMentionOnly ? roomInfo.highlightCount : roomInfo.notificationCount

if notificationCount > 0 {
Expand Down
29 changes: 18 additions & 11 deletions MatrixSDK/Space/MXSpaceService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -454,24 +454,31 @@ public class MXSpaceService: NSObject {
}

var _room: MXRoom?
var _space: MXSpace?
var space: MXSpace?
var isRoomDirect = false
var _directUserId: String?
self.sdkProcessingQueue.sync {
var directUserId: String?
self.sdkProcessingQueue.async {
_room = self.session.room(withRoomId: roomIds[index])

if let room = _room {
_space = self.spacesPerId[room.roomId] ?? room.toSpace()
space = self.spacesPerId[room.roomId] ?? room.toSpace()
isRoomDirect = room.isDirect
_directUserId = room.directUserId
directUserId = room.directUserId
}

guard let room = _room else {
self.prepareData(with: roomIds, index: index+1, output: output, completion: completion)
return
}

self.prepareData(with: roomIds, index: index, output: output, room: room, space: space, isRoomDirect: isRoomDirect, directUserId: directUserId, completion: completion)
}
guard let room = _room else {
self.prepareData(with: roomIds, index: index+1, output: output, completion: completion)
return
}
}
}
gileluard marked this conversation as resolved.
Show resolved Hide resolved

private func prepareData(with roomIds:[String], index: Int, output: PrepareDataResult, room: MXRoom, space _space: MXSpace?, isRoomDirect:Bool, directUserId _directUserId: String?, completion: @escaping (_ result: PrepareDataResult) -> Void) {

self.processingQueue.async {
if let space = _space {
output.setComputing(true, forSpace: space)
space.readChildRoomsAndMembers {
Expand Down
1 change: 1 addition & 0 deletions changelog.d/4999.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[MXSPaceService, MXSpaceNotificationCounter] Avoid calling SDK dispatch queue synchroniously