From e31c4810a83c42c0298d4832fb4f2291dec0e84d Mon Sep 17 00:00:00 2001 From: default Date: Sun, 30 Apr 2023 06:49:51 +0200 Subject: [PATCH] actor_get() returns an actor message for local users. --- data.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/data.c b/data.c index 60c4b26..187d9b9 100644 --- a/data.c +++ b/data.c @@ -1287,27 +1287,43 @@ int is_hidden(snac *snac, const char *id) } -int actor_add(snac *snac, const char *actor, d_char *msg) +int actor_add(snac *snac, const char *actor, xs_dict *msg) /* adds an actor */ { return object_add_ow(actor, msg); } -int actor_get(snac *snac, const char *actor, d_char **data) +int actor_get(snac *snac1, const char *actor, xs_dict **data) /* returns an already downloaded actor */ { int status = 200; - d_char *d; + xs_dict *d; - if (strcmp(actor, snac->actor) == 0) { + if (strcmp(actor, snac1->actor) == 0) { /* this actor */ if (data) - *data = msg_actor(snac); + *data = msg_actor(snac1); return status; } + if (xs_startswith(actor, srv_baseurl)) { + /* it's a (possible) local user */ + xs *l = xs_split(actor, "/"); + const char *uid = xs_list_get(l, -1); + snac user; + + if (!xs_is_null(uid) && user_open(&user, uid)) { + if (data) + *data = msg_actor(&user); + + user_free(&user); + } + else + return 404; + } + /* read the object */ if (!valid_status(status = object_get(actor, &d))) return status;