#561 Improve notification management

Merged trinity-1686a
Coverage Reach
plume-models/src/users.rs plume-models/src/posts.rs plume-models/src/blogs.rs plume-models/src/search/query.rs plume-models/src/search/searcher.rs plume-models/src/search/mod.rs plume-models/src/search/tokenizer.rs plume-models/src/comments.rs plume-models/src/inbox.rs plume-models/src/instance.rs plume-models/src/medias.rs plume-models/src/follows.rs plume-models/src/lib.rs plume-models/src/reshares.rs plume-models/src/likes.rs plume-models/src/notifications.rs plume-models/src/mentions.rs plume-models/src/config.rs plume-models/src/safe_string.rs plume-models/src/migrations.rs plume-models/src/api_tokens.rs plume-models/src/tags.rs plume-models/src/plume_rocket.rs plume-models/src/db_conn.rs plume-models/src/comment_seers.rs plume-models/src/headers.rs plume-models/src/apps.rs plume-models/src/blog_authors.rs plume-models/src/admin.rs plume-models/src/post_authors.rs src/routes/posts.rs src/routes/user.rs src/routes/instance.rs src/routes/blogs.rs src/routes/session.rs src/routes/comments.rs src/routes/medias.rs src/routes/mod.rs src/routes/well_known.rs src/routes/search.rs src/routes/likes.rs src/routes/reshares.rs src/routes/errors.rs src/routes/notifications.rs src/routes/tags.rs src/api/posts.rs src/api/mod.rs src/api/apps.rs src/api/authorization.rs src/template_utils.rs src/main.rs src/inbox.rs src/mail.rs src/test_routes.rs plume-common/src/activity_pub/inbox.rs plume-common/src/activity_pub/sign.rs plume-common/src/activity_pub/mod.rs plume-common/src/activity_pub/request.rs plume-common/src/utils.rs plume-cli/src/users.rs plume-cli/src/search.rs plume-cli/src/instance.rs plume-cli/src/main.rs plume-cli/src/migration.rs plume-macro/src/lib.rs plume-api/src/posts.rs plume-api/src/apps.rs

Flags

Flags have been temporarily removed from this view while the flagging feature is refactored for better performance and user experience.

You can still use flags when viewing individual files. Flag-level thresholds will also remain on pull and merge requests in your repository provider.

More information can be found in our documentation.


@@ -15,7 +15,7 @@
Loading
15 15
use mentions::Mention;
16 16
use notifications::*;
17 17
use plume_common::activity_pub::{
18 -
    inbox::{AsObject, FromId},
18 +
    inbox::{AsActor, AsObject, FromId},
19 19
    Id, IntoId, PUBLIC_VISIBILITY,
20 20
};
21 21
use plume_common::utils;
@@ -157,14 +157,20 @@
Loading
157 157
158 158
    pub fn notify(&self, conn: &Connection) -> Result<()> {
159 159
        for author in self.get_post(conn)?.get_authors(conn)? {
160 -
            Notification::insert(
161 -
                conn,
162 -
                NewNotification {
163 -
                    kind: notification_kind::COMMENT.to_string(),
164 -
                    object_id: self.id,
165 -
                    user_id: author.id,
166 -
                },
167 -
            )?;
160 +
            if Mention::list_for_comment(conn, self.id)?
161 +
                .iter()
162 +
                .all(|m| m.get_mentioned(conn).map(|u| u != author).unwrap_or(true))
163 +
                && author.is_local()
164 +
            {
165 +
                Notification::insert(
166 +
                    conn,
167 +
                    NewNotification {
168 +
                        kind: notification_kind::COMMENT.to_string(),
169 +
                        object_id: self.id,
170 +
                        user_id: author.id,
171 +
                    },
172 +
                )?;
173 +
            }
168 174
        }
169 175
        Ok(())
170 176
    }

@@ -4,7 +4,7 @@
Loading
4 4
5 5
use notifications::*;
6 6
use plume_common::activity_pub::{
7 -
    inbox::{AsObject, FromId},
7 +
    inbox::{AsActor, AsObject, FromId},
8 8
    Id, IntoId, PUBLIC_VISIBILITY,
9 9
};
10 10
use posts::Post;
@@ -79,14 +79,16 @@
Loading
79 79
    pub fn notify(&self, conn: &Connection) -> Result<()> {
80 80
        let post = self.get_post(conn)?;
81 81
        for author in post.get_authors(conn)? {
82 -
            Notification::insert(
83 -
                conn,
84 -
                NewNotification {
85 -
                    kind: notification_kind::RESHARE.to_string(),
86 -
                    object_id: self.id,
87 -
                    user_id: author.id,
88 -
                },
89 -
            )?;
82 +
            if author.is_local() {
83 +
                Notification::insert(
84 +
                    conn,
85 +
                    NewNotification {
86 +
                        kind: notification_kind::RESHARE.to_string(),
87 +
                        object_id: self.id,
88 +
                        user_id: author.id,
89 +
                    },
90 +
                )?;
91 +
            }
90 92
        }
91 93
        Ok(())
92 94
    }

@@ -3,6 +3,7 @@
Loading
3 3
4 4
use comments::Comment;
5 5
use notifications::*;
6 +
use plume_common::activity_pub::inbox::AsActor;
6 7
use posts::Post;
7 8
use schema::mentions;
8 9
use users::User;
@@ -129,14 +130,18 @@
Loading
129 130
130 131
    fn notify(&self, conn: &Connection) -> Result<()> {
131 132
        let m = self.get_mentioned(conn)?;
132 -
        Notification::insert(
133 -
            conn,
134 -
            NewNotification {
135 -
                kind: notification_kind::MENTION.to_string(),
136 -
                object_id: self.id,
137 -
                user_id: m.id,
138 -
            },
139 -
        )
140 -
        .map(|_| ())
133 +
        if m.is_local() {
134 +
            Notification::insert(
135 +
                conn,
136 +
                NewNotification {
137 +
                    kind: notification_kind::MENTION.to_string(),
138 +
                    object_id: self.id,
139 +
                    user_id: m.id,
140 +
                },
141 +
            )
142 +
            .map(|_| ())
143 +
        } else {
144 +
            Ok(())
145 +
        }
141 146
    }
142 147
}

@@ -67,15 +67,18 @@
Loading
67 67
        Ok(act)
68 68
    }
69 69
70 -
    pub fn notify(&self, conn: &Connection) -> Result<Notification> {
71 -
        Notification::insert(
72 -
            conn,
73 -
            NewNotification {
74 -
                kind: notification_kind::FOLLOW.to_string(),
75 -
                object_id: self.id,
76 -
                user_id: self.following_id,
77 -
            },
78 -
        )
70 +
    pub fn notify(&self, conn: &Connection) -> Result<()> {
71 +
        if User::get(conn, self.following_id)?.is_local() {
72 +
            Notification::insert(
73 +
                conn,
74 +
                NewNotification {
75 +
                    kind: notification_kind::FOLLOW.to_string(),
76 +
                    object_id: self.id,
77 +
                    user_id: self.following_id,
78 +
                },
79 +
            )?;
80 +
        }
81 +
        Ok(())
79 82
    }
80 83
81 84
    /// from -> The one sending the follow request

@@ -4,7 +4,7 @@
Loading
4 4
5 5
use notifications::*;
6 6
use plume_common::activity_pub::{
7 -
    inbox::{AsObject, FromId},
7 +
    inbox::{AsActor, AsObject, FromId},
8 8
    Id, IntoId, PUBLIC_VISIBILITY,
9 9
};
10 10
use posts::Post;
@@ -54,14 +54,16 @@
Loading
54 54
    pub fn notify(&self, conn: &Connection) -> Result<()> {
55 55
        let post = Post::get(conn, self.post_id)?;
56 56
        for author in post.get_authors(conn)? {
57 -
            Notification::insert(
58 -
                conn,
59 -
                NewNotification {
60 -
                    kind: notification_kind::LIKE.to_string(),
61 -
                    object_id: self.id,
62 -
                    user_id: author.id,
63 -
                },
64 -
            )?;
57 +
            if author.is_local() {
58 +
                Notification::insert(
59 +
                    conn,
60 +
                    NewNotification {
61 +
                        kind: notification_kind::LIKE.to_string(),
62 +
                        object_id: self.id,
63 +
                        user_id: author.id,
64 +
                    },
65 +
                )?;
66 +
            }
65 67
        }
66 68
        Ok(())
67 69
    }

Click to load this diff.
Loading diff...

Learn more Showing 1 files with coverage changes found.

Changes in plume-models/src/lib.rs
-1
Loading file...
Files Coverage
plume-api/src 0.00%
plume-cli/src 52.40%
plume-common/src 54.14%
plume-models/src -0.04% 48.00%
src 4.09%
plume-macro/src/lib.rs 87.50%
Project Totals (67 files) 35.05%
Loading