summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorGravatar shtrophic2025-04-17 22:01:21 +0200
committerGravatar shtrophic2025-04-17 22:01:21 +0200
commitac8b03f9e96d5778b3c0ddfea94b54e17963a3d4 (patch)
treeb650f683bd6cea37e4d88ae247411f4f9edb2a32 /data.c
parentMerge tag '2.74' into curl-smtp (diff)
parentVersion 2.75 RELEASED. (diff)
downloadsnac2-ac8b03f9e96d5778b3c0ddfea94b54e17963a3d4.tar.gz
snac2-ac8b03f9e96d5778b3c0ddfea94b54e17963a3d4.tar.xz
snac2-ac8b03f9e96d5778b3c0ddfea94b54e17963a3d4.zip
Merge tag '2.75' into curl-smtp
Diffstat (limited to 'data.c')
-rw-r--r--data.c75
1 files changed, 71 insertions, 4 deletions
diff --git a/data.c b/data.c
index ae85aaf..4a19680 100644
--- a/data.c
+++ b/data.c
@@ -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));
@@ -1929,6 +1931,70 @@ xs_list *draft_list(snac *user)
1929} 1931}
1930 1932
1931 1933
1934/** scheduled posts **/
1935
1936int is_scheduled(snac *user, const char *id)
1937/* returns true if this note is scheduled for future sending */
1938{
1939 return object_user_cache_in(user, id, "sched");
1940}
1941
1942
1943void schedule_del(snac *user, const char *id)
1944/* deletes an scheduled post */
1945{
1946 object_user_cache_del(user, id, "sched");
1947}
1948
1949
1950void schedule_add(snac *user, const char *id, const xs_dict *msg)
1951/* schedules this post for later */
1952{
1953 /* delete from the index, in case it was already there */
1954 schedule_del(user, id);
1955
1956 /* overwrite object */
1957 object_add_ow(id, msg);
1958
1959 /* [re]add to the index */
1960 object_user_cache_add(user, id, "sched");
1961}
1962
1963
1964xs_list *scheduled_list(snac *user)
1965/* return the list of scheduled posts */
1966{
1967 return object_user_cache_list(user, "sched", XS_ALL, 1);
1968}
1969
1970
1971void scheduled_process(snac *user)
1972/* processes the scheduled list, sending those ready to be sent */
1973{
1974 xs *posts = scheduled_list(user);
1975 const char *md5;
1976 xs *right_now = xs_str_utctime(0, ISO_DATE_SPEC);
1977
1978 xs_list_foreach(posts, md5) {
1979 xs *msg = NULL;
1980
1981 if (valid_status(object_get_by_md5(md5, &msg))) {
1982 if (strcmp(xs_dict_get(msg, "published"), right_now) < 0) {
1983 /* due date! */
1984 const char *id = xs_dict_get(msg, "id");
1985
1986 timeline_add(user, id, msg);
1987
1988 xs *c_msg = msg_create(user, msg);
1989 enqueue_message(user, c_msg);
1990
1991 schedule_del(user, id);
1992 }
1993 }
1994 }
1995}
1996
1997
1932/** hiding **/ 1998/** hiding **/
1933 1999
1934xs_str *_hidden_fn(snac *snac, const char *id) 2000xs_str *_hidden_fn(snac *snac, const char *id)
@@ -2619,10 +2685,9 @@ xs_list *inbox_list(void)
2619 xs_list *ibl = xs_list_new(); 2685 xs_list *ibl = xs_list_new();
2620 xs *spec = xs_fmt("%s/inbox/" "*", srv_basedir); 2686 xs *spec = xs_fmt("%s/inbox/" "*", srv_basedir);
2621 xs *files = xs_glob(spec, 0, 0); 2687 xs *files = xs_glob(spec, 0, 0);
2622 xs_list *p = files;
2623 const xs_val *v; 2688 const xs_val *v;
2624 2689
2625 while (xs_list_iter(&p, &v)) { 2690 xs_list_foreach(files, v) {
2626 FILE *f; 2691 FILE *f;
2627 2692
2628 if ((f = fopen(v, "r")) != NULL) { 2693 if ((f = fopen(v, "r")) != NULL) {
@@ -2630,7 +2695,9 @@ xs_list *inbox_list(void)
2630 2695
2631 if (line && *line) { 2696 if (line && *line) {
2632 line = xs_strip_i(line); 2697 line = xs_strip_i(line);
2633 ibl = xs_list_append(ibl, line); 2698
2699 if (!is_instance_blocked(line))
2700 ibl = xs_list_append(ibl, line);
2634 } 2701 }
2635 2702
2636 fclose(f); 2703 fclose(f);
@@ -3696,7 +3763,7 @@ void purge_user(snac *snac)
3696 _purge_user_subdir(snac, "public", pub_days); 3763 _purge_user_subdir(snac, "public", pub_days);
3697 3764
3698 const char *idxs[] = { "followers.idx", "private.idx", "public.idx", 3765 const char *idxs[] = { "followers.idx", "private.idx", "public.idx",
3699 "pinned.idx", "bookmark.idx", "draft.idx", NULL }; 3766 "pinned.idx", "bookmark.idx", "draft.idx", "sched.idx", NULL };
3700 3767
3701 for (n = 0; idxs[n]; n++) { 3768 for (n = 0; idxs[n]; n++) {
3702 xs *idx = xs_fmt("%s/%s", snac->basedir, idxs[n]); 3769 xs *idx = xs_fmt("%s/%s", snac->basedir, idxs[n]);