From f209c3205dccad85ad788cd3044dfe98580e4e19 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 28 Nov 2022 15:49:56 +0100 Subject: Use xs_set in recipient_list() and inbox_list(). --- activitypub.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'activitypub.c') diff --git a/activitypub.c b/activitypub.c index d22261d..1e4130c 100644 --- a/activitypub.c +++ b/activitypub.c @@ -9,6 +9,7 @@ #include "xs_openssl.h" #include "xs_regex.h" #include "xs_time.h" +#include "xs_set.h" #include "snac.h" @@ -169,11 +170,13 @@ int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_s d_char *recipient_list(snac *snac, char *msg, int expand_public) /* returns the list of recipients for a message */ { - d_char *list = xs_list_new(); char *to = xs_dict_get(msg, "to"); char *cc = xs_dict_get(msg, "cc"); + xs_set rcpts; int n; + xs_set_init(&rcpts); + char *lists[] = { to, cc, NULL }; for (n = 0; lists[n]; n++) { char *l = lists[n]; @@ -195,40 +198,38 @@ d_char *recipient_list(snac *snac, char *msg, int expand_public) char *actor; char *p = fwers; - while (xs_list_iter(&p, &actor)) { - if (xs_list_in(list, actor) == -1) - list = xs_list_append(list, actor); - } + while (xs_list_iter(&p, &actor)) + xs_set_add(&rcpts, actor); } else - if (xs_list_in(list, v) == -1) - list = xs_list_append(list, v); + xs_set_add(&rcpts, v); } } - return list; + return xs_set_result(&rcpts); } d_char *inbox_list(snac *snac, char *msg) /* returns the list of inboxes that are recipients of this message */ { - d_char *list = xs_list_new(); - xs *rcpts = recipient_list(snac, msg, 1); + xs *rcpts = recipient_list(snac, msg, 1); + xs_set inboxes; char *p, *v; + xs_set_init(&inboxes); + p = rcpts; while (xs_list_iter(&p, &v)) { xs *inbox; if ((inbox = get_actor_inbox(snac, v)) != NULL) { /* add the inbox if it's not already there */ - if (xs_list_in(list, inbox) == -1) - list = xs_list_append(list, inbox); + xs_set_add(&inboxes, inbox); } } - return list; + return xs_set_result(&inboxes); } -- cgit v1.2.3