feat(xep): Small fixes - review cycle 1.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
This commit is contained in:
parent
66195f66fa
commit
1f1321b269
@ -83,6 +83,8 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
),
|
),
|
||||||
MessageManager(),
|
MessageManager(),
|
||||||
PresenceManager(),
|
PresenceManager(),
|
||||||
|
OccupantIdManager(),
|
||||||
|
MUCManager()
|
||||||
])
|
])
|
||||||
..registerFeatureNegotiators([
|
..registerFeatureNegotiators([
|
||||||
ResourceBindingNegotiator(),
|
ResourceBindingNegotiator(),
|
||||||
@ -158,6 +160,47 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
),
|
),
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
),
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
// final muc = connection.getManagerById<MUCManager>(mucManager);
|
||||||
|
// final roomInformationResult = await muc!.queryRoomInformation(
|
||||||
|
// JID.fromString('moxxmpp-muc-test@muc.moxxy.org'));
|
||||||
|
// if (roomInformationResult.isType<RoomInformation>()) {
|
||||||
|
// print('Room information received');
|
||||||
|
// print(roomInformationResult.get<RoomInformation>().jid);
|
||||||
|
// print(roomInformationResult.get<RoomInformation>().name);
|
||||||
|
// print(roomInformationResult.get<RoomInformation>().features);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// final muc = connection.getManagerById<MUCManager>(mucManager);
|
||||||
|
// print('joining room');
|
||||||
|
// final roomInformationResult = await muc!.joinRoom(
|
||||||
|
// JID.fromString('moxxmpp-muc-test@muc.moxxy.org/test_1'));
|
||||||
|
// if (roomInformationResult.isType<MUCError>()) {
|
||||||
|
// print(roomInformationResult.get());
|
||||||
|
// } else {
|
||||||
|
// print(roomInformationResult.get());
|
||||||
|
// }
|
||||||
|
|
||||||
|
print('HERE IS YOUR JID');
|
||||||
|
print(connection.resource);
|
||||||
|
final sid = connection.generateId();
|
||||||
|
final originId = connection.generateId();
|
||||||
|
final message =
|
||||||
|
connection.getManagerById<MessageManager>(messageManager);
|
||||||
|
message!.sendMessage(
|
||||||
|
JID.fromString('moxxmpp-muc-test@muc.moxxy.org/ISD'),
|
||||||
|
TypedMap<StanzaHandlerExtension>.fromList([
|
||||||
|
const MessageBodyData('Testing'),
|
||||||
|
const MarkableData(true),
|
||||||
|
MessageIdData(sid),
|
||||||
|
StableIdData(originId, null),
|
||||||
|
ConversationTypeData(ConversationType.groupchatprivate)
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: const Text('Test'),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -33,3 +33,4 @@ const stickersManager = 'org.moxxmpp.stickersmanager';
|
|||||||
const entityCapabilitiesManager = 'org.moxxmpp.entitycapabilities';
|
const entityCapabilitiesManager = 'org.moxxmpp.entitycapabilities';
|
||||||
const messageProcessingHintManager = 'org.moxxmpp.messageprocessinghint';
|
const messageProcessingHintManager = 'org.moxxmpp.messageprocessinghint';
|
||||||
const occupantIdManager = 'org.moxxmpp.occupantidmanager';
|
const occupantIdManager = 'org.moxxmpp.occupantidmanager';
|
||||||
|
const mucManager = 'org.moxxmpp.mucmanager';
|
||||||
|
@ -8,7 +8,6 @@ import 'package:moxxmpp/src/managers/namespaces.dart';
|
|||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
import 'package:moxxmpp/src/util/typed_map.dart';
|
import 'package:moxxmpp/src/util/typed_map.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0045/xep_0045.dart';
|
|
||||||
import 'package:moxxmpp/src/xeps/xep_0066.dart';
|
import 'package:moxxmpp/src/xeps/xep_0066.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0447.dart';
|
import 'package:moxxmpp/src/xeps/xep_0447.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0449.dart';
|
import 'package:moxxmpp/src/xeps/xep_0449.dart';
|
||||||
@ -97,17 +96,15 @@ class MessageManager extends XmppManagerBase {
|
|||||||
/// data for building the message.
|
/// data for building the message.
|
||||||
Future<void> sendMessage(
|
Future<void> sendMessage(
|
||||||
JID to,
|
JID to,
|
||||||
TypedMap<StanzaHandlerExtension> extensions,
|
TypedMap<StanzaHandlerExtension> extensions, {
|
||||||
) async {
|
String type = 'chat',
|
||||||
|
}) async {
|
||||||
await getAttributes().sendStanza(
|
await getAttributes().sendStanza(
|
||||||
StanzaDetails(
|
StanzaDetails(
|
||||||
Stanza.message(
|
Stanza.message(
|
||||||
to: to.toString(),
|
to: to.toString(),
|
||||||
id: extensions.get<MessageIdData>()?.id,
|
id: extensions.get<MessageIdData>()?.id,
|
||||||
type: extensions.get<ConversationTypeData>()?.conversationType ==
|
type: type,
|
||||||
ConversationType.groupchat
|
|
||||||
? 'groupchat'
|
|
||||||
: 'chat',
|
|
||||||
children: _messageSendingCallbacks
|
children: _messageSendingCallbacks
|
||||||
.map((c) => c(extensions))
|
.map((c) => c(extensions))
|
||||||
.flattened
|
.flattened
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
|
/// Represents an error related to Multi-User Chat (MUC).
|
||||||
abstract class MUCError {}
|
abstract class MUCError {}
|
||||||
|
|
||||||
|
/// Error indicating an invalid (non-supported) stanza received while going
|
||||||
|
/// through normal operation/flow of an MUC.
|
||||||
class InvalidStanzaFormat extends MUCError {}
|
class InvalidStanzaFormat extends MUCError {}
|
||||||
|
|
||||||
|
/// Represents an error indicating an abnormal condition while parsing
|
||||||
|
/// the DiscoInfo response stanza in Multi-User Chat (MUC).
|
||||||
class InvalidDiscoInfoResponse extends MUCError {}
|
class InvalidDiscoInfoResponse extends MUCError {}
|
||||||
|
|
||||||
|
/// Returned when no nickname was specified from the client side while trying to
|
||||||
|
/// perform some actions on the MUC, such as joining the room.
|
||||||
class NoNicknameSpecified extends MUCError {}
|
class NoNicknameSpecified extends MUCError {}
|
||||||
|
@ -2,22 +2,33 @@ import 'package:moxxmpp/src/jid.dart';
|
|||||||
import 'package:moxxmpp/src/xeps/xep_0030/types.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/types.dart';
|
||||||
|
|
||||||
class RoomInformation {
|
class RoomInformation {
|
||||||
|
/// Represents information about a Multi-User Chat (MUC) room.
|
||||||
RoomInformation({
|
RoomInformation({
|
||||||
required this.jid,
|
required this.jid,
|
||||||
required this.features,
|
required this.features,
|
||||||
required this.name,
|
required this.name,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// Constructs a [RoomInformation] object from a [DiscoInfo] object.
|
||||||
|
/// The [DiscoInfo] object contains the necessary information to populate
|
||||||
|
/// the [RoomInformation] fields.
|
||||||
factory RoomInformation.fromDiscoInfo({
|
factory RoomInformation.fromDiscoInfo({
|
||||||
required DiscoInfo discoInfo,
|
required DiscoInfo discoInfo,
|
||||||
}) =>
|
}) =>
|
||||||
RoomInformation(
|
RoomInformation(
|
||||||
jid: discoInfo.jid!,
|
jid: discoInfo.jid!,
|
||||||
features: discoInfo.features,
|
features: discoInfo.features,
|
||||||
name: discoInfo.identities[0].name!,
|
name: discoInfo.identities
|
||||||
|
.firstWhere((i) => i.category == 'conference')
|
||||||
|
.name!,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// The JID (Jabber ID) of the Multi-User Chat (MUC) room.
|
||||||
final JID jid;
|
final JID jid;
|
||||||
|
|
||||||
|
/// A list of features supported by the Multi-User Chat (MUC) room.
|
||||||
final List<String> features;
|
final List<String> features;
|
||||||
|
|
||||||
|
/// The name or title of the Multi-User Chat (MUC) room.
|
||||||
final String name;
|
final String name;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import 'package:moxxmpp/src/stanza.dart';
|
|||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
import 'package:moxxmpp/src/types/result.dart';
|
import 'package:moxxmpp/src/types/result.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/errors.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/errors.dart';
|
||||||
|
import 'package:moxxmpp/src/xeps/xep_0030/types.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0045/errors.dart';
|
import 'package:moxxmpp/src/xeps/xep_0045/errors.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0045/types.dart';
|
import 'package:moxxmpp/src/xeps/xep_0045/types.dart';
|
||||||
@ -27,16 +28,15 @@ class MUCManager extends XmppManagerBase {
|
|||||||
Future<Result<RoomInformation, MUCError>> queryRoomInformation(
|
Future<Result<RoomInformation, MUCError>> queryRoomInformation(
|
||||||
JID roomJID,
|
JID roomJID,
|
||||||
) async {
|
) async {
|
||||||
|
final result = await getAttributes()
|
||||||
|
.getManagerById<DiscoManager>(discoManager)!
|
||||||
|
.discoInfoQuery(roomJID);
|
||||||
|
if (result.isType<DiscoError>()) {
|
||||||
|
return Result(InvalidStanzaFormat());
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
final attrs = getAttributes();
|
|
||||||
final result = await attrs
|
|
||||||
.getManagerById<DiscoManager>(discoManager)
|
|
||||||
?.discoInfoQuery(roomJID);
|
|
||||||
if (result!.isType<DiscoError>()) {
|
|
||||||
return Result(InvalidStanzaFormat());
|
|
||||||
}
|
|
||||||
final roomInformation = RoomInformation.fromDiscoInfo(
|
final roomInformation = RoomInformation.fromDiscoInfo(
|
||||||
discoInfo: result.get(),
|
discoInfo: result.get<DiscoInfo>(),
|
||||||
);
|
);
|
||||||
return Result(roomInformation);
|
return Result(roomInformation);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -45,30 +45,26 @@ class MUCManager extends XmppManagerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Result<bool, MUCError>> joinRoom(
|
Future<Result<bool, MUCError>> joinRoom(
|
||||||
JID roomJIDWithNickname,
|
JID roomJID,
|
||||||
|
String nick,
|
||||||
) async {
|
) async {
|
||||||
if (roomJIDWithNickname.resource.isEmpty) {
|
if (nick.isEmpty) {
|
||||||
return Result(NoNicknameSpecified());
|
return Result(NoNicknameSpecified());
|
||||||
}
|
}
|
||||||
final attrs = getAttributes();
|
await getAttributes().sendStanza(
|
||||||
try {
|
StanzaDetails(
|
||||||
await attrs.sendStanza(
|
Stanza.presence(
|
||||||
StanzaDetails(
|
to: roomJID.withResource(nick).toString(),
|
||||||
Stanza.presence(
|
children: [
|
||||||
to: roomJIDWithNickname.toString(),
|
XMLNode.xmlns(
|
||||||
children: [
|
tag: 'x',
|
||||||
XMLNode.xmlns(
|
xmlns: mucXmlns,
|
||||||
tag: 'x',
|
)
|
||||||
xmlns: mucXmlns,
|
],
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
return const Result(true);
|
);
|
||||||
} catch (e) {
|
return const Result(true);
|
||||||
return Result(InvalidStanzaFormat());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Result<bool, MUCError>> leaveRoom(
|
Future<Result<bool, MUCError>> leaveRoom(
|
||||||
@ -77,19 +73,14 @@ class MUCManager extends XmppManagerBase {
|
|||||||
if (roomJIDWithNickname.resource.isEmpty) {
|
if (roomJIDWithNickname.resource.isEmpty) {
|
||||||
return Result(NoNicknameSpecified());
|
return Result(NoNicknameSpecified());
|
||||||
}
|
}
|
||||||
final attrs = getAttributes();
|
await getAttributes().sendStanza(
|
||||||
try {
|
StanzaDetails(
|
||||||
await attrs.sendStanza(
|
Stanza.presence(
|
||||||
StanzaDetails(
|
to: roomJIDWithNickname.toString(),
|
||||||
Stanza.presence(
|
type: 'unavailable',
|
||||||
to: roomJIDWithNickname.toString(),
|
|
||||||
type: 'unavailable',
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
return const Result(true);
|
);
|
||||||
} catch (e) {
|
return const Result(true);
|
||||||
return Result(InvalidStanzaFormat());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user