aboutsummaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorltning <ltning@noreply.codeberg.org>2025-01-27 18:07:00 +0000
committerltning <ltning@noreply.codeberg.org>2025-01-27 18:07:00 +0000
commitf6044d3aa0241a832b0ad1d2c394c0a1b814dbe3 (patch)
tree72334e7a24b997957d201490681552b6b1ad2e2f /data.c
parent4528029dabb7d79cddefaa5677ae314e16ab51f4 (diff)
parent5d267968cb0d2670f8a4bd7587e505f812dfa3bc (diff)
Merge branch 'master' into master
Diffstat (limited to 'data.c')
-rw-r--r--data.c63
1 files changed, 55 insertions, 8 deletions
diff --git a/data.c b/data.c
index 0fd3528..40382d2 100644
--- a/data.c
+++ b/data.c
@@ -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);
}