#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct EditComment {
- pub content: String,
pub comment_id: CommentId,
+ pub content: Option<String>,
+ pub distinguished: Option<bool>,
pub form_id: Option<String>,
pub auth: Sensitive<String>,
}
check_community_deleted_or_removed,
check_post_deleted_or_removed,
get_local_user_view_from_jwt,
+ is_mod_or_admin,
},
};
use lemmy_apub::protocol::activities::{
CommentView::read(conn, comment_id, None)
})
.await??;
+ let mut updated_comment = orig_comment.comment.clone();
// TODO is this necessary? It should really only need to check on create
check_community_ban(
return Err(LemmyError::from_message("no_comment_edit_allowed"));
}
- // Do the update
- let content_slurs_removed =
- remove_slurs(&data.content.to_owned(), &context.settings().slur_regex());
- let comment_id = data.comment_id;
- let updated_comment = blocking(context.pool(), move |conn| {
- Comment::update_content(conn, comment_id, &content_slurs_removed)
- })
- .await?
- .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
+ if let Some(distinguished) = data.distinguished {
+ // Verify that only a mod or admin can distinguish a comment
+ is_mod_or_admin(
+ context.pool(),
+ local_user_view.person.id,
+ orig_comment.community.id,
+ )
+ .await?;
+
+ updated_comment = blocking(context.pool(), move |conn| {
+ Comment::update_distinguished(conn, comment_id, distinguished)
+ })
+ .await?
+ .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
+ }
+
+ // Update the Content
+ if let Some(content) = &data.content {
+ let content_slurs_removed = remove_slurs(content, &context.settings().slur_regex());
+ let comment_id = data.comment_id;
+ updated_comment = blocking(context.pool(), move |conn| {
+ Comment::update_content(conn, comment_id, &content_slurs_removed)
+ })
+ .await?
+ .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
+ };
// Do the mentions / recipients
let updated_comment_content = updated_comment.content.to_owned();
"@type": "@id",
"@id": "lemmy:moderators"
},
- "expires": "as:endTime"
+ "expires": "as:endTime",
+ "distinguished": "lemmy:distinguished"
}
]
"name": "@picard@enterprise.lemmy.ml"
}
],
+ "distinguished": false,
"published": "2021-03-01T13:42:43.966208+00:00",
"updated": "2021-03-01T13:43:03.955787+00:00"
}
published: Some(convert_datetime(self.published)),
updated: self.updated.map(convert_datetime),
tag: maa.tags,
+ distinguished: Some(self.distinguished),
};
Ok(note)
updated: note.updated.map(|u| u.naive_local()),
deleted: None,
ap_id: Some(note.id.into()),
+ distinguished: note.distinguished,
local: Some(false),
};
let parent_comment_path = parent_comment.map(|t| t.0.path);
pub(crate) updated: Option<DateTime<FixedOffset>>,
#[serde(default)]
pub(crate) tag: Vec<MentionOrValue>,
+ // lemmy extension
+ pub(crate) distinguished: Option<bool>,
}
impl Note {
.get_result::<Self>(conn)
}
+ pub fn update_distinguished(
+ conn: &PgConnection,
+ comment_id: CommentId,
+ new_distinguished: bool,
+ ) -> Result<Self, Error> {
+ use crate::schema::comment::dsl::*;
+ diesel::update(comment.find(comment_id))
+ .set((distinguished.eq(new_distinguished), updated.eq(naive_now())))
+ .get_result::<Self>(conn)
+ }
+
pub fn create(
conn: &PgConnection,
comment_form: &CommentForm,
published: inserted_comment.published,
updated: None,
ap_id: inserted_comment.ap_id.to_owned(),
+ distinguished: false,
local: true,
};
ap_id -> Varchar,
local -> Bool,
path -> Ltree,
+ distinguished -> Bool,
}
}
pub local: bool,
#[serde(with = "LtreeDef")]
pub path: Ltree,
+ pub distinguished: bool,
}
#[derive(Clone, Default)]
pub deleted: Option<bool>,
pub ap_id: Option<DbUrl>,
pub local: Option<bool>,
+ pub distinguished: Option<bool>,
}
#[derive(PartialEq, Debug, Clone)]
ap_id: inserted_comment_0.ap_id,
updated: None,
local: true,
+ distinguished: false,
path: top_path,
},
creator: PersonSafe {
--- /dev/null
+alter table comment drop column distinguished;
--- /dev/null
+alter table comment add column distinguished boolean not null default false;