summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'data.c')
-rw-r--r--data.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/data.c b/data.c
index 4a05f1b..5117b99 100644
--- a/data.c
+++ b/data.c
@@ -6,6 +6,7 @@
6#include "xs_json.h" 6#include "xs_json.h"
7#include "xs_openssl.h" 7#include "xs_openssl.h"
8#include "xs_glob.h" 8#include "xs_glob.h"
9#include "xs_set.h"
9 10
10#include "snac.h" 11#include "snac.h"
11 12
@@ -1038,6 +1039,58 @@ int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer
1038} 1039}
1039 1040
1040 1041
1042d_char *timeline_top_level(snac *snac, const char *index)
1043/* returns the top level entries from this index */
1044{
1045 int max = 256;
1046 xs *list = index_list_desc(index, max);
1047 xs *tl = xs_list_new();
1048 xs_set seen;
1049 char *p, *v;
1050
1051 xs_set_init(&seen);
1052
1053 p = list;
1054 while (xs_list_iter(&p, &v)) {
1055 char line[256] = "";
1056
1057 strcpy(line, v);
1058
1059 for (;;) {
1060 char line2[256];
1061 xs *fn = _object_fn_by_md5(line);
1062 fn = xs_replace_i(fn, ".json", "_p.idx");
1063
1064 /* if it doesn't have a parent, we got it */
1065 if (index_first(fn, line2, strlen(line2)) == 0) {
1066 strcpy(line, line2);
1067 break;
1068 }
1069
1070 xs *pfn = _object_fn_by_md5(line2);
1071
1072 /* well, there is a parent... if it's not here, we're done */
1073 if (mtime(pfn) == 0.0)
1074 break;
1075
1076 /* it's here! try again with its own parent */
1077 strcpy(line, line2);
1078 }
1079
1080 if (xs_set_add(&seen, line) == 1) {
1081 xs *obj = NULL;
1082
1083 if (valid_status(object_get(line, &obj, NULL)))
1084 tl = xs_list_append(tl, obj);
1085 }
1086 }
1087
1088 xs_set_free(&seen);
1089
1090 return tl;
1091}
1092
1093
1041void timeline_admire(snac *snac, char *id, char *admirer, int like) 1094void timeline_admire(snac *snac, char *id, char *admirer, int like)
1042/* updates a timeline entry with a new admiration */ 1095/* updates a timeline entry with a new admiration */
1043{ 1096{