diff --git a/packages/moxxmpp/lib/moxxmpp.dart b/packages/moxxmpp/lib/moxxmpp.dart index e44a60f..f719c21 100644 --- a/packages/moxxmpp/lib/moxxmpp.dart +++ b/packages/moxxmpp/lib/moxxmpp.dart @@ -48,6 +48,7 @@ export 'package:moxxmpp/src/xeps/xep_0030/errors.dart'; export 'package:moxxmpp/src/xeps/xep_0030/helpers.dart'; export 'package:moxxmpp/src/xeps/xep_0030/types.dart'; export 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart'; +export 'package:moxxmpp/src/xeps/xep_0045/xep_0045.dart'; export 'package:moxxmpp/src/xeps/xep_0054.dart'; export 'package:moxxmpp/src/xeps/xep_0060/errors.dart'; export 'package:moxxmpp/src/xeps/xep_0060/helpers.dart'; diff --git a/packages/moxxmpp/lib/src/namespaces.dart b/packages/moxxmpp/lib/src/namespaces.dart index f0be542..c821412 100644 --- a/packages/moxxmpp/lib/src/namespaces.dart +++ b/packages/moxxmpp/lib/src/namespaces.dart @@ -20,6 +20,9 @@ const discoItemsXmlns = 'http://jabber.org/protocol/disco#items'; // XEP-0033 const extendedAddressingXmlns = 'http://jabber.org/protocol/address'; +// XEP-0045 +const mucXmlns = 'http://jabber.org/protocol/muc'; + // XEP-0054 const vCardTempXmlns = 'vcard-temp'; const vCardTempUpdate = 'vcard-temp:x:update'; diff --git a/packages/moxxmpp/lib/src/xeps/xep_0045/errors.dart b/packages/moxxmpp/lib/src/xeps/xep_0045/errors.dart index 4b07b68..db5bcbf 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0045/errors.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0045/errors.dart @@ -1,3 +1,5 @@ abstract class MUCError {} class InvalidStanzaFormat extends MUCError {} + +class NoNicknameSpecified extends MUCError {} diff --git a/packages/moxxmpp/lib/src/xeps/xep_0045/types.dart b/packages/moxxmpp/lib/src/xeps/xep_0045/types.dart index c0ef218..675a835 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0045/types.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0045/types.dart @@ -9,7 +9,7 @@ class RoomInformation { }); factory RoomInformation.fromStanza({ - required String roomJID, + required JID roomJID, required XMLNode stanza, }) { final featureNodes = stanza.children[0].findTags('feature'); @@ -31,7 +31,7 @@ class RoomInformation { throw InvalidStanzaFormat(); } } - final String jid; + final JID jid; final List features; final String name; } 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 e04ab5e..0b3f61e 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart @@ -8,15 +8,16 @@ class MUCManager extends XmppManagerBase { @override Future isSupported() async => true; - Future> queryRoomInformation( - String roomJID) async { + Future> queryRoomInformation({ + required JID roomJID, + }) async { final attrs = getAttributes(); try { final result = await attrs.sendStanza( StanzaDetails( Stanza.iq( type: 'get', - to: roomJID, + to: roomJID.toString(), children: [ XMLNode.xmlns( tag: 'query', @@ -33,4 +34,53 @@ class MUCManager extends XmppManagerBase { return Result(InvalidStanzaFormat()); } } + + Future> joinRoom({ + required JID roomJIDWithNickname, + }) async { + if (roomJIDWithNickname.resource.isEmpty) { + return Result(NoNicknameSpecified()); + } + final attrs = getAttributes(); + try { + await attrs.sendStanza( + StanzaDetails( + Stanza.presence( + to: roomJIDWithNickname.toString(), + children: [ + XMLNode.xmlns( + tag: 'x', + xmlns: mucXmlns, + ) + ], + ), + ), + ); + return const Result(true); + } catch (e) { + return Result(InvalidStanzaFormat()); + } + } + + Future> leaveRoom({ + required JID roomJIDWithNickname, + }) async { + if (roomJIDWithNickname.resource.isEmpty) { + return Result(NoNicknameSpecified()); + } + final attrs = getAttributes(); + try { + await attrs.sendStanza( + StanzaDetails( + Stanza.presence( + to: roomJIDWithNickname.toString(), + type: 'unavailable', + ), + ), + ); + return const Result(true); + } catch (e) { + return Result(InvalidStanzaFormat()); + } + } }