Przeglądaj źródła

New function was_mentioned().

grunfink 1 tydzień temu
rodzic
commit
5d265cf47c
4 zmienionych plików z 24 dodań i 30 usunięć
  1. 18 0
      activitypub.c
  2. 1 13
      data.c
  3. 4 17
      html.c
  4. 1 0
      snac.h

+ 18 - 0
activitypub.c

@@ -755,6 +755,24 @@ void followed_hashtag_distribute(const xs_dict *msg)
 }
 
 
+int was_mentioned(snac *user, const xs_dict *msg)
+/* checks if user was mentioned here */
+{
+    const xs_list *l = xs_dict_get_def(msg, "tag", xs_stock(XSTYPE_LIST));
+    const xs_dict *d;
+
+    xs_list_foreach(l, d) {
+        const char *type = xs_dict_get_def(d, "type", "");
+        const char *href = xs_dict_get_def(d, "href", "");
+
+        if (strcmp(type, "Mention") == 0 && strcmp(href, user->actor) == 0)
+            return 1;
+    }
+
+    return 0;
+}
+
+
 int is_msg_for_me(snac *snac, const xs_dict *c_msg)
 /* checks if this message is for me */
 {

+ 1 - 13
data.c

@@ -3667,19 +3667,7 @@ xs_list *notify_filter_list(snac *snac, xs_list *notifs, int skip, int show)
         if (strcmp(type, "EmojiReact") == 0 && xs_is_true(xs_dict_get(srv_config, "disable_emojireact")))
             continue;
         if (strcmp(type, "Create") == 0) {
-            int is_mention = 0;
-            const xs_list *l = xs_dict_get_def(obj, "tag", xs_stock(XSTYPE_LIST));
-            const xs_dict *d;
-
-            xs_list_foreach(l, d) {
-                const char *type = xs_dict_get_def(d, "type", "");
-                const char *href = xs_dict_get_def(d, "href", "");
-
-                if (strcmp(type, "Mention") == 0 && strcmp(href, snac->actor) == 0) {
-                    is_mention = 1;
-                    break;
-                }
-            }
+            int is_mention = was_mentioned(snac, obj);
 
             if (is_mention) {
                 if (!n_ments_on)

+ 4 - 17
html.c

@@ -4490,23 +4490,10 @@ xs_str *html_notifications(snac *user, int skip, int show)
         const char *label = label_sanitized;
 
         if (strcmp(type, "Create") == 0) {
-            label = L("Post");
-
-            /* check if it's a mention */
-            const xs_list *l = xs_dict_get_def(obj, "tag", xs_stock(XSTYPE_LIST));
-            const xs_dict *d;
-
-            xs_list_foreach(l, d) {
-                if (xs_is_dict(d)) {
-                    const char *type = xs_dict_get_def(d, "type", "");
-                    const char *href = xs_dict_get_def(d, "href", "");
-
-                    if (strcmp(type, "Mention") == 0 && strcmp(href, user->actor) == 0) {
-                        label = L("Mention");
-                        break;
-                    }
-                }
-            }
+            if (was_mentioned(user, obj))
+                label = L("Mention");
+            else
+                label = L("Post");
         }
         else
         if (strcmp(type, "Update") == 0 && strcmp(utype, "Question") == 0)

+ 1 - 0
snac.h

@@ -419,6 +419,7 @@ int send_to_actor(snac *snac, const char *actor, const xs_dict *msg,
 int is_msg_mine(snac *user, const char *id);
 int is_msg_public(const xs_dict *msg);
 int is_msg_from_private_user(const xs_dict *msg);
+int was_mentioned(snac *user, const xs_dict *msg);
 int is_msg_for_me(snac *snac, const xs_dict *msg);
 
 int process_user_queue(snac *snac);