summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorGravatar default2022-09-30 09:56:29 +0200
committerGravatar default2022-09-30 09:56:29 +0200
commit3d544233a63a2105d8d91e7fd4f62f7703fef6e0 (patch)
tree021cca6da8ae40a6fbc3e8fb73499f0f9777044b /data.c
parentLikes and Boosts can be done from the web interface. (diff)
downloadsnac2-3d544233a63a2105d8d91e7fd4f62f7703fef6e0.tar.gz
snac2-3d544233a63a2105d8d91e7fd4f62f7703fef6e0.tar.xz
snac2-3d544233a63a2105d8d91e7fd4f62f7703fef6e0.zip
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)
178 struct stat st; 178 struct stat st;
179 float r = 0.0; 179 float r = 0.0;
180 180
181 if (stat(fn, &st) != -1) 181 if (fn && stat(fn, &st) != -1)
182 r = (float)st.st_mtim.tv_sec; 182 r = (float)st.st_mtim.tv_sec;
183 183
184 return r; 184 return r;
@@ -275,6 +275,13 @@ d_char *follower_list(snac *snac)
275} 275}
276 276
277 277
278float timeline_mtime(snac *snac)
279{
280 xs *fn = xs_fmt("%s/timeline", snac->basedir);
281 return mtime(fn);
282}
283
284
278d_char *_timeline_find_fn(snac *snac, char *id) 285d_char *_timeline_find_fn(snac *snac, char *id)
279/* returns the file name of a timeline entry by its id */ 286/* returns the file name of a timeline entry by its id */
280{ 287{
@@ -831,6 +838,53 @@ int static_get(snac *snac, char *id, d_char **data, int *size)
831} 838}
832 839
833 840
841d_char *_history_fn(snac *snac, char *id)
842/* gets the filename for the history */
843{
844 return xs_fmt("%s/history/%s", snac->basedir, id);
845}
846
847
848float history_mtime(snac *snac, char * id)
849{
850 float t = 0.0;
851 xs *fn = _history_fn(snac, id);
852
853 if (fn != NULL)
854 t = mtime(fn);
855
856 return t;
857}
858
859
860void history_add(snac *snac, char *id, char *content, int size)
861/* adds something to the history */
862{
863 xs *fn = _history_fn(snac, id);
864 FILE *f;
865
866 if ((f = fopen(fn, "w")) != NULL) {
867 fwrite(content, size, 1, f);
868 fclose(f);
869 }
870}
871
872
873d_char *history_get(snac *snac, char *id)
874{
875 d_char *content = NULL;
876 xs *fn = _history_fn(snac, id);
877 FILE *f;
878
879 if ((f = fopen(fn, "r")) != NULL) {
880 content = xs_readall(f);
881 fclose(f);
882 }
883
884 return content;
885}
886
887
834void enqueue_input(snac *snac, char *msg, char *req, int retries) 888void enqueue_input(snac *snac, char *msg, char *req, int retries)
835/* enqueues an input message */ 889/* enqueues an input message */
836{ 890{