mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 05:15:04 +00:00
More timeline work.
This commit is contained in:
parent
9a01f731d7
commit
f6b34ce539
1 changed files with 49 additions and 0 deletions
49
data.c
49
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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue