diff options
| author | 2024-04-29 09:50:22 +0200 | |
|---|---|---|
| committer | 2024-04-29 09:50:22 +0200 | |
| commit | 7f322302e5b5cf0345de110afe78767bfb03ae51 (patch) | |
| tree | 32c2e4a11f43665519c9fddbbd207572e3d3015b | |
| parent | More work in lists. (diff) | |
| download | penes-snac2-7f322302e5b5cf0345de110afe78767bfb03ae51.tar.gz penes-snac2-7f322302e5b5cf0345de110afe78767bfb03ae51.tar.xz penes-snac2-7f322302e5b5cf0345de110afe78767bfb03ae51.zip | |
New function list_distribute().
| -rw-r--r-- | data.c | 28 | ||||
| -rw-r--r-- | snac.h | 1 |
2 files changed, 29 insertions, 0 deletions
| @@ -1154,6 +1154,8 @@ int timeline_add(snac *snac, const char *id, const xs_dict *o_msg) | |||
| 1154 | 1154 | ||
| 1155 | tag_index(id, o_msg); | 1155 | tag_index(id, o_msg); |
| 1156 | 1156 | ||
| 1157 | list_distribute(snac, o_msg); | ||
| 1158 | |||
| 1157 | snac_debug(snac, 1, xs_fmt("timeline_add %s", id)); | 1159 | snac_debug(snac, 1, xs_fmt("timeline_add %s", id)); |
| 1158 | 1160 | ||
| 1159 | return ret; | 1161 | return ret; |
| @@ -1859,6 +1861,32 @@ xs_val *list_content(snac *user, const char *list, const char *actor_md5, int op | |||
| 1859 | } | 1861 | } |
| 1860 | 1862 | ||
| 1861 | 1863 | ||
| 1864 | void list_distribute(snac *user, const xs_dict *post) | ||
| 1865 | /* distributes the post to all appropriate lists */ | ||
| 1866 | { | ||
| 1867 | char *atto = get_atto(post); | ||
| 1868 | char *id = xs_dict_get(post, "id"); | ||
| 1869 | |||
| 1870 | if (xs_type(atto) == XSTYPE_STRING && xs_type(id) == XSTYPE_STRING) { | ||
| 1871 | xs *a_md5 = xs_md5_hex(atto, strlen(atto)); | ||
| 1872 | xs *i_md5 = xs_md5_hex(id, strlen(id)); | ||
| 1873 | xs *spec = xs_fmt("%s/list/" "*.lst", user->basedir); | ||
| 1874 | xs *ls = xs_glob(spec, 0, 0); | ||
| 1875 | int c = 0; | ||
| 1876 | char *v; | ||
| 1877 | |||
| 1878 | while (xs_list_next(ls, &v, &c)) { | ||
| 1879 | /* is the actor in this list? */ | ||
| 1880 | if (index_in_md5(v, a_md5)) { | ||
| 1881 | /* it is; add post md5 to its timeline */ | ||
| 1882 | xs *idx = xs_replace(v, ".lst", ".idx"); | ||
| 1883 | index_add(idx, i_md5); | ||
| 1884 | } | ||
| 1885 | } | ||
| 1886 | } | ||
| 1887 | } | ||
| 1888 | |||
| 1889 | |||
| 1862 | /** static data **/ | 1890 | /** static data **/ |
| 1863 | 1891 | ||
| 1864 | static int _load_raw_file(const char *fn, xs_val **data, int *size, | 1892 | static int _load_raw_file(const char *fn, xs_val **data, int *size, |
| @@ -176,6 +176,7 @@ xs_list *tag_search(char *tag, int skip, int show); | |||
| 176 | 176 | ||
| 177 | xs_val *list_maint(snac *user, const char *list, int op); | 177 | xs_val *list_maint(snac *user, const char *list, int op); |
| 178 | xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int op); | 178 | xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int op); |
| 179 | void list_distribute(snac *user, const xs_dict *post); | ||
| 179 | 180 | ||
| 180 | int actor_add(const char *actor, xs_dict *msg); | 181 | int actor_add(const char *actor, xs_dict *msg); |
| 181 | int actor_get(const char *actor, xs_dict **data); | 182 | int actor_get(const char *actor, xs_dict **data); |