From 775be3deece7adb53650ff41b75fca388e3674a7 Mon Sep 17 00:00:00 2001 From: ferologics Date: Wed, 16 Feb 2022 10:49:30 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20`directRooms`=20array?= =?UTF-8?q?=20argument=20is=20not=20an=20NSArray=20exception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This exception would occur when event.content has exactly one direct room and MXJSONModelSetDictionary converts it to an NSString and not an NSArray --- MatrixSDK/MXSession.m | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 From 0945fa277bf9a60480da72ea833d031aa634c023 Mon Sep 17 00:00:00 2001 From: ferologics Date: Wed, 16 Feb 2022 10:54:04 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9D=20Add=20CHANGELOG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.d/1371.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/1371.bugfix 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