[FIX] Leaves now actually do matter on Matrix

This commit is contained in:
LDA 2024-09-07 18:37:45 +02:00
commit 53739dd42d
4 changed files with 46 additions and 1 deletions

View file

@ -13,6 +13,9 @@
#include <ctype.h>
static const char *
GetXMPPInformation(ParseeData *data, HashMap *event, char **from, char **to);
static void
JoinMUC(ParseeData *data, HashMap *event, char *jid, char *muc, char *name)
{
@ -121,6 +124,21 @@ ParseeMemberHandler(ParseeData *data, HashMap *event)
muc_id = ParseeGetMUCID(data, chat_id);
if (!chat_id)
{
/* If it can't be found, try to see if it's as a DM */
char *info_from = NULL, *info_to = NULL;
const char *type = GetXMPPInformation(data, event, &info_from, &info_to);
if (StrEquals(type, "chat"))
{
char *jid_to = ParseeTrimJID(info_to);
Log(LOG_DEBUG, "('%s'->'%s') is gone.", state_key, info_to);
/* TODO: Send a last DM, signifying that all is gone. */
ParseeDeleteDM(data, state_key, jid_to);
Free(jid_to);
}
Free(info_from);
Free(info_to);
goto end;
}

View file

@ -353,6 +353,22 @@ ParseePushDMRoom(ParseeData *d, char *mxid, char *jid, char *r)
Free(dmid);
return;
}
void
ParseeDeleteDM(ParseeData *d, char *mxid, char *jid)
{
DbRef *ref;
HashMap *j;
char *dmid;
if (!d || !mxid || !jid)
{
return;
}
dmid = ParseeGetDMID(mxid, jid);
DbDelete(d->db, 2, "users", dmid);
Free(dmid);
return;
}
char *
ParseeTrimJID(char *jid)

View file

@ -192,6 +192,7 @@ end_error:
/* TODO: CLEAN THAT UP INTO A CREATEDM FUNCTION */
mroom_id = ParseeGetBridgedRoom(args, stanza);
Log(LOG_DEBUG, "Bridging to '%s'", mroom_id);
if (!mroom_id && !room && !XMPPIsParseeStanza(stanza) &&
to && *to == '@')
{
@ -202,6 +203,7 @@ end_error:
ASRegisterUser(args->config, from_matrix);
room = ASCreateDM(args->config, from_matrix, to);
mroom_id = StrDuplicate(room);
Log(LOG_INFO, "Creating a DM to '%s'(%s)", to, mroom_id);
if (room)
{
room_ref = DbCreate(args->db, 3, "rooms", room, "data");

View file

@ -223,9 +223,18 @@ extern char * ParseeFindDMRoom(ParseeData *data, char *mxid, char *jid);
/* Gets a DM ID from a Matrix and Jabber user */
extern char * ParseeGetDMID(char *mxid, char *jid);
/* Creates a DM mapping in the database */
/** Creates a DM mapping in the database.
* -------------------------
* Modifies: the Parsee database
* See-Also: ParseeDeleteDM */
extern void ParseePushDMRoom(ParseeData *, char *mxid, char *jid, char *r);
/** Destroys a DM mapping from the database, making it effectively non-existant.
* ---------------------
* Modifies: the Parsee database
* See-Also: ParseePushDMRoom */
extern void ParseeDeleteDM(ParseeData *data, char *mxid, char *jid);
/* Trims the component from a JID */
extern char * ParseeTrimJID(char *jid);