diff --git a/src/Parsee/Chats.c b/src/Parsee/Chats.c new file mode 100644 index 0000000..6207b05 --- /dev/null +++ b/src/Parsee/Chats.c @@ -0,0 +1,39 @@ +#include + +#include +#include + +void +ParseeUnlinkRoom(ParseeData *data, char *chat_id) +{ + char *muc, *room; + DbRef *ref; + if (!data || !chat_id) + { + return; + } + + muc = ParseeGetMUCID(data, chat_id); + room = ParseeGetRoomID(data, chat_id); + if (!muc || !room) + { + Free(muc); + Free(room); + return; + } + + ref = DbLock(data->db, 1, "chats"); + JsonValueFree(HashMapDelete( + GrabObject(DbJson(ref), 1, "rooms"), + room + )); + JsonValueFree(HashMapDelete( + GrabObject(DbJson(ref), 1, "mucs"), + muc + )); + DbUnlock(data->db, ref); + DbDelete(data->db, 2, "chats", chat_id); + + Free(muc); + Free(room); +} diff --git a/src/XMPPThread/Stanzas/Presence.c b/src/XMPPThread/Stanzas/Presence.c index b2ae52a..89448b6 100644 --- a/src/XMPPThread/Stanzas/Presence.c +++ b/src/XMPPThread/Stanzas/Presence.c @@ -216,20 +216,8 @@ PresenceStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr) (IsStatus(301) || IsStatus(307))) { char *chat_id = ParseeGetFromRoomID(args, room); - char *muc = ParseeTrimJID(oid); - DbRef *ref; - ref = DbLock(args->db, 1, "chats"); - JsonValueFree(HashMapDelete( - GrabObject(DbJson(ref), 1, "rooms"), - room - )); - JsonValueFree(HashMapDelete( - GrabObject(DbJson(ref), 1, "mucs"), - muc - )); - DbUnlock(args->db, ref); - DbDelete(args->db, 2, "chats", chat_id); + ParseeUnlinkRoom(args, chat_id); Free(ASSend( args->config, room, parsee, @@ -238,7 +226,6 @@ PresenceStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr) )); ASLeave(args->config, room, parsee); Free(chat_id); - Free(muc); } diff --git a/src/include/Parsee.h b/src/include/Parsee.h index efa59eb..d0e3f1c 100644 --- a/src/include/Parsee.h +++ b/src/include/Parsee.h @@ -344,7 +344,8 @@ extern bool ParseeManageBan(ParseeData *, char *user, char *room); extern bool ParseeVerifyDMStanza(ParseeData *data, char *room_id, char *id); -/** Checks if a Matrix/XMPP user is considered as "administrator" by Parsee. +/** Checks if a Matrix/XMPP user is considered as "administrator" by + * Parsee. * ---------------------- * Returns: (whenever the user is an admin) * Modifies: NOTHING */ @@ -411,4 +412,10 @@ extern char * ParseeHMAC(char *key, uint8_t *msg, size_t msglen); * Returns: NOTHING */ extern void ParseeBroadcastStanza(ParseeData *data, char *from, XMLElement *s); +/** Destroys the mapping between a MUC and a room from a chat ID. + * ---------------- + * Modifies: the DB's room mappings + * Returns: NOTHING */ +extern void ParseeUnlinkRoom(ParseeData *data, char *chat_id); + #endif