From 23c56caa2df089d43a9b2d784b8a8136f94b97db Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 14 Jun 2019 08:07:51 +0200 Subject: [PATCH] Use onError stream for chat creation --- lib/src/User.dart | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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;