diff options
| author | 2022-11-26 18:52:51 +0100 | |
|---|---|---|
| committer | 2022-11-26 18:52:51 +0100 | |
| commit | 2ad703e52028814a27918f5e840f734aa98adfd1 (patch) | |
| tree | d910e0f050cf58f7c24dedf33ea839ef7506b2c9 | |
| parent | New function timeline_top_level() (untested). (diff) | |
| download | snac2-2ad703e52028814a27918f5e840f734aa98adfd1.tar.gz snac2-2ad703e52028814a27918f5e840f734aa98adfd1.tar.xz snac2-2ad703e52028814a27918f5e840f734aa98adfd1.zip | |
timeline_top_level() works.
| -rw-r--r-- | data.c | 24 | ||||
| -rw-r--r-- | main.c | 9 | ||||
| -rw-r--r-- | snac.h | 2 |
3 files changed, 18 insertions, 17 deletions
| @@ -1039,12 +1039,10 @@ int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer | |||
| 1039 | } | 1039 | } |
| 1040 | 1040 | ||
| 1041 | 1041 | ||
| 1042 | d_char *timeline_top_level(snac *snac, const char *index) | 1042 | d_char *timeline_top_level(snac *snac, d_char *list) |
| 1043 | /* returns the top level entries from this index */ | 1043 | /* returns the top level md5 entries from this index */ |
| 1044 | { | 1044 | { |
| 1045 | int max = 256; | 1045 | d_char *tl = xs_list_new(); |
| 1046 | xs *list = index_list_desc(index, max); | ||
| 1047 | xs *tl = xs_list_new(); | ||
| 1048 | xs_set seen; | 1046 | xs_set seen; |
| 1049 | char *p, *v; | 1047 | char *p, *v; |
| 1050 | 1048 | ||
| @@ -1061,15 +1059,13 @@ d_char *timeline_top_level(snac *snac, const char *index) | |||
| 1061 | xs *fn = _object_fn_by_md5(line); | 1059 | xs *fn = _object_fn_by_md5(line); |
| 1062 | fn = xs_replace_i(fn, ".json", "_p.idx"); | 1060 | fn = xs_replace_i(fn, ".json", "_p.idx"); |
| 1063 | 1061 | ||
| 1064 | /* if it doesn't have a parent, we got it */ | 1062 | /* if it doesn't have a parent, use this */ |
| 1065 | if (index_first(fn, line2, strlen(line2)) == 0) { | 1063 | if (index_first(fn, line2, sizeof(line2)) == 0) |
| 1066 | strcpy(line, line2); | ||
| 1067 | break; | 1064 | break; |
| 1068 | } | ||
| 1069 | 1065 | ||
| 1070 | xs *pfn = _object_fn_by_md5(line2); | 1066 | xs *pfn = _object_fn_by_md5(line2); |
| 1071 | 1067 | ||
| 1072 | /* well, there is a parent... if it's not here, we're done */ | 1068 | /* well, there is a parent... but if it's not there, use this */ |
| 1073 | if (mtime(pfn) == 0.0) | 1069 | if (mtime(pfn) == 0.0) |
| 1074 | break; | 1070 | break; |
| 1075 | 1071 | ||
| @@ -1077,12 +1073,8 @@ d_char *timeline_top_level(snac *snac, const char *index) | |||
| 1077 | strcpy(line, line2); | 1073 | strcpy(line, line2); |
| 1078 | } | 1074 | } |
| 1079 | 1075 | ||
| 1080 | if (xs_set_add(&seen, line) == 1) { | 1076 | if (xs_set_add(&seen, line) == 1) |
| 1081 | xs *obj = NULL; | 1077 | tl = xs_list_append(tl, line); |
| 1082 | |||
| 1083 | if (valid_status(object_get(line, &obj, NULL))) | ||
| 1084 | tl = xs_list_append(tl, obj); | ||
| 1085 | } | ||
| 1086 | } | 1078 | } |
| 1087 | 1079 | ||
| 1088 | xs_set_free(&seen); | 1080 | xs_set_free(&seen); |
| @@ -156,12 +156,21 @@ int main(int argc, char *argv[]) | |||
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | if (strcmp(cmd, "timeline") == 0) { | 158 | if (strcmp(cmd, "timeline") == 0) { |
| 159 | #if 0 | ||
| 159 | xs *list = local_list(&snac, XS_ALL); | 160 | xs *list = local_list(&snac, XS_ALL); |
| 160 | xs *body = html_timeline(&snac, list, 1); | 161 | xs *body = html_timeline(&snac, list, 1); |
| 161 | 162 | ||
| 162 | printf("%s\n", body); | 163 | printf("%s\n", body); |
| 163 | user_free(&snac); | 164 | user_free(&snac); |
| 164 | srv_free(); | 165 | srv_free(); |
| 166 | #endif | ||
| 167 | |||
| 168 | xs *idx = xs_fmt("%s/private.idx", snac.basedir); | ||
| 169 | xs *list = index_list_desc(idx, 256); | ||
| 170 | xs *tl = timeline_top_level(&snac, list); | ||
| 171 | |||
| 172 | xs *j = xs_json_dumps_pp(tl, 4); | ||
| 173 | printf("%s\n", j); | ||
| 165 | 174 | ||
| 166 | return 0; | 175 | return 0; |
| 167 | } | 176 | } |
| @@ -76,7 +76,7 @@ d_char *timeline_list(snac *snac, int max); | |||
| 76 | int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer); | 76 | int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer); |
| 77 | void timeline_admire(snac *snac, char *id, char *admirer, int like); | 77 | void timeline_admire(snac *snac, char *id, char *admirer, int like); |
| 78 | 78 | ||
| 79 | d_char *timeline_top_level(snac *snac, const char *index); | 79 | d_char *timeline_top_level(snac *snac, d_char *list); |
| 80 | 80 | ||
| 81 | d_char *local_list(snac *snac, int max); | 81 | d_char *local_list(snac *snac, int max); |
| 82 | 82 | ||