[ADD/WIP] Matrix<->XMPP DMs.

There is still this fun issue with the blocking XML parser leaking
memory on pthread_cancel, I'll try to deal with that later, maybe with a
test stanza.

I also apologise for swearing in the last commit. I promise it won't
happen again, Prosody.
This commit is contained in:
LDA 2024-06-18 20:59:35 +02:00
commit 2cc4b0ed17
11 changed files with 325 additions and 63 deletions

View file

@ -15,6 +15,7 @@ ParseeMemberHandler(ParseeData *data, HashMap *event)
char *state_key = GrabString(event, 1, "state_key");
char *membership = GrabString(event, 2, "content", "membership");
char *room_id = GrabString(event, 1, "room_id");
char *sender = GrabString(event, 1, "sender");
const ParseeConfig *conf = data->config;
Log(LOG_INFO, "Membership '%s'->'%s'", state_key, membership);
@ -23,28 +24,22 @@ ParseeMemberHandler(ParseeData *data, HashMap *event)
DbRef *ref;
HashMap *json;
char *jid;
Log(LOG_INFO, "Looks like %s was invited to %s",
state_key,
room_id
);
ASJoin(conf, room_id, state_key);
ref = DbCreate(data->db, 3, "rooms", room_id, "data");
json = DbJson(ref);
Log(LOG_INFO, "Grabbing JID");
jid = ParseeDecodeLocalJID(conf, state_key);
Log(LOG_INFO, "JID: %s", jid);
ref = DbCreate(data->db, 3, "rooms", room_id, "data");
json = DbJson(ref);
HashMapSet(json, "is_direct", JsonValueBoolean(true));
HashMapSet(json, "xmpp_user", JsonValueString(jid));
DbUnlock(data->db, ref);
ParseePushDMRoom(data, sender, jid, room_id);
/* Pretend everything is a dm, ignoring is_direct */
if (jid)
{
Free(jid);
}
DbUnlock(data->db, ref);
}
}
static void
@ -59,9 +54,16 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
char *id = GrabString(event, 1, "room_id");
char *sender = GrabString(event, 1, "sender");
if (ParseeIsPuppet(data->config, sender))
{
Log(LOG_INFO, "Do not bridge the puppet");
return;
}
ref = DbLock(data->db, 3, "rooms", id, "data");
json = DbJson(ref);
if (JsonValueAsBoolean(HashMapGet(json, "is_direct")))
{
char *user = GrabString(json, 1, "xmpp_user");
@ -85,11 +87,6 @@ ParseeEventHandler(ParseeData *data, HashMap *event)
return;
}
Log(LOG_INFO, "Event by '%s', with type '%s'",
JsonValueAsString(HashMapGet(event, "sender")),
JsonValueAsString(HashMapGet(event, "type"))
);
event_type = GrabString(event, 1, "type");
if (StrEquals(event_type, "m.room.member"))
{