feat(xep): Set base for XEP 0045 implementation

Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
This commit is contained in:
Ikjot Singh Dhody 2023-05-29 17:10:41 +05:30
parent 83ebe58c47
commit 762cf1c77a
4 changed files with 77 additions and 0 deletions

View File

@ -31,3 +31,4 @@ const lastMessageCorrectionManager = 'org.moxxmpp.lastmessagecorrectionmanager';
const messageReactionsManager = 'org.moxxmpp.messagereactionsmanager'; const messageReactionsManager = 'org.moxxmpp.messagereactionsmanager';
const stickersManager = 'org.moxxmpp.stickersmanager'; const stickersManager = 'org.moxxmpp.stickersmanager';
const entityCapabilitiesManager = 'org.moxxmpp.entitycapabilities'; const entityCapabilitiesManager = 'org.moxxmpp.entitycapabilities';
const mucManager = 'org.moxxmpp.mucmanager';

View File

@ -0,0 +1,3 @@
abstract class MUCError {}
class InvalidStanzaFormat extends MUCError {}

View File

@ -0,0 +1,37 @@
import 'package:moxxmpp/moxxmpp.dart';
import 'package:moxxmpp/src/xeps/xep_0045/errors.dart';
class RoomInformation {
RoomInformation({
required this.jid,
required this.features,
required this.name,
});
factory RoomInformation.fromStanza({
required String roomJID,
required XMLNode stanza,
}) {
final featureNodes = stanza.children[0].findTags('feature');
final identityNodes = stanza.children[0].findTags('identity');
if (featureNodes.isNotEmpty && identityNodes.isNotEmpty) {
final features = featureNodes
.map((xmlNode) => xmlNode.attributes['var'].toString())
.toList();
final name = identityNodes[0].attributes['name'].toString();
return RoomInformation(
jid: roomJID,
features: features,
name: name,
);
} else {
// ignore: only_throw_errors
throw InvalidStanzaFormat();
}
}
final String jid;
final List<String> features;
final String name;
}

View File

@ -0,0 +1,36 @@
import 'package:moxxmpp/moxxmpp.dart';
import 'package:moxxmpp/src/xeps/xep_0045/errors.dart';
import 'package:moxxmpp/src/xeps/xep_0045/types.dart';
class MUCManager extends XmppManagerBase {
MUCManager() : super(mucManager);
@override
Future<bool> isSupported() async => true;
Future<Result<RoomInformation, MUCError>> queryRoomInformation(
String roomJID) async {
final attrs = getAttributes();
try {
final result = await attrs.sendStanza(
StanzaDetails(
Stanza.iq(
type: 'get',
to: roomJID,
children: [
XMLNode.xmlns(
tag: 'query',
xmlns: discoInfoXmlns,
)
],
),
),
);
final roomInformation =
RoomInformation.fromStanza(roomJID: roomJID, stanza: result!);
return Result(roomInformation);
} catch (e) {
return Result(InvalidStanzaFormat());
}
}
}