feat: Message events now contain the stanza error, if available

This commit is contained in:
PapaTutuWawa 2022-11-22 22:49:10 +01:00
parent beff05765b
commit eb8f6ba17a
3 changed files with 25 additions and 0 deletions

View File

@ -63,6 +63,7 @@ class MessageEvent extends XmppEvent {
required this.isMarkable,
required this.encrypted,
required this.other,
this.error,
this.type,
this.oob,
this.sfs,
@ -74,6 +75,7 @@ class MessageEvent extends XmppEvent {
this.funCancellation,
this.messageRetraction,
});
final StanzaError? error;
final String body;
final JID fromJid;
final JID toJid;

View File

@ -99,6 +99,7 @@ class MessageManager extends XmppManagerBase {
encrypted: state.encrypted,
messageRetraction: state.messageRetraction,
other: state.other,
error: StanzaError.fromStanza(message),
),);
return state.copyWith(done: true);

View File

@ -1,6 +1,28 @@
import 'package:moxxmpp/src/namespaces.dart';
import 'package:moxxmpp/src/stringxml.dart';
/// A simple description of the <error /> element that may be inside a stanza
class StanzaError {
StanzaError(this.type, this.error);
String type;
String error;
/// Returns a StanzaError if [stanza] contains a <error /> element. If not, returns
/// null.
static StanzaError? fromStanza(Stanza stanza) {
final error = stanza.firstTag('error');
if (error == null) return null;
final stanzaError = error.firstTagByXmlns(fullStanzaXmlns);
if (stanzaError == null) return null;
return StanzaError(
error.attributes['type']! as String,
stanzaError.tag,
);
}
}
class Stanza extends XMLNode {
// ignore: use_super_parameters
Stanza({ this.to, this.from, this.type, this.id, List<XMLNode> children = const [], required String tag, Map<String, String> attributes = const {} }) : super(