소스 검색

New function timeline_top_level() (untested).

default 3 년 전
부모
커밋
159a591f45
2개의 변경된 파일55개의 추가작업 그리고 0개의 파일을 삭제
  1. 53 0
      data.c
  2. 2 0
      snac.h

+ 53 - 0
data.c

@@ -6,6 +6,7 @@
 #include "xs_json.h"
 #include "xs_openssl.h"
 #include "xs_glob.h"
+#include "xs_set.h"
 
 #include "snac.h"
 
@@ -1038,6 +1039,58 @@ int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer
 }
 
 
+d_char *timeline_top_level(snac *snac, const char *index)
+/* returns the top level entries from this index */
+{
+    int max  = 256;
+    xs *list = index_list_desc(index, max);
+    xs *tl   = xs_list_new();
+    xs_set seen;
+    char *p, *v;
+
+    xs_set_init(&seen);
+
+    p = list;
+    while (xs_list_iter(&p, &v)) {
+        char line[256] = "";
+
+        strcpy(line, v);
+
+        for (;;) {
+            char line2[256];
+            xs *fn = _object_fn_by_md5(line);
+            fn     = xs_replace_i(fn, ".json", "_p.idx");
+
+            /* if it doesn't have a parent, we got it */
+            if (index_first(fn, line2, strlen(line2)) == 0) {
+                strcpy(line, line2);
+                break;
+            }
+
+            xs *pfn = _object_fn_by_md5(line2);
+
+            /* well, there is a parent... if it's not here, we're done */
+            if (mtime(pfn) == 0.0)
+                break;
+
+            /* it's here! try again with its own parent */
+            strcpy(line, line2);
+        }
+
+        if (xs_set_add(&seen, line) == 1) {
+            xs *obj = NULL;
+
+            if (valid_status(object_get(line, &obj, NULL)))
+                tl = xs_list_append(tl, obj);
+        }
+    }
+
+    xs_set_free(&seen);
+
+    return tl;
+}
+
+
 void timeline_admire(snac *snac, char *id, char *admirer, int like)
 /* updates a timeline entry with a new admiration */
 {

+ 2 - 0
snac.h

@@ -76,6 +76,8 @@ d_char *timeline_list(snac *snac, int max);
 int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer);
 void timeline_admire(snac *snac, char *id, char *admirer, int like);
 
+d_char *timeline_top_level(snac *snac, const char *index);
+
 d_char *local_list(snac *snac, int max);
 
 int following_add(snac *snac, char *actor, char *msg);