commit 159a591f45f132df8d5007d3e64faf836aad3f66
parent 4f261ec7b949b89146b699d04bd9e79ce87f7f10
Author: default <nobody@localhost>
Date: Sat, 26 Nov 2022 18:04:05 +0100
New function timeline_top_level() (untested).
Diffstat:
M | data.c | | | 53 | +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
M | snac.h | | | 2 | ++ |
2 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/data.c b/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 */
{
diff --git a/snac.h b/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);