New function object_user_cache().

This commit is contained in:
default 2022-11-25 17:48:43 +01:00
parent e93a79e06d
commit c0e3193529

28
data.c
View File

@ -206,6 +206,8 @@ double mtime_nl(const char *fn, int *n_link)
/** database 2.1+ **/
/** indexes **/
int index_add_md5(const char *fn, const char *md5)
/* adds an md5 to an index */
{
@ -363,6 +365,8 @@ d_char *index_list_desc(const char *fn, int max)
}
/** objects **/
d_char *_object_fn_by_md5(const char *md5)
{
xs *bfn = xs_fmt("%s/object/%c%c", srv_basedir, md5[0], md5[1]);
@ -526,6 +530,19 @@ int object_admire(const char *id, const char *actor, int like)
}
int object_user_cache(snac *snac, const char *id, const char *cachedir)
/* caches an object into a user cache */
{
xs *ofn = _object_fn(id);
xs *l = xs_split(ofn, "/");
xs *cfn = xs_fmt("%s/%s/%s", snac->basedir, cachedir, xs_list_get(l, -1));
return link(ofn, cfn);
}
/** specialized functions **/
d_char *_follower_fn(snac *snac, char *actor)
{
xs *md5 = xs_md5_hex(actor, strlen(actor));
@ -905,21 +922,14 @@ void timeline_object_add(snac *snac, const char *id, char *msg)
xs *idx = xs_fmt("%s/private.idx", snac->basedir);
index_add(idx, id);
/* build the name for the linked copy in the private cache */
xs *ofn = _object_fn(id);
xs *l = xs_split(ofn, "/");
xs *cfn = xs_fmt("%s/private/%s", snac->basedir, xs_list_get(l, -1));
link(ofn, cfn);
object_user_cache(snac, id, "private");
if (xs_startswith(id, snac->actor)) {
/* add to the public index */
idx = xs_replace_i(idx, "private", "public");
index_add(idx, id);
/* add to the public cache */
cfn = xs_replace_i(cfn, "private", "public");
link(ofn, cfn);
object_user_cache(snac, id, "public");
}
}