feat(xep): Set base for XEP 0045 implementation
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
This commit is contained in:
parent
83ebe58c47
commit
762cf1c77a
@ -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';
|
||||||
|
3
packages/moxxmpp/lib/src/xeps/xep_0045/errors.dart
Normal file
3
packages/moxxmpp/lib/src/xeps/xep_0045/errors.dart
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
abstract class MUCError {}
|
||||||
|
|
||||||
|
class InvalidStanzaFormat extends MUCError {}
|
37
packages/moxxmpp/lib/src/xeps/xep_0045/types.dart
Normal file
37
packages/moxxmpp/lib/src/xeps/xep_0045/types.dart
Normal 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;
|
||||||
|
}
|
36
packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart
Normal file
36
packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user