diff options
author | default <nobody@localhost> | 2022-09-30 09:56:29 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2022-09-30 09:56:29 +0200 |
commit | 3d544233a63a2105d8d91e7fd4f62f7703fef6e0 (patch) | |
tree | 021cca6da8ae40a6fbc3e8fb73499f0f9777044b /data.c | |
parent | 41767992960f4a60a34b212d9ae3d25e9ca2a3f8 (diff) |
Timeline is cached.
Diffstat (limited to 'data.c')
-rw-r--r-- | data.c | 56 |
1 files changed, 55 insertions, 1 deletions
@@ -178,7 +178,7 @@ float mtime(char *fn) struct stat st; float r = 0.0; - if (stat(fn, &st) != -1) + if (fn && stat(fn, &st) != -1) r = (float)st.st_mtim.tv_sec; return r; @@ -275,6 +275,13 @@ d_char *follower_list(snac *snac) } +float timeline_mtime(snac *snac) +{ + xs *fn = xs_fmt("%s/timeline", snac->basedir); + return mtime(fn); +} + + d_char *_timeline_find_fn(snac *snac, char *id) /* returns the file name of a timeline entry by its id */ { @@ -831,6 +838,53 @@ int static_get(snac *snac, char *id, d_char **data, int *size) } +d_char *_history_fn(snac *snac, char *id) +/* gets the filename for the history */ +{ + return xs_fmt("%s/history/%s", snac->basedir, id); +} + + +float history_mtime(snac *snac, char * id) +{ + float t = 0.0; + xs *fn = _history_fn(snac, id); + + if (fn != NULL) + t = mtime(fn); + + return t; +} + + +void history_add(snac *snac, char *id, char *content, int size) +/* adds something to the history */ +{ + xs *fn = _history_fn(snac, id); + FILE *f; + + if ((f = fopen(fn, "w")) != NULL) { + fwrite(content, size, 1, f); + fclose(f); + } +} + + +d_char *history_get(snac *snac, char *id) +{ + d_char *content = NULL; + xs *fn = _history_fn(snac, id); + FILE *f; + + if ((f = fopen(fn, "r")) != NULL) { + content = xs_readall(f); + fclose(f); + } + + return content; +} + + void enqueue_input(snac *snac, char *msg, char *req, int retries) /* enqueues an input message */ { |