commit 5d265cf

grunfink  ·  2026-09-10 14:35:47 +0000 UTC
parent ab05857
New function was_mentioned().
4 files changed,  +24, -30
M data.c
M html.c
M snac.h
+18, -0
 1@@ -755,6 +755,24 @@ void followed_hashtag_distribute(const xs_dict *msg)
 2 }
 3 
 4 
 5+int was_mentioned(snac *user, const xs_dict *msg)
 6+/* checks if user was mentioned here */
 7+{
 8+    const xs_list *l = xs_dict_get_def(msg, "tag", xs_stock(XSTYPE_LIST));
 9+    const xs_dict *d;
10+
11+    xs_list_foreach(l, d) {
12+        const char *type = xs_dict_get_def(d, "type", "");
13+        const char *href = xs_dict_get_def(d, "href", "");
14+
15+        if (strcmp(type, "Mention") == 0 && strcmp(href, user->actor) == 0)
16+            return 1;
17+    }
18+
19+    return 0;
20+}
21+
22+
23 int is_msg_for_me(snac *snac, const xs_dict *c_msg)
24 /* checks if this message is for me */
25 {
M data.c
+1, -13
 1@@ -3667,19 +3667,7 @@ xs_list *notify_filter_list(snac *snac, xs_list *notifs, int skip, int show)
 2         if (strcmp(type, "EmojiReact") == 0 && xs_is_true(xs_dict_get(srv_config, "disable_emojireact")))
 3             continue;
 4         if (strcmp(type, "Create") == 0) {
 5-            int is_mention = 0;
 6-            const xs_list *l = xs_dict_get_def(obj, "tag", xs_stock(XSTYPE_LIST));
 7-            const xs_dict *d;
 8-
 9-            xs_list_foreach(l, d) {
10-                const char *type = xs_dict_get_def(d, "type", "");
11-                const char *href = xs_dict_get_def(d, "href", "");
12-
13-                if (strcmp(type, "Mention") == 0 && strcmp(href, snac->actor) == 0) {
14-                    is_mention = 1;
15-                    break;
16-                }
17-            }
18+            int is_mention = was_mentioned(snac, obj);
19 
20             if (is_mention) {
21                 if (!n_ments_on)
M html.c
+4, -17
 1@@ -4490,23 +4490,10 @@ xs_str *html_notifications(snac *user, int skip, int show)
 2         const char *label = label_sanitized;
 3 
 4         if (strcmp(type, "Create") == 0) {
 5-            label = L("Post");
 6-
 7-            /* check if it's a mention */
 8-            const xs_list *l = xs_dict_get_def(obj, "tag", xs_stock(XSTYPE_LIST));
 9-            const xs_dict *d;
10-
11-            xs_list_foreach(l, d) {
12-                if (xs_is_dict(d)) {
13-                    const char *type = xs_dict_get_def(d, "type", "");
14-                    const char *href = xs_dict_get_def(d, "href", "");
15-
16-                    if (strcmp(type, "Mention") == 0 && strcmp(href, user->actor) == 0) {
17-                        label = L("Mention");
18-                        break;
19-                    }
20-                }
21-            }
22+            if (was_mentioned(user, obj))
23+                label = L("Mention");
24+            else
25+                label = L("Post");
26         }
27         else
28         if (strcmp(type, "Update") == 0 && strcmp(utype, "Question") == 0)
M snac.h
+1, -0
1@@ -419,6 +419,7 @@ int send_to_actor(snac *snac, const char *actor, const xs_dict *msg,
2 int is_msg_mine(snac *user, const char *id);
3 int is_msg_public(const xs_dict *msg);
4 int is_msg_from_private_user(const xs_dict *msg);
5+int was_mentioned(snac *user, const xs_dict *msg);
6 int is_msg_for_me(snac *snac, const xs_dict *msg);
7 
8 int process_user_queue(snac *snac);