diff options
| author | 2025-01-27 18:07:00 +0000 | |
|---|---|---|
| committer | 2025-01-27 18:07:00 +0000 | |
| commit | f6044d3aa0241a832b0ad1d2c394c0a1b814dbe3 (patch) | |
| tree | 72334e7a24b997957d201490681552b6b1ad2e2f /data.c | |
| parent | Add short_description_raw option (diff) | |
| parent | Fixed crash in the notification area after deleting a post. (diff) | |
| download | penes-snac2-f6044d3aa0241a832b0ad1d2c394c0a1b814dbe3.tar.gz penes-snac2-f6044d3aa0241a832b0ad1d2c394c0a1b814dbe3.tar.xz penes-snac2-f6044d3aa0241a832b0ad1d2c394c0a1b814dbe3.zip | |
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 @@ | |||
| 1 | /* snac - A simple, minimalistic ActivityPub instance */ | 1 | /* snac - A simple, minimalistic ActivityPub instance */ |
| 2 | /* copyright (c) 2022 - 2024 grunfink et al. / MIT license */ | 2 | /* copyright (c) 2022 - 2025 grunfink et al. / MIT license */ |
| 3 | 3 | ||
| 4 | #include "xs.h" | 4 | #include "xs.h" |
| 5 | #include "xs_hex.h" | 5 | #include "xs_hex.h" |
| @@ -319,7 +319,8 @@ int user_persist(snac *snac, int publish) | |||
| 319 | 319 | ||
| 320 | if (old != NULL) { | 320 | if (old != NULL) { |
| 321 | int nw = 0; | 321 | int nw = 0; |
| 322 | const char *fields[] = { "header", "avatar", "name", "bio", "metadata", NULL }; | 322 | const char *fields[] = { "header", "avatar", "name", "bio", |
| 323 | "metadata", "latitude", "longitude", NULL }; | ||
| 323 | 324 | ||
| 324 | for (int n = 0; fields[n]; n++) { | 325 | for (int n = 0; fields[n]; n++) { |
| 325 | const char *of = xs_dict_get(old, fields[n]); | 326 | const char *of = xs_dict_get(old, fields[n]); |
| @@ -336,6 +337,10 @@ int user_persist(snac *snac, int publish) | |||
| 336 | 337 | ||
| 337 | if (!nw) | 338 | if (!nw) |
| 338 | publish = 0; | 339 | publish = 0; |
| 340 | else { | ||
| 341 | /* uncache the actor object */ | ||
| 342 | object_del(snac->actor); | ||
| 343 | } | ||
| 339 | } | 344 | } |
| 340 | } | 345 | } |
| 341 | } | 346 | } |
| @@ -674,6 +679,37 @@ int index_desc_first(FILE *f, char md5[MD5_HEX_SIZE], int skip) | |||
| 674 | return 1; | 679 | return 1; |
| 675 | } | 680 | } |
| 676 | 681 | ||
| 682 | int index_asc_first(FILE *f,char md5[MD5_HEX_SIZE], const char *seek_md5) | ||
| 683 | /* reads the first entry of an ascending index, starting from a given md5 */ | ||
| 684 | { | ||
| 685 | fseek(f, SEEK_SET, 0); | ||
| 686 | while (fread(md5, MD5_HEX_SIZE, 1, f)) { | ||
| 687 | md5[MD5_HEX_SIZE - 1] = '\0'; | ||
| 688 | if (strcmp(md5,seek_md5) == 0) { | ||
| 689 | return index_asc_next(f, md5); | ||
| 690 | } | ||
| 691 | } | ||
| 692 | return 0; | ||
| 693 | } | ||
| 694 | |||
| 695 | int index_asc_next(FILE *f, char md5[MD5_HEX_SIZE]) | ||
| 696 | /* reads the next entry of an ascending index */ | ||
| 697 | { | ||
| 698 | for (;;) { | ||
| 699 | /* read an md5 */ | ||
| 700 | if (!fread(md5, MD5_HEX_SIZE, 1, f)) | ||
| 701 | return 0; | ||
| 702 | |||
| 703 | /* deleted, skip */ | ||
| 704 | if (md5[0] != '-') | ||
| 705 | break; | ||
| 706 | } | ||
| 707 | |||
| 708 | md5[MD5_HEX_SIZE - 1] = '\0'; | ||
| 709 | |||
| 710 | return 1; | ||
| 711 | } | ||
| 712 | |||
| 677 | 713 | ||
| 678 | xs_list *index_list_desc(const char *fn, int skip, int show) | 714 | xs_list *index_list_desc(const char *fn, int skip, int show) |
| 679 | /* returns an index as a list, in reverse order */ | 715 | /* returns an index as a list, in reverse order */ |
| @@ -1363,11 +1399,13 @@ void timeline_update_indexes(snac *snac, const char *id) | |||
| 1363 | if (valid_status(object_get(id, &msg))) { | 1399 | if (valid_status(object_get(id, &msg))) { |
| 1364 | /* if its ours and is public, also store in public */ | 1400 | /* if its ours and is public, also store in public */ |
| 1365 | if (is_msg_public(msg)) { | 1401 | if (is_msg_public(msg)) { |
| 1366 | object_user_cache_add(snac, id, "public"); | 1402 | if (object_user_cache_add(snac, id, "public") >= 0) { |
| 1367 | 1403 | /* also add it to the instance public timeline */ | |
| 1368 | /* also add it to the instance public timeline */ | 1404 | xs *ipt = xs_fmt("%s/public.idx", srv_basedir); |
| 1369 | xs *ipt = xs_fmt("%s/public.idx", srv_basedir); | 1405 | index_add(ipt, id); |
| 1370 | index_add(ipt, id); | 1406 | } |
| 1407 | else | ||
| 1408 | srv_debug(1, xs_fmt("Not added to public instance index %s", id)); | ||
| 1371 | } | 1409 | } |
| 1372 | } | 1410 | } |
| 1373 | } | 1411 | } |
| @@ -1488,8 +1526,17 @@ xs_list *timeline_instance_list(int skip, int show) | |||
| 1488 | /* returns the timeline for the full instance */ | 1526 | /* returns the timeline for the full instance */ |
| 1489 | { | 1527 | { |
| 1490 | xs *idx = instance_index_fn(); | 1528 | xs *idx = instance_index_fn(); |
| 1529 | xs *lst = index_list_desc(idx, skip, show); | ||
| 1491 | 1530 | ||
| 1492 | return index_list_desc(idx, skip, show); | 1531 | /* make the list unique */ |
| 1532 | xs_set rep; | ||
| 1533 | xs_set_init(&rep); | ||
| 1534 | const char *md5; | ||
| 1535 | |||
| 1536 | xs_list_foreach(lst, md5) | ||
| 1537 | xs_set_add(&rep, md5); | ||
| 1538 | |||
| 1539 | return xs_set_result(&rep); | ||
| 1493 | } | 1540 | } |
| 1494 | 1541 | ||
| 1495 | 1542 | ||