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

View file

@ -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<dynamic> startDirectChat() async {
/// Returns null on error.
Future<String> 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;