get method
- ChatId id
override
Returns an RxChat by the provided id
.
Implementation
@override
FutureOr<RxChatImpl?> get(ChatId id) {
Log.debug('get($id)', '$runtimeType');
if (id.isLocalWith(me)) {
id = monolog;
}
RxChatImpl? chat = chats[id];
if (chat != null) {
return chat;
}
// If [chat] doesn't exists, we should lock the [mutex] to avoid remote
// double invoking.
Mutex? mutex = _getGuards[id];
if (mutex == null) {
mutex = Mutex();
_getGuards[id] = mutex;
}
return mutex.protect(() async {
chat = chats[id];
if (chat == null) {
final DtoChat? dto = await _chatLocal.read(id);
if (dto != null) {
chat = RxChatImpl(
this,
_chatLocal,
_draftLocal,
_itemsLocal,
_membersLocal,
dto,
);
chat!.init();
}
if (id.isLocal) {
chat ??= await _createLocalDialog(id.userId);
} else if (chat == null) {
var query = (await _graphQlProvider.getChat(id)).chat;
if (query != null) {
chat = await _putEntry(_chat(query));
}
}
if (chat != null) {
chats[id] = chat!;
}
}
return chat;
});
}