summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorGravatar default2024-05-14 05:17:33 +0200
committerGravatar default2024-05-14 05:17:33 +0200
commit281f934f74c662d3c2e58db556f3046a736a2f00 (patch)
treebf06a77cb0d01ac1f4d8ad94ee2c882298500298 /data.c
parentUpdated RELEASE_NOTES. (diff)
downloadpenes-snac2-281f934f74c662d3c2e58db556f3046a736a2f00.tar.gz
penes-snac2-281f934f74c662d3c2e58db556f3046a736a2f00.tar.xz
penes-snac2-281f934f74c662d3c2e58db556f3046a736a2f00.zip
content_search() also searches the instance timeline.
Diffstat (limited to 'data.c')
-rw-r--r--data.c79
1 files changed, 33 insertions, 46 deletions
diff --git a/data.c b/data.c
index 706e8e1..6df5f5c 100644
--- a/data.c
+++ b/data.c
@@ -2508,73 +2508,56 @@ xs_list *content_search(snac *user, const char *regex,
2508 time_t t = time(NULL) + max_secs; 2508 time_t t = time(NULL) + max_secs;
2509 *timeout = 0; 2509 *timeout = 0;
2510 2510
2511 /* iterate both timelines simultaneously */ 2511 /* iterate all timelines simultaneously */
2512 xs *pub_tl = timeline_simple_list(user, "public", 0, XS_ALL); 2512 xs_list *tls[3] = {0};
2513 int pub_c = 0; 2513 char *md5s[3] = {0};
2514 char *pub_md5 = NULL; 2514 int c[3] = {0};
2515 2515
2516 xs *priv_tl = priv ? timeline_simple_list(user, "private", 0, XS_ALL) : xs_list_new(); 2516 tls[0] = timeline_simple_list(user, "public", 0, XS_ALL); /* public */
2517 int priv_c = 0; 2517 tls[1] = timeline_instance_list(0, XS_ALL); /* instance */
2518 char *priv_md5 = NULL; 2518 tls[2] = priv ? timeline_simple_list(user, "private", 0, XS_ALL) : xs_list_new(); /* private or none */
2519 2519
2520 /* first positioning */ 2520 /* first positioning */
2521 xs_list_next(pub_tl, &pub_md5, &pub_c); 2521 for (int n = 0; n < 3; n++)
2522 xs_list_next(priv_tl, &priv_md5, &priv_c); 2522 xs_list_next(tls[n], &md5s[n], &c[n]);
2523 2523
2524 show += skip; 2524 show += skip;
2525 2525
2526 while (show > 0) { 2526 while (show > 0) {
2527 char *md5 = NULL;
2528 enum { NONE, PUBLIC, PRIVATE } from = NONE;
2529
2530 /* timeout? */ 2527 /* timeout? */
2531 if (time(NULL) > t) { 2528 if (time(NULL) > t) {
2532 *timeout = 1; 2529 *timeout = 1;
2533 break; 2530 break;
2534 } 2531 }
2535 2532
2536 if (pub_md5 == NULL) { 2533 /* find the newest post */
2537 /* out of both lists? done */ 2534 int newest = -1;
2538 if (priv_md5 == NULL) 2535 double mtime = 0.0;
2539 break;
2540
2541 /* out of public: take element from the private timeline and advance */
2542 from = PRIVATE;
2543 }
2544 else
2545 if (priv_md5 == NULL) {
2546 /* out of private: take element from the public timeline and advance */
2547 from = PUBLIC;
2548 }
2549 else {
2550 /* candidates from both: choose one from the file dates */
2551 xs *pub_fn = xs_fmt("%s/public/%s.json", user->basedir, pub_md5);
2552 xs *priv_fn = xs_fmt("%s/private/%s.json", user->basedir, priv_md5);
2553 2536
2554 if (mtime(pub_fn) < mtime(priv_fn)) 2537 for (int n = 0; n < 3; n++) {
2555 from = PRIVATE; 2538 if (md5s[n] != NULL) {
2556 else 2539 xs *fn = _object_fn_by_md5(md5s[n], "content_search");
2557 from = PUBLIC; 2540 double mt = mtime(fn);
2558 }
2559 2541
2560 if (from == PUBLIC) { /* public */ 2542 if (mt > mtime) {
2561 md5 = pub_md5; 2543 newest = n;
2562 if (!xs_list_next(pub_tl, &pub_md5, &pub_c)) 2544 mtime = mt;
2563 pub_md5 = NULL; 2545 }
2564 } 2546 }
2565 else
2566 if (from == PRIVATE) { /* private */
2567 md5 = priv_md5;
2568 if (!xs_list_next(priv_tl, &priv_md5, &priv_c))
2569 priv_md5 = NULL;
2570 } 2547 }
2571 2548
2572 if (md5 == NULL) 2549 if (newest == -1)
2573 break; 2550 break;
2574 2551
2552 char *md5 = md5s[newest];
2553
2554 /* advance the chosen timeline */
2555 if (!xs_list_next(tls[newest], &md5s[newest], &c[newest]))
2556 md5s[newest] = NULL;
2557
2575 xs *post = NULL; 2558 xs *post = NULL;
2576 2559
2577 if (!valid_status(timeline_get_by_md5(user, md5, &post))) 2560 if (!valid_status(object_get_by_md5(md5, &post)))
2578 continue; 2561 continue;
2579 2562
2580 if (!xs_match(xs_dict_get_def(post, "type", "-"), POSTLIKE_OBJECT_TYPE)) 2563 if (!xs_match(xs_dict_get_def(post, "type", "-"), POSTLIKE_OBJECT_TYPE))
@@ -2608,6 +2591,10 @@ xs_list *content_search(snac *user, const char *regex,
2608 } 2591 }
2609 } 2592 }
2610 2593
2594 xs_free(tls[0]);
2595 xs_free(tls[1]);
2596 xs_free(tls[2]);
2597
2611 return r; 2598 return r;
2612} 2599}
2613 2600