fix(xep): Fix replies in the context of Gajim

This commit is contained in:
PapaTutuWawa 2024-06-16 14:56:07 +02:00
parent b3c8a6cd2f
commit 365ff2f238
3 changed files with 35 additions and 34 deletions

View File

@ -166,7 +166,6 @@ const stickersXmlns = 'urn:xmpp:stickers:0';
// XEP-0461 // XEP-0461
const replyXmlns = 'urn:xmpp:reply:0'; const replyXmlns = 'urn:xmpp:reply:0';
const fallbackXmlns = 'urn:xmpp:feature-fallback:0';
// ??? // ???
const urlDataXmlns = 'http://jabber.org/protocol/url-data'; const urlDataXmlns = 'http://jabber.org/protocol/url-data';

View File

@ -107,40 +107,41 @@ class MessageRepliesManager extends XmppManagerBase {
TypedMap<StanzaHandlerExtension> extensions, TypedMap<StanzaHandlerExtension> extensions,
) { ) {
final data = extensions.get<ReplyData>(); final data = extensions.get<ReplyData>();
return data != null if (data == null) {
? [ return [];
XMLNode.xmlns( }
tag: 'reply', return [
xmlns: replyXmlns, XMLNode.xmlns(
attributes: { tag: 'reply',
// The to attribute is optional xmlns: replyXmlns,
if (data.jid != null) 'to': data.jid!.toString(), attributes: {
// The to attribute is optional
if (data.jid != null) 'to': data.jid!.toString(),
'id': data.id, 'id': data.id,
},
),
if (data.body != null)
XMLNode(
tag: 'body',
text: data.body,
),
if (data.body != null)
XMLNode.xmlns(
tag: 'fallback',
xmlns: fallbackIndicationXmlns,
attributes: {'for': replyXmlns},
children: [
XMLNode(
tag: 'body',
attributes: {
'start': data.start!.toString(),
'end': data.end!.toString(),
}, },
), ),
if (data.body != null) ],
XMLNode( ),
tag: 'body', ];
text: data.body,
),
if (data.body != null)
XMLNode.xmlns(
tag: 'fallback',
xmlns: fallbackXmlns,
attributes: {'for': replyXmlns},
children: [
XMLNode(
tag: 'body',
attributes: {
'start': data.start!.toString(),
'end': data.end!.toString(),
},
),
],
),
]
: [];
} }
Future<StanzaHandlerData> _onMessage( Future<StanzaHandlerData> _onMessage(
@ -154,7 +155,8 @@ class MessageRepliesManager extends XmppManagerBase {
int? end; int? end;
// TODO(Unknown): Maybe extend firstTag to also look for attributes // TODO(Unknown): Maybe extend firstTag to also look for attributes
final fallback = stanza.firstTag('fallback', xmlns: fallbackXmlns); final fallback =
stanza.firstTag('fallback', xmlns: fallbackIndicationXmlns);
if (fallback != null) { if (fallback != null) {
final body = fallback.firstTag('body')!; final body = fallback.firstTag('body')!;
start = int.parse(body.attributes['start']! as String); start = int.parse(body.attributes['start']! as String);

View File

@ -253,7 +253,7 @@ void main() {
<message id="aaaaaaaaa" from="user@example.org" to="polynomdivision@test.server/abc123" type="chat"> <message id="aaaaaaaaa" from="user@example.org" to="polynomdivision@test.server/abc123" type="chat">
<body>> Anna wrote:\n> We should bake a cake\nGreat idea!</body> <body>> Anna wrote:\n> We should bake a cake\nGreat idea!</body>
<reply to='anna@example.com/laptop' id='message-id1' xmlns='urn:xmpp:reply:0' /> <reply to='anna@example.com/laptop' id='message-id1' xmlns='urn:xmpp:reply:0' />
<fallback xmlns='urn:xmpp:feature-fallback:0' for='urn:xmpp:reply:0'> <fallback xmlns='urn:xmpp:fallback:0' for='urn:xmpp:reply:0'>
<body start="0" end="38" /> <body start="0" end="38" />
</fallback> </fallback>
</message> </message>