diff options
| author | ltning <ltning@noreply.codeberg.org> | 2025-01-27 18:07:00 +0000 |
|---|---|---|
| committer | ltning <ltning@noreply.codeberg.org> | 2025-01-27 18:07:00 +0000 |
| commit | f6044d3aa0241a832b0ad1d2c394c0a1b814dbe3 (patch) | |
| tree | 72334e7a24b997957d201490681552b6b1ad2e2f /data.c | |
| parent | 4528029dabb7d79cddefaa5677ae314e16ab51f4 (diff) | |
| parent | 5d267968cb0d2670f8a4bd7587e505f812dfa3bc (diff) | |
Merge branch 'master' into master
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 63 |
1 files changed, 55 insertions, 8 deletions
@@ -1,5 +1,5 @@ /* snac - A simple, minimalistic ActivityPub instance */ -/* copyright (c) 2022 - 2024 grunfink et al. / MIT license */ +/* copyright (c) 2022 - 2025 grunfink et al. / MIT license */ #include "xs.h" #include "xs_hex.h" @@ -319,7 +319,8 @@ int user_persist(snac *snac, int publish) if (old != NULL) { int nw = 0; - const char *fields[] = { "header", "avatar", "name", "bio", "metadata", NULL }; + const char *fields[] = { "header", "avatar", "name", "bio", + "metadata", "latitude", "longitude", NULL }; for (int n = 0; fields[n]; n++) { const char *of = xs_dict_get(old, fields[n]); @@ -336,6 +337,10 @@ int user_persist(snac *snac, int publish) if (!nw) publish = 0; + else { + /* uncache the actor object */ + object_del(snac->actor); + } } } } @@ -674,6 +679,37 @@ int index_desc_first(FILE *f, char md5[MD5_HEX_SIZE], int skip) return 1; } +int index_asc_first(FILE *f,char md5[MD5_HEX_SIZE], const char *seek_md5) +/* reads the first entry of an ascending index, starting from a given md5 */ +{ + fseek(f, SEEK_SET, 0); + while (fread(md5, MD5_HEX_SIZE, 1, f)) { + md5[MD5_HEX_SIZE - 1] = '\0'; + if (strcmp(md5,seek_md5) == 0) { + return index_asc_next(f, md5); + } + } + return 0; +} + +int index_asc_next(FILE *f, char md5[MD5_HEX_SIZE]) +/* reads the next entry of an ascending index */ +{ + for (;;) { + /* read an md5 */ + if (!fread(md5, MD5_HEX_SIZE, 1, f)) + return 0; + + /* deleted, skip */ + if (md5[0] != '-') + break; + } + + md5[MD5_HEX_SIZE - 1] = '\0'; + + return 1; +} + xs_list *index_list_desc(const char *fn, int skip, int show) /* returns an index as a list, in reverse order */ @@ -1363,11 +1399,13 @@ void timeline_update_indexes(snac *snac, const char *id) if (valid_status(object_get(id, &msg))) { /* if its ours and is public, also store in public */ if (is_msg_public(msg)) { - object_user_cache_add(snac, id, "public"); - - /* also add it to the instance public timeline */ - xs *ipt = xs_fmt("%s/public.idx", srv_basedir); - index_add(ipt, id); + if (object_user_cache_add(snac, id, "public") >= 0) { + /* also add it to the instance public timeline */ + xs *ipt = xs_fmt("%s/public.idx", srv_basedir); + index_add(ipt, id); + } + else + srv_debug(1, xs_fmt("Not added to public instance index %s", id)); } } } @@ -1488,8 +1526,17 @@ xs_list *timeline_instance_list(int skip, int show) /* returns the timeline for the full instance */ { xs *idx = instance_index_fn(); + xs *lst = index_list_desc(idx, skip, show); - return index_list_desc(idx, skip, show); + /* make the list unique */ + xs_set rep; + xs_set_init(&rep); + const char *md5; + + xs_list_foreach(lst, md5) + xs_set_add(&rep, md5); + + return xs_set_result(&rep); } |