diff --git a/lib/src/User.dart b/lib/src/User.dart index 12c0a2aa..e14c1b93 100644 --- a/lib/src/User.dart +++ b/lib/src/User.dart @@ -126,8 +126,8 @@ class User { } /// Returns an existing direct chat ID with this user or creates a new one. - /// May return ErrorResponse on error. - Future startDirectChat() async { + /// Returns null on error. + Future startDirectChat() async { // Try to find an existing direct chat String roomID = await room.client?.store.getDirectChatRoomID(id); if (roomID != null) return roomID; @@ -140,10 +140,15 @@ class User { "preset": "trusted_private_chat" }); - if (resp is ErrorResponse || resp["room_id"] == null) return resp; + if (resp is ErrorResponse) { + room.client.connection.onError.add(resp); + return null; + } final String newRoomID = resp["room_id"]; + if (newRoomID == null) return newRoomID; + await Room(id: newRoomID, client: room.client).addToDirectChat(id); return newRoomID;