commit 7f32230

default  ·  2024-04-29 07:50:22 +0000 UTC
parent 29fb430
New function list_distribute().
2 files changed,  +29, -0
M data.c
M snac.h
M data.c
+28, -0
 1@@ -1154,6 +1154,8 @@ int timeline_add(snac *snac, const char *id, const xs_dict *o_msg)
 2 
 3     tag_index(id, o_msg);
 4 
 5+    list_distribute(snac, o_msg);
 6+
 7     snac_debug(snac, 1, xs_fmt("timeline_add %s", id));
 8 
 9     return ret;
10@@ -1859,6 +1861,32 @@ xs_val *list_content(snac *user, const char *list, const char *actor_md5, int op
11 }
12 
13 
14+void list_distribute(snac *user, const xs_dict *post)
15+/* distributes the post to all appropriate lists */
16+{
17+    char *atto = get_atto(post);
18+    char *id   = xs_dict_get(post, "id");
19+
20+    if (xs_type(atto) == XSTYPE_STRING && xs_type(id) == XSTYPE_STRING) {
21+        xs *a_md5 = xs_md5_hex(atto, strlen(atto));
22+        xs *i_md5 = xs_md5_hex(id, strlen(id));
23+        xs *spec  = xs_fmt("%s/list/" "*.lst", user->basedir);
24+        xs *ls    = xs_glob(spec, 0, 0);
25+        int c = 0;
26+        char *v;
27+
28+        while (xs_list_next(ls, &v, &c)) {
29+            /* is the actor in this list? */
30+            if (index_in_md5(v, a_md5)) {
31+                /* it is; add post md5 to its timeline */
32+                xs *idx = xs_replace(v, ".lst", ".idx");
33+                index_add(idx, i_md5);
34+            }
35+        }
36+    }
37+}
38+
39+
40 /** static data **/
41 
42 static int _load_raw_file(const char *fn, xs_val **data, int *size,
M snac.h
+1, -0
1@@ -176,6 +176,7 @@ xs_list *tag_search(char *tag, int skip, int show);
2 
3 xs_val *list_maint(snac *user, const char *list, int op);
4 xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int op);
5+void list_distribute(snac *user, const xs_dict *post);
6 
7 int actor_add(const char *actor, xs_dict *msg);
8 int actor_get(const char *actor, xs_dict **data);