[ADD/WIP] XMPP->Matrix user statuses

Still untested because of performance reasons around statuses. Also,
how is presence basically a spec feature, and yet somehow manages to be
implemented by _no one_? Please, _implement it_ into yall's clients.
This commit is contained in:
LDA 2024-07-09 15:49:03 +02:00
commit e4c6994f61
3 changed files with 92 additions and 2 deletions

View file

@ -946,3 +946,45 @@ ASRedact(const ParseeConfig *c, char *room, char *user, char *e_id)
return;
}
void
ASSetStatus(const ParseeConfig *c, char *user, UserStatus status, char *msg)
{
HttpClientContext *ctx = NULL;
HashMap *request;
char *path;
char *status_str = NULL;
if (!c || !user || !msg)
{
return;
}
switch (status)
{
case USER_STATUS_ONLINE: status_str = "online"; break;
case USER_STATUS_OFFLINE: status_str = "offline"; break;
case USER_STATUS_UNAVAILABLE: status_str = "unavailable"; break;
default: return;
}
user = HttpUrlEncode(user);
path = StrConcat(5,
"/_matrix/client/v3/presence/",user,"/status",
"?user_id=", user
);
Free(user);
request = HashMapCreate();
HashMapSet(request, "presence", JsonValueString(status_str));
if (msg)
{
HashMapSet(request, "status_msg", JsonValueString(msg));
}
ctx = ParseeCreateRequest(c, HTTP_PUT, path);
ASAuthenticateRequest(c, ctx);
ParseeSetRequestJSON(ctx, request);
JsonFree(request);
HttpClientContextFree(ctx);
Free(path);
}