From 5bd2466c54acd9663a70f5d6111b133e2a1aa4f5 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Tue, 26 Sep 2023 14:00:27 +0200 Subject: [PATCH] feat(xep): Parse the room info from the extended disco info --- packages/moxxmpp/lib/src/namespaces.dart | 2 ++ packages/moxxmpp/lib/src/xeps/xep_0045/types.dart | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/moxxmpp/lib/src/namespaces.dart b/packages/moxxmpp/lib/src/namespaces.dart index 6da96fb..2846ba6 100644 --- a/packages/moxxmpp/lib/src/namespaces.dart +++ b/packages/moxxmpp/lib/src/namespaces.dart @@ -13,6 +13,7 @@ const subscriptionPreApprovalXmlns = 'urn:xmpp:features:pre-approval'; // XEP-0004 const dataFormsXmlns = 'jabber:x:data'; +const formVarFormType = 'FORM_TYPE'; // XEP-0030 const discoInfoXmlns = 'http://jabber.org/protocol/disco#info'; @@ -23,6 +24,7 @@ const extendedAddressingXmlns = 'http://jabber.org/protocol/address'; // XEP-0045 const mucXmlns = 'http://jabber.org/protocol/muc'; +const roomInfoFormType = 'http://jabber.org/protocol/muc#roominfo'; // XEP-0054 const vCardTempXmlns = 'vcard-temp'; diff --git a/packages/moxxmpp/lib/src/xeps/xep_0045/types.dart b/packages/moxxmpp/lib/src/xeps/xep_0045/types.dart index d26a080..d6b506a 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0045/types.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0045/types.dart @@ -1,4 +1,7 @@ +import 'package:collection/collection.dart'; import 'package:moxxmpp/src/jid.dart'; +import 'package:moxxmpp/src/namespaces.dart'; +import 'package:moxxmpp/src/xeps/xep_0004.dart'; import 'package:moxxmpp/src/xeps/xep_0030/types.dart'; class RoomInformation { @@ -7,6 +10,7 @@ class RoomInformation { required this.jid, required this.features, required this.name, + this.roomInfo, }); /// Constructs a [RoomInformation] object from a [DiscoInfo] object. @@ -21,6 +25,11 @@ class RoomInformation { name: discoInfo.identities .firstWhere((i) => i.category == 'conference') .name!, + roomInfo: discoInfo.extendedInfo.firstWhereOrNull((form) { + final field = form.getFieldByVar(formVarFormType); + return field?.type == 'hidden' && + field?.values.first == roomInfoFormType; + }), ); /// The JID of the Multi-User Chat (MUC) room. @@ -31,6 +40,9 @@ class RoomInformation { /// The name or title of the Multi-User Chat (MUC) room. final String name; + + /// The data form containing room information. + final DataForm? roomInfo; } /// The used message-id and an optional origin-id.