summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'data.c')
-rw-r--r--data.c66
1 files changed, 65 insertions, 1 deletions
diff --git a/data.c b/data.c
index a192830..6661472 100644
--- a/data.c
+++ b/data.c
@@ -1929,6 +1929,70 @@ xs_list *draft_list(snac *user)
1929} 1929}
1930 1930
1931 1931
1932/** scheduled posts **/
1933
1934int is_scheduled(snac *user, const char *id)
1935/* returns true if this note is scheduled for future sending */
1936{
1937 return object_user_cache_in(user, id, "sched");
1938}
1939
1940
1941void schedule_del(snac *user, const char *id)
1942/* deletes an scheduled post */
1943{
1944 object_user_cache_del(user, id, "sched");
1945}
1946
1947
1948void schedule_add(snac *user, const char *id, const xs_dict *msg)
1949/* schedules this post for later */
1950{
1951 /* delete from the index, in case it was already there */
1952 schedule_del(user, id);
1953
1954 /* overwrite object */
1955 object_add_ow(id, msg);
1956
1957 /* [re]add to the index */
1958 object_user_cache_add(user, id, "sched");
1959}
1960
1961
1962xs_list *scheduled_list(snac *user)
1963/* return the list of scheduled posts */
1964{
1965 return object_user_cache_list(user, "sched", XS_ALL, 1);
1966}
1967
1968
1969void scheduled_process(snac *user)
1970/* processes the scheduled list, sending those ready to be sent */
1971{
1972 xs *posts = scheduled_list(user);
1973 const char *md5;
1974 xs *right_now = xs_str_utctime(0, ISO_DATE_SPEC);
1975
1976 xs_list_foreach(posts, md5) {
1977 xs *msg = NULL;
1978
1979 if (valid_status(object_get_by_md5(md5, &msg))) {
1980 if (strcmp(xs_dict_get(msg, "published"), right_now) < 0) {
1981 /* due date! */
1982 const char *id = xs_dict_get(msg, "id");
1983
1984 timeline_add(user, id, msg);
1985
1986 xs *c_msg = msg_create(user, msg);
1987 enqueue_message(user, c_msg);
1988
1989 schedule_del(user, id);
1990 }
1991 }
1992 }
1993}
1994
1995
1932/** hiding **/ 1996/** hiding **/
1933 1997
1934xs_str *_hidden_fn(snac *snac, const char *id) 1998xs_str *_hidden_fn(snac *snac, const char *id)
@@ -3697,7 +3761,7 @@ void purge_user(snac *snac)
3697 _purge_user_subdir(snac, "public", pub_days); 3761 _purge_user_subdir(snac, "public", pub_days);
3698 3762
3699 const char *idxs[] = { "followers.idx", "private.idx", "public.idx", 3763 const char *idxs[] = { "followers.idx", "private.idx", "public.idx",
3700 "pinned.idx", "bookmark.idx", "draft.idx", NULL }; 3764 "pinned.idx", "bookmark.idx", "draft.idx", "sched.idx", NULL };
3701 3765
3702 for (n = 0; idxs[n]; n++) { 3766 for (n = 0; idxs[n]; n++) {
3703 xs *idx = xs_fmt("%s/%s", snac->basedir, idxs[n]); 3767 xs *idx = xs_fmt("%s/%s", snac->basedir, idxs[n]);