summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'data.c')
-rw-r--r--data.c46
1 files changed, 19 insertions, 27 deletions
diff --git a/data.c b/data.c
index 11b306d..f062d7c 100644
--- a/data.c
+++ b/data.c
@@ -1013,10 +1013,16 @@ int object_unadmire(const char *id, const char *actor, int like)
1013} 1013}
1014 1014
1015 1015
1016xs_str *object_user_cache_fn_by_md5(snac *user, const char *md5, const char *cachedir)
1017{
1018 return xs_fmt("%s/%s/%s.json", user->basedir, cachedir, md5);
1019}
1020
1021
1016xs_str *object_user_cache_fn(snac *user, const char *id, const char *cachedir) 1022xs_str *object_user_cache_fn(snac *user, const char *id, const char *cachedir)
1017{ 1023{
1018 xs *md5 = xs_md5_hex(id, strlen(id)); 1024 xs *md5 = xs_md5_hex(id, strlen(id));
1019 return xs_fmt("%s/%s/%s.json", user->basedir, cachedir, md5); 1025 return object_user_cache_fn_by_md5(user, md5, cachedir);
1020} 1026}
1021 1027
1022 1028
@@ -1067,6 +1073,14 @@ int object_user_cache_in(snac *user, const char *id, const char *cachedir)
1067} 1073}
1068 1074
1069 1075
1076int object_user_cache_in_by_md5(snac *user, const char *md5, const char *cachedir)
1077/* checks if an object is stored in a cache */
1078{
1079 xs *cfn = object_user_cache_fn_by_md5(user, md5, cachedir);
1080 return !!(mtime(cfn) != 0.0);
1081}
1082
1083
1070xs_list *object_user_cache_list(snac *user, const char *cachedir, int max, int inv) 1084xs_list *object_user_cache_list(snac *user, const char *cachedir, int max, int inv)
1071/* returns the objects in a cache as a list */ 1085/* returns the objects in a cache as a list */
1072{ 1086{
@@ -1571,25 +1585,16 @@ int unbookmark(snac *user, const char *id)
1571 1585
1572/** pinning **/ 1586/** pinning **/
1573 1587
1574xs_str *_pinned_fn(snac *user, const char *id)
1575{
1576 xs *md5 = xs_md5_hex(id, strlen(id));
1577 return xs_fmt("%s/pinned/%s.json", user->basedir, md5);
1578}
1579
1580
1581int is_pinned(snac *user, const char *id) 1588int is_pinned(snac *user, const char *id)
1582/* returns true if this note is pinned */ 1589/* returns true if this note is pinned */
1583{ 1590{
1584 xs *fn = _pinned_fn(user, id); 1591 return object_user_cache_in(user, id, "pinned");
1585 return !!(mtime(fn) != 0.0);
1586} 1592}
1587 1593
1588 1594
1589int is_pinned_by_md5(snac *user, const char *md5) 1595int is_pinned_by_md5(snac *user, const char *md5)
1590{ 1596{
1591 xs *fn = xs_fmt("%s/pinned/%s.json", user->basedir, md5); 1597 return object_user_cache_in_by_md5(user, md5, "pinned");
1592 return !!(mtime(fn) != 0.0);
1593} 1598}
1594 1599
1595 1600
@@ -1601,13 +1606,8 @@ int pin(snac *user, const char *id)
1601 if (xs_startswith(id, user->actor)) { 1606 if (xs_startswith(id, user->actor)) {
1602 if (is_pinned(user, id)) 1607 if (is_pinned(user, id))
1603 ret = -3; 1608 ret = -3;
1604 else { 1609 else
1605 /* create the subfolder, if it does not exist */
1606 xs *fn = xs_fmt("%s/pinned/", user->basedir);
1607 mkdirx(fn);
1608
1609 ret = object_user_cache_add(user, id, "pinned"); 1610 ret = object_user_cache_add(user, id, "pinned");
1610 }
1611 } 1611 }
1612 1612
1613 return ret; 1613 return ret;
@@ -1617,15 +1617,7 @@ int pin(snac *user, const char *id)
1617int unpin(snac *user, const char *id) 1617int unpin(snac *user, const char *id)
1618/* unpin a message */ 1618/* unpin a message */
1619{ 1619{
1620 int ret = object_user_cache_del(user, id, "pinned"); 1620 return object_user_cache_del(user, id, "pinned");
1621
1622 if (ret != -1) {
1623 /* delete from the index */
1624 xs *idx = xs_fmt("%s/pinned.idx", user->basedir);
1625 index_del(idx, id);
1626 }
1627
1628 return ret;
1629} 1621}
1630 1622
1631 1623