summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-09-30 09:56:29 +0200
committerdefault <nobody@localhost>2022-09-30 09:56:29 +0200
commit3d544233a63a2105d8d91e7fd4f62f7703fef6e0 (patch)
tree021cca6da8ae40a6fbc3e8fb73499f0f9777044b /data.c
parent41767992960f4a60a34b212d9ae3d25e9ca2a3f8 (diff)
Timeline is cached.
Diffstat (limited to 'data.c')
-rw-r--r--data.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/data.c b/data.c
index ee21a98..5eb729c 100644
--- a/data.c
+++ b/data.c
@@ -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 */
{