[ADD/WIP] Make basic XMPP->Matrix redactions

I'll need to use the actual redaction endpoint eventually, hence the
WIP status.
This commit is contained in:
LDA 2024-07-07 21:52:38 +02:00
commit a167d5d724
3 changed files with 47 additions and 2 deletions

View file

@ -290,6 +290,34 @@ XMPPGetReplacedID(XMLElement *stanza)
return replace ? HashMapGet(replace->attrs, "id") : NULL;
}
char *
XMPPGetRetractedID(XMLElement *stanza)
{
XMLElement *retract = XMLookForTKV(
stanza, "retract",
"xmlns", "urn:xmpp:message-retract:1"
);
char *id = retract ? HashMapGet(retract->attrs, "id") : NULL;
if (!id)
{
/* Pretend its fastened */
XMLElement *fasten = XMLookForTKV(
stanza, "apply-to",
"xmlns", "urn:xmpp:fasten:0"
);
retract = XMLookForTKV(
fasten, "retract",
"xmlns", "urn:xmpp:message-retract:0"
);
if (retract)
{
id = HashMapGet(fasten->attrs, "id");
}
}
return id;
}
char *
XMPPGetReply(XMLElement *elem)
{
XMLElement *rep = XMLookForTKV(elem, "reply", "xmlns", "urn:xmpp:reply:0");

View file

@ -527,6 +527,7 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
char *encoded = ParseeEncodeJID(args->config, decode_from, false);
char *event_id = NULL;
char *replaced = XMPPGetReplacedID(stanza);
char *retracted = XMPPGetRetractedID(stanza);
char *reply_to = XMPPGetReply(stanza);
bool chat = false;
@ -618,11 +619,26 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
Free(event_id);
event_id = NULL;
}
else if (retracted)
{
/* TODO: Use an actual redact. Not doing it now because it's not
* fun to do at the moment... */
event_id = ParseeGetEventFromID(args, stanza, retracted);
Free(ASSend(
args->config, mroom_id, encoded, "m.room.message",
MatrixCreateReplace(event_id, "[Retracted]")
));
ParseePushAllStanza(args, stanza, event_id);
pthread_mutex_unlock(&thr->info->chk_lock);
Free(event_id);
event_id = NULL;
}
else
{
/* TODO: Use HTML-formatted bodies, and respect the fallback
* trims the stanza provides us if possible. Element does
* not like raw bodies on replies too. Go figure. */
* trims the stanza provides us if possible. Element does not
* like raw bodies on replies too. Go figure. */
size_t off =
reply_to ? ParseeFindDatastart(data->data) : 0;
HashMap *ev = MatrixCreateMessage(data->data + off);

View file

@ -67,6 +67,7 @@ extern char * XMPPGetOriginID(XMLElement *);
/* Returns the origin ID of the replaced stanza, if the current one
* is a replacement notice */
extern char * XMPPGetReplacedID(XMLElement *);
extern char * XMPPGetRetractedID(XMLElement *);
/* Get the replied-to stanza ID, if existent. */
extern char * XMPPGetReply(XMLElement *elem);