[FIX/ADD] Fix deadlock and DMs.

This commit is contained in:
LDA 2024-06-30 17:15:03 +02:00
commit 59d5ad6780
7 changed files with 57 additions and 34 deletions

View file

@ -26,19 +26,22 @@ ParseeMemberHandler(ParseeData *data, HashMap *event)
DbRef *ref;
HashMap *json;
char *jid;
bool direct = GrabBoolean(event, 2, "content", "is_direct");
bool bot = !strncmp(sender + 1, local, strlen(local));
ASJoin(conf, room_id, state_key);
jid = ParseeDecodeLocalJID(conf, state_key);
ref = DbCreate(data->db, 3, "rooms", room_id, "data");
json = DbJson(ref);
HashMapSet(json, "is_direct", JsonValueBoolean(!bot));
HashMapSet(json, "xmpp_user", JsonValueString(jid));
DbUnlock(data->db, ref);
if (direct && !bot)
{
ref = DbCreate(data->db, 3, "rooms", room_id, "data");
json = DbJson(ref);
HashMapSet(json, "is_direct", JsonValueBoolean(direct && !bot));
HashMapSet(json, "xmpp_user", JsonValueString(jid));
DbUnlock(data->db, ref);
ParseePushDMRoom(data, sender, jid, room_id);
}
ParseePushDMRoom(data, sender, jid, room_id);
/* Pretend everything is a dm, ignoring is_direct */
if (jid)
{
Free(jid);
@ -170,7 +173,9 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
char *user = GrabString(json, 1, "xmpp_user");
char *local = ParseeEncodeMXID(sender);
XMPPSendPlain(jabber, local, user, body, NULL, NULL, NULL, ev_id, NULL, NULL);
Log(LOG_INFO," Sending to %s as %s", user, local);
XMPPSendPlain(jabber, local, user, body, "chat", NULL, NULL, ev_id, NULL, NULL);
DbUnlock(data->db, ref);
Free(chat_id);