commit 67d5725
default
·
2022-12-02 19:28:27 +0000 UTC
parent c06136a
The old timeline is no longer maintained.
1 files changed,
+11,
-224
M
data.c
M
data.c
+11,
-224
1@@ -847,146 +847,6 @@ d_char *_timeline_new_fn(snac *snac, char *id)
2 }
3
4
5-int _timeline_write(snac *snac, char *id, char *msg, char *parent, char *referrer)
6-/* writes a timeline entry and refreshes the ancestors */
7-{
8- xs *fn = _timeline_new_fn(snac, id);
9- xs *pfn = NULL;
10- xs *p_msg = NULL;
11- FILE *f;
12-
13- if (!xs_is_null(parent)) {
14- /* get the parent */
15- pfn = _timeline_find_fn(snac, parent);
16-
17- if (pfn != NULL && (f = fopen(pfn, "r")) != NULL) {
18- xs *j;
19-
20- j = xs_readall(f);
21- fclose(f);
22-
23- p_msg = xs_json_loads(j);
24- }
25- }
26-
27- /* write the message */
28- if ((f = fopen(fn, "w")) != NULL) {
29- xs *j = xs_json_dumps_pp(msg, 4);
30-
31- fwrite(j, strlen(j), 1, f);
32- fclose(f);
33-
34- snac_debug(snac, 1, xs_fmt("_timeline_write %s %s", id, fn));
35- }
36-
37- /* related to this user? link to local timeline */
38- if (xs_startswith(id, snac->actor) ||
39- (!xs_is_null(parent) && xs_startswith(parent, snac->actor)) ||
40- (!xs_is_null(referrer) && xs_startswith(referrer, snac->actor))) {
41- xs *lfn = xs_replace(fn, "/timeline/", "/local/");
42- link(fn, lfn);
43-
44- snac_debug(snac, 1, xs_fmt("_timeline_write (local) %s %s", id, lfn));
45- }
46-
47- if (p_msg != NULL) {
48- /* update the parent, adding this id to its children list */
49- xs *meta = xs_dup(xs_dict_get(p_msg, "_snac"));
50- xs *children = xs_dup(xs_dict_get(meta, "children"));
51-
52- /* add the child if it's not already there */
53- if (xs_list_in(children, id) == -1)
54- children = xs_list_append(children, id);
55-
56- /* re-store */
57- meta = xs_dict_set(meta, "children", children);
58- p_msg = xs_dict_set(p_msg, "_snac", meta);
59-
60- xs *nfn = _timeline_new_fn(snac, parent);
61-
62- if ((f = fopen(nfn, "w")) != NULL) {
63- xs *j = xs_json_dumps_pp(p_msg, 4);
64-
65- fwrite(j, strlen(j), 1, f);
66- fclose(f);
67-
68- unlink(pfn);
69-
70- snac_debug(snac, 1,
71- xs_fmt("_timeline_write updated parent %s %s", parent, nfn));
72-
73- /* try to do the same with the local */
74- xs *olfn = xs_replace(pfn, "/timeline/", "/local/");
75-
76- if (unlink(olfn) != -1 || xs_startswith(id, snac->actor)) {
77- xs *nlfn = xs_replace(nfn, "/timeline/", "/local/");
78-
79- link(nfn, nlfn);
80-
81- snac_debug(snac, 1,
82- xs_fmt("_timeline_write updated parent (local) %s %s", parent, nlfn));
83- }
84- }
85- else
86- return 0;
87-
88- /* now iterate all parents up, just renaming the files */
89- xs *grampa = xs_dup(xs_dict_get(meta, "parent"));
90-
91- int max_levels = 20;
92-
93- while (!xs_is_null(grampa)) {
94- xs *gofn = _timeline_find_fn(snac, grampa);
95-
96- if (gofn == NULL)
97- break;
98-
99- /* create the new filename */
100- xs *gnfn = _timeline_new_fn(snac, grampa);
101-
102- rename(gofn, gnfn);
103-
104- snac_debug(snac, 1,
105- xs_fmt("_timeline_write updated grampa %s %s", grampa, gnfn));
106-
107- /* try to do the same with the local */
108- xs *golfn = xs_replace(gofn, "/timeline/", "/local/");
109-
110- if (unlink(golfn) != -1) {
111- xs *gnlfn = xs_replace(gnfn, "/timeline/", "/local/");
112-
113- link(gnfn, gnlfn);
114-
115- snac_debug(snac, 1,
116- xs_fmt("_timeline_write updated grampa (local) %s %s", parent, gnlfn));
117- }
118-
119- /* now open it and get its own parent */
120- if ((f = fopen(gnfn, "r")) != NULL) {
121- xs *j = xs_readall(f);
122- fclose(f);
123-
124- xs *g_msg = xs_json_loads(j);
125- char *meta = xs_dict_get(g_msg, "_snac");
126- char *p = xs_dict_get(meta, "parent");
127-
128- xs_free(grampa);
129- grampa = xs_dup(p);
130- }
131- else
132- break;
133-
134- if (--max_levels == 0) {
135- snac_debug(snac, 1, xs_dup("_timeline_write maximum grampa levels reached"));
136- break;
137- }
138- }
139- }
140-
141- return 1;
142-}
143-
144-
145 void timeline_update_indexes(snac *snac, const char *id)
146 /* updates the indexes */
147 {
148@@ -1000,43 +860,22 @@ void timeline_update_indexes(snac *snac, const char *id)
149 int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer)
150 /* adds a message to the timeline */
151 {
152- xs *pfn = _timeline_find_fn(snac, id);
153- int ret = 0;
154+ int ret = object_add(id, o_msg);
155+ timeline_update_indexes(snac, id);
156
157- if (pfn != NULL) {
158- snac_log(snac, xs_fmt("timeline_add refusing rewrite %s %s", id, pfn));
159- return 0;
160- }
161-
162- xs *msg = xs_dup(o_msg);
163- xs *md;
164-
165- /* add new metadata */
166- md = xs_json_loads("{"
167- "\"children\": [],"
168- "\"liked_by\": [],"
169- "\"announced_by\": [],"
170- "\"version\": \"" USER_AGENT "\","
171- "\"referrer\": null,"
172- "\"parent\": null"
173- "}");
174-
175- if (!xs_is_null(parent))
176- md = xs_dict_set(md, "parent", parent);
177+ snac_debug(snac, 1, xs_fmt("timeline_add %s", id));
178
179- if (!xs_is_null(referrer))
180- md = xs_dict_set(md, "referrer", referrer);
181-
182- msg = xs_dict_set(msg, "_snac", md);
183+ return ret;
184+}
185
186- if ((ret = _timeline_write(snac, id, msg, parent, referrer))) {
187- snac_debug(snac, 1, xs_fmt("timeline_add %s", id));
188
189- object_add(id, o_msg);
190- timeline_update_indexes(snac, id);
191- }
192+void timeline_admire(snac *snac, char *o_msg, char *id, char *admirer, int like)
193+/* updates a timeline entry with a new admiration */
194+{
195+ object_admire(id, admirer, like);
196
197- return ret;
198+ snac_debug(snac, 1, xs_fmt("timeline_admire (%s) %s %s",
199+ like ? "Like" : "Announce", id, admirer));
200 }
201
202
203@@ -1103,58 +942,6 @@ d_char *timeline_list(snac *snac, const char *idx_name, int max)
204 }
205
206
207-void timeline_admire(snac *snac, char *o_msg, char *id, char *admirer, int like)
208-/* updates a timeline entry with a new admiration */
209-{
210- xs *ofn = _timeline_find_fn(snac, id);
211- FILE *f;
212-
213- if (ofn != NULL && (f = fopen(ofn, "r")) != NULL) {
214- xs *j1 = xs_readall(f);
215- fclose(f);
216-
217- xs *msg = xs_json_loads(j1);
218- xs *meta = xs_dup(xs_dict_get(msg, "_snac"));
219- xs *list;
220-
221- if (like)
222- list = xs_dup(xs_dict_get(meta, "liked_by"));
223- else
224- list = xs_dup(xs_dict_get(meta, "announced_by"));
225-
226- /* add the admirer if it's not already there */
227- if (xs_list_in(list, admirer) == -1)
228- list = xs_list_append(list, admirer);
229-
230- /* set the admirer as the referrer (if not already set or it's us) */
231- if (!like && (xs_is_null(xs_dict_get(meta, "referrer")) ||
232- strcmp(admirer, snac->actor) == 0))
233- meta = xs_dict_set(meta, "referrer", admirer);
234-
235- /* re-store */
236- if (like)
237- meta = xs_dict_set(meta, "liked_by", list);
238- else
239- meta = xs_dict_set(meta, "announced_by", list);
240-
241- msg = xs_dict_set(msg, "_snac", meta);
242-
243- unlink(ofn);
244- ofn = xs_replace_i(ofn, "/timeline/", "/local/");
245- unlink(ofn);
246-
247- _timeline_write(snac, id, msg, xs_dict_get(meta, "parent"), like ? NULL : admirer);
248-
249- snac_debug(snac, 1, xs_fmt("timeline_admire (%s) %s %s",
250- like ? "Like" : "Announce", id, admirer));
251- }
252- else
253- snac_log(snac, xs_fmt("timeline_admire ignored for unknown object %s", id));
254-
255- object_admire(id, admirer, like);
256-}
257-
258-
259 /** following **/
260
261 /* this needs special treatment and cannot use the object db as is,