Use onError stream for chat creation

This commit is contained in:
Christian Pauly 2019-06-14 08:07:51 +02:00
parent c13b23dd0a
commit 23c56caa2d
1 changed files with 8 additions and 3 deletions

View File

@ -126,8 +126,8 @@ class User {
} }
/// Returns an existing direct chat ID with this user or creates a new one. /// Returns an existing direct chat ID with this user or creates a new one.
/// May return ErrorResponse on error. /// Returns null on error.
Future<dynamic> startDirectChat() async { Future<String> startDirectChat() async {
// Try to find an existing direct chat // Try to find an existing direct chat
String roomID = await room.client?.store.getDirectChatRoomID(id); String roomID = await room.client?.store.getDirectChatRoomID(id);
if (roomID != null) return roomID; if (roomID != null) return roomID;
@ -140,10 +140,15 @@ class User {
"preset": "trusted_private_chat" "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"]; final String newRoomID = resp["room_id"];
if (newRoomID == null) return newRoomID;
await Room(id: newRoomID, client: room.client).addToDirectChat(id); await Room(id: newRoomID, client: room.client).addToDirectChat(id);
return newRoomID; return newRoomID;