[FIX] Use the puppet's name when pinged if possible

This commit is contained in:
lda 2025-02-11 17:18:01 +00:00
commit 176f390c4b
4 changed files with 26 additions and 16 deletions

View file

@ -370,7 +370,7 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
char *ev_id = GrabString(event, 1, "event_id"); char *ev_id = GrabString(event, 1, "event_id");
char *chat_id = NULL, *muc_id = NULL; char *chat_id = NULL, *muc_id = NULL;
char *reply_id = MatrixGetReply(event); char *reply_id = MatrixGetReply(event);
char *xepd = ParseeXMPPify(event); char *xepd = ParseeXMPPify(data, event);
char *type, *user, *xmppified_user = NULL, *to = NULL; char *type, *user, *xmppified_user = NULL, *to = NULL;
char *unauth = NULL; char *unauth = NULL;
char *origin_id = NULL, *stanza = NULL; char *origin_id = NULL, *stanza = NULL;

View file

@ -20,7 +20,7 @@ typedef struct XMPPFlags {
bool quote; bool quote;
} XMPPFlags; } XMPPFlags;
static char * static char *
XMPPifyElement(HashMap *event, XMLElement *elem, XMPPFlags flags) XMPPifyElement(const ParseeConfig *conf, HashMap *event, XMLElement *elem, XMPPFlags flags)
{ {
char *xepd = NULL, *tmp = NULL; char *xepd = NULL, *tmp = NULL;
@ -70,7 +70,7 @@ XMPPifyElement(HashMap *event, XMLElement *elem, XMPPFlags flags)
for (i = 0; i < ArraySize(elem->children); i++) for (i = 0; i < ArraySize(elem->children); i++)
{ {
child = ArrayGet(elem->children, i); child = ArrayGet(elem->children, i);
subxep = XMPPifyElement(event, child, flags); subxep = XMPPifyElement(conf, event, child, flags);
Concat(subxep); Concat(subxep);
Free(subxep); Free(subxep);
@ -83,7 +83,7 @@ XMPPifyElement(HashMap *event, XMLElement *elem, XMPPFlags flags)
for (i = 0; i < ArraySize(elem->children); i++) for (i = 0; i < ArraySize(elem->children); i++)
{ {
child = ArrayGet(elem->children, i); child = ArrayGet(elem->children, i);
subxep = XMPPifyElement(event, child, flags); subxep = XMPPifyElement(conf, event, child, flags);
Concat(subxep); Concat(subxep);
Free(subxep); Free(subxep);
@ -96,7 +96,7 @@ XMPPifyElement(HashMap *event, XMLElement *elem, XMPPFlags flags)
for (i = 0; i < ArraySize(elem->children); i++) for (i = 0; i < ArraySize(elem->children); i++)
{ {
child = ArrayGet(elem->children, i); child = ArrayGet(elem->children, i);
subxep = XMPPifyElement(event, child, flags); subxep = XMPPifyElement(conf, event, child, flags);
Concat(subxep); Concat(subxep);
Free(subxep); Free(subxep);
@ -129,7 +129,7 @@ XMPPifyElement(HashMap *event, XMLElement *elem, XMPPFlags flags)
for (i = 0; i < ArraySize(elem->children); i++) for (i = 0; i < ArraySize(elem->children); i++)
{ {
child = ArrayGet(elem->children, i); child = ArrayGet(elem->children, i);
subxep = XMPPifyElement(event, child, flags); subxep = XMPPifyElement(conf, event, child, flags);
Concat(subxep); Concat(subxep);
Free(subxep); Free(subxep);
@ -144,7 +144,7 @@ XMPPifyElement(HashMap *event, XMLElement *elem, XMPPFlags flags)
for (i = 0; i < ArraySize(elem->children); i++) for (i = 0; i < ArraySize(elem->children); i++)
{ {
child = ArrayGet(elem->children, i); child = ArrayGet(elem->children, i);
subxep = XMPPifyElement(event, child, flags); subxep = XMPPifyElement(conf, event, child, flags);
Concat(subxep); Concat(subxep);
Free(subxep); Free(subxep);
@ -162,11 +162,19 @@ XMPPifyElement(HashMap *event, XMLElement *elem, XMPPFlags flags)
UserID *id = MatrixParseIDFromMTO(pref); UserID *id = MatrixParseIDFromMTO(pref);
if (id) if (id)
{ {
char *real_id = StrConcat(4, "@", id->localpart, ":", id->server);
/* TODO: Detect if it already is a Parsee user */ /* TODO: Detect if it already is a Parsee user */
Concat("@"); if (ParseeIsPuppet(conf, real_id))
Concat(id->localpart); {
Concat(":"); char *name = ASGetName(conf, NULL, real_id);
Concat(id->server); Concat((name ? name : real_id));
Free(name);
}
else
{
Concat(real_id);
}
Free(real_id);
} }
else else
{ {
@ -180,7 +188,7 @@ XMPPifyElement(HashMap *event, XMLElement *elem, XMPPFlags flags)
for (i = 0; i < ArraySize(elem->children); i++) for (i = 0; i < ArraySize(elem->children); i++)
{ {
child = ArrayGet(elem->children, i); child = ArrayGet(elem->children, i);
subxep = XMPPifyElement(event, child, flags); subxep = XMPPifyElement(conf, event, child, flags);
Concat(subxep); Concat(subxep);
Free(subxep); Free(subxep);
@ -196,7 +204,7 @@ XMPPifyElement(HashMap *event, XMLElement *elem, XMPPFlags flags)
for (i = 0; i < ArraySize(elem->children); i++) for (i = 0; i < ArraySize(elem->children); i++)
{ {
child = ArrayGet(elem->children, i); child = ArrayGet(elem->children, i);
subxep = XMPPifyElement(event, child, flags); subxep = XMPPifyElement(conf, event, child, flags);
Concat(subxep); Concat(subxep);
Free(subxep); Free(subxep);
@ -237,7 +245,7 @@ GetHTMLBody(HashMap *event)
return GrabString(event, 2, "content", "formatted_body"); return GrabString(event, 2, "content", "formatted_body");
} }
char * char *
ParseeXMPPify(HashMap *event) ParseeXMPPify(ParseeData *data, HashMap *event)
{ {
char *type, *format, *html; char *type, *format, *html;
char *xepd = NULL; char *xepd = NULL;
@ -278,7 +286,7 @@ ParseeXMPPify(HashMap *event)
} }
flags.quote = false; flags.quote = false;
xepd = XMPPifyElement(event, elem, flags); xepd = XMPPifyElement(data ? data->config : NULL, event, elem, flags);
XMLFreeElement(elem); XMLFreeElement(elem);
Free(html); Free(html);

View file

@ -56,6 +56,8 @@ XMPPDispatcher(void *argp)
if (!stanza) if (!stanza)
{ {
/* TODO: We shouldn't be busywaiting. Even with a sleep call.
*/
UtilSleepMillis(10); UtilSleepMillis(10);
continue; continue;
} }

View file

@ -356,7 +356,7 @@ extern int ParseeFindDatastartU(char *data);
/* XMPP-ifies a message event to XEP-0393 if possible. */ /* XMPP-ifies a message event to XEP-0393 if possible. */
extern char * ParseeXMPPify(HashMap *event); extern char * ParseeXMPPify(ParseeData *data, HashMap *event);
/* Finds an event ID from an ID in the stanza's attributes */ /* Finds an event ID from an ID in the stanza's attributes */
extern char * ParseeEventFromID(ParseeData *d, char *c_id, char *ori_id); extern char * ParseeEventFromID(ParseeData *d, char *c_id, char *ori_id);