mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 16:55:10 +00:00
[ADD] Starting DMs XMPP->Matrix
This commit is contained in:
parent
ed712a9f28
commit
299f473a81
4 changed files with 108 additions and 5 deletions
40
src/AS.c
40
src/AS.c
|
|
@ -431,6 +431,46 @@ ASCreateRoom(const ParseeConfig *conf, char *by, char *alias)
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
char *
|
||||||
|
ASCreateDM(const ParseeConfig *conf, char *by, char *with)
|
||||||
|
{
|
||||||
|
HttpClientContext *ctx = NULL;
|
||||||
|
HashMap *json = NULL;
|
||||||
|
char *path, *id;
|
||||||
|
if (!conf || !by || !with)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
path = StrConcat(3,
|
||||||
|
"/_matrix/client/v3/createRoom",
|
||||||
|
"?user_id=", by
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx = ParseeCreateRequest(
|
||||||
|
conf,
|
||||||
|
HTTP_POST, path
|
||||||
|
);
|
||||||
|
Free(path);
|
||||||
|
json = HashMapCreate();
|
||||||
|
{
|
||||||
|
Array *invitees = ArrayCreate();
|
||||||
|
|
||||||
|
ArrayAdd(invitees, JsonValueString(with));
|
||||||
|
HashMapSet(json, "invite", JsonValueArray(invitees));
|
||||||
|
HashMapSet(json, "is_direct", JsonValueBoolean(true));
|
||||||
|
}
|
||||||
|
ASAuthenticateRequest(conf, ctx);
|
||||||
|
ParseeSetRequestJSON(ctx, json);
|
||||||
|
|
||||||
|
JsonFree(json);
|
||||||
|
json = JsonDecode(HttpClientStream(ctx));
|
||||||
|
id = StrDuplicate(JsonValueAsString(HashMapGet(json, "room_id")));
|
||||||
|
HttpClientContextFree(ctx);
|
||||||
|
JsonFree(json);
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
void
|
void
|
||||||
ASSetAvatar(const ParseeConfig *conf, char *user, char *mxc)
|
ASSetAvatar(const ParseeConfig *conf, char *user, char *mxc)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -63,3 +63,49 @@ StrFreeLines(char **split)
|
||||||
|
|
||||||
Free(orig);
|
Free(orig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
StrLines(char **split)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
if (!split)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; *split++; i++)
|
||||||
|
{
|
||||||
|
/* Left blank */
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
static size_t
|
||||||
|
StrMaxLine(char **split)
|
||||||
|
{
|
||||||
|
size_t max = 0;
|
||||||
|
if (!split)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (*split)
|
||||||
|
{
|
||||||
|
size_t len = strlen(*split++);
|
||||||
|
if (len > max)
|
||||||
|
{
|
||||||
|
max = len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringRect
|
||||||
|
StrFullRect(char **split)
|
||||||
|
{
|
||||||
|
return ((StringRect) {
|
||||||
|
.start_line = 0, .start_char = 0,
|
||||||
|
.end_line = StrLines(split),
|
||||||
|
.end_char = StrMaxLine(split),
|
||||||
|
.source_lines = split
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -286,10 +286,7 @@ ParseeVerifyAllStanza(ParseeData *args, XMLElement *stanza)
|
||||||
struct XMPPThread;
|
struct XMPPThread;
|
||||||
typedef struct XMPPThreadInfo {
|
typedef struct XMPPThreadInfo {
|
||||||
/* A FIFO of stanzas inbound, to be read by dispatcher
|
/* A FIFO of stanzas inbound, to be read by dispatcher
|
||||||
* threads.
|
* threads. */
|
||||||
*
|
|
||||||
* TODO: Using it's length in !stats can be useful
|
|
||||||
* for having a "congestion" metric for Parsee admins... */
|
|
||||||
Array *stanzas;
|
Array *stanzas;
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
|
|
||||||
|
|
@ -583,6 +580,25 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
||||||
room = ParseeFindDMRoom(args, to, from);
|
room = ParseeFindDMRoom(args, to, from);
|
||||||
data = ArrayGet(body->children, 0);
|
data = ArrayGet(body->children, 0);
|
||||||
|
|
||||||
|
/* TODO: CLEAN THAT UP */
|
||||||
|
mroom_id = ParseeGetBridgedRoom(args, stanza);
|
||||||
|
if (!mroom_id && !room && !XMPPIsParseeStanza(stanza) &&
|
||||||
|
to && *to == '@')
|
||||||
|
{
|
||||||
|
DbRef *room_ref;
|
||||||
|
HashMap *room_json;
|
||||||
|
char *from = HashMapGet(stanza->attrs, "from");
|
||||||
|
|
||||||
|
room = ASCreateDM(args->config, from_matrix, to);
|
||||||
|
|
||||||
|
room_ref = DbCreate(args->db, 3, "rooms", room, "data");
|
||||||
|
room_json = DbJson(room_ref);
|
||||||
|
HashMapSet(room_json, "is_direct", JsonValueBoolean(true));
|
||||||
|
HashMapSet(room_json, "xmpp_user", JsonValueString(from));
|
||||||
|
DbUnlock(args->db, room_ref);
|
||||||
|
ParseePushDMRoom(args, to, from, room);
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO: THIS IS A HACK. THIS CODE IGNORES ALL MUC MESSAGES EVER
|
/* TODO: THIS IS A HACK. THIS CODE IGNORES ALL MUC MESSAGES EVER
|
||||||
* SENT TO NON-PARSEE PUPPETS, AS A "FIX" TO THE MULTITHREADED
|
* SENT TO NON-PARSEE PUPPETS, AS A "FIX" TO THE MULTITHREADED
|
||||||
* ISSUE.
|
* ISSUE.
|
||||||
|
|
@ -596,7 +612,6 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mroom_id = ParseeGetBridgedRoom(args, stanza);
|
|
||||||
if (mroom_id && !XMPPIsParseeStanza(stanza))
|
if (mroom_id && !XMPPIsParseeStanza(stanza))
|
||||||
{
|
{
|
||||||
char *res = ParseeGetResource(from);
|
char *res = ParseeGetResource(from);
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,8 @@ extern void ASSetPL(const ParseeConfig *conf, char *id, HashMap *m);
|
||||||
* returns it's ID if it exists. */
|
* returns it's ID if it exists. */
|
||||||
extern char * ASCreateRoom(const ParseeConfig *c, char *by, char *alias);
|
extern char * ASCreateRoom(const ParseeConfig *c, char *by, char *alias);
|
||||||
|
|
||||||
|
extern char * ASCreateDM(const ParseeConfig *c, char *by, char *with);
|
||||||
|
|
||||||
/** Sets the user's global display{name]
|
/** Sets the user's global display{name]
|
||||||
* --------
|
* --------
|
||||||
* Returns: NOTHING
|
* Returns: NOTHING
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue