commit 6743113

shtrophic  ·  2024-11-19 20:40:18 +0000 UTC
parents 972783f, 3a91185
Merge remote-tracking branch 'upstream/master'
9 files changed,  +69, -18
M data.c
M html.c
M main.c
M snac.h
+10, -4
 1@@ -16,10 +16,6 @@ Important: deleting a follower should do more that just delete the object, see h
 2 
 3 ## Wishlist
 4 
 5-Implement Proxying for Media Links to Enhance User Privacy (see https://codeberg.org/grunfink/snac2/issues/219 for more information).
 6-
 7-Consider showing only posts by the account owner (not full trees) (see https://codeberg.org/grunfink/snac2/issues/217 for more information).
 8-
 9 Add support for subscribing and posting to relays (see https://codeberg.org/grunfink/snac2/issues/216 for more information).
10 
11 The instance timeline should also show boosts from users.
12@@ -357,3 +353,13 @@ Fix a crash when posting from the links browser (2.63, 2024-11-08T15:57:25+0100)
13 Fix some repeated images in Lemmy posts (2.63, 2024-11-08T15:57:25+0100).
14 
15 Fix a crash when posting an image from the tooot mobile app (2.63, 2024-11-11T19:42:11+0100).
16+
17+Fix some URL proxying (2.64, 2024-11-16T07:26:23+0100).
18+
19+Allow underscores in hashtags (2.64, 2024-11-16T07:26:23+0100).
20+
21+Add a pidfile (2.64, 2024-11-17T10:21:29+0100).
22+
23+Implement Proxying for Media Links to Enhance User Privacy (see https://codeberg.org/grunfink/snac2/issues/219 for more information) (2024-11-18T20:36:39+0100).
24+
25+Consider showing only posts by the account owner (not full trees) (see https://codeberg.org/grunfink/snac2/issues/217 for more information) (2024-11-18T20:36:39+0100).
+16, -4
 1@@ -183,6 +183,18 @@ const char *get_atto(const xs_dict *msg)
 2 }
 3 
 4 
 5+const char *get_in_reply_to(const xs_dict *msg)
 6+/* gets the inReplyTo id */
 7+{
 8+    const xs_val *in_reply_to = xs_dict_get(msg, "inReplyTo");
 9+
10+    if (xs_type(in_reply_to) == XSTYPE_DICT)
11+        in_reply_to = xs_dict_get(in_reply_to, "id");
12+
13+    return in_reply_to;
14+}
15+
16+
17 xs_list *get_attachments(const xs_dict *msg)
18 /* unify the garbage fire that are the attachments */
19 {
20@@ -373,7 +385,7 @@ int timeline_request(snac *snac, const char **id, xs_str **wrk, int level)
21                             }
22 
23                             /* does it have an ancestor? */
24-                            const char *in_reply_to = xs_dict_get(object, "inReplyTo");
25+                            const char *in_reply_to = get_in_reply_to(object);
26 
27                             /* store */
28                             timeline_add(snac, nid, object);
29@@ -671,7 +683,7 @@ int is_msg_for_me(snac *snac, const xs_dict *c_msg)
30         return 3;
31 
32     /* is this message a reply to another? */
33-    const char *irt = xs_dict_get(msg, "inReplyTo");
34+    const char *irt = get_in_reply_to(msg);
35     if (!xs_is_null(irt)) {
36         xs *r_msg = NULL;
37 
38@@ -724,7 +736,7 @@ xs_str *process_tags(snac *snac, const char *content, xs_list **tag)
39         /* use this same server */
40         def_srv = xs_dup(xs_dict_get(srv_config, "host"));
41 
42-    split = xs_regex_split(content, "(@[A-Za-z0-9_]+(@[A-Za-z0-9\\.-]+)?|&#[0-9]+;|#[^[:punct:][:space:]]+)");
43+    split = xs_regex_split(content, "(@[A-Za-z0-9_]+(@[A-Za-z0-9\\.-]+)?|&#[0-9]+;|#(_|[^[:punct:][:space:]])+)");
44 
45     p = split;
46     while (xs_list_iter(&p, &v)) {
47@@ -1957,7 +1969,7 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
48 
49         if (xs_match(utype, "Note|Article")) { /** **/
50             const char *id          = xs_dict_get(object, "id");
51-            const char *in_reply_to = xs_dict_get(object, "inReplyTo");
52+            const char *in_reply_to = get_in_reply_to(object);
53             const char *atto        = get_atto(object);
54             xs *wrk           = NULL;
55 
M data.c
+1, -1
1@@ -762,7 +762,7 @@ int _object_add(const char *id, const xs_dict *obj, int ow)
2         fclose(f);
3 
4         /* does this object has a parent? */
5-        const char *in_reply_to = xs_dict_get(obj, "inReplyTo");
6+        const char *in_reply_to = get_in_reply_to(obj);
7 
8         if (!xs_is_null(in_reply_to) && *in_reply_to) {
9             /* update the children index of the parent */
+2, -0
1@@ -209,6 +209,8 @@ web interface.
2 .It Pa history/
3 This directory contains generated HTML files. They may be snapshots of the
4 local timeline in previous months or other cached data.
5+.It Pa server.pid
6+This file stores the server PID in a single text line.
7 .El
8 .Sh SEE ALSO
9 .Xr snac 1 ,
M html.c
+2, -2
 1@@ -1670,7 +1670,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
 2     if (strcmp(type, "Note") == 0) {
 3         if (level == 0) {
 4             /* is the parent not here? */
 5-            const char *parent = xs_dict_get(msg, "inReplyTo");
 6+            const char *parent = get_in_reply_to(msg);
 7 
 8             if (user && !xs_is_null(parent) && *parent && !timeline_here(user, parent)) {
 9                 xs_html_add(post_header,
10@@ -2329,7 +2329,7 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only,
11 
12         /* is this message a non-public reply? */
13         if (user != NULL && !is_msg_public(msg)) {
14-            const char *irt = xs_dict_get(msg, "inReplyTo");
15+            const char *irt = get_in_reply_to(msg);
16 
17             /* is it a reply to something not in the storage? */
18             if (!xs_is_null(irt) && !object_here(irt)) {
+14, -0
 1@@ -774,6 +774,7 @@ void httpd(void)
 2     xs *sem_name = NULL;
 3     xs *shm_name = NULL;
 4     sem_t anon_job_sem;
 5+    xs *pidfile = xs_fmt("%s/server.pid", srv_basedir);
 6 
 7     address = xs_dict_get(srv_config, "address");
 8 
 9@@ -809,6 +810,17 @@ void httpd(void)
10     srv_log(xs_fmt("httpd%s start %s %s", p_state->use_fcgi ? " (FastCGI)" : "",
11                     full_address, USER_AGENT));
12 
13+    {
14+        FILE *f;
15+
16+        if ((f = fopen(pidfile, "w")) != NULL) {
17+            fprintf(f, "%d\n", getpid());
18+            fclose(f);
19+        }
20+        else
21+            srv_log(xs_fmt("Cannot create %s: %s", pidfile, strerror(errno)));
22+    }
23+
24     /* show the number of usable file descriptors */
25     struct rlimit r;
26     getrlimit(RLIMIT_NOFILE, &r);
27@@ -894,4 +906,6 @@ void httpd(void)
28     srv_log(xs_fmt("httpd%s stop %s (run time: %s)",
29                 p_state->use_fcgi ? " (FastCGI)" : "",
30                 full_address, uptime));
31+
32+    unlink(pidfile);
33 }
M main.c
+5, -1
 1@@ -558,7 +558,11 @@ int main(int argc, char *argv[])
 2         if (data != NULL) {
 3             xs_json_dump(data, 4, stdout);
 4             enqueue_actor_refresh(&snac, xs_dict_get(data, "attributedTo"), 0);
 5-            timeline_add(&snac, url, data);
 6+
 7+            if (!timeline_here(&snac, url))
 8+                timeline_add(&snac, url, data);
 9+            else
10+                printf("Post %s already here\n", url);
11         }
12 
13         return 0;
+18, -6
 1@@ -171,7 +171,7 @@ const char *login_page = ""
 2 "<body><h1>%s OAuth identify</h1>\n"
 3 "<div style=\"background-color: red; color: white\">%s</div>\n"
 4 "<form method=\"post\" action=\"%s:/" "/%s/%s\">\n"
 5-"<p>Login: <input type=\"text\" name=\"login\"></p>\n"
 6+"<p>Login: <input type=\"text\" name=\"login\" autocapitalize=\"off\"></p>\n"
 7 "<p>Password: <input type=\"password\" name=\"passwd\"></p>\n"
 8 "<input type=\"hidden\" name=\"redir\" value=\"%s\">\n"
 9 "<input type=\"hidden\" name=\"cid\" value=\"%s\">\n"
10@@ -1024,7 +1024,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
11     st = xs_dict_append(st, "in_reply_to_id",         xs_stock(XSTYPE_NULL));
12     st = xs_dict_append(st, "in_reply_to_account_id", xs_stock(XSTYPE_NULL));
13 
14-    tmp = xs_dict_get(msg, "inReplyTo");
15+    tmp = get_in_reply_to(msg);
16     if (!xs_is_null(tmp)) {
17         xs *irto = NULL;
18 
19@@ -1727,11 +1727,11 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
20         if (logged_in) {
21             xs *l      = notify_list(&snac1, 0, 64);
22             xs *out    = xs_list_new();
23-            xs_list *p = l;
24             const xs_dict *v;
25             const xs_list *excl = xs_dict_get(args, "exclude_types[]");
26+            const char *max_id = xs_dict_get(args, "max_id");
27 
28-            while (xs_list_iter(&p, &v)) {
29+            xs_list_foreach(l, v) {
30                 xs *noti = notify_get(&snac1, v);
31 
32                 if (noti == NULL)
33@@ -1740,6 +1740,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
34                 const char *type  = xs_dict_get(noti, "type");
35                 const char *utype = xs_dict_get(noti, "utype");
36                 const char *objid = xs_dict_get(noti, "objid");
37+                const char *id    = xs_dict_get(noti, "id");
38+                xs *fid = xs_replace(id, ".", "");
39                 xs *actor = NULL;
40                 xs *entry = NULL;
41 
42@@ -1752,6 +1754,13 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
43                 if (is_hidden(&snac1, objid))
44                     continue;
45 
46+                if (max_id) {
47+                    if (strcmp(fid, max_id) == 0)
48+                        max_id = NULL;
49+
50+                    continue;
51+                }
52+
53                 /* convert the type */
54                 if (strcmp(type, "Like") == 0 || strcmp(type, "EmojiReact") == 0)
55                     type = "favourite";
56@@ -1778,12 +1787,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
57 
58                 mn = xs_dict_append(mn, "type", type);
59 
60-                xs *id = xs_replace(xs_dict_get(noti, "id"), ".", "");
61-                mn = xs_dict_append(mn, "id", id);
62+                mn = xs_dict_append(mn, "id", fid);
63 
64                 mn = xs_dict_append(mn, "created_at", xs_dict_get(noti, "date"));
65 
66                 xs *acct = mastoapi_account(&snac1, actor);
67+
68+                if (acct == NULL)
69+                    continue;
70+
71                 mn = xs_dict_append(mn, "account", acct);
72 
73                 if (strcmp(type, "follow") != 0 && !xs_is_null(objid)) {
M snac.h
+1, -0
1@@ -298,6 +298,7 @@ const char *default_avatar_base64(void);
2 xs_str *process_tags(snac *snac, const char *content, xs_list **tag);
3 
4 const char *get_atto(const xs_dict *msg);
5+const char *get_in_reply_to(const xs_dict *msg);
6 xs_list *get_attachments(const xs_dict *msg);
7 
8 xs_dict *msg_admiration(snac *snac, const char *object, const char *type);