refactor: New start direct chat method in client
This commit is contained in:
parent
771b552801
commit
9faf07e31a
|
|
@ -479,6 +479,27 @@ class Client extends MatrixApi {
|
||||||
return completer.future;
|
return completer.future;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns an existing direct room ID with this user or creates a new one.
|
||||||
|
/// Returns null on error.
|
||||||
|
Future<String> startDirectChat(String mxid) async {
|
||||||
|
// Try to find an existing direct chat
|
||||||
|
var roomId = getDirectChatFromUserId(mxid);
|
||||||
|
if (roomId != null) return roomId;
|
||||||
|
|
||||||
|
// Start a new direct chat
|
||||||
|
roomId = await createRoom(
|
||||||
|
invite: [mxid],
|
||||||
|
isDirect: true,
|
||||||
|
preset: CreateRoomPreset.trusted_private_chat,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (roomId == null) return roomId;
|
||||||
|
|
||||||
|
await Room(id: roomId, client: this).addToDirectChat(mxid);
|
||||||
|
|
||||||
|
return roomId;
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the user's own displayname and avatar url. In Matrix it is possible that
|
/// Returns the user's own displayname and avatar url. In Matrix it is possible that
|
||||||
/// one user can have different displaynames and avatar urls in different rooms. So
|
/// one user can have different displaynames and avatar urls in different rooms. So
|
||||||
/// this endpoint first checks if the profile is the same in all rooms. If not, the
|
/// this endpoint first checks if the profile is the same in all rooms. If not, the
|
||||||
|
|
|
||||||
|
|
@ -144,24 +144,7 @@ class User extends Event {
|
||||||
|
|
||||||
/// 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.
|
||||||
/// Returns null on error.
|
/// Returns null on error.
|
||||||
Future<String> startDirectChat() async {
|
Future<String> startDirectChat() => room.client.startDirectChat(id);
|
||||||
// Try to find an existing direct chat
|
|
||||||
var roomID = await room.client?.getDirectChatFromUserId(id);
|
|
||||||
if (roomID != null) return roomID;
|
|
||||||
|
|
||||||
// Start a new direct chat
|
|
||||||
final newRoomID = await room.client.createRoom(
|
|
||||||
invite: [id],
|
|
||||||
isDirect: true,
|
|
||||||
preset: CreateRoomPreset.trusted_private_chat,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (newRoomID == null) return newRoomID;
|
|
||||||
|
|
||||||
await Room(id: newRoomID, client: room.client).addToDirectChat(id);
|
|
||||||
|
|
||||||
return newRoomID;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The newest presence of this user if there is any and null if not.
|
/// The newest presence of this user if there is any and null if not.
|
||||||
Presence get presence => room.client.presences[id];
|
Presence get presence => room.client.presences[id];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue