Skip to content

Commit f61a6bb

Browse files
committed
Handled case where some kind 40 don't have json, only text; otherwise it was crashing on starting
1 parent 9f507cc commit f61a6bb

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/tree_ds.dart

+14-8
Original file line numberDiff line numberDiff line change
@@ -846,21 +846,27 @@ class Store {
846846

847847
try {
848848
dynamic json = jsonDecode(ce.eventData.content);
849-
Channel? channel = getChannel(rooms, chatRoomId);
850-
if( channel != null) {
851-
if( channel.chatRoomName == "" && json.containsKey('name')) {
852-
channel.chatRoomName = json['name'];
853-
}
854-
} else {
855-
String roomName = "", roomAbout = "";
849+
String roomName = "", roomAbout = "";
850+
if( json is String) {
851+
// in case there is no json in kind 40, we assume the string is room name
852+
roomName = json;
853+
} else {
856854
if( json.containsKey('name') ) {
857855
roomName = json['name']??"";
858856
}
859857

860858
if( json.containsKey('about')) {
861859
roomAbout = json['about']??"";
862860
}
863-
861+
}
862+
863+
Channel? channel = getChannel(rooms, chatRoomId);
864+
if( channel != null) {
865+
if( channel.chatRoomName == "" ) {
866+
channel.chatRoomName = roomName;
867+
}
868+
} else {
869+
864870
List<String> emptyMessageList = [];
865871
Channel room = Channel(chatRoomId, roomName, roomAbout, "", emptyMessageList, {}, ce.eventData.createdAt, enumRoomType.kind40);
866872
rooms.add( room);

0 commit comments

Comments
 (0)