diff --git a/MatrixSDK/MXSession.m b/MatrixSDK/MXSession.m index fc36fb6a49..4030efe7de 100644 --- a/MatrixSDK/MXSession.m +++ b/MatrixSDK/MXSession.m @@ -1737,6 +1737,17 @@ - (void)handleAccountData:(NSDictionary*)accountDataUpdate NSMutableSet *directRoomIds = [NSMutableSet set]; [directRoomIds unionSet:[self directRoomIds]]; + NSMutableDictionary*> *_directRooms; + _directRooms = [directRooms mutableCopy]; + /// fixes Thread 1: "*** -[NSMutableSet addObjectsFromArray:]: array argument is not an NSArray" error + for (NSString* key in directRooms) { + /// the check for class kind is needed when event.content has exactly one direct room and MXJSONModelSetDictionary converts it to an NSString and not an NSArray. Ideally the server would always send an array even with one direct room, but that's not always the case, ergo the sanity check on client side. + if ([directRooms[key] isKindOfClass:[NSString class]]) { + _directRooms[key] = @[directRooms[key]]; + } + } + directRooms = [_directRooms copy]; + self.directRooms = directRooms; // And collect current ones diff --git a/changelog.d/1371.bugfix b/changelog.d/1371.bugfix new file mode 100644 index 0000000000..c3799a5459 --- /dev/null +++ b/changelog.d/1371.bugfix @@ -0,0 +1 @@ +🐛 Fix directRooms array argument is not an NSArray exception - This exception would occur when event.content has exactly one direct room and MXJSONModelSetDictionary converts it to an NSString and not an NSArray