commit 534ee67
Merge pull request 'fix user matching' (#502) from rakoo/snac2:master into master Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/502
6 files changed,
+18,
-18
+7,
-7
1@@ -779,7 +779,7 @@ int is_msg_for_me(snac *snac, const xs_dict *c_msg)
2 object_get(object, &obj);
3
4 /* if it's about one of our posts, accept it */
5- if (xs_startswith(object, snac->actor))
6+ if (is_msg_mine(snac, object))
7 return 2;
8
9 /* blocked by hashtag? */
10@@ -1242,7 +1242,7 @@ void notify(snac *snac, const char *type, const char *utype, const char *actor,
11
12 if (xs_match(type, "Like|Announce|EmojiReact")) {
13 /* if it's not an admiration about something by us, done */
14- if (xs_is_null(objid) || !xs_startswith(objid, snac->actor))
15+ if (xs_is_null(objid) || !is_msg_mine(snac, objid))
16 return;
17
18 /* if it's an announce by our own relay, done */
19@@ -1267,7 +1267,7 @@ void notify(snac *snac, const char *type, const char *utype, const char *actor,
20 return;
21
22 /* if it's not ours and we didn't vote, discard */
23- if (!xs_startswith(poll_id, snac->actor) && !was_question_voted(snac, poll_id))
24+ if (!is_msg_mine(snac, poll_id) && !was_question_voted(snac, poll_id))
25 return;
26 }
27
28@@ -2792,10 +2792,10 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
29 if (xs_is_null(object))
30 snac_log(snac, xs_fmt("malformed message: no 'id' field"));
31 else
32- if (is_muted(snac, actor) && !xs_startswith(object, snac->actor))
33+ if (is_muted(snac, actor) && !is_msg_mine(snac, object))
34 snac_log(snac, xs_fmt("dropped 'Announce' from muted actor %s", actor));
35 else
36- if (is_limited(snac, actor) && !xs_startswith(object, snac->actor))
37+ if (is_limited(snac, actor) && !is_msg_mine(snac, object))
38 snac_log(snac, xs_fmt("dropped 'Announce' from limited actor %s", actor));
39 else {
40 xs *a_msg = NULL;
41@@ -2903,7 +2903,7 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
42 snac_log(snac, xs_fmt("malformed message: no 'id' field"));
43 else
44 if (object_here(object)) {
45- if (xs_startswith(object, srv_baseurl) && !xs_startswith(object, actor))
46+ if (xs_startswith(object, srv_baseurl) && !is_msg_mine(snac, object))
47 snac_log(snac, xs_fmt("ignored incorrect 'Delete' %s %s", actor, object));
48 else {
49 timeline_del(snac, object);
50@@ -3716,7 +3716,7 @@ int activitypub_get_handler(const xs_dict *req, const char *q_path,
51 const char *type = xs_dict_get(i, "type");
52 const char *id = xs_dict_get(i, "id");
53
54- if (type && id && strcmp(type, "Note") == 0 && xs_startswith(id, snac.actor)) {
55+ if (type && id && strcmp(type, "Note") == 0 && is_msg_mine(&snac, id)) {
56 if (is_msg_public(i)) {
57 xs *c_msg = msg_create(&snac, i);
58 list = xs_list_append(list, c_msg);
M
data.c
+4,
-4
1@@ -1467,7 +1467,7 @@ void timeline_update_indexes(snac *snac, const char *id)
2 {
3 object_user_cache_add(snac, id, "private");
4
5- if (xs_startswith(id, snac->actor)) {
6+ if (is_msg_mine(snac, id)) {
7 xs *msg = NULL;
8
9 if (valid_status(object_get(id, &msg))) {
10@@ -1927,7 +1927,7 @@ int pin(snac *user, const char *id)
11 {
12 int ret = -2;
13
14- if (xs_startswith(id, user->actor)) {
15+ if (is_msg_mine(user, id)) {
16 if (is_pinned(user, id))
17 ret = -3;
18 else
19@@ -3527,7 +3527,7 @@ void enqueue_output(snac *snac, const xs_dict *msg,
20 const xs_str *inbox, int retries, int p_status)
21 /* enqueues an output message to an inbox */
22 {
23- if (xs_startswith(inbox, snac->actor)) {
24+ if (is_msg_mine(snac, inbox)) {
25 snac_debug(snac, 1, xs_str_new("refusing enqueue to myself"));
26 return;
27 }
28@@ -4055,7 +4055,7 @@ void delete_purged_posts(snac *user, int days)
29 if (xs_is_dict(msg)) {
30 const char *id = xs_dict_get(msg, "id");
31
32- if (xs_is_string(id) && xs_startswith(id, user->actor)) {
33+ if (xs_is_string(id) && is_msg_mine(user, id)) {
34 xs *d_msg = msg_delete(user, id);
35
36 enqueue_message(user, d_msg);
M
html.c
+3,
-3
1@@ -1898,7 +1898,7 @@ xs_html *html_entry_controls(snac *user, const char *actor,
2 xs_html_attr("name", "redir"),
3 xs_html_attr("value", redir))));
4
5- if (!xs_startswith(id, user->actor)) {
6+ if (!is_msg_mine(user, id)) {
7 if (xs_list_in(likes, user->md5) == -1) {
8 /* not already liked; add button */
9 xs_html_add(form,
10@@ -2426,7 +2426,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
11 if (read_only)
12 closed = 1; /* non-identified page; show as closed */
13 else
14- if (user && xs_startswith(id, user->actor))
15+ if (user && is_msg_mine(user, id))
16 closed = 1; /* we questioned; closed for us */
17 else
18 if (user && was_question_voted(user, id))
19@@ -5022,7 +5022,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
20 }
21 else {
22 /* delete an entry */
23- if (xs_startswith(id, snac.actor) && !is_draft(&snac, id)) {
24+ if (is_msg_mine(&snac, id) && !is_draft(&snac, id)) {
25 /* it's a post by us: generate a delete */
26 xs *msg = msg_delete(&snac, id);
27
+2,
-2
1@@ -1919,7 +1919,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2 /* add only posts by the author */
3 if (!xs_is_null(msg_id) &&
4 strcmp(xs_dict_get(msg, "type"), "Note") == 0 &&
5- xs_startswith(xs_dict_get(msg, "id"), snac2.actor) && is_msg_public(msg)) {
6+ is_msg_mine(&snac2, xs_dict_get(msg, "id")) && is_msg_public(msg)) {
7
8 /* if max_id is set, skip entries until we find it */
9 if (skip_until_max) {
10@@ -3824,7 +3824,7 @@ int mastoapi_delete_handler(const xs_dict *req, const char *q_path,
11 if (valid_status(object_get_by_md5(p, &obj))) {
12 const char *id = xs_dict_get(obj, "id");
13
14- if (xs_is_string(id) && xs_startswith(id, snac.actor)) {
15+ if (xs_is_string(id) && is_msg_mine(&snac, id)) {
16 xs *out = mastoapi_status(&snac, obj);
17
18 xs *msg = msg_delete(&snac, id);
M
rss.c
+1,
-1
1@@ -59,7 +59,7 @@ xs_str *rss_from_timeline(snac *user, const xs_list *timeline,
2 const char *content = xs_dict_get(msg, "content");
3 const char *published = xs_dict_get(msg, "published");
4
5- if (user && !xs_startswith(id, user->actor))
6+ if (user && !is_msg_mine(user, id))
7 continue;
8
9 if (!id || !content || !published)
+1,
-1
1@@ -213,7 +213,7 @@ int snac_upgrade(xs_str **error)
2 object_add_ow(id, o);
3
4 /* if it's from us, add to public */
5- if (xs_startswith(id, snac.actor)) {
6+ if (is_msg_mine(&snac, id)) {
7 const xs_list *p;
8 const char *v;
9 int c;