Skip to content

Commit

Permalink
Handled case where some kind 40 don't have json, only text; otherwise…
Browse files Browse the repository at this point in the history
… it was crashing on starting
  • Loading branch information
vishalxl committed Jun 9, 2024
1 parent 9f507cc commit f61a6bb
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/tree_ds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -846,21 +846,27 @@ class Store {

try {
dynamic json = jsonDecode(ce.eventData.content);
Channel? channel = getChannel(rooms, chatRoomId);
if( channel != null) {
if( channel.chatRoomName == "" && json.containsKey('name')) {
channel.chatRoomName = json['name'];
}
} else {
String roomName = "", roomAbout = "";
String roomName = "", roomAbout = "";
if( json is String) {
// in case there is no json in kind 40, we assume the string is room name
roomName = json;
} else {
if( json.containsKey('name') ) {
roomName = json['name']??"";
}

if( json.containsKey('about')) {
roomAbout = json['about']??"";
}

}

Channel? channel = getChannel(rooms, chatRoomId);
if( channel != null) {
if( channel.chatRoomName == "" ) {
channel.chatRoomName = roomName;
}
} else {

List<String> emptyMessageList = [];
Channel room = Channel(chatRoomId, roomName, roomAbout, "", emptyMessageList, {}, ce.eventData.createdAt, enumRoomType.kind40);
rooms.add( room);
Expand Down

0 comments on commit f61a6bb

Please sign in to comment.