diff --git a/activitypub.c b/activitypub.c index e871c8d..c9cf066 100644 --- a/activitypub.c +++ b/activitypub.c @@ -316,7 +316,7 @@ xs_str *get_actor_inbox(snac *snac, const char *actor) } -int send_to_actor(snac *snac, const char *actor, const char *msg, +int send_to_actor(snac *snac, const char *actor, const xs_dict *msg, xs_val **payload, int *p_size, int timeout) /* sends a message to an actor */ { @@ -330,6 +330,21 @@ int send_to_actor(snac *snac, const char *actor, const char *msg, } +void post_message(snac *snac, const char *actor, const xs_dict *msg) +/* posts a message immediately (bypassing the output queues) */ +{ + xs *payload = NULL; + int p_size; + int status; + + if (valid_status(status = send_to_actor(snac, actor, msg, &payload, &p_size, 3))) + srv_log(xs_fmt("post_message to actor %s %d", actor, status)); + else + /* cannot send right now, enqueue */ + enqueue_message(snac, msg); +} + + xs_list *recipient_list(snac *snac, const xs_dict *msg, int expand_public) /* returns the list of recipients for a message */ { @@ -1411,7 +1426,7 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) xs *f_msg = xs_dup(msg); xs *reply = msg_accept(snac, f_msg, actor); - enqueue_message(snac, reply); + post_message(snac, actor, reply); if (xs_is_null(xs_dict_get(f_msg, "published"))) { /* add a date if it doesn't include one (Mastodon) */ diff --git a/data.c b/data.c index 2c2ff8b..24a0bc8 100644 --- a/data.c +++ b/data.c @@ -2092,7 +2092,7 @@ void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id) } -void enqueue_message(snac *snac, xs_dict *msg) +void enqueue_message(snac *snac, const xs_dict *msg) /* enqueues an output message */ { xs *qmsg = _new_qmsg("message", msg, 0); diff --git a/snac.h b/snac.h index cee6470..e36a60b 100644 --- a/snac.h +++ b/snac.h @@ -173,7 +173,7 @@ void enqueue_output(snac *snac, xs_dict *msg, xs_str *inbox, int retries); void enqueue_output_by_actor(snac *snac, xs_dict *msg, const xs_str *actor, int retries); void enqueue_email(xs_str *msg, int retries); void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id); -void enqueue_message(snac *snac, char *msg); +void enqueue_message(snac *snac, const xs_dict *msg); void enqueue_close_question(snac *user, const char *id, int end_secs); void enqueue_request_replies(snac *user, const char *id); int was_question_voted(snac *user, const char *id); @@ -235,7 +235,7 @@ int send_to_inbox_raw(const char *keyid, const char *seckey, int send_to_inbox(snac *snac, const xs_str *inbox, const xs_dict *msg, xs_val **payload, int *p_size, int timeout); xs_str *get_actor_inbox(snac *snac, const char *actor); -int send_to_actor(snac *snac, const char *actor, const char *msg, +int send_to_actor(snac *snac, const char *actor, const xs_dict *msg, xs_val **payload, int *p_size, int timeout); int is_msg_public(snac *snac, const xs_dict *msg); int is_msg_for_me(snac *snac, const xs_dict *msg);