From 217c3ac236572fd557c31db1e7fe091757479520 Mon Sep 17 00:00:00 2001 From: Ikjot Singh Dhody Date: Tue, 20 Jun 2023 17:38:30 +0530 Subject: [PATCH] feat(xep): Fix cache issue with join/leaveRoom. Signed-off-by: Ikjot Singh Dhody --- .../lib/src/xeps/xep_0045/xep_0045.dart | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart b/packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart index 1a32c79..66e1150 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart @@ -45,7 +45,7 @@ class MUCManager extends XmppManagerBase { } Future> joinRoom( - JID roomJID, + JID roomJid, String nick, ) async { if (nick.isEmpty) { @@ -54,7 +54,7 @@ class MUCManager extends XmppManagerBase { await getAttributes().sendStanza( StanzaDetails( Stanza.presence( - to: roomJID.withResource(nick).toString(), + to: roomJid.withResource(nick).toString(), children: [ XMLNode.xmlns( tag: 'x', @@ -66,28 +66,31 @@ class MUCManager extends XmppManagerBase { ); await _cacheLock.synchronized( () { - _mucRoomCache[roomJID]!.nick = nick; + _mucRoomCache[roomJid] = RoomState(roomJid: roomJid, nick: nick); }, ); return const Result(true); } Future> leaveRoom( - JID roomJID, + JID roomJid, ) async { - final nick = - await _cacheLock.synchronized(() => _mucRoomCache[roomJID]!.nick); + final nick = await _cacheLock.synchronized(() { + final nick = _mucRoomCache[roomJid]?.nick; + _mucRoomCache.remove(roomJid); + return nick; + }); await getAttributes().sendStanza( StanzaDetails( Stanza.presence( - to: roomJID.withResource(nick!).toString(), + to: roomJid.withResource(nick!).toString(), type: 'unavailable', ), ), ); await _cacheLock.synchronized( () { - _mucRoomCache.remove(roomJID); + _mucRoomCache.remove(roomJid); }, ); return const Result(true);