feat(xep): XEP-0045 cache fixes.

Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
This commit is contained in:
Ikjot Singh Dhody
2023-06-19 18:40:39 +05:30
parent 8728166a4d
commit 51bca6c25d
3 changed files with 5 additions and 72 deletions

View File

@@ -23,7 +23,7 @@ class RoomInformation {
.name!,
);
/// The JID (Jabber ID) of the Multi-User Chat (MUC) room.
/// The JID of the Multi-User Chat (MUC) room.
final JID jid;
/// A list of features supported by the Multi-User Chat (MUC) room.
@@ -36,10 +36,8 @@ class RoomInformation {
class RoomState {
RoomState({
required this.roomJid,
required this.roomInformation,
this.nick,
});
final JID roomJid;
final RoomInformation roomInformation;
String? nick;
}

View File

@@ -13,13 +13,6 @@ import 'package:moxxmpp/src/xeps/xep_0045/errors.dart';
import 'package:moxxmpp/src/xeps/xep_0045/types.dart';
import 'package:synchronized/synchronized.dart';
enum ConversationType { chat, groupchat, groupchatprivate }
class ConversationTypeData extends StanzaHandlerExtension {
ConversationTypeData(this.conversationType);
final ConversationType conversationType;
}
class MUCManager extends XmppManagerBase {
MUCManager() : super(mucManager);
@@ -45,14 +38,6 @@ class MUCManager extends XmppManagerBase {
final roomInformation = RoomInformation.fromDiscoInfo(
discoInfo: result.get<DiscoInfo>(),
);
await _cacheLock.synchronized(
() async {
_mucRoomCache[roomJID] = RoomState(
roomJid: roomJID,
roomInformation: roomInformation,
);
},
);
return Result(roomInformation);
} catch (e) {
return Result(InvalidDiscoInfoResponse);
@@ -80,7 +65,7 @@ class MUCManager extends XmppManagerBase {
),
);
await _cacheLock.synchronized(
() async {
() {
_mucRoomCache[roomJID]!.nick = nick;
},
);
@@ -90,15 +75,8 @@ class MUCManager extends XmppManagerBase {
Future<Result<bool, MUCError>> leaveRoom(
JID roomJID,
) async {
String? nick;
await _cacheLock.synchronized(
() async {
nick = _mucRoomCache[roomJID]!.nick;
},
);
if (nick!.isEmpty) {
return Result(NoNicknameSpecified());
}
final nick =
await _cacheLock.synchronized(() => _mucRoomCache[roomJID]!.nick);
await getAttributes().sendStanza(
StanzaDetails(
Stanza.presence(
@@ -108,7 +86,7 @@ class MUCManager extends XmppManagerBase {
),
);
await _cacheLock.synchronized(
() async {
() {
_mucRoomCache.remove(roomJID);
},
);