summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-09-20 11:16:24 +0200
committerdefault <nobody@localhost>2022-09-20 11:16:24 +0200
commitf6b34ce539e3db3803333038abaff90a2bcab71f (patch)
treebde2980dfb4cf71a9b2caa1e2894168eaadc9b8c /data.c
parent9a01f731d76f5b14f98ecf022a7961e24a3360b9 (diff)
More timeline work.
Diffstat (limited to 'data.c')
-rw-r--r--data.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/data.c b/data.c
index b03a84f..a1a9f66 100644
--- a/data.c
+++ b/data.c
@@ -377,3 +377,52 @@ d_char *timeline_list(snac *snac)
return list;
}
+
+
+void timeline_add(snac *snac, char *id, char *msg, char *parent)
+/* adds a message to the timeline */
+{
+ xs *pfn = _timeline_find_fn(snac, id);
+ FILE *f;
+
+ if (pfn != NULL) {
+ snac_log(snac, xs_fmt("timeline_add refusing rewrite %s %s", id, pfn));
+ return;
+ }
+
+ /* build the new filename */
+ xs *ntid = tid();
+ xs *md5 = xs_md5_hex(id, strlen(id));
+ xs *fn = xs_fmt("%s/timeline/%s-%s.json", snac->basedir, ntid, md5);
+ xs *md;
+
+ /* add metadata */
+ md = xs_json_loads("{"
+ "\"children\": [],"
+ "\"liked_by\": [],"
+ "\"announced_by\": [],"
+ "\"parent\": null"
+ "}");
+
+ if (parent != NULL)
+ md = xs_dict_set(md, "parent", parent);
+
+ msg = xs_dict_set(msg, "_snac", md);
+
+ if ((f = fopen(fn, "w")) != NULL) {
+ xs *j = xs_json_dumps_pp(msg, 4);
+
+ fwrite(j, strlen(j), 1, f);
+ fclose(f);
+
+ snac_debug(snac, 1, xs_fmt("timeline_add %s %s", id, fn));
+ }
+
+ /* generated by this user? link to local timeline */
+ if (xs_startswith(id, snac->actor)) {
+ xs *lfn = xs_replace(fn, "/timeline/", "/local/");
+ link(fn, lfn);
+
+ snac_debug(snac, 1, xs_fmt("timeline_add (local) %s %s", id, lfn));
+ }
+}