mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
Rewritten actor_get() to not depend on a user.
This commit is contained in:
parent
499697258d
commit
cac1c6febd
5 changed files with 12 additions and 20 deletions
|
@ -117,7 +117,7 @@ int actor_request(snac *snac, const char *actor, xs_dict **data)
|
||||||
*data = NULL;
|
*data = NULL;
|
||||||
|
|
||||||
/* get from disk first */
|
/* get from disk first */
|
||||||
status = actor_get(snac, actor, data);
|
status = actor_get(actor, data);
|
||||||
|
|
||||||
if (status != 200) {
|
if (status != 200) {
|
||||||
/* actor data non-existent or stale: get from the net */
|
/* actor data non-existent or stale: get from the net */
|
||||||
|
|
10
data.c
10
data.c
|
@ -1439,20 +1439,12 @@ int actor_add(const char *actor, xs_dict *msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int actor_get(snac *snac1, const char *actor, xs_dict **data)
|
int actor_get(const char *actor, xs_dict **data)
|
||||||
/* returns an already downloaded actor */
|
/* returns an already downloaded actor */
|
||||||
{
|
{
|
||||||
int status = 200;
|
int status = 200;
|
||||||
xs_dict *d = NULL;
|
xs_dict *d = NULL;
|
||||||
|
|
||||||
if (strcmp(actor, snac1->actor) == 0) {
|
|
||||||
/* this actor */
|
|
||||||
if (data)
|
|
||||||
*data = msg_actor(snac1);
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xs_startswith(actor, srv_baseurl)) {
|
if (xs_startswith(actor, srv_baseurl)) {
|
||||||
/* it's a (possible) local user */
|
/* it's a (possible) local user */
|
||||||
xs *l = xs_split(actor, "/");
|
xs *l = xs_split(actor, "/");
|
||||||
|
|
14
html.c
14
html.c
|
@ -188,7 +188,7 @@ xs_str *html_actor_icon(xs_str *os, char *actor,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
xs_str *html_msg_icon(snac *snac, xs_str *os, const xs_dict *msg)
|
xs_str *html_msg_icon(xs_str *os, const xs_dict *msg)
|
||||||
{
|
{
|
||||||
char *actor_id;
|
char *actor_id;
|
||||||
xs *actor = NULL;
|
xs *actor = NULL;
|
||||||
|
@ -196,7 +196,7 @@ xs_str *html_msg_icon(snac *snac, xs_str *os, const xs_dict *msg)
|
||||||
if ((actor_id = xs_dict_get(msg, "attributedTo")) == NULL)
|
if ((actor_id = xs_dict_get(msg, "attributedTo")) == NULL)
|
||||||
actor_id = xs_dict_get(msg, "actor");
|
actor_id = xs_dict_get(msg, "actor");
|
||||||
|
|
||||||
if (actor_id && valid_status(actor_get(snac, actor_id, &actor))) {
|
if (actor_id && valid_status(actor_get(actor_id, &actor))) {
|
||||||
char *date = NULL;
|
char *date = NULL;
|
||||||
char *udate = NULL;
|
char *udate = NULL;
|
||||||
char *url = NULL;
|
char *url = NULL;
|
||||||
|
@ -870,7 +870,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
|
||||||
xs *s1 = xs_fmt("<div class=\"snac-origin\">%s</div>\n", L("follows you"));
|
xs *s1 = xs_fmt("<div class=\"snac-origin\">%s</div>\n", L("follows you"));
|
||||||
s = xs_str_cat(s, s1);
|
s = xs_str_cat(s, s1);
|
||||||
|
|
||||||
s = html_msg_icon(snac, s, msg);
|
s = html_msg_icon(s, msg);
|
||||||
|
|
||||||
s = xs_str_cat(s, "</div>\n</div>\n");
|
s = xs_str_cat(s, "</div>\n</div>\n");
|
||||||
|
|
||||||
|
@ -894,7 +894,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
|
||||||
if (is_muted(snac, actor))
|
if (is_muted(snac, actor))
|
||||||
return os;
|
return os;
|
||||||
|
|
||||||
if (strcmp(actor, snac->actor) != 0 && !valid_status(actor_get(snac, actor, NULL)))
|
if (strcmp(actor, snac->actor) != 0 && !valid_status(actor_get(actor, NULL)))
|
||||||
return os;
|
return os;
|
||||||
|
|
||||||
if (level == 0)
|
if (level == 0)
|
||||||
|
@ -990,7 +990,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s = html_msg_icon(snac, s, msg);
|
s = html_msg_icon(s, msg);
|
||||||
|
|
||||||
/* add the content */
|
/* add the content */
|
||||||
s = xs_str_cat(s, "</div>\n<div class=\"e-content snac-content\">\n"); /** **/
|
s = xs_str_cat(s, "</div>\n<div class=\"e-content snac-content\">\n"); /** **/
|
||||||
|
@ -1450,7 +1450,7 @@ xs_str *html_people_list(snac *snac, xs_str *os, xs_list *list, const char *head
|
||||||
xs *md5 = xs_md5_hex(actor_id, strlen(actor_id));
|
xs *md5 = xs_md5_hex(actor_id, strlen(actor_id));
|
||||||
xs *actor = NULL;
|
xs *actor = NULL;
|
||||||
|
|
||||||
if (valid_status(actor_get(snac, actor_id, &actor))) {
|
if (valid_status(actor_get(actor_id, &actor))) {
|
||||||
s = xs_str_cat(s, "<div class=\"snac-post\">\n<div class=\"snac-post-header\">\n");
|
s = xs_str_cat(s, "<div class=\"snac-post\">\n<div class=\"snac-post-header\">\n");
|
||||||
|
|
||||||
s = html_actor_icon(s, actor, xs_dict_get(actor, "published"), NULL, NULL, 0);
|
s = html_actor_icon(s, actor, xs_dict_get(actor, "published"), NULL, NULL, 0);
|
||||||
|
@ -1608,7 +1608,7 @@ xs_str *html_notifications(snac *snac)
|
||||||
const char *actor_id = xs_dict_get(noti, "actor");
|
const char *actor_id = xs_dict_get(noti, "actor");
|
||||||
xs *actor = NULL;
|
xs *actor = NULL;
|
||||||
|
|
||||||
if (!valid_status(actor_get(snac, actor_id, &actor)))
|
if (!valid_status(actor_get(actor_id, &actor)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
xs *a_name = actor_name(actor);
|
xs *a_name = actor_name(actor);
|
||||||
|
|
|
@ -632,7 +632,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
|
||||||
/* converts an ActivityPub note to a Mastodon status */
|
/* converts an ActivityPub note to a Mastodon status */
|
||||||
{
|
{
|
||||||
xs *actor = NULL;
|
xs *actor = NULL;
|
||||||
actor_get(snac, xs_dict_get(msg, "attributedTo"), &actor);
|
actor_get(xs_dict_get(msg, "attributedTo"), &actor);
|
||||||
|
|
||||||
/* if the author is not here, discard */
|
/* if the author is not here, discard */
|
||||||
if (actor == NULL)
|
if (actor == NULL)
|
||||||
|
@ -1310,7 +1310,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
||||||
xs *actor = NULL;
|
xs *actor = NULL;
|
||||||
xs *entry = NULL;
|
xs *entry = NULL;
|
||||||
|
|
||||||
if (!valid_status(actor_get(&snac1, xs_dict_get(noti, "actor"), &actor)))
|
if (!valid_status(actor_get(xs_dict_get(noti, "actor"), &actor)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (objid != NULL && !valid_status(object_get(objid, &entry)))
|
if (objid != NULL && !valid_status(object_get(objid, &entry)))
|
||||||
|
|
2
snac.h
2
snac.h
|
@ -141,7 +141,7 @@ void hide(snac *snac, const char *id);
|
||||||
int is_hidden(snac *snac, const char *id);
|
int is_hidden(snac *snac, const char *id);
|
||||||
|
|
||||||
int actor_add(const char *actor, xs_dict *msg);
|
int actor_add(const char *actor, xs_dict *msg);
|
||||||
int actor_get(snac *snac, const char *actor, xs_dict **data);
|
int actor_get(const char *actor, xs_dict **data);
|
||||||
|
|
||||||
int static_get(snac *snac, const char *id, xs_val **data, int *size, const char *inm, xs_str **etag);
|
int static_get(snac *snac, const char *id, xs_val **data, int *size, const char *inm, xs_str **etag);
|
||||||
void static_put(snac *snac, const char *id, const char *data, int size);
|
void static_put(snac *snac, const char *id, const char *data, int size);
|
||||||
|
|
Loading…
Reference in a new issue