Delete notifications when deleting comments (#499)
* Implement find_for_comment for notifications * Delete notifications when deleting a comment This should tackle #463 * Apply rustfmt * Implement `find_for_mention` and remove order by from `find_for_comment` There is no need to order the notifications * Delete notifications for mentions * Fix notifications for comments and mentions
This commit is contained in:
parent
f0d6b9d1e8
commit
c7ee779f51
|
@ -330,9 +330,17 @@ impl<'a> Deletable<Connection, Delete> for Comment {
|
|||
act.object_props
|
||||
.set_to_link_vec(vec![Id::new(PUBLIC_VISIBILTY)])?;
|
||||
|
||||
for m in Mention::list_for_comment(&conn, self.id)? {
|
||||
for m in Mention::list_for_comment(conn, self.id)? {
|
||||
for n in Notification::find_for_mention(conn, &m)? {
|
||||
n.delete(conn)?;
|
||||
}
|
||||
m.delete(conn)?;
|
||||
}
|
||||
|
||||
for n in Notification::find_for_comment(conn, &self)? {
|
||||
n.delete(conn)?;
|
||||
}
|
||||
|
||||
diesel::update(comments::table)
|
||||
.filter(comments::in_response_to_id.eq(self.id))
|
||||
.set(comments::in_response_to_id.eq(self.in_response_to_id))
|
||||
|
|
|
@ -59,7 +59,7 @@ fn get_rocket_config() -> Result<RocketConfig, RocketError> {
|
|||
pub struct LogoConfig {
|
||||
pub main: String,
|
||||
pub favicon: String,
|
||||
pub other: Vec<Icon> //url, size, type
|
||||
pub other: Vec<Icon>, //url, size, type
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
@ -82,14 +82,12 @@ impl Icon {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl Default for LogoConfig {
|
||||
fn default() -> Self {
|
||||
let to_icon = |(src, sizes, image_type): &(&str, Option<&str>, Option<&str>)| Icon {
|
||||
src: str::to_owned(src),
|
||||
sizes: sizes.map(str::to_owned),
|
||||
image_type: image_type.map(str::to_owned)
|
||||
image_type: image_type.map(str::to_owned),
|
||||
};
|
||||
let icons = [
|
||||
(
|
||||
|
@ -132,29 +130,34 @@ impl Default for LogoConfig {
|
|||
Some("512x512"),
|
||||
Some("image/png"),
|
||||
),
|
||||
(
|
||||
"icons/trwnh/feather/plumeFeather.svg",
|
||||
None,
|
||||
None,
|
||||
)
|
||||
].iter().map(to_icon).collect();
|
||||
("icons/trwnh/feather/plumeFeather.svg", None, None),
|
||||
]
|
||||
.iter()
|
||||
.map(to_icon)
|
||||
.collect();
|
||||
|
||||
let custom_main = var("PLUME_LOGO").ok();
|
||||
let custom_favicon = var("PLUME_LOGO_FAVICON").ok().or_else(|| custom_main.clone());
|
||||
let custom_favicon = var("PLUME_LOGO_FAVICON")
|
||||
.ok()
|
||||
.or_else(|| custom_main.clone());
|
||||
let other = if let Some(main) = custom_main.clone() {
|
||||
let ext = |path: &str| match path.rsplitn(2, '.').next() {
|
||||
Some("png") => Some("image/png".to_owned()),
|
||||
Some("jpg")| Some("jpeg") => Some("image/jpeg".to_owned()),
|
||||
Some("jpg") | Some("jpeg") => Some("image/jpeg".to_owned()),
|
||||
Some("svg") => Some("image/svg+xml".to_owned()),
|
||||
Some("webp") => Some("image/webp".to_owned()),
|
||||
_ => None,
|
||||
};
|
||||
let mut custom_icons = env::vars()
|
||||
.filter_map(|(var, val)| if var.starts_with("PLUME_LOGO_") {
|
||||
.filter_map(|(var, val)| {
|
||||
if var.starts_with("PLUME_LOGO_") {
|
||||
Some((var[11..].to_owned(), val))
|
||||
} else { None })
|
||||
.filter_map(|(var, val)| var.parse::<u64>().ok().map(|var| (var,val)))
|
||||
.map(|(dim,src)| Icon {
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.filter_map(|(var, val)| var.parse::<u64>().ok().map(|var| (var, val)))
|
||||
.map(|(dim, src)| Icon {
|
||||
image_type: ext(&src),
|
||||
src,
|
||||
sizes: Some(format!("{}x{}", dim, dim)),
|
||||
|
@ -171,8 +174,11 @@ impl Default for LogoConfig {
|
|||
};
|
||||
|
||||
LogoConfig {
|
||||
main: custom_main.unwrap_or_else(|| "icons/trwnh/feather/plumeFeather256.png".to_owned()),
|
||||
favicon: custom_favicon.unwrap_or_else(|| "icons/trwnh/feather-filled/plumeFeatherFilled64.png".to_owned()),
|
||||
main: custom_main
|
||||
.unwrap_or_else(|| "icons/trwnh/feather/plumeFeather256.png".to_owned()),
|
||||
favicon: custom_favicon.unwrap_or_else(|| {
|
||||
"icons/trwnh/feather-filled/plumeFeatherFilled64.png".to_owned()
|
||||
}),
|
||||
other,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,22 @@ impl Notification {
|
|||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
pub fn find_for_mention(conn: &Connection, mention: &Mention) -> Result<Vec<Notification>> {
|
||||
notifications::table
|
||||
.filter(notifications::kind.eq(notification_kind::MENTION))
|
||||
.filter(notifications::object_id.eq(mention.id))
|
||||
.load::<Notification>(conn)
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
pub fn find_for_comment(conn: &Connection, comment: &Comment) -> Result<Vec<Notification>> {
|
||||
notifications::table
|
||||
.filter(notifications::kind.eq(notification_kind::COMMENT))
|
||||
.filter(notifications::object_id.eq(comment.id))
|
||||
.load::<Notification>(conn)
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
pub fn count_for_user(conn: &Connection, user: &User) -> Result<i64> {
|
||||
notifications::table
|
||||
.filter(notifications::user_id.eq(user.id))
|
||||
|
|
|
@ -7,7 +7,11 @@ use validator::Validate;
|
|||
use std::time::Duration;
|
||||
|
||||
use plume_common::{
|
||||
activity_pub::{broadcast, inbox::Deletable, ActivityStream, ApRequest},
|
||||
activity_pub::{
|
||||
broadcast,
|
||||
inbox::{Deletable, Notify},
|
||||
ActivityStream, ApRequest,
|
||||
},
|
||||
utils,
|
||||
};
|
||||
use plume_models::{
|
||||
|
@ -60,6 +64,7 @@ pub fn create(
|
|||
},
|
||||
)
|
||||
.expect("comments::create: insert error");
|
||||
comm.notify(&*conn).expect("comments::create: notify error");
|
||||
let new_comment = comm
|
||||
.create_activity(&*conn)
|
||||
.expect("comments::create: activity error");
|
||||
|
@ -70,8 +75,8 @@ pub fn create(
|
|||
&*conn,
|
||||
&Mention::build_activity(&*conn, &ment)
|
||||
.expect("comments::create: build mention error"),
|
||||
post.id,
|
||||
true,
|
||||
comm.id,
|
||||
false,
|
||||
true,
|
||||
)
|
||||
.expect("comments::create: mention save error");
|
||||
|
|
Loading…
Reference in New Issue