From 387964944a4de2468114549e0ba13436a03eaf29 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 8 Oct 2024 17:37:15 +0200 Subject: [PATCH] More migration work. --- activitypub.c | 26 +++++++++++++++----------- data.c | 2 +- snac.h | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/activitypub.c b/activitypub.c index babca3d..19e39a9 100644 --- a/activitypub.c +++ b/activitypub.c @@ -419,7 +419,7 @@ int send_to_inbox(snac *snac, const xs_str *inbox, const xs_dict *msg, } -xs_str *get_actor_inbox(const char *actor) +xs_str *get_actor_inbox(const char *actor, int shared) /* gets an actor's inbox */ { xs *data = NULL; @@ -427,7 +427,7 @@ xs_str *get_actor_inbox(const char *actor) if (valid_status(actor_request(NULL, actor, &data))) { /* try first endpoints/sharedInbox */ - if ((v = xs_dict_get(data, "endpoints"))) + if (shared && (v = xs_dict_get(data, "endpoints"))) v = xs_dict_get(v, "sharedInbox"); /* try then the regular inbox */ @@ -444,7 +444,7 @@ int send_to_actor(snac *snac, const char *actor, const xs_dict *msg, /* sends a message to an actor */ { int status = HTTP_STATUS_BAD_REQUEST; - xs *inbox = get_actor_inbox(actor); + xs *inbox = get_actor_inbox(actor, 1); if (!xs_is_null(inbox)) status = send_to_inbox(snac, inbox, msg, payload, p_size, timeout); @@ -2290,7 +2290,7 @@ void process_user_queue_item(snac *snac, xs_dict *q_item) /* iterate the recipients */ c = 0; while (xs_list_next(rcpts, &actor, &c)) { - xs *inbox = get_actor_inbox(actor); + xs *inbox = get_actor_inbox(actor, 1); if (inbox != NULL) { /* add to the set and, if it's not there, send message */ @@ -2699,14 +2699,18 @@ int migrate_account(snac *user) xs *move = msg_move(user, new_account); xs *fwers = follower_list(user); -/* - xs_json_dump(move, 4, stdout); - printf("\n"); - xs_json_dump(fwers, 4, stdout); - printf("\n"); -*/ + snac_log(user, xs_fmt("WORK IN PROGRESS - ANYTHING CAN HAPPEN")); - printf("WORK IN PROGRESS - NOT YET USABLE (BUT HARMLESS)\n"); + const char *actor; + xs_list_foreach(fwers, actor) { + /* get the actor inbox, excluding the shared one */ + xs *inbox = get_actor_inbox(actor, 0); + + if (xs_is_null(inbox)) + snac_log(user, xs_fmt("migrate_account: cannot get inbox for actor %s", actor)); + else + enqueue_output(user, move, inbox, 0, 0); + } return 0; } diff --git a/data.c b/data.c index ded3c42..8b1a92e 100644 --- a/data.c +++ b/data.c @@ -2948,7 +2948,7 @@ void enqueue_output_by_actor(snac *snac, const xs_dict *msg, const xs_str *actor, int retries) /* enqueues an output message for an actor */ { - xs *inbox = get_actor_inbox(actor); + xs *inbox = get_actor_inbox(actor, 1); if (!xs_is_null(inbox)) enqueue_output(snac, msg, inbox, retries, 0); diff --git a/snac.h b/snac.h index 90413ea..379b81d 100644 --- a/snac.h +++ b/snac.h @@ -322,7 +322,7 @@ int send_to_inbox_raw(const char *keyid, const char *seckey, xs_val **payload, int *p_size, int timeout); 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(const char *actor); +xs_str *get_actor_inbox(const char *actor, int shared); 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(const xs_dict *msg);