diff options
| author | 2022-11-26 18:04:05 +0100 | |
|---|---|---|
| committer | 2022-11-26 18:04:05 +0100 | |
| commit | 159a591f45f132df8d5007d3e64faf836aad3f66 (patch) | |
| tree | 9faa3f2bfd3ed39fd107b0cb7b388a6ae41dd91c | |
| parent | New function index_first(). (diff) | |
| download | snac2-159a591f45f132df8d5007d3e64faf836aad3f66.tar.gz snac2-159a591f45f132df8d5007d3e64faf836aad3f66.tar.xz snac2-159a591f45f132df8d5007d3e64faf836aad3f66.zip | |
New function timeline_top_level() (untested).
| -rw-r--r-- | data.c | 53 | ||||
| -rw-r--r-- | snac.h | 2 |
2 files changed, 55 insertions, 0 deletions
| @@ -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 | ||
| 1042 | d_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 | |||
| 1041 | void timeline_admire(snac *snac, char *id, char *admirer, int like) | 1094 | void 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 | { |
| @@ -76,6 +76,8 @@ 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); | ||
| 80 | |||
| 79 | d_char *local_list(snac *snac, int max); | 81 | d_char *local_list(snac *snac, int max); |
| 80 | 82 | ||
| 81 | int following_add(snac *snac, char *actor, char *msg); | 83 | int following_add(snac *snac, char *actor, char *msg); |