mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 21:25:11 +00:00
120 lines
2.8 KiB
C
120 lines
2.8 KiB
C
#include <AS.h>
|
|
|
|
#include <Cytoplasm/Memory.h>
|
|
#include <Cytoplasm/Str.h>
|
|
#include <Cytoplasm/Log.h>
|
|
#include <Cytoplasm/Uri.h>
|
|
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <Matrix.h>
|
|
|
|
void
|
|
ASType(const ParseeConfig *c, char *user, char *room, bool status)
|
|
{
|
|
HttpClientContext *ctx = NULL;
|
|
HashMap *json;
|
|
char *path;
|
|
if (!c || !user || !room)
|
|
{
|
|
return;
|
|
}
|
|
|
|
user = HttpUrlEncode(user);
|
|
path = StrConcat(6,
|
|
"/_matrix/client/v3/rooms/",
|
|
room, "/typing/", user,
|
|
"?user_id=", user
|
|
);
|
|
|
|
json = HashMapCreate();
|
|
HashMapSet(json, "typing", JsonValueBoolean(status));
|
|
/* If someone types for 5 minutes straight, they got something
|
|
* weird man. */
|
|
HashMapSet(json, "timeout", JsonValueInteger(5 MINUTES));
|
|
ctx = ParseeCreateRequest(c, HTTP_PUT, path);
|
|
Free(path);
|
|
ASAuthenticateRequest(c, ctx);
|
|
ParseeSetRequestJSON(ctx, json);
|
|
JsonFree(json);
|
|
|
|
HttpClientContextFree(ctx);
|
|
Free(user);
|
|
}
|
|
|
|
void
|
|
ASPresence(const ParseeConfig *c, char *user, char *room, char *ev)
|
|
{
|
|
HttpClientContext *ctx = NULL;
|
|
HashMap *json;
|
|
char *path;
|
|
if (!c || !user || !room || !ev)
|
|
{
|
|
return;
|
|
}
|
|
|
|
user = HttpUrlEncode(user);
|
|
room = HttpUrlEncode(room);
|
|
ev = HttpUrlEncode(ev);
|
|
path = StrConcat(6,
|
|
"/_matrix/client/v3/rooms/",
|
|
room, "/receipt/m.read/", ev,
|
|
"?user_id=", user
|
|
);
|
|
|
|
json = HashMapCreate();
|
|
ctx = ParseeCreateRequest(c, HTTP_POST, path);
|
|
Free(path);
|
|
ASAuthenticateRequest(c, ctx);
|
|
ParseeSetRequestJSON(ctx, json);
|
|
JsonFree(json);
|
|
|
|
HttpClientContextFree(ctx);
|
|
Free(user);
|
|
Free(room);
|
|
Free(ev);
|
|
}
|
|
|
|
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)
|
|
{
|
|
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);
|
|
}
|