فهرست منبع

Merge pull request 'Add keep_replied_posts and keep_replied_me feathers, and auto-mention post author when reply to a post' (#617) from hanchan/snac2-dev:master into master

Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/617
grunfink 2 ماه پیش
والد
کامیت
14d4e9afcd
4فایلهای تغییر یافته به همراه60 افزوده شده و 1 حذف شده
  1. 31 0
      data.c
  2. 5 0
      doc/snac.8
  3. 21 0
      html.c
  4. 3 1
      utils.c

+ 31 - 0
data.c

@@ -1562,6 +1562,37 @@ void timeline_update_indexes(snac *snac, const char *id)
             else
             else
                 /* also add it to public, it will be discarded later */
                 /* also add it to public, it will be discarded later */
                 object_user_cache_add(snac, id, "public");
                 object_user_cache_add(snac, id, "public");
+
+            /* if `keep_replied_posts` is `true` and a local post is a reply to a remote post, add the parent remote post to the public */
+            if (xs_is_true(xs_dict_get(srv_config, "keep_replied_posts"))) {
+                const char *in_reply_to = get_in_reply_to(msg);
+
+                if (xs_is_string(in_reply_to) && *in_reply_to &&
+                    !is_msg_mine(snac, in_reply_to)) {
+                    if (object_user_cache_add(snac, in_reply_to, "public") >= 0) {
+                        snac_debug(snac, 1,
+                            xs_fmt("keep_replied_posts: added parent %s to public", in_reply_to));
+                    }
+                }
+            }
+        }
+    }
+    else {
+        /* if `keep_replied_me` is `true` and a remote post is a reply to one of local posts, add it to public */
+        if (xs_is_true(xs_dict_get(srv_config, "keep_replied_me"))) {
+            xs *msg = NULL;
+
+            if (valid_status(object_get(id, &msg))) {
+                const char *in_reply_to = get_in_reply_to(msg);
+
+                if (xs_is_string(in_reply_to) && *in_reply_to &&
+                    is_msg_mine(snac, in_reply_to)) {
+                    if (object_user_cache_add(snac, id, "public") >= 0) {
+                        snac_debug(snac, 1,
+                            xs_fmt("keep_replied_me: added reply %s to public", id));
+                    }
+                }
+            }
         }
         }
     }
     }
 }
 }

+ 5 - 0
doc/snac.8

@@ -327,6 +327,11 @@ Overrides the default "mogrify" command name or path. Use this if the tool is no
 Overrides the default "ffmpeg" command name or path. Use this if the tool is not in the system PATH or has a different name.
 Overrides the default "ffmpeg" command name or path. Use this if the tool is not in the system PATH or has a different name.
 .It Ic purge_static
 .It Ic purge_static
 If set to true, user static directories are purged; any file stored in these subdirectories (usually images or other media) that is not attached to any post, not used as avatar, header or favicon, and not served as an emoji, is deleted from the filesystem. Don't enable this option if any of your users are serving other files (like, e.g., CSS assets) this way.
 If set to true, user static directories are purged; any file stored in these subdirectories (usually images or other media) that is not attached to any post, not used as avatar, header or favicon, and not served as an emoji, is deleted from the filesystem. Don't enable this option if any of your users are serving other files (like, e.g., CSS assets) this way.
+.It Ic keep_replied_posts
+If set to true, when you reply to a remote post, the parent remote post will be added to local public timeline.
+.It Ic keep_replied_me
+If set to true, when a remote user replies to one of local posts, the
+remote reply will be added to local public timeline.
 .El
 .El
 .Pp
 .Pp
 You must restart the server to make effective these changes.
 You must restart the server to make effective these changes.

+ 21 - 0
html.c

@@ -2035,6 +2035,27 @@ xs_str *build_mentions(snac *user, const xs_dict *msg)
         }
         }
     }
     }
 
 
+    /* also add the author of this post as a mention */
+    const char *atto = get_atto(msg);
+
+    if (xs_is_string(atto) && *atto && strcmp(atto, user->actor) != 0) {
+        /* check if this author is already in the mentions string */
+        xs *l = xs_split(atto, "/");
+
+        if (xs_list_len(l) > 3) {
+            xs *actor_o = NULL;
+            if (valid_status(object_get(atto, &actor_o))) {
+                const char *uname = xs_dict_get(actor_o, "preferredUsername");
+                if (!xs_is_null(uname) && *uname) {
+                    xs *handle = xs_fmt("@%s@%s ", uname, xs_list_get(l, 2));
+                    if (xs_str_in(s, handle) == -1) {
+                        s = xs_str_cat(s, handle);
+                    }
+                }
+            }
+        }
+    }
+
     if (*s) {
     if (*s) {
         xs *s1 = s;
         xs *s1 = s;
         s = xs_fmt("\n\n\nCC: %s", s1);
         s = xs_fmt("\n\n\nCC: %s", s1);

+ 3 - 1
utils.c

@@ -44,7 +44,9 @@ static const char * const default_srv_config = "{"
     "\"protocol\":             \"https\","
     "\"protocol\":             \"https\","
     "\"fastcgi\":              false,"
     "\"fastcgi\":              false,"
     "\"disable_inbox_collection\": true,"
     "\"disable_inbox_collection\": true,"
-    "\"disable_history\": true"
+    "\"disable_history\": true,"
+    "\"keep_replied_posts\":     false,"
+    "\"keep_replied_me\":        false"
     "}";
     "}";
 
 
 static const char * const default_css =
 static const char * const default_css =