mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-14 00:45:10 +00:00
[MOD/ADD] Separate AS code, XMPP reactions removal
This commit is contained in:
parent
1b62072a3a
commit
fb511b4df0
16 changed files with 1183 additions and 1029 deletions
119
src/AS/Indicators.c
Normal file
119
src/AS/Indicators.c
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
#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 10 minutes straight, they got something weird man. */
|
||||
HashMapSet(json, "timeout", JsonValueBoolean(10 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue