commit 159a591
default
·
2022-11-26 17:04:05 +0000 UTC
parent 4f261ec
New function timeline_top_level() (untested).
M
data.c
+53,
-0
1@@ -6,6 +6,7 @@
2 #include "xs_json.h"
3 #include "xs_openssl.h"
4 #include "xs_glob.h"
5+#include "xs_set.h"
6
7 #include "snac.h"
8
9@@ -1038,6 +1039,58 @@ int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer
10 }
11
12
13+d_char *timeline_top_level(snac *snac, const char *index)
14+/* returns the top level entries from this index */
15+{
16+ int max = 256;
17+ xs *list = index_list_desc(index, max);
18+ xs *tl = xs_list_new();
19+ xs_set seen;
20+ char *p, *v;
21+
22+ xs_set_init(&seen);
23+
24+ p = list;
25+ while (xs_list_iter(&p, &v)) {
26+ char line[256] = "";
27+
28+ strcpy(line, v);
29+
30+ for (;;) {
31+ char line2[256];
32+ xs *fn = _object_fn_by_md5(line);
33+ fn = xs_replace_i(fn, ".json", "_p.idx");
34+
35+ /* if it doesn't have a parent, we got it */
36+ if (index_first(fn, line2, strlen(line2)) == 0) {
37+ strcpy(line, line2);
38+ break;
39+ }
40+
41+ xs *pfn = _object_fn_by_md5(line2);
42+
43+ /* well, there is a parent... if it's not here, we're done */
44+ if (mtime(pfn) == 0.0)
45+ break;
46+
47+ /* it's here! try again with its own parent */
48+ strcpy(line, line2);
49+ }
50+
51+ if (xs_set_add(&seen, line) == 1) {
52+ xs *obj = NULL;
53+
54+ if (valid_status(object_get(line, &obj, NULL)))
55+ tl = xs_list_append(tl, obj);
56+ }
57+ }
58+
59+ xs_set_free(&seen);
60+
61+ return tl;
62+}
63+
64+
65 void timeline_admire(snac *snac, char *id, char *admirer, int like)
66 /* updates a timeline entry with a new admiration */
67 {
M
snac.h
+2,
-0
1@@ -76,6 +76,8 @@ d_char *timeline_list(snac *snac, int max);
2 int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer);
3 void timeline_admire(snac *snac, char *id, char *admirer, int like);
4
5+d_char *timeline_top_level(snac *snac, const char *index);
6+
7 d_char *local_list(snac *snac, int max);
8
9 int following_add(snac *snac, char *actor, char *msg);