diff --git a/data.c b/data.c index fa631e1..79c7001 100644 --- a/data.c +++ b/data.c @@ -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 **/ double timeline_mtime(snac *snac) diff --git a/snac.h b/snac.h index bcddab4..25f7b74 100644 --- a/snac.h +++ b/snac.h @@ -142,6 +142,8 @@ int follower_check(snac *snac, const char *actor); xs_list *follower_list(snac *snac); 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); int timeline_touch(snac *snac);