2021-10-16 13:33:38 +00:00
|
|
|
use crate::{
|
|
|
|
newtypes::PersonId,
|
2024-11-11 10:34:10 +00:00
|
|
|
schema::{person, person_actions},
|
2024-09-10 18:32:12 +00:00
|
|
|
source::{
|
|
|
|
person::Person,
|
|
|
|
person_block::{PersonBlock, PersonBlockForm},
|
|
|
|
},
|
2021-10-16 13:33:38 +00:00
|
|
|
traits::Blockable,
|
2024-11-11 10:34:10 +00:00
|
|
|
utils::{action_query, find_action, get_conn, now, uplete, DbPool},
|
2021-08-19 20:54:15 +00:00
|
|
|
};
|
2023-11-09 11:03:25 +00:00
|
|
|
use diesel::{
|
2024-09-24 00:55:35 +00:00
|
|
|
dsl::{exists, insert_into, not},
|
2024-11-11 10:34:10 +00:00
|
|
|
expression::SelectableHelper,
|
2023-11-09 11:03:25 +00:00
|
|
|
result::Error,
|
|
|
|
select,
|
2024-09-10 18:32:12 +00:00
|
|
|
ExpressionMethods,
|
|
|
|
JoinOnDsl,
|
2024-11-11 10:34:10 +00:00
|
|
|
NullableExpressionMethods,
|
2023-11-09 11:03:25 +00:00
|
|
|
QueryDsl,
|
|
|
|
};
|
2022-11-09 10:05:00 +00:00
|
|
|
use diesel_async::RunQueryDsl;
|
2024-11-04 09:44:58 +00:00
|
|
|
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
2021-08-19 20:54:15 +00:00
|
|
|
|
2021-10-16 13:33:38 +00:00
|
|
|
impl PersonBlock {
|
2022-11-09 10:05:00 +00:00
|
|
|
pub async fn read(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2021-08-19 20:54:15 +00:00
|
|
|
for_person_id: PersonId,
|
|
|
|
for_recipient_id: PersonId,
|
2024-09-24 00:55:35 +00:00
|
|
|
) -> LemmyResult<()> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2024-11-11 10:34:10 +00:00
|
|
|
select(not(exists(find_action(
|
|
|
|
person_actions::blocked,
|
|
|
|
(for_person_id, for_recipient_id),
|
|
|
|
))))
|
2024-09-24 00:55:35 +00:00
|
|
|
.get_result::<bool>(conn)
|
|
|
|
.await?
|
|
|
|
.then_some(())
|
|
|
|
.ok_or(LemmyErrorType::PersonIsBlocked.into())
|
2024-09-10 18:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn for_person(
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
person_id: PersonId,
|
|
|
|
) -> Result<Vec<Person>, Error> {
|
|
|
|
let conn = &mut get_conn(pool).await?;
|
|
|
|
let target_person_alias = diesel::alias!(person as person1);
|
|
|
|
|
2024-11-11 10:34:10 +00:00
|
|
|
action_query(person_actions::blocked)
|
|
|
|
.inner_join(person::table.on(person_actions::person_id.eq(person::id)))
|
2024-09-10 18:32:12 +00:00
|
|
|
.inner_join(
|
2024-11-11 10:34:10 +00:00
|
|
|
target_person_alias.on(person_actions::target_id.eq(target_person_alias.field(person::id))),
|
2024-09-10 18:32:12 +00:00
|
|
|
)
|
|
|
|
.select(target_person_alias.fields(person::all_columns))
|
2024-11-11 10:34:10 +00:00
|
|
|
.filter(person_actions::person_id.eq(person_id))
|
2024-09-10 18:32:12 +00:00
|
|
|
.filter(target_person_alias.field(person::deleted).eq(false))
|
2024-11-11 10:34:10 +00:00
|
|
|
.order_by(person_actions::blocked)
|
2024-09-10 18:32:12 +00:00
|
|
|
.load::<Person>(conn)
|
Remove id column and use different primary key on some tables (#4093)
* post_saved
* fmt
* remove unique and not null
* put person_id first in primary key and remove index
* use post_saved.find
* change captcha_answer
* remove removal of not null
* comment_aggregates
* comment_like
* comment_saved
* aggregates
* remove "\"
* deduplicate site_aggregates
* person_post_aggregates
* community_moderator
* community_block
* community_person_ban
* custom_emoji_keyword
* federation allow/block list
* federation_queue_state
* instance_block
* local_site_rate_limit, local_user_language, login_token
* person_ban, person_block, person_follower, post_like, post_read, received_activity
* community_follower, community_language, site_language
* fmt
* image_upload
* remove unused newtypes
* remove more indexes
* use .find
* merge
* fix site_aggregates_site function
* fmt
* Primary keys dess (#17)
* Also order reports by oldest first (ref #4123) (#4129)
* Support signed fetch for federation (fixes #868) (#4125)
* Support signed fetch for federation (fixes #868)
* taplo
* add federation queue state to get_federated_instances api (#4104)
* add federation queue state to get_federated_instances api
* feature gate
* move retry sleep function
* move stuff around
* Add UI setting for collapsing bot comments. Fixes #3838 (#4098)
* Add UI setting for collapsing bot comments. Fixes #3838
* Fixing clippy check.
* Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131)
* Only check auth secure on release mode. (#4127)
* Only check auth secure on release mode.
* Fixing wrong js-client.
* Adding is_debug_mode var.
* Fixing the desktop image on the README. (#4135)
* Delete dupes and add possibly missing unique constraint on person_aggregates.
* Fixing clippy lints.
---------
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
* fmt
* Update community_block.rs
* Update instance_block.rs
* Update person_block.rs
* Update person_block.rs
---------
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
|
|
|
.await
|
2021-08-19 20:54:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
#[async_trait]
|
2021-08-19 20:54:15 +00:00
|
|
|
impl Blockable for PersonBlock {
|
|
|
|
type Form = PersonBlockForm;
|
2023-07-11 13:09:59 +00:00
|
|
|
async fn block(
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
person_block_form: &PersonBlockForm,
|
|
|
|
) -> Result<Self, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2024-11-11 10:34:10 +00:00
|
|
|
let person_block_form = (
|
|
|
|
person_block_form,
|
|
|
|
person_actions::blocked.eq(now().nullable()),
|
|
|
|
);
|
|
|
|
insert_into(person_actions::table)
|
2021-08-19 20:54:15 +00:00
|
|
|
.values(person_block_form)
|
2024-11-11 10:34:10 +00:00
|
|
|
.on_conflict((person_actions::person_id, person_actions::target_id))
|
2021-08-19 20:54:15 +00:00
|
|
|
.do_update()
|
|
|
|
.set(person_block_form)
|
2024-11-11 10:34:10 +00:00
|
|
|
.returning(Self::as_select())
|
2021-08-19 20:54:15 +00:00
|
|
|
.get_result::<Self>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2021-08-19 20:54:15 +00:00
|
|
|
}
|
2024-11-11 10:34:10 +00:00
|
|
|
async fn unblock(
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
person_block_form: &Self::Form,
|
|
|
|
) -> Result<uplete::Count, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2024-11-11 10:34:10 +00:00
|
|
|
uplete::new(
|
|
|
|
person_actions::table.find((person_block_form.person_id, person_block_form.target_id)),
|
2024-09-10 18:32:12 +00:00
|
|
|
)
|
2024-11-11 10:34:10 +00:00
|
|
|
.set_null(person_actions::blocked)
|
|
|
|
.get_result(conn)
|
2024-09-10 18:32:12 +00:00
|
|
|
.await
|
2021-08-19 20:54:15 +00:00
|
|
|
}
|
|
|
|
}
|