commit 2ad703e

default  ·  2022-11-26 17:52:51 +0000 UTC
parent 159a591
timeline_top_level() works.
3 files changed,  +18, -17
M data.c
M main.c
M snac.h
M data.c
+8, -16
 1@@ -1039,12 +1039,10 @@ int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer
 2 }
 3 
 4 
 5-d_char *timeline_top_level(snac *snac, const char *index)
 6-/* returns the top level entries from this index */
 7+d_char *timeline_top_level(snac *snac, d_char *list)
 8+/* returns the top level md5 entries from this index */
 9 {
10-    int max  = 256;
11-    xs *list = index_list_desc(index, max);
12-    xs *tl   = xs_list_new();
13+    d_char *tl = xs_list_new();
14     xs_set seen;
15     char *p, *v;
16 
17@@ -1061,15 +1059,13 @@ d_char *timeline_top_level(snac *snac, const char *index)
18             xs *fn = _object_fn_by_md5(line);
19             fn     = xs_replace_i(fn, ".json", "_p.idx");
20 
21-            /* if it doesn't have a parent, we got it */
22-            if (index_first(fn, line2, strlen(line2)) == 0) {
23-                strcpy(line, line2);
24+            /* if it doesn't have a parent, use this */
25+            if (index_first(fn, line2, sizeof(line2)) == 0)
26                 break;
27-            }
28 
29             xs *pfn = _object_fn_by_md5(line2);
30 
31-            /* well, there is a parent... if it's not here, we're done */
32+            /* well, there is a parent... but if it's not there, use this */
33             if (mtime(pfn) == 0.0)
34                 break;
35 
36@@ -1077,12 +1073,8 @@ d_char *timeline_top_level(snac *snac, const char *index)
37             strcpy(line, line2);
38         }
39 
40-        if (xs_set_add(&seen, line) == 1) {
41-            xs *obj = NULL;
42-
43-            if (valid_status(object_get(line, &obj, NULL)))
44-                tl = xs_list_append(tl, obj);
45-        }
46+        if (xs_set_add(&seen, line) == 1)
47+            tl = xs_list_append(tl, line);
48     }
49 
50     xs_set_free(&seen);
M main.c
+9, -0
 1@@ -156,12 +156,21 @@ int main(int argc, char *argv[])
 2     }
 3 
 4     if (strcmp(cmd, "timeline") == 0) {
 5+#if 0
 6         xs *list = local_list(&snac, XS_ALL);
 7         xs *body = html_timeline(&snac, list, 1);
 8 
 9         printf("%s\n", body);
10         user_free(&snac);
11         srv_free();
12+#endif
13+
14+        xs *idx  = xs_fmt("%s/private.idx", snac.basedir);
15+        xs *list = index_list_desc(idx, 256);
16+        xs *tl   = timeline_top_level(&snac, list);
17+
18+        xs *j    = xs_json_dumps_pp(tl, 4);
19+        printf("%s\n", j);
20 
21         return 0;
22     }
M snac.h
+1, -1
1@@ -76,7 +76,7 @@ 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+d_char *timeline_top_level(snac *snac, d_char *list);
7 
8 d_char *local_list(snac *snac, int max);
9