mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 12:15:12 +00:00
[MOD] Timestamp Matrix messages
This commit is contained in:
parent
ca5f8fd5c5
commit
55ac682d26
9 changed files with 48 additions and 19 deletions
BIN
etc/media/unknown.png
Normal file
BIN
etc/media/unknown.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 542 B |
|
|
@ -1,21 +1,38 @@
|
||||||
#include <AS.h>
|
#include <AS.h>
|
||||||
|
|
||||||
#include <Cytoplasm/Memory.h>
|
#include <Cytoplasm/Memory.h>
|
||||||
|
#include <Cytoplasm/Util.h>
|
||||||
#include <Cytoplasm/Str.h>
|
#include <Cytoplasm/Str.h>
|
||||||
#include <Cytoplasm/Log.h>
|
#include <Cytoplasm/Log.h>
|
||||||
#include <Cytoplasm/Uri.h>
|
#include <Cytoplasm/Uri.h>
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <Matrix.h>
|
#include <Matrix.h>
|
||||||
|
|
||||||
|
static char *
|
||||||
|
TSToStr(uint64_t ts)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
len = snprintf(NULL, 0, "%"PRIu64, ts);
|
||||||
|
str = Malloc(len+1);
|
||||||
|
snprintf(str, len+1, "%"PRIu64, ts);
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
ASSend(const ParseeConfig *conf, char *id, char *user, char *type, HashMap *c)
|
ASSend(const ParseeConfig *conf, char *id, char *user, char *type, HashMap *c, uint64_t ts)
|
||||||
{
|
{
|
||||||
HttpClientContext *ctx = NULL;
|
HttpClientContext *ctx = NULL;
|
||||||
char *path;
|
char *path;
|
||||||
char *txn, *ret;
|
char *txn, *ret;
|
||||||
|
char *ts_str;
|
||||||
HashMap *reply;
|
HashMap *reply;
|
||||||
if (!conf || !id || !type || !user || !c)
|
if (!conf || !id || !type || !user || !c)
|
||||||
{
|
{
|
||||||
|
|
@ -23,13 +40,20 @@ ASSend(const ParseeConfig *conf, char *id, char *user, char *type, HashMap *c)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ts)
|
||||||
|
{
|
||||||
|
ts = UtilTsMillis();
|
||||||
|
}
|
||||||
|
ts_str = TSToStr(ts);
|
||||||
|
|
||||||
txn = StrRandom(16);
|
txn = StrRandom(16);
|
||||||
path = StrConcat(9,
|
path = StrConcat(11,
|
||||||
"/_matrix/client/v3/rooms/",
|
"/_matrix/client/v3/rooms/",
|
||||||
id, "/send/", type, "/", txn, "?",
|
id, "/send/", type, "/", txn, "?",
|
||||||
"user_id=", user
|
"user_id=", user, "&ts=", ts_str
|
||||||
);
|
);
|
||||||
Free(txn);
|
Free(txn);
|
||||||
|
Free(ts_str);
|
||||||
|
|
||||||
ctx = ParseeCreateRequest(conf, HTTP_PUT, path);
|
ctx = ParseeCreateRequest(conf, HTTP_PUT, path);
|
||||||
Free(path);
|
Free(path);
|
||||||
|
|
|
||||||
|
|
@ -263,7 +263,7 @@ ParseeBotHandler(ParseeData *data, HashMap *event)
|
||||||
Free(ASSend(
|
Free(ASSend(
|
||||||
data->config, id, profile,
|
data->config, id, profile,
|
||||||
"m.room.message",
|
"m.room.message",
|
||||||
MatrixCreateNotice("Please enter a valid command")
|
MatrixCreateNotice("Please enter a valid command"), 0
|
||||||
));
|
));
|
||||||
Free(profile);
|
Free(profile);
|
||||||
return;
|
return;
|
||||||
|
|
@ -274,7 +274,7 @@ ParseeBotHandler(ParseeData *data, HashMap *event)
|
||||||
Free(ASSend(
|
Free(ASSend(
|
||||||
data->config, id, profile,
|
data->config, id, profile,
|
||||||
"m.room.message",
|
"m.room.message",
|
||||||
MatrixCreateNotice("You are not authorised to do this.")
|
MatrixCreateNotice("You are not authorised to do this."), 0
|
||||||
));
|
));
|
||||||
Free(profile);
|
Free(profile);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ AvatarGrab(ParseeData *data, char *mxc, char **mime, char **b64, size_t *len)
|
||||||
{
|
{
|
||||||
Free(b64i);
|
Free(b64i);
|
||||||
Free(mimei);
|
Free(mimei);
|
||||||
b64i = StrDuplicate(media_parsee_logo); /* TODO: Different assets! */
|
b64i = StrDuplicate(media_unknown); /* TODO: Different assets! */
|
||||||
mimei = StrDuplicate("image/png");
|
mimei = StrDuplicate("image/png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ LazyRegister(ParseeData *data, char *mxid, char *name)
|
||||||
Free(hash);
|
Free(hash);
|
||||||
}
|
}
|
||||||
static char *
|
static char *
|
||||||
LazySend(ParseeData *args, char *mxid, char *mroom_id, char *type, HashMap *ev)
|
LazySend(ParseeData *args, char *mxid, char *mroom_id, char *type, HashMap *ev, uint64_t ts)
|
||||||
{
|
{
|
||||||
HashMap *duplicate;
|
HashMap *duplicate;
|
||||||
char *event;
|
char *event;
|
||||||
|
|
@ -59,8 +59,7 @@ LazySend(ParseeData *args, char *mxid, char *mroom_id, char *type, HashMap *ev)
|
||||||
duplicate = JsonDuplicate(ev);
|
duplicate = JsonDuplicate(ev);
|
||||||
event = ASSend(
|
event = ASSend(
|
||||||
args->config, mroom_id, mxid,
|
args->config, mroom_id, mxid,
|
||||||
type,
|
type, ev, ts
|
||||||
ev
|
|
||||||
);
|
);
|
||||||
if (event)
|
if (event)
|
||||||
{
|
{
|
||||||
|
|
@ -73,7 +72,7 @@ LazySend(ParseeData *args, char *mxid, char *mroom_id, char *type, HashMap *ev)
|
||||||
|
|
||||||
return ASSend(
|
return ASSend(
|
||||||
args->config, mroom_id, mxid,
|
args->config, mroom_id, mxid,
|
||||||
type, duplicate
|
type, duplicate, ts
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -254,7 +253,8 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
||||||
room = ParseeGetBridgedRoom(args, stanza);
|
room = ParseeGetBridgedRoom(args, stanza);
|
||||||
Free(LazySend(
|
Free(LazySend(
|
||||||
args, parsee, room, NULL,
|
args, parsee, room, NULL,
|
||||||
MatrixCreateNotice(message)
|
MatrixCreateNotice(message),
|
||||||
|
time
|
||||||
));
|
));
|
||||||
|
|
||||||
end_error:
|
end_error:
|
||||||
|
|
@ -431,7 +431,7 @@ end_error:
|
||||||
|
|
||||||
event_id = LazySend(
|
event_id = LazySend(
|
||||||
args, encoded, mroom_id, NULL,
|
args, encoded, mroom_id, NULL,
|
||||||
content
|
content, time
|
||||||
);
|
);
|
||||||
Free(mxc);
|
Free(mxc);
|
||||||
}
|
}
|
||||||
|
|
@ -477,7 +477,8 @@ end_error:
|
||||||
ShoveStanza(
|
ShoveStanza(
|
||||||
MatrixCreateReact(event_id, react_data->data),
|
MatrixCreateReact(event_id, react_data->data),
|
||||||
stanza
|
stanza
|
||||||
)
|
),
|
||||||
|
time
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Free(event_id);
|
Free(event_id);
|
||||||
|
|
@ -510,7 +511,7 @@ end_error:
|
||||||
ShoveStanza(ev, stanza);
|
ShoveStanza(ev, stanza);
|
||||||
event_id = LazySend(
|
event_id = LazySend(
|
||||||
args, encoded, mroom_id, NULL,
|
args, encoded, mroom_id, NULL,
|
||||||
ev
|
ev, time
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
pthread_mutex_lock(&thr->info->chk_lock);
|
pthread_mutex_lock(&thr->info->chk_lock);
|
||||||
|
|
@ -533,7 +534,7 @@ end_error:
|
||||||
Log(LOG_DEBUG, "Replacing events in %s(%s)", mroom_id, event_id);
|
Log(LOG_DEBUG, "Replacing events in %s(%s)", mroom_id, event_id);
|
||||||
Free(LazySend(
|
Free(LazySend(
|
||||||
args, encoded, mroom_id, NULL,
|
args, encoded, mroom_id, NULL,
|
||||||
ev
|
ev, time
|
||||||
));
|
));
|
||||||
ParseePushAllStanza(args, stanza, event_id);
|
ParseePushAllStanza(args, stanza, event_id);
|
||||||
pthread_mutex_unlock(&thr->info->chk_lock);
|
pthread_mutex_unlock(&thr->info->chk_lock);
|
||||||
|
|
|
||||||
|
|
@ -278,7 +278,8 @@ PresenceStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
||||||
Free(ASSend(
|
Free(ASSend(
|
||||||
args->config, room, parsee,
|
args->config, room, parsee,
|
||||||
"m.room.message",
|
"m.room.message",
|
||||||
MatrixCreateNotice("This room has been unlinked.")
|
MatrixCreateNotice("This room has been unlinked."),
|
||||||
|
0
|
||||||
));
|
));
|
||||||
ASLeave(args->config, room, parsee);
|
ASLeave(args->config, room, parsee);
|
||||||
Free(chat_id);
|
Free(chat_id);
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,8 @@ extern HashMap * ASFind(const ParseeConfig *, char *, char *);
|
||||||
|
|
||||||
/* Sends a message event with a specific type and body.
|
/* Sends a message event with a specific type and body.
|
||||||
* Said body is freed during the function's execution. */
|
* Said body is freed during the function's execution. */
|
||||||
extern char * ASSend(const ParseeConfig *, char *, char *, char *, HashMap *);
|
extern char *
|
||||||
|
ASSend(const ParseeConfig *, char *, char *, char *, HashMap *, uint64_t ts);
|
||||||
extern void ASType(const ParseeConfig *, char *, char *, bool);
|
extern void ASType(const ParseeConfig *, char *, char *, bool);
|
||||||
extern void ASPresence(const ParseeConfig *, char *, char *, char *);
|
extern void ASPresence(const ParseeConfig *, char *, char *, char *);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
Free(ASSend( \
|
Free(ASSend( \
|
||||||
data->config, id, profile, \
|
data->config, id, profile, \
|
||||||
"m.room.message", \
|
"m.room.message", \
|
||||||
MatrixCreateNotice(rep) \
|
MatrixCreateNotice(rep), 0 \
|
||||||
)); \
|
)); \
|
||||||
} \
|
} \
|
||||||
while(0)
|
while(0)
|
||||||
|
|
@ -45,7 +45,7 @@
|
||||||
Free(ASSend( \
|
Free(ASSend( \
|
||||||
data->config, id, profile, \
|
data->config, id, profile, \
|
||||||
"m.room.message", \
|
"m.room.message", \
|
||||||
MatrixCreateNotice(formatted) \
|
MatrixCreateNotice(formatted), 0 \
|
||||||
)); \
|
)); \
|
||||||
Free(formatted); \
|
Free(formatted); \
|
||||||
} \
|
} \
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,8 @@ typedef struct Argument {
|
||||||
|
|
||||||
/* A base64-encoded Parsee logo */
|
/* A base64-encoded Parsee logo */
|
||||||
extern const char media_parsee_logo[];
|
extern const char media_parsee_logo[];
|
||||||
|
/* "Unknown avatar" */
|
||||||
|
extern const char media_unknown[];
|
||||||
|
|
||||||
/* An ASCII-art rendition of "小橋".
|
/* An ASCII-art rendition of "小橋".
|
||||||
* I'm sorry for its quality. If anyone wants to redraw it, feel free. */
|
* I'm sorry for its quality. If anyone wants to redraw it, feel free. */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue