diff options
| author | 2025-05-21 21:11:47 +0200 | |
|---|---|---|
| committer | 2025-05-21 21:11:47 +0200 | |
| commit | 979718e3cc5489efdce2acc6f8c86f6d00bb91c7 (patch) | |
| tree | 7b4936bdb5ea07c7dd617d508c487d70020f0146 /data.c | |
| parent | po/de_DE.po aktualisiert (diff) | |
| parent | Merge pull request 'make greetings theme adaptive; define style in header' (#... (diff) | |
| download | snac2-979718e3cc5489efdce2acc6f8c86f6d00bb91c7.tar.gz snac2-979718e3cc5489efdce2acc6f8c86f6d00bb91c7.tar.xz snac2-979718e3cc5489efdce2acc6f8c86f6d00bb91c7.zip | |
Merge pull request 'master refresh' (#8) from grunfink/snac2:master into master
Reviewed-on: https://codeberg.org/zen/snac2/pulls/8
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 137 |
1 files changed, 129 insertions, 8 deletions
| @@ -282,6 +282,8 @@ int user_open(snac *user, const char *uid) | |||
| 282 | } | 282 | } |
| 283 | else | 283 | else |
| 284 | srv_log(xs_fmt("error parsing '%s'", cfg_file)); | 284 | srv_log(xs_fmt("error parsing '%s'", cfg_file)); |
| 285 | |||
| 286 | user->tz = xs_dict_get_def(user->config, "tz", "UTC"); | ||
| 285 | } | 287 | } |
| 286 | else | 288 | else |
| 287 | srv_debug(2, xs_fmt("error opening '%s' %d", cfg_file, errno)); | 289 | srv_debug(2, xs_fmt("error opening '%s' %d", cfg_file, errno)); |
| @@ -1213,6 +1215,14 @@ int follower_check(snac *snac, const char *actor) | |||
| 1213 | } | 1215 | } |
| 1214 | 1216 | ||
| 1215 | 1217 | ||
| 1218 | int follower_list_len(snac *snac) | ||
| 1219 | /* returns the number of followers */ | ||
| 1220 | { | ||
| 1221 | xs *list = object_user_cache_list(snac, "followers", XS_ALL, 0); | ||
| 1222 | return xs_list_len(list); | ||
| 1223 | } | ||
| 1224 | |||
| 1225 | |||
| 1216 | xs_list *follower_list(snac *snac) | 1226 | xs_list *follower_list(snac *snac) |
| 1217 | /* returns the list of followers */ | 1227 | /* returns the list of followers */ |
| 1218 | { | 1228 | { |
| @@ -1333,6 +1343,16 @@ xs_list *pending_list(snac *user) | |||
| 1333 | } | 1343 | } |
| 1334 | 1344 | ||
| 1335 | 1345 | ||
| 1346 | int pending_count(snac *user) | ||
| 1347 | /* returns the number of pending follow confirmations */ | ||
| 1348 | { | ||
| 1349 | xs *spec = xs_fmt("%s/pending/""*.json", user->basedir); | ||
| 1350 | xs *l = xs_glob(spec, 0, 0); | ||
| 1351 | |||
| 1352 | return xs_list_len(l); | ||
| 1353 | } | ||
| 1354 | |||
| 1355 | |||
| 1336 | /** timeline **/ | 1356 | /** timeline **/ |
| 1337 | 1357 | ||
| 1338 | double timeline_mtime(snac *snac) | 1358 | double timeline_mtime(snac *snac) |
| @@ -1697,6 +1717,15 @@ int following_get(snac *snac, const char *actor, xs_dict **data) | |||
| 1697 | } | 1717 | } |
| 1698 | 1718 | ||
| 1699 | 1719 | ||
| 1720 | int following_list_len(snac *snac) | ||
| 1721 | /* returns number of people being followed */ | ||
| 1722 | { | ||
| 1723 | xs *spec = xs_fmt("%s/following/" "*_a.json", snac->basedir); | ||
| 1724 | xs *glist = xs_glob(spec, 0, 0); | ||
| 1725 | return xs_list_len(glist); | ||
| 1726 | } | ||
| 1727 | |||
| 1728 | |||
| 1700 | xs_list *following_list(snac *snac) | 1729 | xs_list *following_list(snac *snac) |
| 1701 | /* returns the list of people being followed */ | 1730 | /* returns the list of people being followed */ |
| 1702 | { | 1731 | { |
| @@ -1929,6 +1958,70 @@ xs_list *draft_list(snac *user) | |||
| 1929 | } | 1958 | } |
| 1930 | 1959 | ||
| 1931 | 1960 | ||
| 1961 | /** scheduled posts **/ | ||
| 1962 | |||
| 1963 | int is_scheduled(snac *user, const char *id) | ||
| 1964 | /* returns true if this note is scheduled for future sending */ | ||
| 1965 | { | ||
| 1966 | return object_user_cache_in(user, id, "sched"); | ||
| 1967 | } | ||
| 1968 | |||
| 1969 | |||
| 1970 | void schedule_del(snac *user, const char *id) | ||
| 1971 | /* deletes an scheduled post */ | ||
| 1972 | { | ||
| 1973 | object_user_cache_del(user, id, "sched"); | ||
| 1974 | } | ||
| 1975 | |||
| 1976 | |||
| 1977 | void schedule_add(snac *user, const char *id, const xs_dict *msg) | ||
| 1978 | /* schedules this post for later */ | ||
| 1979 | { | ||
| 1980 | /* delete from the index, in case it was already there */ | ||
| 1981 | schedule_del(user, id); | ||
| 1982 | |||
| 1983 | /* overwrite object */ | ||
| 1984 | object_add_ow(id, msg); | ||
| 1985 | |||
| 1986 | /* [re]add to the index */ | ||
| 1987 | object_user_cache_add(user, id, "sched"); | ||
| 1988 | } | ||
| 1989 | |||
| 1990 | |||
| 1991 | xs_list *scheduled_list(snac *user) | ||
| 1992 | /* return the list of scheduled posts */ | ||
| 1993 | { | ||
| 1994 | return object_user_cache_list(user, "sched", XS_ALL, 1); | ||
| 1995 | } | ||
| 1996 | |||
| 1997 | |||
| 1998 | void scheduled_process(snac *user) | ||
| 1999 | /* processes the scheduled list, sending those ready to be sent */ | ||
| 2000 | { | ||
| 2001 | xs *posts = scheduled_list(user); | ||
| 2002 | const char *md5; | ||
| 2003 | xs *right_now = xs_str_utctime(0, ISO_DATE_SPEC); | ||
| 2004 | |||
| 2005 | xs_list_foreach(posts, md5) { | ||
| 2006 | xs *msg = NULL; | ||
| 2007 | |||
| 2008 | if (valid_status(object_get_by_md5(md5, &msg))) { | ||
| 2009 | if (strcmp(xs_dict_get(msg, "published"), right_now) < 0) { | ||
| 2010 | /* due date! */ | ||
| 2011 | const char *id = xs_dict_get(msg, "id"); | ||
| 2012 | |||
| 2013 | timeline_add(user, id, msg); | ||
| 2014 | |||
| 2015 | xs *c_msg = msg_create(user, msg); | ||
| 2016 | enqueue_message(user, c_msg); | ||
| 2017 | |||
| 2018 | schedule_del(user, id); | ||
| 2019 | } | ||
| 2020 | } | ||
| 2021 | } | ||
| 2022 | } | ||
| 2023 | |||
| 2024 | |||
| 1932 | /** hiding **/ | 2025 | /** hiding **/ |
| 1933 | 2026 | ||
| 1934 | xs_str *_hidden_fn(snac *snac, const char *id) | 2027 | xs_str *_hidden_fn(snac *snac, const char *id) |
| @@ -2199,7 +2292,8 @@ xs_val *list_maint(snac *user, const char *list, int op) | |||
| 2199 | xs *l2 = xs_split(v2, "/"); | 2292 | xs *l2 = xs_split(v2, "/"); |
| 2200 | 2293 | ||
| 2201 | /* return [ list_id, list_title ] */ | 2294 | /* return [ list_id, list_title ] */ |
| 2202 | l = xs_list_append(l, xs_list_append(xs_list_new(), xs_list_get(l2, -1), title)); | 2295 | xs *tmp_list = xs_list_append(xs_list_new(), xs_list_get(l2, -1), title); |
| 2296 | l = xs_list_append(l, tmp_list); | ||
| 2203 | } | 2297 | } |
| 2204 | } | 2298 | } |
| 2205 | } | 2299 | } |
| @@ -2274,6 +2368,19 @@ xs_val *list_maint(snac *user, const char *list, int op) | |||
| 2274 | } | 2368 | } |
| 2275 | 2369 | ||
| 2276 | break; | 2370 | break; |
| 2371 | |||
| 2372 | case 4: /** find list id by name **/ | ||
| 2373 | if (xs_is_string(list)) { | ||
| 2374 | xs *lol = list_maint(user, NULL, 0); | ||
| 2375 | const xs_list *li; | ||
| 2376 | |||
| 2377 | xs_list_foreach(lol, li) { | ||
| 2378 | if (strcmp(list, xs_list_get(li, 1)) == 0) { | ||
| 2379 | l = xs_dup(xs_list_get(li, 0)); | ||
| 2380 | break; | ||
| 2381 | } | ||
| 2382 | } | ||
| 2383 | } | ||
| 2277 | } | 2384 | } |
| 2278 | 2385 | ||
| 2279 | return l; | 2386 | return l; |
| @@ -2325,7 +2432,7 @@ xs_val *list_content(snac *user, const char *list, const char *actor_md5, int op | |||
| 2325 | break; | 2432 | break; |
| 2326 | 2433 | ||
| 2327 | case 1: /** append actor to list **/ | 2434 | case 1: /** append actor to list **/ |
| 2328 | if (actor_md5 != NULL) { | 2435 | if (xs_is_string(actor_md5) && xs_is_hex(actor_md5)) { |
| 2329 | if (!index_in_md5(fn, actor_md5)) | 2436 | if (!index_in_md5(fn, actor_md5)) |
| 2330 | index_add_md5(fn, actor_md5); | 2437 | index_add_md5(fn, actor_md5); |
| 2331 | } | 2438 | } |
| @@ -2333,7 +2440,7 @@ xs_val *list_content(snac *user, const char *list, const char *actor_md5, int op | |||
| 2333 | break; | 2440 | break; |
| 2334 | 2441 | ||
| 2335 | case 2: /** delete actor from list **/ | 2442 | case 2: /** delete actor from list **/ |
| 2336 | if (actor_md5 != NULL) | 2443 | if (xs_is_string(actor_md5) && xs_is_hex(actor_md5)) |
| 2337 | index_del_md5(fn, actor_md5); | 2444 | index_del_md5(fn, actor_md5); |
| 2338 | 2445 | ||
| 2339 | break; | 2446 | break; |
| @@ -2619,10 +2726,9 @@ xs_list *inbox_list(void) | |||
| 2619 | xs_list *ibl = xs_list_new(); | 2726 | xs_list *ibl = xs_list_new(); |
| 2620 | xs *spec = xs_fmt("%s/inbox/" "*", srv_basedir); | 2727 | xs *spec = xs_fmt("%s/inbox/" "*", srv_basedir); |
| 2621 | xs *files = xs_glob(spec, 0, 0); | 2728 | xs *files = xs_glob(spec, 0, 0); |
| 2622 | xs_list *p = files; | ||
| 2623 | const xs_val *v; | 2729 | const xs_val *v; |
| 2624 | 2730 | ||
| 2625 | while (xs_list_iter(&p, &v)) { | 2731 | xs_list_foreach(files, v) { |
| 2626 | FILE *f; | 2732 | FILE *f; |
| 2627 | 2733 | ||
| 2628 | if ((f = fopen(v, "r")) != NULL) { | 2734 | if ((f = fopen(v, "r")) != NULL) { |
| @@ -2630,7 +2736,9 @@ xs_list *inbox_list(void) | |||
| 2630 | 2736 | ||
| 2631 | if (line && *line) { | 2737 | if (line && *line) { |
| 2632 | line = xs_strip_i(line); | 2738 | line = xs_strip_i(line); |
| 2633 | ibl = xs_list_append(ibl, line); | 2739 | |
| 2740 | if (!is_instance_blocked(line)) | ||
| 2741 | ibl = xs_list_append(ibl, line); | ||
| 2634 | } | 2742 | } |
| 2635 | 2743 | ||
| 2636 | fclose(f); | 2744 | fclose(f); |
| @@ -3276,7 +3384,7 @@ void enqueue_output_by_actor(snac *snac, const xs_dict *msg, | |||
| 3276 | } | 3384 | } |
| 3277 | 3385 | ||
| 3278 | 3386 | ||
| 3279 | void enqueue_email(const xs_str *msg, int retries) | 3387 | void enqueue_email(const xs_dict *msg, int retries) |
| 3280 | /* enqueues an email message to be sent */ | 3388 | /* enqueues an email message to be sent */ |
| 3281 | { | 3389 | { |
| 3282 | xs *qmsg = _new_qmsg("email", msg, retries); | 3390 | xs *qmsg = _new_qmsg("email", msg, retries); |
| @@ -3392,6 +3500,19 @@ void enqueue_actor_refresh(snac *user, const char *actor, int forward_secs) | |||
| 3392 | } | 3500 | } |
| 3393 | 3501 | ||
| 3394 | 3502 | ||
| 3503 | void enqueue_webmention(const xs_dict *msg) | ||
| 3504 | /* enqueues a webmention for the post */ | ||
| 3505 | { | ||
| 3506 | xs *qmsg = _new_qmsg("webmention", msg, 0); | ||
| 3507 | const char *ntid = xs_dict_get(qmsg, "ntid"); | ||
| 3508 | xs *fn = xs_fmt("%s/queue/%s.json", srv_basedir, ntid); | ||
| 3509 | |||
| 3510 | qmsg = _enqueue_put(fn, qmsg); | ||
| 3511 | |||
| 3512 | srv_debug(1, xs_fmt("enqueue_webmention")); | ||
| 3513 | } | ||
| 3514 | |||
| 3515 | |||
| 3395 | int was_question_voted(snac *user, const char *id) | 3516 | int was_question_voted(snac *user, const char *id) |
| 3396 | /* returns true if the user voted in this poll */ | 3517 | /* returns true if the user voted in this poll */ |
| 3397 | { | 3518 | { |
| @@ -3696,7 +3817,7 @@ void purge_user(snac *snac) | |||
| 3696 | _purge_user_subdir(snac, "public", pub_days); | 3817 | _purge_user_subdir(snac, "public", pub_days); |
| 3697 | 3818 | ||
| 3698 | const char *idxs[] = { "followers.idx", "private.idx", "public.idx", | 3819 | const char *idxs[] = { "followers.idx", "private.idx", "public.idx", |
| 3699 | "pinned.idx", "bookmark.idx", "draft.idx", NULL }; | 3820 | "pinned.idx", "bookmark.idx", "draft.idx", "sched.idx", NULL }; |
| 3700 | 3821 | ||
| 3701 | for (n = 0; idxs[n]; n++) { | 3822 | for (n = 0; idxs[n]; n++) { |
| 3702 | xs *idx = xs_fmt("%s/%s", snac->basedir, idxs[n]); | 3823 | xs *idx = xs_fmt("%s/%s", snac->basedir, idxs[n]); |