|
|
@@ -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));
|
|
|
+ }
|
|
|
+}
|