mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-12 05:54:51 +00:00
Allow disabling private messages. Fixes #3640
This commit is contained in:
parent
5d48ee3dc8
commit
9973a49533
|
@ -119,6 +119,7 @@ pub async fn save_user_settings(
|
|||
post_listing_mode: data.post_listing_mode,
|
||||
enable_keyboard_navigation: data.enable_keyboard_navigation,
|
||||
enable_animated_images: data.enable_animated_images,
|
||||
enable_private_messages: data.enable_private_messages,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
|
|
@ -129,6 +129,8 @@ pub struct SaveUserSettings {
|
|||
pub enable_keyboard_navigation: Option<bool>,
|
||||
/// Whether user avatars or inline images in the UI that are gifs should be allowed to play or should be paused
|
||||
pub enable_animated_images: Option<bool>,
|
||||
/// Whether a user can send / receive private messages
|
||||
pub enable_private_messages: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
|
|
|
@ -259,6 +259,16 @@ pub fn check_private_instance(
|
|||
}
|
||||
}
|
||||
|
||||
/// If private messages are disabled, dont allow them to be sent / received
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub fn check_private_messages_enabled(local_user_view: &LocalUserView) -> Result<(), LemmyError> {
|
||||
if !local_user_view.local_user.enable_private_messages {
|
||||
Err(LemmyErrorType::CouldntCreatePrivateMessage)?
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn build_federated_instances(
|
||||
local_site: &LocalSite,
|
||||
|
|
|
@ -6,6 +6,7 @@ use lemmy_api_common::{
|
|||
send_activity::{ActivityChannel, SendActivityData},
|
||||
utils::{
|
||||
check_person_block,
|
||||
check_private_messages_enabled,
|
||||
generate_local_apub_endpoint,
|
||||
get_interface_language,
|
||||
local_site_to_slur_regex,
|
||||
|
@ -44,6 +45,16 @@ pub async fn create_private_message(
|
|||
)
|
||||
.await?;
|
||||
|
||||
check_private_messages_enabled(&local_user_view)?;
|
||||
|
||||
// Don't allow local sends to people to have private messages disabled
|
||||
let recipient_local_user_opt = LocalUserView::read_person(&mut context.pool(), data.recipient_id)
|
||||
.await
|
||||
.ok();
|
||||
if let Some(recipient_local_user) = recipient_local_user_opt {
|
||||
check_private_messages_enabled(&recipient_local_user)?;
|
||||
}
|
||||
|
||||
let private_message_form = PrivateMessageInsertForm::builder()
|
||||
.content(content.clone())
|
||||
.creator_id(local_user_view.person.id)
|
||||
|
|
|
@ -12,7 +12,10 @@ use activitypub_federation::{
|
|||
traits::Object,
|
||||
};
|
||||
use chrono::{DateTime, Utc};
|
||||
use lemmy_api_common::{context::LemmyContext, utils::check_person_block};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
utils::{check_person_block, check_private_messages_enabled},
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
person::Person,
|
||||
|
@ -20,6 +23,7 @@ use lemmy_db_schema::{
|
|||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_views::structs::LocalUserView;
|
||||
use lemmy_utils::{
|
||||
error::{LemmyError, LemmyErrorType},
|
||||
utils::markdown::markdown_to_html,
|
||||
|
@ -121,6 +125,10 @@ impl Object for ApubPrivateMessage {
|
|||
let recipient = note.to[0].dereference(context).await?;
|
||||
check_person_block(creator.id, recipient.id, &mut context.pool()).await?;
|
||||
|
||||
let recipient_local_user =
|
||||
LocalUserView::read_person(&mut context.pool(), recipient.id).await?;
|
||||
check_private_messages_enabled(&recipient_local_user)?;
|
||||
|
||||
let content = read_from_string_or_source(¬e.content, &None, ¬e.source);
|
||||
|
||||
let form = PrivateMessageInsertForm {
|
||||
|
|
|
@ -445,6 +445,7 @@ diesel::table! {
|
|||
totp_2fa_enabled -> Bool,
|
||||
enable_keyboard_navigation -> Bool,
|
||||
enable_animated_images -> Bool,
|
||||
enable_private_messages -> Bool,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,8 @@ pub struct LocalUser {
|
|||
pub enable_keyboard_navigation: bool,
|
||||
/// Whether user avatars and inline images in the UI that are gifs should be allowed to play or should be paused
|
||||
pub enable_animated_images: bool,
|
||||
/// Whether a user can send / receive private messages
|
||||
pub enable_private_messages: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, TypedBuilder)]
|
||||
|
@ -94,6 +96,7 @@ pub struct LocalUserInsertForm {
|
|||
pub totp_2fa_enabled: Option<bool>,
|
||||
pub enable_keyboard_navigation: Option<bool>,
|
||||
pub enable_animated_images: Option<bool>,
|
||||
pub enable_private_messages: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
|
@ -124,4 +127,5 @@ pub struct LocalUserUpdateForm {
|
|||
pub totp_2fa_enabled: Option<bool>,
|
||||
pub enable_keyboard_navigation: Option<bool>,
|
||||
pub enable_animated_images: Option<bool>,
|
||||
pub enable_private_messages: Option<bool>,
|
||||
}
|
||||
|
|
|
@ -268,6 +268,7 @@ mod tests {
|
|||
totp_2fa_enabled: inserted_sara_local_user.totp_2fa_enabled,
|
||||
enable_keyboard_navigation: inserted_sara_local_user.enable_keyboard_navigation,
|
||||
enable_animated_images: inserted_sara_local_user.enable_animated_images,
|
||||
enable_private_messages: inserted_sara_local_user.enable_private_messages,
|
||||
},
|
||||
creator: Person {
|
||||
id: inserted_sara_person.id,
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE local_user
|
||||
DROP COLUMN enable_private_messages;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE local_user
|
||||
ADD COLUMN enable_private_messages boolean DEFAULT TRUE NOT NULL;
|
||||
|
Loading…
Reference in a new issue