diff options
| -rw-r--r-- | data.c | 72 |
1 files changed, 58 insertions, 14 deletions
| @@ -1013,13 +1013,19 @@ int object_unadmire(const char *id, const char *actor, int like) | |||
| 1013 | } | 1013 | } |
| 1014 | 1014 | ||
| 1015 | 1015 | ||
| 1016 | int _object_user_cache(snac *snac, const char *id, const char *cachedir, int del) | 1016 | xs_str *object_user_cache_fn(snac *user, const char *id, const char *cachedir) |
| 1017 | { | ||
| 1018 | xs *md5 = xs_md5_hex(id, strlen(id)); | ||
| 1019 | return xs_fmt("%s/%s/%s.json", user->basedir, cachedir, md5); | ||
| 1020 | } | ||
| 1021 | |||
| 1022 | |||
| 1023 | int _object_user_cache(snac *user, const char *id, const char *cachedir, int del) | ||
| 1017 | /* adds or deletes from a user cache */ | 1024 | /* adds or deletes from a user cache */ |
| 1018 | { | 1025 | { |
| 1019 | xs *ofn = _object_fn(id); | 1026 | xs *ofn = _object_fn(id); |
| 1020 | xs *l = xs_split(ofn, "/"); | 1027 | xs *cfn = object_user_cache_fn(user, id, cachedir); |
| 1021 | xs *cfn = xs_fmt("%s/%s/%s", snac->basedir, cachedir, xs_list_get(l, -1)); | 1028 | xs *idx = xs_fmt("%s/%s.idx", user->basedir, cachedir); |
| 1022 | xs *idx = xs_fmt("%s/%s.idx", snac->basedir, cachedir); | ||
| 1023 | int ret; | 1029 | int ret; |
| 1024 | 1030 | ||
| 1025 | if (del) { | 1031 | if (del) { |
| @@ -1035,34 +1041,32 @@ int _object_user_cache(snac *snac, const char *id, const char *cachedir, int del | |||
| 1035 | } | 1041 | } |
| 1036 | 1042 | ||
| 1037 | 1043 | ||
| 1038 | int object_user_cache_add(snac *snac, const char *id, const char *cachedir) | 1044 | int object_user_cache_add(snac *user, const char *id, const char *cachedir) |
| 1039 | /* caches an object into a user cache */ | 1045 | /* caches an object into a user cache */ |
| 1040 | { | 1046 | { |
| 1041 | return _object_user_cache(snac, id, cachedir, 0); | 1047 | return _object_user_cache(user, id, cachedir, 0); |
| 1042 | } | 1048 | } |
| 1043 | 1049 | ||
| 1044 | 1050 | ||
| 1045 | int object_user_cache_del(snac *snac, const char *id, const char *cachedir) | 1051 | int object_user_cache_del(snac *user, const char *id, const char *cachedir) |
| 1046 | /* deletes an object from a user cache */ | 1052 | /* deletes an object from a user cache */ |
| 1047 | { | 1053 | { |
| 1048 | return _object_user_cache(snac, id, cachedir, 1); | 1054 | return _object_user_cache(user, id, cachedir, 1); |
| 1049 | } | 1055 | } |
| 1050 | 1056 | ||
| 1051 | 1057 | ||
| 1052 | int object_user_cache_in(snac *snac, const char *id, const char *cachedir) | 1058 | int object_user_cache_in(snac *user, const char *id, const char *cachedir) |
| 1053 | /* checks if an object is stored in a cache */ | 1059 | /* checks if an object is stored in a cache */ |
| 1054 | { | 1060 | { |
| 1055 | xs *md5 = xs_md5_hex(id, strlen(id)); | 1061 | xs *cfn = object_user_cache_fn(user, id, cachedir); |
| 1056 | xs *cfn = xs_fmt("%s/%s/%s.json", snac->basedir, cachedir, md5); | ||
| 1057 | |||
| 1058 | return !!(mtime(cfn) != 0.0); | 1062 | return !!(mtime(cfn) != 0.0); |
| 1059 | } | 1063 | } |
| 1060 | 1064 | ||
| 1061 | 1065 | ||
| 1062 | xs_list *object_user_cache_list(snac *snac, const char *cachedir, int max, int inv) | 1066 | xs_list *object_user_cache_list(snac *user, const char *cachedir, int max, int inv) |
| 1063 | /* returns the objects in a cache as a list */ | 1067 | /* returns the objects in a cache as a list */ |
| 1064 | { | 1068 | { |
| 1065 | xs *idx = xs_fmt("%s/%s.idx", snac->basedir, cachedir); | 1069 | xs *idx = xs_fmt("%s/%s.idx", user->basedir, cachedir); |
| 1066 | return inv ? index_list_desc(idx, 0, max) : index_list(idx, max); | 1070 | return inv ? index_list_desc(idx, 0, max) : index_list(idx, max); |
| 1067 | } | 1071 | } |
| 1068 | 1072 | ||
| @@ -1535,6 +1539,44 @@ int is_muted(snac *snac, const char *actor) | |||
| 1535 | } | 1539 | } |
| 1536 | 1540 | ||
| 1537 | 1541 | ||
| 1542 | /** bookmarking **/ | ||
| 1543 | |||
| 1544 | xs_str *_bookmark_fn(snac *user, const char *id) | ||
| 1545 | { | ||
| 1546 | xs *md5 = xs_md5_hex(id, strlen(id)); | ||
| 1547 | return xs_fmt("%s/bookmark/%s.json", user->basedir, md5); | ||
| 1548 | } | ||
| 1549 | |||
| 1550 | |||
| 1551 | int is_bookmarked(snac *user, const char *id) | ||
| 1552 | /* returns true if this note is bookmarked */ | ||
| 1553 | { | ||
| 1554 | xs *fn = _bookmark_fn(user, id); | ||
| 1555 | return !!(mtime(fn) != 0.0); | ||
| 1556 | } | ||
| 1557 | |||
| 1558 | |||
| 1559 | int bookmark(snac *user, const char *id) | ||
| 1560 | /* bookmarks a post */ | ||
| 1561 | { | ||
| 1562 | if (is_bookmarked(user, id)) | ||
| 1563 | return -3; | ||
| 1564 | |||
| 1565 | /* create the subfolder, if it does not exist */ | ||
| 1566 | xs *fn = xs_fmt("%s/bookmark/", user->basedir); | ||
| 1567 | mkdirx(fn); | ||
| 1568 | |||
| 1569 | return object_user_cache_add(user, id, "bookmark"); | ||
| 1570 | } | ||
| 1571 | |||
| 1572 | |||
| 1573 | int unbookmark(snac *user, const char *id) | ||
| 1574 | /* unbookmarks a post */ | ||
| 1575 | { | ||
| 1576 | return object_user_cache_del(user, id, "bookmark"); | ||
| 1577 | } | ||
| 1578 | |||
| 1579 | |||
| 1538 | /** pinning **/ | 1580 | /** pinning **/ |
| 1539 | 1581 | ||
| 1540 | xs_str *_pinned_fn(snac *user, const char *id) | 1582 | xs_str *_pinned_fn(snac *user, const char *id) |
| @@ -1602,6 +1644,8 @@ xs_list *pinned_list(snac *user) | |||
| 1602 | } | 1644 | } |
| 1603 | 1645 | ||
| 1604 | 1646 | ||
| 1647 | /** hiding **/ | ||
| 1648 | |||
| 1605 | xs_str *_hidden_fn(snac *snac, const char *id) | 1649 | xs_str *_hidden_fn(snac *snac, const char *id) |
| 1606 | { | 1650 | { |
| 1607 | xs *md5 = xs_md5_hex(id, strlen(id)); | 1651 | xs *md5 = xs_md5_hex(id, strlen(id)); |