Merge remote-tracking branch 'origin/main' into auto_mark_posts_as_read

This commit is contained in:
Dessalines 2024-11-10 10:16:05 -05:00
commit 11730a23d5
15 changed files with 61 additions and 10 deletions

View file

@ -76,7 +76,7 @@
# Timeout for uploading images to pictrs (in seconds) # Timeout for uploading images to pictrs (in seconds)
upload_timeout: 30 upload_timeout: 30
# Resize post thumbnails to this maximum width/height. # Resize post thumbnails to this maximum width/height.
max_thumbnail_size: 256 max_thumbnail_size: 512
} }
# Email sending configuration. All options except login/password are mandatory # Email sending configuration. All options except login/password are mandatory
email: { email: {

View file

@ -141,6 +141,7 @@ pub async fn save_user_settings(
post_listing_mode: data.post_listing_mode, post_listing_mode: data.post_listing_mode,
enable_keyboard_navigation: data.enable_keyboard_navigation, enable_keyboard_navigation: data.enable_keyboard_navigation,
enable_animated_images: data.enable_animated_images, enable_animated_images: data.enable_animated_images,
enable_private_messages: data.enable_private_messages,
collapse_bot_comments: data.collapse_bot_comments, collapse_bot_comments: data.collapse_bot_comments,
auto_mark_fetched_posts_as_read: data.auto_mark_fetched_posts_as_read, auto_mark_fetched_posts_as_read: data.auto_mark_fetched_posts_as_read,
..Default::default() ..Default::default()

View file

@ -163,6 +163,9 @@ pub struct SaveUserSettings {
/// should be paused /// should be paused
#[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", ts(optional))]
pub enable_animated_images: Option<bool>, pub enable_animated_images: Option<bool>,
/// Whether a user can send / receive private messages
#[cfg_attr(feature = "full", ts(optional))]
pub enable_private_messages: Option<bool>,
/// Whether to auto-collapse bot comments. /// Whether to auto-collapse bot comments.
#[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", ts(optional))]
pub collapse_bot_comments: Option<bool>, pub collapse_bot_comments: Option<bool>,

View file

@ -342,6 +342,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)] #[tracing::instrument(skip_all)]
pub async fn build_federated_instances( pub async fn build_federated_instances(
local_site: &LocalSite, local_site: &LocalSite,

View file

@ -5,6 +5,7 @@ use lemmy_api_common::{
private_message::{CreatePrivateMessage, PrivateMessageResponse}, private_message::{CreatePrivateMessage, PrivateMessageResponse},
send_activity::{ActivityChannel, SendActivityData}, send_activity::{ActivityChannel, SendActivityData},
utils::{ utils::{
check_private_messages_enabled,
get_interface_language, get_interface_language,
get_url_blocklist, get_url_blocklist,
local_site_to_slur_regex, local_site_to_slur_regex,
@ -46,6 +47,16 @@ pub async fn create_private_message(
) )
.await?; .await?;
check_private_messages_enabled(&local_user_view)?;
// Don't allow local sends to people who 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::new( let private_message_form = PrivateMessageInsertForm::new(
local_user_view.person.id, local_user_view.person.id,
data.recipient_id, data.recipient_id,

View file

@ -16,7 +16,12 @@ use activitypub_federation::{
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
utils::{get_url_blocklist, local_site_opt_to_slur_regex, process_markdown}, utils::{
check_private_messages_enabled,
get_url_blocklist,
local_site_opt_to_slur_regex,
process_markdown,
},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{ source::{
@ -28,6 +33,7 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
utils::naive_now, utils::naive_now,
}; };
use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::{ use lemmy_utils::{
error::{FederationError, LemmyError, LemmyErrorType, LemmyResult}, error::{FederationError, LemmyError, LemmyErrorType, LemmyResult},
utils::markdown::markdown_to_html, utils::markdown::markdown_to_html,
@ -130,9 +136,16 @@ impl Object for ApubPrivateMessage {
let recipient = note.to[0].dereference(context).await?; let recipient = note.to[0].dereference(context).await?;
PersonBlock::read(&mut context.pool(), recipient.id, creator.id).await?; PersonBlock::read(&mut context.pool(), recipient.id, creator.id).await?;
// Check that they can receive private messages
if let Ok(recipient_local_user) =
LocalUserView::read_person(&mut context.pool(), recipient.id).await
{
check_private_messages_enabled(&recipient_local_user)?;
}
let local_site = LocalSite::read(&mut context.pool()).await.ok(); let local_site = LocalSite::read(&mut context.pool()).await.ok();
let slur_regex = &local_site_opt_to_slur_regex(&local_site); let slur_regex = &local_site_opt_to_slur_regex(&local_site);
let url_blocklist = get_url_blocklist(context).await?; let url_blocklist = get_url_blocklist(context).await?;
let content = read_from_string_or_source(&note.content, &None, &note.source); let content = read_from_string_or_source(&note.content, &None, &note.source);
let content = process_markdown(&content, slur_regex, &url_blocklist, context).await?; let content = process_markdown(&content, slur_regex, &url_blocklist, context).await?;
let content = markdown_rewrite_remote_links(content, context).await; let content = markdown_rewrite_remote_links(content, context).await;

View file

@ -480,6 +480,7 @@ diesel::table! {
totp_2fa_enabled -> Bool, totp_2fa_enabled -> Bool,
enable_keyboard_navigation -> Bool, enable_keyboard_navigation -> Bool,
enable_animated_images -> Bool, enable_animated_images -> Bool,
enable_private_messages -> Bool,
collapse_bot_comments -> Bool, collapse_bot_comments -> Bool,
default_comment_sort_type -> CommentSortTypeEnum, default_comment_sort_type -> CommentSortTypeEnum,
auto_mark_fetched_posts_as_read -> Bool, auto_mark_fetched_posts_as_read -> Bool,

View file

@ -63,6 +63,8 @@ pub struct LocalUser {
/// Whether user avatars and inline images in the UI that are gifs should be allowed to play or /// Whether user avatars and inline images in the UI that are gifs should be allowed to play or
/// should be paused /// should be paused
pub enable_animated_images: bool, pub enable_animated_images: bool,
/// Whether a user can send / receive private messages
pub enable_private_messages: bool,
/// Whether to auto-collapse bot comments. /// Whether to auto-collapse bot comments.
pub collapse_bot_comments: bool, pub collapse_bot_comments: bool,
pub default_comment_sort_type: CommentSortType, pub default_comment_sort_type: CommentSortType,
@ -119,6 +121,8 @@ pub struct LocalUserInsertForm {
#[new(default)] #[new(default)]
pub enable_animated_images: Option<bool>, pub enable_animated_images: Option<bool>,
#[new(default)] #[new(default)]
pub enable_private_messages: Option<bool>,
#[new(default)]
pub collapse_bot_comments: Option<bool>, pub collapse_bot_comments: Option<bool>,
#[new(default)] #[new(default)]
pub default_comment_sort_type: Option<CommentSortType>, pub default_comment_sort_type: Option<CommentSortType>,
@ -152,6 +156,7 @@ pub struct LocalUserUpdateForm {
pub totp_2fa_enabled: Option<bool>, pub totp_2fa_enabled: Option<bool>,
pub enable_keyboard_navigation: Option<bool>, pub enable_keyboard_navigation: Option<bool>,
pub enable_animated_images: Option<bool>, pub enable_animated_images: Option<bool>,
pub enable_private_messages: Option<bool>,
pub collapse_bot_comments: Option<bool>, pub collapse_bot_comments: Option<bool>,
pub default_comment_sort_type: Option<CommentSortType>, pub default_comment_sort_type: Option<CommentSortType>,
pub auto_mark_fetched_posts_as_read: Option<bool>, pub auto_mark_fetched_posts_as_read: Option<bool>,

View file

@ -240,6 +240,7 @@ mod tests {
totp_2fa_enabled: inserted_sara_local_user.totp_2fa_enabled, totp_2fa_enabled: inserted_sara_local_user.totp_2fa_enabled,
enable_keyboard_navigation: inserted_sara_local_user.enable_keyboard_navigation, enable_keyboard_navigation: inserted_sara_local_user.enable_keyboard_navigation,
enable_animated_images: inserted_sara_local_user.enable_animated_images, enable_animated_images: inserted_sara_local_user.enable_animated_images,
enable_private_messages: inserted_sara_local_user.enable_private_messages,
collapse_bot_comments: inserted_sara_local_user.collapse_bot_comments, collapse_bot_comments: inserted_sara_local_user.collapse_bot_comments,
auto_mark_fetched_posts_as_read: false, auto_mark_fetched_posts_as_read: false,
}, },

View file

@ -92,7 +92,7 @@ pub struct PictrsConfig {
pub upload_timeout: u64, pub upload_timeout: u64,
/// Resize post thumbnails to this maximum width/height. /// Resize post thumbnails to this maximum width/height.
#[default(256)] #[default(512)]
pub max_thumbnail_size: u32, pub max_thumbnail_size: u32,
} }

@ -1 +1 @@
Subproject commit 7adddded581fcd965ab33b91c5fe10e0d7247208 Subproject commit dbb09b0784982827d5d9b7dcf39f1703c1212b83

View file

@ -23,7 +23,7 @@ services:
lemmy: lemmy:
# use "image" to pull down an already compiled lemmy. make sure to comment out "build". # use "image" to pull down an already compiled lemmy. make sure to comment out "build".
# image: dessalines/lemmy:0.19.5 # image: dessalines/lemmy:0.19.6
# platform: linux/x86_64 # no arm64 support. uncomment platform if using m1. # platform: linux/x86_64 # no arm64 support. uncomment platform if using m1.
# use "build" to build your local lemmy server image for development. make sure to comment out "image". # use "build" to build your local lemmy server image for development. make sure to comment out "image".
# run: docker compose up --build # run: docker compose up --build
@ -31,9 +31,9 @@ services:
build: build:
context: ../ context: ../
dockerfile: docker/Dockerfile dockerfile: docker/Dockerfile
# args: # args:
# RUST_RELEASE_MODE: release # RUST_RELEASE_MODE: release
# CARGO_BUILD_FEATURES: default # CARGO_BUILD_FEATURES: default
# this hostname is used in nginx reverse proxy and also for lemmy ui to connect to the backend, do not change # this hostname is used in nginx reverse proxy and also for lemmy ui to connect to the backend, do not change
hostname: lemmy hostname: lemmy
restart: unless-stopped restart: unless-stopped
@ -53,7 +53,7 @@ services:
lemmy-ui: lemmy-ui:
# use "image" to pull down an already compiled lemmy-ui. make sure to comment out "build". # use "image" to pull down an already compiled lemmy-ui. make sure to comment out "build".
image: dessalines/lemmy-ui:0.19.5 image: dessalines/lemmy-ui:0.19.6
# platform: linux/x86_64 # no arm64 support. uncomment platform if using m1. # platform: linux/x86_64 # no arm64 support. uncomment platform if using m1.
# use "build" to build your local lemmy ui image for development. make sure to comment out "image". # use "build" to build your local lemmy ui image for development. make sure to comment out "image".
# run: docker compose up --build # run: docker compose up --build

View file

@ -2,7 +2,7 @@ version: "3.7"
x-ui-default: &ui-default x-ui-default: &ui-default
init: true init: true
image: dessalines/lemmy-ui:0.19.5 image: dessalines/lemmy-ui:0.19.6
# assuming lemmy-ui is cloned besides lemmy directory # assuming lemmy-ui is cloned besides lemmy directory
# build: # build:
# context: ../../../lemmy-ui # context: ../../../lemmy-ui

View file

@ -0,0 +1,3 @@
ALTER TABLE local_user
DROP COLUMN enable_private_messages;

View file

@ -0,0 +1,3 @@
ALTER TABLE local_user
ADD COLUMN enable_private_messages boolean DEFAULT TRUE NOT NULL;