feat(xep): Add joinRoom, leaveRoom routines.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
This commit is contained in:
		
							parent
							
								
									762cf1c77a
								
							
						
					
					
						commit
						68809469f6
					
				@ -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/helpers.dart';
 | 
				
			||||||
export 'package:moxxmpp/src/xeps/xep_0030/types.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_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_0054.dart';
 | 
				
			||||||
export 'package:moxxmpp/src/xeps/xep_0060/errors.dart';
 | 
					export 'package:moxxmpp/src/xeps/xep_0060/errors.dart';
 | 
				
			||||||
export 'package:moxxmpp/src/xeps/xep_0060/helpers.dart';
 | 
					export 'package:moxxmpp/src/xeps/xep_0060/helpers.dart';
 | 
				
			||||||
 | 
				
			|||||||
@ -20,6 +20,9 @@ const discoItemsXmlns = 'http://jabber.org/protocol/disco#items';
 | 
				
			|||||||
// XEP-0033
 | 
					// XEP-0033
 | 
				
			||||||
const extendedAddressingXmlns = 'http://jabber.org/protocol/address';
 | 
					const extendedAddressingXmlns = 'http://jabber.org/protocol/address';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// XEP-0045
 | 
				
			||||||
 | 
					const mucXmlns = 'http://jabber.org/protocol/muc';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// XEP-0054
 | 
					// XEP-0054
 | 
				
			||||||
const vCardTempXmlns = 'vcard-temp';
 | 
					const vCardTempXmlns = 'vcard-temp';
 | 
				
			||||||
const vCardTempUpdate = 'vcard-temp:x:update';
 | 
					const vCardTempUpdate = 'vcard-temp:x:update';
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,5 @@
 | 
				
			|||||||
abstract class MUCError {}
 | 
					abstract class MUCError {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class InvalidStanzaFormat extends MUCError {}
 | 
					class InvalidStanzaFormat extends MUCError {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class NoNicknameSpecified extends MUCError {}
 | 
				
			||||||
 | 
				
			|||||||
@ -9,7 +9,7 @@ class RoomInformation {
 | 
				
			|||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  factory RoomInformation.fromStanza({
 | 
					  factory RoomInformation.fromStanza({
 | 
				
			||||||
    required String roomJID,
 | 
					    required JID roomJID,
 | 
				
			||||||
    required XMLNode stanza,
 | 
					    required XMLNode stanza,
 | 
				
			||||||
  }) {
 | 
					  }) {
 | 
				
			||||||
    final featureNodes = stanza.children[0].findTags('feature');
 | 
					    final featureNodes = stanza.children[0].findTags('feature');
 | 
				
			||||||
@ -31,7 +31,7 @@ class RoomInformation {
 | 
				
			|||||||
      throw InvalidStanzaFormat();
 | 
					      throw InvalidStanzaFormat();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  final String jid;
 | 
					  final JID jid;
 | 
				
			||||||
  final List<String> features;
 | 
					  final List<String> features;
 | 
				
			||||||
  final String name;
 | 
					  final String name;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -8,15 +8,16 @@ class MUCManager extends XmppManagerBase {
 | 
				
			|||||||
  @override
 | 
					  @override
 | 
				
			||||||
  Future<bool> isSupported() async => true;
 | 
					  Future<bool> isSupported() async => true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Future<Result<RoomInformation, MUCError>> queryRoomInformation(
 | 
					  Future<Result<RoomInformation, MUCError>> queryRoomInformation({
 | 
				
			||||||
      String roomJID) async {
 | 
					    required JID roomJID,
 | 
				
			||||||
 | 
					  }) async {
 | 
				
			||||||
    final attrs = getAttributes();
 | 
					    final attrs = getAttributes();
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      final result = await attrs.sendStanza(
 | 
					      final result = await attrs.sendStanza(
 | 
				
			||||||
        StanzaDetails(
 | 
					        StanzaDetails(
 | 
				
			||||||
          Stanza.iq(
 | 
					          Stanza.iq(
 | 
				
			||||||
            type: 'get',
 | 
					            type: 'get',
 | 
				
			||||||
            to: roomJID,
 | 
					            to: roomJID.toString(),
 | 
				
			||||||
            children: [
 | 
					            children: [
 | 
				
			||||||
              XMLNode.xmlns(
 | 
					              XMLNode.xmlns(
 | 
				
			||||||
                tag: 'query',
 | 
					                tag: 'query',
 | 
				
			||||||
@ -33,4 +34,53 @@ class MUCManager extends XmppManagerBase {
 | 
				
			|||||||
      return Result(InvalidStanzaFormat());
 | 
					      return Result(InvalidStanzaFormat());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Future<Result<bool, MUCError>> 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<Result<bool, MUCError>> 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());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user