[ADD/WIP] Continue MUCwerk

oh man this is gonna be painful to do... xmpp is fine iff youre doing
DMs isnt it?
This commit is contained in:
LDA 2024-06-21 00:48:27 +02:00
commit d3b7f2fee0
19 changed files with 707 additions and 44 deletions

View file

@ -144,6 +144,30 @@ ASJoin(const ParseeConfig *conf, char *id, char *masquerade)
JsonFree(json);
}
void
ASSetState(const ParseeConfig *conf, char *id, char *type, char *key, char *mask, HashMap *state)
{
HttpClientContext *ctx = NULL;
char *path, *params;
if (!conf || !id || !type || !mask || !state)
{
JsonFree(state);
return;
}
path = StrConcat(9,
"/_matrix/client/v3/rooms/", id, "/state/",
type, "/", key, "?", "user_id=", mask
);
ctx = ParseeCreateRequest(conf, HTTP_PUT, path);
Free(path);
ASAuthenticateRequest(conf, ctx);
ParseeSetRequestJSON(ctx, state);
HttpClientContextFree(ctx);
JsonFree(state);
}
void
ASSend(const ParseeConfig *conf, char *id, char *user, char *type, HashMap *c)
{
HttpClientContext *ctx = NULL;
@ -151,6 +175,7 @@ ASSend(const ParseeConfig *conf, char *id, char *user, char *type, HashMap *c)
char *txn;
if (!conf || !id || !type || !user || !c)
{
JsonFree(c);
return;
}
@ -170,3 +195,59 @@ ASSend(const ParseeConfig *conf, char *id, char *user, char *type, HashMap *c)
HttpClientContextFree(ctx);
JsonFree(c);
}
char *
ASCreateRoom(const ParseeConfig *conf, char *by, char *alias)
{
HttpClientContext *ctx = NULL;
HashMap *json = NULL;
char *path, *id;
if (!conf || !by)
{
return NULL;
}
path = StrConcat(3,
"/_matrix/client/v3/createRoom",
"?user_id=", by
);
ctx = ParseeCreateRequest(
conf,
HTTP_POST, path
);
Free(path);
json = HashMapCreate();
if (alias)
{
char *trimmed = StrDuplicate(alias);
if (*alias == '#')
{
char *tmp, cb[2] = { 0 };
alias++;
Free(trimmed);
trimmed = NULL;
while (*alias && *alias != ':')
{
cb[0] = *alias;
tmp = trimmed;
trimmed = StrConcat(2, trimmed, cb);
Free(tmp);
alias ++;
}
}
HashMapSet(json, "room_alias_name", JsonValueString(trimmed));
Free(trimmed);
}
HashMapSet(json, "visibility", JsonValueString("public"));
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;
}