summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorGravatar shtrophic2025-02-15 14:37:36 +0100
committerGravatar shtrophic2025-02-15 14:37:36 +0100
commit7611a6bee4bcbad2f1710aafa99aba730e5cf995 (patch)
tree33ab7bee30379e16f6869b2efda5494be8aeb858 /data.c
parentenforce tls when supported && add tests (diff)
parentVersion 2.72 RELEASED. (diff)
downloadsnac2-7611a6bee4bcbad2f1710aafa99aba730e5cf995.tar.gz
snac2-7611a6bee4bcbad2f1710aafa99aba730e5cf995.tar.xz
snac2-7611a6bee4bcbad2f1710aafa99aba730e5cf995.zip
Merge tag '2.72' into curl-smtp
Version 2.72 RELEASED.
Diffstat (limited to 'data.c')
-rw-r--r--data.c82
1 files changed, 68 insertions, 14 deletions
diff --git a/data.c b/data.c
index b148ac7..6995611 100644
--- a/data.c
+++ b/data.c
@@ -1399,11 +1399,13 @@ void timeline_update_indexes(snac *snac, const char *id)
1399 if (valid_status(object_get(id, &msg))) { 1399 if (valid_status(object_get(id, &msg))) {
1400 /* if its ours and is public, also store in public */ 1400 /* if its ours and is public, also store in public */
1401 if (is_msg_public(msg)) { 1401 if (is_msg_public(msg)) {
1402 object_user_cache_add(snac, id, "public"); 1402 if (object_user_cache_add(snac, id, "public") >= 0) {
1403 1403 /* also add it to the instance public timeline */
1404 /* also add it to the instance public timeline */ 1404 xs *ipt = xs_fmt("%s/public.idx", srv_basedir);
1405 xs *ipt = xs_fmt("%s/public.idx", srv_basedir); 1405 index_add(ipt, id);
1406 index_add(ipt, id); 1406 }
1407 else
1408 srv_debug(1, xs_fmt("Not added to public instance index %s", id));
1407 } 1409 }
1408 } 1410 }
1409 } 1411 }
@@ -1487,16 +1489,28 @@ xs_str *user_index_fn(snac *user, const char *idx_name)
1487} 1489}
1488 1490
1489 1491
1490xs_list *timeline_simple_list(snac *user, const char *idx_name, int skip, int show) 1492xs_list *timeline_simple_list(snac *user, const char *idx_name, int skip, int show, int *more)
1491/* returns a timeline (with all entries) */ 1493/* returns a timeline (with all entries) */
1492{ 1494{
1493 xs *idx = user_index_fn(user, idx_name); 1495 xs *idx = user_index_fn(user, idx_name);
1494 1496
1495 return index_list_desc(idx, skip, show); 1497 /* if a more flag is sent, request one more */
1498 xs_list *lst = index_list_desc(idx, skip, show + (more != NULL ? 1 : 0));
1499
1500 if (more != NULL) {
1501 if (xs_list_len(lst) > show) {
1502 *more = 1;
1503 lst = xs_list_del(lst, -1);
1504 }
1505 else
1506 *more = 0;
1507 }
1508
1509 return lst;
1496} 1510}
1497 1511
1498 1512
1499xs_list *timeline_list(snac *snac, const char *idx_name, int skip, int show) 1513xs_list *timeline_list(snac *snac, const char *idx_name, int skip, int show, int *more)
1500/* returns a timeline (only top level entries) */ 1514/* returns a timeline (only top level entries) */
1501{ 1515{
1502 int c_max; 1516 int c_max;
@@ -1508,12 +1522,33 @@ xs_list *timeline_list(snac *snac, const char *idx_name, int skip, int show)
1508 if (show > c_max) 1522 if (show > c_max)
1509 show = c_max; 1523 show = c_max;
1510 1524
1511 xs *list = timeline_simple_list(snac, idx_name, skip, show); 1525 xs *list = timeline_simple_list(snac, idx_name, skip, show, more);
1512 1526
1513 return timeline_top_level(snac, list); 1527 return timeline_top_level(snac, list);
1514} 1528}
1515 1529
1516 1530
1531void timeline_add_mark(snac *user)
1532/* adds an "already seen" mark to the private timeline */
1533{
1534 xs *fn = xs_fmt("%s/private.idx", user->basedir);
1535 char last_entry[MD5_HEX_SIZE] = "";
1536 FILE *f;
1537
1538 /* get the last entry in the index */
1539 if ((f = fopen(fn, "r")) != NULL) {
1540 index_desc_first(f, last_entry, 0);
1541 fclose(f);
1542 }
1543
1544 /* is the last entry *not* a mark? */
1545 if (strcmp(last_entry, MD5_ALREADY_SEEN_MARK) != 0) {
1546 /* add it */
1547 index_add_md5(fn, MD5_ALREADY_SEEN_MARK);
1548 }
1549}
1550
1551
1517xs_str *instance_index_fn(void) 1552xs_str *instance_index_fn(void)
1518{ 1553{
1519 return xs_fmt("%s/public.idx", srv_basedir); 1554 return xs_fmt("%s/public.idx", srv_basedir);
@@ -1524,8 +1559,17 @@ xs_list *timeline_instance_list(int skip, int show)
1524/* returns the timeline for the full instance */ 1559/* returns the timeline for the full instance */
1525{ 1560{
1526 xs *idx = instance_index_fn(); 1561 xs *idx = instance_index_fn();
1562 xs *lst = index_list_desc(idx, skip, show);
1527 1563
1528 return index_list_desc(idx, skip, show); 1564 /* make the list unique */
1565 xs_set rep;
1566 xs_set_init(&rep);
1567 const char *md5;
1568
1569 xs_list_foreach(lst, md5)
1570 xs_set_add(&rep, md5);
1571
1572 return xs_set_result(&rep);
1529} 1573}
1530 1574
1531 1575
@@ -2557,7 +2601,7 @@ xs_list *inbox_list(void)
2557 if ((f = fopen(v, "r")) != NULL) { 2601 if ((f = fopen(v, "r")) != NULL) {
2558 xs *line = xs_readline(f); 2602 xs *line = xs_readline(f);
2559 2603
2560 if (line) { 2604 if (line && *line) {
2561 line = xs_strip_i(line); 2605 line = xs_strip_i(line);
2562 ibl = xs_list_append(ibl, line); 2606 ibl = xs_list_append(ibl, line);
2563 } 2607 }
@@ -2698,9 +2742,9 @@ xs_list *content_search(snac *user, const char *regex,
2698 const char *md5s[3] = {0}; 2742 const char *md5s[3] = {0};
2699 int c[3] = {0}; 2743 int c[3] = {0};
2700 2744
2701 tls[0] = timeline_simple_list(user, "public", 0, XS_ALL); /* public */ 2745 tls[0] = timeline_simple_list(user, "public", 0, XS_ALL, NULL); /* public */
2702 tls[1] = timeline_instance_list(0, XS_ALL); /* instance */ 2746 tls[1] = timeline_instance_list(0, XS_ALL); /* instance */
2703 tls[2] = priv ? timeline_simple_list(user, "private", 0, XS_ALL) : xs_list_new(); /* private or none */ 2747 tls[2] = priv ? timeline_simple_list(user, "private", 0, XS_ALL, NULL) : xs_list_new(); /* private or none */
2704 2748
2705 /* first positioning */ 2749 /* first positioning */
2706 for (int n = 0; n < 3; n++) 2750 for (int n = 0; n < 3; n++)
@@ -2722,7 +2766,17 @@ xs_list *content_search(snac *user, const char *regex,
2722 for (int n = 0; n < 3; n++) { 2766 for (int n = 0; n < 3; n++) {
2723 if (md5s[n] != NULL) { 2767 if (md5s[n] != NULL) {
2724 xs *fn = _object_fn_by_md5(md5s[n], "content_search"); 2768 xs *fn = _object_fn_by_md5(md5s[n], "content_search");
2725 double mt = mtime(fn); 2769 double mt;
2770
2771 while ((mt = mtime(fn)) == 0 && md5s[n] != NULL) {
2772 /* object is not here: move to the next one */
2773 if (xs_list_next(tls[n], &md5s[n], &c[n])) {
2774 xs_free(fn);
2775 fn = _object_fn_by_md5(md5s[n], "content_search_2");
2776 }
2777 else
2778 md5s[n] = NULL;
2779 }
2726 2780
2727 if (mt > mtime) { 2781 if (mt > mtime) {
2728 newest = n; 2782 newest = n;