mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 19:55:10 +00:00
[MOD] One-way Matrix->XMPP comms.
This is not sanitised. I need to make an XML writer.
This commit is contained in:
parent
868f0e4d9c
commit
bdb4fd2f68
17 changed files with 421 additions and 61 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include <Parsee.h>
|
||||
|
||||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Json.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
|
|
@ -9,42 +10,77 @@
|
|||
|
||||
#define GrabString(obj, ...) JsonValueAsString(JsonGet(obj, __VA_ARGS__))
|
||||
static void
|
||||
ParseeMemberHandler(const ParseeConfig *conf, HashMap *event)
|
||||
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");
|
||||
const ParseeConfig *conf = data->config;
|
||||
Log(LOG_INFO, "Membership '%s'->'%s'", state_key, membership);
|
||||
|
||||
if (StrEquals(membership, "invite") && ParseeIsPuppet(conf, state_key))
|
||||
{
|
||||
DbRef *ref;
|
||||
HashMap *json;
|
||||
char *jid;
|
||||
Log(LOG_INFO, "Looks like %s was invited to %s",
|
||||
state_key,
|
||||
GrabString(event, 1, "room_id")
|
||||
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);
|
||||
|
||||
HashMapSet(json, "is_direct", JsonValueBoolean(true));
|
||||
HashMapSet(json, "xmpp_user", JsonValueString(jid));
|
||||
|
||||
/* Pretend everything is a dm, ignoring is_direct */
|
||||
if (jid)
|
||||
{
|
||||
Free(jid);
|
||||
}
|
||||
DbUnlock(data->db, ref);
|
||||
}
|
||||
}
|
||||
static void
|
||||
ParseeMessageHandler(const ParseeConfig *conf, HashMap *event)
|
||||
ParseeMessageHandler(ParseeData *data, HashMap *event)
|
||||
{
|
||||
XMPPComponent *jabber = data->jabber;
|
||||
DbRef *ref;
|
||||
HashMap *json;
|
||||
|
||||
char *msgtype = GrabString(event, 2, "content", "msgtype");
|
||||
char *body = GrabString(event, 2, "content", "body");
|
||||
char *id = GrabString(event, 1, "room_id");
|
||||
if (StrEquals(body, "!help"))
|
||||
char *sender = GrabString(event, 1, "sender");
|
||||
|
||||
ref = DbLock(data->db, 3, "rooms", id, "data");
|
||||
json = DbJson(ref);
|
||||
|
||||
if (JsonValueAsBoolean(HashMapGet(json, "is_direct")))
|
||||
{
|
||||
Log(LOG_ERR, "Not implemented!");
|
||||
ASSend(conf, id, NULL, "m.room.message",
|
||||
MatrixCreateNotice("No help, pal.")
|
||||
);
|
||||
char *user = GrabString(json, 1, "xmpp_user");
|
||||
char *local = ParseeEncodeMXID(sender);
|
||||
|
||||
Log(LOG_INFO, "Sending to %s on XMPP", user);
|
||||
XMPPSendPlain(jabber, local, user, body, NULL);
|
||||
|
||||
Free(local);
|
||||
}
|
||||
|
||||
DbUnlock(data->db, ref);
|
||||
}
|
||||
|
||||
void
|
||||
ParseeEventHandler(const ParseeConfig *conf, HashMap *event)
|
||||
ParseeEventHandler(ParseeData *data, HashMap *event)
|
||||
{
|
||||
char *event_type;
|
||||
if (!conf || !event)
|
||||
if (!data || !event)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -57,12 +93,12 @@ ParseeEventHandler(const ParseeConfig *conf, HashMap *event)
|
|||
event_type = GrabString(event, 1, "type");
|
||||
if (StrEquals(event_type, "m.room.member"))
|
||||
{
|
||||
ParseeMemberHandler(conf, event);
|
||||
ParseeMemberHandler(data, event);
|
||||
return;
|
||||
}
|
||||
if (StrEquals(event_type, "m.room.message"))
|
||||
{
|
||||
ParseeMessageHandler(conf, event);
|
||||
ParseeMessageHandler(data, event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue