summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
authorGravatar default2022-11-28 15:49:56 +0100
committerGravatar default2022-11-28 15:49:56 +0100
commitf209c3205dccad85ad788cd3044dfe98580e4e19 (patch)
tree847f5b5fa5383f8dd2ebebbfe4c0e197d1189b9d /activitypub.c
parentBackport from xs. (diff)
downloadsnac2-f209c3205dccad85ad788cd3044dfe98580e4e19.tar.gz
snac2-f209c3205dccad85ad788cd3044dfe98580e4e19.tar.xz
snac2-f209c3205dccad85ad788cd3044dfe98580e4e19.zip
Use xs_set in recipient_list() and inbox_list().
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/activitypub.c b/activitypub.c
index d22261d..1e4130c 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -9,6 +9,7 @@
9#include "xs_openssl.h" 9#include "xs_openssl.h"
10#include "xs_regex.h" 10#include "xs_regex.h"
11#include "xs_time.h" 11#include "xs_time.h"
12#include "xs_set.h"
12 13
13#include "snac.h" 14#include "snac.h"
14 15
@@ -169,11 +170,13 @@ int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_s
169d_char *recipient_list(snac *snac, char *msg, int expand_public) 170d_char *recipient_list(snac *snac, char *msg, int expand_public)
170/* returns the list of recipients for a message */ 171/* returns the list of recipients for a message */
171{ 172{
172 d_char *list = xs_list_new();
173 char *to = xs_dict_get(msg, "to"); 173 char *to = xs_dict_get(msg, "to");
174 char *cc = xs_dict_get(msg, "cc"); 174 char *cc = xs_dict_get(msg, "cc");
175 xs_set rcpts;
175 int n; 176 int n;
176 177
178 xs_set_init(&rcpts);
179
177 char *lists[] = { to, cc, NULL }; 180 char *lists[] = { to, cc, NULL };
178 for (n = 0; lists[n]; n++) { 181 for (n = 0; lists[n]; n++) {
179 char *l = lists[n]; 182 char *l = lists[n];
@@ -195,40 +198,38 @@ d_char *recipient_list(snac *snac, char *msg, int expand_public)
195 char *actor; 198 char *actor;
196 199
197 char *p = fwers; 200 char *p = fwers;
198 while (xs_list_iter(&p, &actor)) { 201 while (xs_list_iter(&p, &actor))
199 if (xs_list_in(list, actor) == -1) 202 xs_set_add(&rcpts, actor);
200 list = xs_list_append(list, actor);
201 }
202 } 203 }
203 else 204 else
204 if (xs_list_in(list, v) == -1) 205 xs_set_add(&rcpts, v);
205 list = xs_list_append(list, v);
206 } 206 }
207 } 207 }
208 208
209 return list; 209 return xs_set_result(&rcpts);
210} 210}
211 211
212 212
213d_char *inbox_list(snac *snac, char *msg) 213d_char *inbox_list(snac *snac, char *msg)
214/* returns the list of inboxes that are recipients of this message */ 214/* returns the list of inboxes that are recipients of this message */
215{ 215{
216 d_char *list = xs_list_new(); 216 xs *rcpts = recipient_list(snac, msg, 1);
217 xs *rcpts = recipient_list(snac, msg, 1); 217 xs_set inboxes;
218 char *p, *v; 218 char *p, *v;
219 219
220 xs_set_init(&inboxes);
221
220 p = rcpts; 222 p = rcpts;
221 while (xs_list_iter(&p, &v)) { 223 while (xs_list_iter(&p, &v)) {
222 xs *inbox; 224 xs *inbox;
223 225
224 if ((inbox = get_actor_inbox(snac, v)) != NULL) { 226 if ((inbox = get_actor_inbox(snac, v)) != NULL) {
225 /* add the inbox if it's not already there */ 227 /* add the inbox if it's not already there */
226 if (xs_list_in(list, inbox) == -1) 228 xs_set_add(&inboxes, inbox);
227 list = xs_list_append(list, inbox);
228 } 229 }
229 } 230 }
230 231
231 return list; 232 return xs_set_result(&inboxes);
232} 233}
233 234
234 235