Use xs_set in recipient_list() and inbox_list().

This commit is contained in:
default 2022-11-28 15:49:56 +01:00
parent 3699b61f08
commit f209c3205d
3 changed files with 16 additions and 14 deletions

View file

@ -9,6 +9,7 @@
#include "xs_openssl.h" #include "xs_openssl.h"
#include "xs_regex.h" #include "xs_regex.h"
#include "xs_time.h" #include "xs_time.h"
#include "xs_set.h"
#include "snac.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) d_char *recipient_list(snac *snac, char *msg, int expand_public)
/* returns the list of recipients for a message */ /* returns the list of recipients for a message */
{ {
d_char *list = xs_list_new();
char *to = xs_dict_get(msg, "to"); char *to = xs_dict_get(msg, "to");
char *cc = xs_dict_get(msg, "cc"); char *cc = xs_dict_get(msg, "cc");
xs_set rcpts;
int n; int n;
xs_set_init(&rcpts);
char *lists[] = { to, cc, NULL }; char *lists[] = { to, cc, NULL };
for (n = 0; lists[n]; n++) { for (n = 0; lists[n]; n++) {
char *l = lists[n]; char *l = lists[n];
@ -195,40 +198,38 @@ d_char *recipient_list(snac *snac, char *msg, int expand_public)
char *actor; char *actor;
char *p = fwers; char *p = fwers;
while (xs_list_iter(&p, &actor)) { while (xs_list_iter(&p, &actor))
if (xs_list_in(list, actor) == -1) xs_set_add(&rcpts, actor);
list = xs_list_append(list, actor);
}
} }
else else
if (xs_list_in(list, v) == -1) xs_set_add(&rcpts, v);
list = xs_list_append(list, v);
} }
} }
return list; return xs_set_result(&rcpts);
} }
d_char *inbox_list(snac *snac, char *msg) d_char *inbox_list(snac *snac, char *msg)
/* returns the list of inboxes that are recipients of this message */ /* 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; char *p, *v;
xs_set_init(&inboxes);
p = rcpts; p = rcpts;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
xs *inbox; xs *inbox;
if ((inbox = get_actor_inbox(snac, v)) != NULL) { if ((inbox = get_actor_inbox(snac, v)) != NULL) {
/* add the inbox if it's not already there */ /* add the inbox if it's not already there */
if (xs_list_in(list, inbox) == -1) xs_set_add(&inboxes, inbox);
list = xs_list_append(list, inbox);
} }
} }
return list; return xs_set_result(&inboxes);
} }

View file

@ -12,6 +12,7 @@ typedef struct _xs_set {
} xs_set; } xs_set;
void xs_set_init(xs_set *s); void xs_set_init(xs_set *s);
d_char *xs_set_result(xs_set *s);
void xs_set_free(xs_set *s); void xs_set_free(xs_set *s);
int xs_set_add(xs_set *s, const char *data); int xs_set_add(xs_set *s, const char *data);

View file

@ -1 +1 @@
/* e9effd101e5ad45cc4209759ae25e4a6de9259e8 */ /* c18371e1f1d3de0f872354f93024a736caebea4d */