New function post_message(), to send a message bypassing the output queue.

This is used when accepting Follow requests; this way, follows are
confirmed as fast as possible.

If the message cannot be immediately sent, it's queued as always.
This commit is contained in:
default 2023-07-13 18:18:23 +02:00
parent 137f775605
commit 545af948db
3 changed files with 20 additions and 5 deletions

View File

@ -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) */

2
data.c
View File

@ -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);

4
snac.h
View File

@ -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);