diff --git a/etc/media/unknown.png b/etc/media/unknown.png new file mode 100644 index 0000000..00ccf91 Binary files /dev/null and b/etc/media/unknown.png differ diff --git a/src/AS/Send.c b/src/AS/Send.c index 4032423..766f393 100644 --- a/src/AS/Send.c +++ b/src/AS/Send.c @@ -1,21 +1,38 @@ #include #include +#include #include #include #include +#include #include #include +#include #include +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 * -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; char *path; char *txn, *ret; + char *ts_str; HashMap *reply; if (!conf || !id || !type || !user || !c) { @@ -23,13 +40,20 @@ ASSend(const ParseeConfig *conf, char *id, char *user, char *type, HashMap *c) return NULL; } + if (!ts) + { + ts = UtilTsMillis(); + } + ts_str = TSToStr(ts); + txn = StrRandom(16); - path = StrConcat(9, + path = StrConcat(11, "/_matrix/client/v3/rooms/", id, "/send/", type, "/", txn, "?", - "user_id=", user + "user_id=", user, "&ts=", ts_str ); Free(txn); + Free(ts_str); ctx = ParseeCreateRequest(conf, HTTP_PUT, path); Free(path); diff --git a/src/MatrixEventHandler.c b/src/MatrixEventHandler.c index 234001b..3d6a69e 100644 --- a/src/MatrixEventHandler.c +++ b/src/MatrixEventHandler.c @@ -263,7 +263,7 @@ ParseeBotHandler(ParseeData *data, HashMap *event) Free(ASSend( data->config, id, profile, "m.room.message", - MatrixCreateNotice("Please enter a valid command") + MatrixCreateNotice("Please enter a valid command"), 0 )); Free(profile); return; @@ -274,7 +274,7 @@ ParseeBotHandler(ParseeData *data, HashMap *event) Free(ASSend( data->config, id, profile, "m.room.message", - MatrixCreateNotice("You are not authorised to do this.") + MatrixCreateNotice("You are not authorised to do this."), 0 )); Free(profile); return; diff --git a/src/XMPPThread/Stanzas/IQ.c b/src/XMPPThread/Stanzas/IQ.c index 562fc22..32aa0c9 100644 --- a/src/XMPPThread/Stanzas/IQ.c +++ b/src/XMPPThread/Stanzas/IQ.c @@ -69,7 +69,7 @@ AvatarGrab(ParseeData *data, char *mxc, char **mime, char **b64, size_t *len) { Free(b64i); Free(mimei); - b64i = StrDuplicate(media_parsee_logo); /* TODO: Different assets! */ + b64i = StrDuplicate(media_unknown); /* TODO: Different assets! */ mimei = StrDuplicate("image/png"); } diff --git a/src/XMPPThread/Stanzas/Message.c b/src/XMPPThread/Stanzas/Message.c index d72d4d9..0962fc0 100644 --- a/src/XMPPThread/Stanzas/Message.c +++ b/src/XMPPThread/Stanzas/Message.c @@ -43,7 +43,7 @@ LazyRegister(ParseeData *data, char *mxid, char *name) Free(hash); } 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; char *event; @@ -59,8 +59,7 @@ LazySend(ParseeData *args, char *mxid, char *mroom_id, char *type, HashMap *ev) duplicate = JsonDuplicate(ev); event = ASSend( args->config, mroom_id, mxid, - type, - ev + type, ev, ts ); if (event) { @@ -73,7 +72,7 @@ LazySend(ParseeData *args, char *mxid, char *mroom_id, char *type, HashMap *ev) return ASSend( 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); Free(LazySend( args, parsee, room, NULL, - MatrixCreateNotice(message) + MatrixCreateNotice(message), + time )); end_error: @@ -431,7 +431,7 @@ end_error: event_id = LazySend( args, encoded, mroom_id, NULL, - content + content, time ); Free(mxc); } @@ -477,7 +477,8 @@ end_error: ShoveStanza( MatrixCreateReact(event_id, react_data->data), stanza - ) + ), + time )); } Free(event_id); @@ -510,7 +511,7 @@ end_error: ShoveStanza(ev, stanza); event_id = LazySend( args, encoded, mroom_id, NULL, - ev + ev, time ); } 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); Free(LazySend( args, encoded, mroom_id, NULL, - ev + ev, time )); ParseePushAllStanza(args, stanza, event_id); pthread_mutex_unlock(&thr->info->chk_lock); diff --git a/src/XMPPThread/Stanzas/Presence.c b/src/XMPPThread/Stanzas/Presence.c index 4a66f94..5c7c21d 100644 --- a/src/XMPPThread/Stanzas/Presence.c +++ b/src/XMPPThread/Stanzas/Presence.c @@ -278,7 +278,8 @@ PresenceStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr) Free(ASSend( args->config, room, parsee, "m.room.message", - MatrixCreateNotice("This room has been unlinked.") + MatrixCreateNotice("This room has been unlinked."), + 0 )); ASLeave(args->config, room, parsee); Free(chat_id); diff --git a/src/include/AS.h b/src/include/AS.h index ad91e60..8afef6f 100644 --- a/src/include/AS.h +++ b/src/include/AS.h @@ -67,7 +67,8 @@ extern HashMap * ASFind(const ParseeConfig *, char *, char *); /* Sends a message event with a specific type and body. * 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 ASPresence(const ParseeConfig *, char *, char *, char *); diff --git a/src/include/Bot.h b/src/include/Bot.h index e2c0340..3154a3a 100644 --- a/src/include/Bot.h +++ b/src/include/Bot.h @@ -26,7 +26,7 @@ Free(ASSend( \ data->config, id, profile, \ "m.room.message", \ - MatrixCreateNotice(rep) \ + MatrixCreateNotice(rep), 0 \ )); \ } \ while(0) @@ -45,7 +45,7 @@ Free(ASSend( \ data->config, id, profile, \ "m.room.message", \ - MatrixCreateNotice(formatted) \ + MatrixCreateNotice(formatted), 0 \ )); \ Free(formatted); \ } \ diff --git a/src/include/Parsee.h b/src/include/Parsee.h index 1cc93bf..6b2d9cc 100644 --- a/src/include/Parsee.h +++ b/src/include/Parsee.h @@ -107,6 +107,8 @@ typedef struct Argument { /* A base64-encoded Parsee logo */ extern const char media_parsee_logo[]; +/* "Unknown avatar" */ +extern const char media_unknown[]; /* An ASCII-art rendition of "小橋". * I'm sorry for its quality. If anyone wants to redraw it, feel free. */