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

@ -83,8 +83,6 @@ class _MyHomePageState extends State<MyHomePage> {
),
MessageManager(),
PresenceManager(),
OccupantIdManager(),
MUCManager()
])
..registerFeatureNegotiators([
ResourceBindingNegotiator(),
@ -160,47 +158,6 @@ class _MyHomePageState extends State<MyHomePage> {
),
obscureText: true,
),
TextButton(
onPressed: () async {
// final muc = connection.getManagerById<MUCManager>(mucManager);
// final roomInformationResult = await muc!.queryRoomInformation(
// JID.fromString('moxxmpp-muc-test@muc.moxxy.org'));
// if (roomInformationResult.isType<RoomInformation>()) {
// print('Room information received');
// print(roomInformationResult.get<RoomInformation>().jid);
// print(roomInformationResult.get<RoomInformation>().name);
// print(roomInformationResult.get<RoomInformation>().features);
// }
// final muc = connection.getManagerById<MUCManager>(mucManager);
// print('joining room');
// final roomInformationResult = await muc!.joinRoom(
// JID.fromString('moxxmpp-muc-test@muc.moxxy.org/test_1'));
// if (roomInformationResult.isType<MUCError>()) {
// print(roomInformationResult.get());
// } else {
// print(roomInformationResult.get());
// }
print('HERE IS YOUR JID');
print(connection.resource);
final sid = connection.generateId();
final originId = connection.generateId();
final message =
connection.getManagerById<MessageManager>(messageManager);
message!.sendMessage(
JID.fromString('moxxmpp-muc-test@muc.moxxy.org/ISD'),
TypedMap<StanzaHandlerExtension>.fromList([
const MessageBodyData('Testing'),
const MarkableData(true),
MessageIdData(sid),
StableIdData(originId, null),
ConversationTypeData(ConversationType.groupchatprivate)
]),
);
},
child: const Text('Test'),
),
],
),
),

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);
},
);