Merge branch 'krille/start-direct-chat' into 'main'
refactor: New start direct chat method in client See merge request famedly/famedlysdk!639
This commit is contained in:
commit
b2a4799c9d
|
|
@ -479,6 +479,27 @@ class Client extends MatrixApi {
|
|||
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
|
||||
/// 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
|
||||
|
|
|
|||
|
|
@ -144,24 +144,7 @@ class User extends Event {
|
|||
|
||||
/// Returns an existing direct chat ID with this user or creates a new one.
|
||||
/// Returns null on error.
|
||||
Future<String> startDirectChat() async {
|
||||
// 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;
|
||||
}
|
||||
Future<String> startDirectChat() => room.client.startDirectChat(id);
|
||||
|
||||
/// The newest presence of this user if there is any and null if not.
|
||||
Presence get presence => room.client.presences[id];
|
||||
|
|
|
|||
Loading…
Reference in New Issue