diff options
| author | 2023-07-13 18:18:23 +0200 | |
|---|---|---|
| committer | 2023-07-13 18:18:23 +0200 | |
| commit | 545af948dbdd571b7c69f6e437fea5bbad4ab766 (patch) | |
| tree | f5f74d654098255a763dea0c09fcdee9bfd36f14 /activitypub.c | |
| parent | Minor prototype tweak. (diff) | |
| download | snac2-545af948dbdd571b7c69f6e437fea5bbad4ab766.tar.gz snac2-545af948dbdd571b7c69f6e437fea5bbad4ab766.tar.xz snac2-545af948dbdd571b7c69f6e437fea5bbad4ab766.zip | |
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.
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 19 |
1 files changed, 17 insertions, 2 deletions
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) | |||
| 316 | } | 316 | } |
| 317 | 317 | ||
| 318 | 318 | ||
| 319 | int send_to_actor(snac *snac, const char *actor, const char *msg, | 319 | int send_to_actor(snac *snac, const char *actor, const xs_dict *msg, |
| 320 | xs_val **payload, int *p_size, int timeout) | 320 | xs_val **payload, int *p_size, int timeout) |
| 321 | /* sends a message to an actor */ | 321 | /* sends a message to an actor */ |
| 322 | { | 322 | { |
| @@ -330,6 +330,21 @@ int send_to_actor(snac *snac, const char *actor, const char *msg, | |||
| 330 | } | 330 | } |
| 331 | 331 | ||
| 332 | 332 | ||
| 333 | void post_message(snac *snac, const char *actor, const xs_dict *msg) | ||
| 334 | /* posts a message immediately (bypassing the output queues) */ | ||
| 335 | { | ||
| 336 | xs *payload = NULL; | ||
| 337 | int p_size; | ||
| 338 | int status; | ||
| 339 | |||
| 340 | if (valid_status(status = send_to_actor(snac, actor, msg, &payload, &p_size, 3))) | ||
| 341 | srv_log(xs_fmt("post_message to actor %s %d", actor, status)); | ||
| 342 | else | ||
| 343 | /* cannot send right now, enqueue */ | ||
| 344 | enqueue_message(snac, msg); | ||
| 345 | } | ||
| 346 | |||
| 347 | |||
| 333 | xs_list *recipient_list(snac *snac, const xs_dict *msg, int expand_public) | 348 | xs_list *recipient_list(snac *snac, const xs_dict *msg, int expand_public) |
| 334 | /* returns the list of recipients for a message */ | 349 | /* returns the list of recipients for a message */ |
| 335 | { | 350 | { |
| @@ -1411,7 +1426,7 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) | |||
| 1411 | xs *f_msg = xs_dup(msg); | 1426 | xs *f_msg = xs_dup(msg); |
| 1412 | xs *reply = msg_accept(snac, f_msg, actor); | 1427 | xs *reply = msg_accept(snac, f_msg, actor); |
| 1413 | 1428 | ||
| 1414 | enqueue_message(snac, reply); | 1429 | post_message(snac, actor, reply); |
| 1415 | 1430 | ||
| 1416 | if (xs_is_null(xs_dict_get(f_msg, "published"))) { | 1431 | if (xs_is_null(xs_dict_get(f_msg, "published"))) { |
| 1417 | /* add a date if it doesn't include one (Mastodon) */ | 1432 | /* add a date if it doesn't include one (Mastodon) */ |