matrix-org / matrix-org/matrix-ios-sdk
Getting left rooms doesn't work (FIXME SYNCV2 Archive/Display the left rooms!)
Nobody has claimed this yet.
- Dominant language
- Objective-C
- Stars
- 484
- Forks
- 225
- PR merge metrics
- No merged PRs in 30d
Description
Hey,
I am trying to get left rooms. As the SDK doesn't seem to have an API for that I try to implement it by using the capabilities that the SDK gives us.
I tried two things:
I start the `mxSession` with a filter for left rooms. The filter:
```swift
let filterLeftRooms: [String: Any] = [
"room": [
"timeline": [
"limit": 1
],
"include_leave": true,
"state": [
"lazy_load_members": true
]
]
];
```
calling
```swift
self.mxSession.start(withSyncFilter: MXFilterJSONModel.init(fromJSON: filterLeftRooms), completion: { (respons) in....
```
however, I can see from the console output:
```text
2020-05-17 14:37:25.403362+0200 Cuvent[60902:562263] [MXSession] Loading room state events to build MXRoom objects...
2020-05-17 14:37:25.404143+0200 Cuvent[60902:562263] [MXSession] Built 20 MXRoomSummaries in 0ms
2020-05-17 14:37:25.404666+0200 Cuvent[60902:562263] [MXSession] Built 20 MXRooms in 0ms
2020-05-17 14:37:25.404753+0200 Cuvent[60902:562263] [MXSession] Total time to mount SDK data from MXStore: 52ms
2020-05-17 14:37:25.405655+0200 Cuvent[60902:562263] [MXSession] startWithSyncFilter: {
room = {
"include_leave" = 1;
state = {
"lazy_load_members" = 1;
};
timeline = {
limit = 1;
};
};
}
2020-05-17 14:37:25.406395+0200 Cuvent[60902:562263] [MXSession] Resuming the events stream from s1949_9294_980_1825_1749_89_1_1646_1...
2020-05-17 14:37:25.406487+0200 Cuvent[60902:562263] [MXSession] resume the event stream from state 3
2020-05-17 14:37:25.406558+0200 Cuvent[60902:562263] [MXSession] Do a server sync (catching up): s1949_9294_980_1825_1749_89_1_1646_1
2020-05-17 14:37:25.406922+0200 Cuvent[60902:562263] [MXHTTPClient] #1 - _matrix/client/r0/sync
2020-05-17 14:37:25.407246+0200 Cuvent[60902:562263] [MXSession] Start crypto
2020-05-17 14:37:25.407313+0200 Cuvent[60902:562263] [MXSession] Start crypto -> No crypto
2020-05-17 14:37:25.407400+0200 Cuvent[60902:562263] [MXSession] Crypto has been started
2020-05-17 14:37:25.407491+0200 Cuvent[60902:562263] [MXSession] refreshHomeserverWellknown
2020-05-17 14:37:25.761140+0200 Cuvent[60902:562263] [MXHTTPClient] cleanupBackgroundTask
2020-05-17 14:37:25.800868+0200 Cuvent[60902:562263] [MXHTTPClient] #1 - _matrix/client/r0/sync completed in 394ms
2020-05-17 14:37:25.801190+0200 Cuvent[60902:562263] [MXHTTPClient] cleanupBackgroundTask
2020-05-17 14:37:25.801559+0200 Cuvent[60902:562263] [MXSession] Received 0 joined rooms, 0 invited rooms, 0 left rooms, 0 toDevice events in 395ms
2020-05-17 14:37:25.801887+0200 Cuvent[60902:562263] [MXSession] preloadRooms: 0 rooms
2020-05-17 14:37:25.802033+0200 Cuvent[60902:562263] [MXSession] preloadRoomsForSyncResponse: DONE
2020-05-17 14:37:25.802185+0200 Cuvent[60902:562263] [MXFileStore commit] queuing saveUsers
2020-05-17 14:37:25.802298+0200 Cuvent[60902:562263] [MXFileStore commit] queuing saveMetaData
2020-05-17 14:37:25.802416+0200 Cuvent[60902:562263] [MXSession] Events stream resumed
2020-05-17 14:37:25.802514+0200 Cuvent[60902:562263] [MXSession] Events stream resumed in 396ms
2020-05-17 14:37:25.802813+0200 Cuvent[60902:562263] [MXSession] Do a server sync: s1949_9297_980_1825_1749_89_1_1647_1
2020-05-17 14:37:25.803085+0200 Cuvent[60902:562263] [MXHTTPClient] #3 - _matrix/client/r0/sync
2020-05-17 14:37:25.804294+0200 Cuvent[60902:562526] [MXFileStore] saveUsers in 2ms
2020-05-17 14:37:25.807004+0200 Cuvent[60902:562526] [MXFileStore commit] lasted 3ms for metadata
2020-05-17 14:37:25.807843+0200 Cuvent[60902:562263] [MXFileStore commit] lasted 6ms
2020-05-17 14:37:55.879984+0200 Cuvent[60902:562263] [MXHTTPClient] cleanupBackgroundTask
2020-05-17 14:37:55.880144+0200 Cuvent[60902:562263] [MXSession] Received 0 joined rooms, 0 invited rooms, 0 left rooms, 0 toDevice events in 30077ms
2020-05-17 14:37:55.880269+0200 Cuvent[60902:562263] [MXSession] preloadRooms: 0 rooms
2020-05-17 14:37:55.880368+0200 Cuvent[60902:562263] [MXSession] preloadRoomsForSyncResponse: DONE
```
which is confusing because it says: "Received 0 left rooms".
The 20 rooms it loads are from the store and do not include the 1 left room the user has.
My second approach was to do a manual sync with the filter, which returns the IDs of the left rooms:
```swift
mxSession.matrixRestClient.setFilter(model, success: { (response) in
self.mxSession.matrixRestClient.sync(fromToken: nil, serverTimeout: 10, clientTimeout: 30000, setPresence: nil, filterId: response) { (roomFilterRes) in
if roomFilterRes.isSuccess {
if roomFilterRes.value?.rooms.leave == nil {
resolve([])
return
}
var rooms: [MXRoom] = [MXRoom]()
roomFilterRes.value?.rooms.leave.keys.forEach({ (roomId) in
print("Found left room with ID " + roomId);
let room = self.mxSession.room(withRoomId: roomId)
if room == nil {
// IT IS ALWAYS NULL
} else {
rooms.append(room!)
}
})
......
```
As you can see, the room is always `nil`. I then thought I could fetch the room information again using the `matrixRestClient`, but I couldn't find any API for that.
I tried to do a `mxSession.matrixRestClient.state(ofRoom: roomId)` but this throws the following error:
```text
2020-05-17 14:49:19.420307+0200 Cuvent[62204:573775] -[__NSArrayI getObjects:andKeys:count:]: unrecognized selector sent to instance 0x6000021b85a0
2020-05-17 14:49:19.425020+0200 Cuvent[62204:573775] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI getObjects:andKeys:count:]: unrecognized selector sent to instance 0x6000021b85a0'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23e39f0e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50ad79b2 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23e5ac34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x00007fff23e3e90c ___forwarding___ + 1436
4 CoreFoundation 0x00007fff23e40bf8 _CF_forwarding_prep_0 + 120
5 libswiftFoundation.dylib 0x00000001120d85d5 $sSD10FoundationE26_forceBridgeFromObjectiveC_6resultySo12NSDictionaryC_SDyxq_GSgztFZSiSryxG_Sryq_GtXEfU0_ + 181
6 libswiftFoundation.dylib 0x0000000112136051 $ss17_NativeDictionaryV28_unsafeUninitializedCapacity18allowingDuplicates16initializingWithAByxq_GSi_SbSiSryxG_Sryq_GtXEtcfC + 225
7 libswiftFoundation.dylib 0x00000001120cd195 $sSD10FoundationE36_unconditionallyBridgeFromObjectiveCySDyxq_GSo12NSDictionaryCSgFZ + 885
8 SwiftMatrixSDK 0x0000000110aed580 $sSDys11AnyHashableVypGSgIegg_So12NSDictionaryCSgIeyBy_TR + 128
9 SwiftMatrixSDK 0x0000000110a274f4 __44-[MXRestClient stateOfRoom:success:failure:]_block_invoke_2 + 36
10 SwiftMatrixSDK 0x0000000110a51330 __49-[MXRestClient dispatchProcessing:andCompletion:]_block_invoke_2 + 32
11 libdispatch.dylib 0x0000000111f7ff11 _dispatch_call_block_and_release + 12
12 libdispatch.dylib 0x0000000111f80e8e _dispatch_client_callout + 8
13 libdispatch.dylib 0x0000000111f8ed97 _dispatch_main_queue_callback_4CF + 1149
14 CoreFoundation 0x00007fff23d9da89 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
15 CoreFoundation 0x00007fff23d985d9 __CFRunLoopRun + 2041
16 CoreFoundation 0x00007fff23d97ac4 CFRunLoopRunSpecific + 404
17 GraphicsServices 0x00007fff38b2fc1a GSEventRunModal + 139
18 UIKitCore 0x00007fff48bc7f80 UIApplicationMain + 1605
19 Cuvent 0x000000010da04d50 main + 112
20 libdyld.dylib 0x00007fff519521fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
```
Thank you in advance for your help!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the left-room sync with MXSession, the manual matrixRestClient sync, and MXRestClient stateOfRoom: inspect how rooms.leave is handled and why room(withRoomId:) returns nil. Done means left rooms can be retrieved as usable MXRoom data without the stateOfRoom response crash.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, objective-c, swift
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100