feat: Message events now contain the stanza error, if available
This commit is contained in:
parent
beff05765b
commit
eb8f6ba17a
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user