diff options
| author | 2024-11-24 08:31:01 +0100 | |
|---|---|---|
| committer | 2024-11-24 08:31:01 +0100 | |
| commit | b91177cb464ffdb118d50569592be3f9789dbef6 (patch) | |
| tree | 1f67098f7c104c5d12e67c2f749b3adcb29ada01 /data.c | |
| parent | New function pending_add(). (diff) | |
| download | penes-snac2-b91177cb464ffdb118d50569592be3f9789dbef6.tar.gz penes-snac2-b91177cb464ffdb118d50569592be3f9789dbef6.tar.xz penes-snac2-b91177cb464ffdb118d50569592be3f9789dbef6.zip | |
New function pending_get() and pending_list().
Diffstat (limited to '')
| -rw-r--r-- | data.c | 38 |
1 files changed, 38 insertions, 0 deletions
| @@ -1224,6 +1224,44 @@ int pending_add(snac *user, const char *actor, const xs_dict *msg) | |||
| 1224 | } | 1224 | } |
| 1225 | 1225 | ||
| 1226 | 1226 | ||
| 1227 | xs_dict *pending_get(snac *user, const char *actor) | ||
| 1228 | /* returns the pending follow confirmation for the actor */ | ||
| 1229 | { | ||
| 1230 | xs *md5 = xs_md5_hex(actor, strlen(actor)); | ||
| 1231 | xs *fn = xs_fmt("%s/pending/%s.json", user->basedir, md5); | ||
| 1232 | xs_dict *msg = NULL; | ||
| 1233 | FILE *f; | ||
| 1234 | |||
| 1235 | if ((f = fopen(fn, "r")) != NULL) { | ||
| 1236 | msg = xs_json_load(f); | ||
| 1237 | fclose(f); | ||
| 1238 | } | ||
| 1239 | |||
| 1240 | return msg; | ||
| 1241 | } | ||
| 1242 | |||
| 1243 | |||
| 1244 | xs_list *pending_list(snac *user) | ||
| 1245 | /* returns a list of pending follow confirmations */ | ||
| 1246 | { | ||
| 1247 | xs *spec = xs_fmt("%s/pending/""*.json", user->basedir); | ||
| 1248 | xs *l = xs_glob(spec, 0, 0); | ||
| 1249 | xs_list *r = xs_list_new(); | ||
| 1250 | const char *v; | ||
| 1251 | |||
| 1252 | xs_list_foreach(l, v) { | ||
| 1253 | const char *actor = xs_dict_get(v, "actor"); | ||
| 1254 | |||
| 1255 | if (xs_type(actor) == XSTYPE_STRING) { | ||
| 1256 | xs *md5 = xs_md5_hex(actor, strlen(actor)); | ||
| 1257 | r = xs_list_append(r, md5); | ||
| 1258 | } | ||
| 1259 | } | ||
| 1260 | |||
| 1261 | return r; | ||
| 1262 | } | ||
| 1263 | |||
| 1264 | |||
| 1227 | /** timeline **/ | 1265 | /** timeline **/ |
| 1228 | 1266 | ||
| 1229 | double timeline_mtime(snac *snac) | 1267 | double timeline_mtime(snac *snac) |