New function pending_get() and pending_list().

This commit is contained in:
default 2024-11-24 08:31:01 +01:00
parent 7287776fd1
commit b91177cb46
2 changed files with 40 additions and 0 deletions

38
data.c
View file

@ -1224,6 +1224,44 @@ int pending_add(snac *user, const char *actor, const xs_dict *msg)
} }
xs_dict *pending_get(snac *user, const char *actor)
/* returns the pending follow confirmation for the actor */
{
xs *md5 = xs_md5_hex(actor, strlen(actor));
xs *fn = xs_fmt("%s/pending/%s.json", user->basedir, md5);
xs_dict *msg = NULL;
FILE *f;
if ((f = fopen(fn, "r")) != NULL) {
msg = xs_json_load(f);
fclose(f);
}
return msg;
}
xs_list *pending_list(snac *user)
/* returns a list of pending follow confirmations */
{
xs *spec = xs_fmt("%s/pending/""*.json", user->basedir);
xs *l = xs_glob(spec, 0, 0);
xs_list *r = xs_list_new();
const char *v;
xs_list_foreach(l, v) {
const char *actor = xs_dict_get(v, "actor");
if (xs_type(actor) == XSTYPE_STRING) {
xs *md5 = xs_md5_hex(actor, strlen(actor));
r = xs_list_append(r, md5);
}
}
return r;
}
/** timeline **/ /** timeline **/
double timeline_mtime(snac *snac) double timeline_mtime(snac *snac)

2
snac.h
View file

@ -142,6 +142,8 @@ int follower_check(snac *snac, const char *actor);
xs_list *follower_list(snac *snac); xs_list *follower_list(snac *snac);
int pending_add(snac *user, const char *actor, const xs_dict *msg); int pending_add(snac *user, const char *actor, const xs_dict *msg);
xs_dict *pending_get(snac *user, const char *actor);
xs_list *pending_list(snac *user);
double timeline_mtime(snac *snac); double timeline_mtime(snac *snac);
int timeline_touch(snac *snac); int timeline_touch(snac *snac);