2022-05-03 17:44:13 +00:00
|
|
|
use crate::structs::PrivateMessageView;
|
2022-11-09 10:05:00 +00:00
|
|
|
use diesel::{
|
|
|
|
debug_query,
|
|
|
|
pg::Pg,
|
|
|
|
result::Error,
|
|
|
|
BoolExpressionMethods,
|
|
|
|
ExpressionMethods,
|
|
|
|
JoinOnDsl,
|
|
|
|
QueryDsl,
|
|
|
|
};
|
|
|
|
use diesel_async::RunQueryDsl;
|
2020-12-18 18:38:32 +00:00
|
|
|
use lemmy_db_schema::{
|
2023-07-28 08:36:50 +00:00
|
|
|
aliases,
|
2021-10-16 13:33:38 +00:00
|
|
|
newtypes::{PersonId, PrivateMessageId},
|
2024-02-14 09:49:55 +00:00
|
|
|
schema::{instance_block, person, person_block, private_message},
|
2023-07-28 08:36:50 +00:00
|
|
|
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
|
2020-12-18 18:38:32 +00:00
|
|
|
};
|
2021-11-23 12:16:47 +00:00
|
|
|
use tracing::debug;
|
2020-12-16 22:16:48 +00:00
|
|
|
|
2023-07-28 08:36:50 +00:00
|
|
|
fn queries<'a>() -> Queries<
|
|
|
|
impl ReadFn<'a, PrivateMessageView, PrivateMessageId>,
|
|
|
|
impl ListFn<'a, PrivateMessageView, (PrivateMessageQuery, PersonId)>,
|
|
|
|
> {
|
|
|
|
let all_joins = |query: private_message::BoxedQuery<'a, Pg>| {
|
|
|
|
query
|
|
|
|
.inner_join(person::table.on(private_message::creator_id.eq(person::id)))
|
|
|
|
.inner_join(
|
|
|
|
aliases::person1.on(private_message::recipient_id.eq(aliases::person1.field(person::id))),
|
|
|
|
)
|
2023-10-25 10:01:40 +00:00
|
|
|
.left_join(
|
|
|
|
person_block::table.on(
|
|
|
|
private_message::creator_id
|
|
|
|
.eq(person_block::target_id)
|
|
|
|
.and(person_block::person_id.eq(aliases::person1.field(person::id))),
|
|
|
|
),
|
|
|
|
)
|
2024-02-14 09:49:55 +00:00
|
|
|
.left_join(
|
|
|
|
instance_block::table.on(
|
|
|
|
person::instance_id
|
|
|
|
.eq(instance_block::instance_id)
|
|
|
|
.and(instance_block::person_id.eq(aliases::person1.field(person::id))),
|
|
|
|
),
|
|
|
|
)
|
2023-07-28 08:36:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let selection = (
|
|
|
|
private_message::all_columns,
|
|
|
|
person::all_columns,
|
|
|
|
aliases::person1.fields(person::all_columns),
|
|
|
|
);
|
|
|
|
|
|
|
|
let read = move |mut conn: DbConn<'a>, private_message_id: PrivateMessageId| async move {
|
|
|
|
all_joins(private_message::table.find(private_message_id).into_boxed())
|
|
|
|
.order_by(private_message::published.desc())
|
|
|
|
.select(selection)
|
2024-04-16 12:48:15 +00:00
|
|
|
.first(&mut conn)
|
2023-07-28 08:36:50 +00:00
|
|
|
.await
|
|
|
|
};
|
|
|
|
|
|
|
|
let list = move |mut conn: DbConn<'a>,
|
|
|
|
(options, recipient_id): (PrivateMessageQuery, PersonId)| async move {
|
2023-10-25 10:01:40 +00:00
|
|
|
let mut query = all_joins(private_message::table.into_boxed())
|
|
|
|
.select(selection)
|
|
|
|
// Dont show replies from blocked users
|
2024-02-14 09:49:55 +00:00
|
|
|
.filter(person_block::person_id.is_null())
|
|
|
|
// Dont show replies from blocked instances
|
|
|
|
.filter(instance_block::person_id.is_null());
|
2023-07-28 08:36:50 +00:00
|
|
|
|
|
|
|
// If its unread, I only want the ones to me
|
2023-08-11 09:13:14 +00:00
|
|
|
if options.unread_only {
|
2023-08-08 09:07:41 +00:00
|
|
|
query = query.filter(private_message::read.eq(false));
|
|
|
|
if let Some(i) = options.creator_id {
|
|
|
|
query = query.filter(private_message::creator_id.eq(i))
|
|
|
|
}
|
|
|
|
query = query.filter(private_message::recipient_id.eq(recipient_id));
|
2023-07-28 08:36:50 +00:00
|
|
|
}
|
|
|
|
// Otherwise, I want the ALL view to show both sent and received
|
|
|
|
else {
|
|
|
|
query = query.filter(
|
|
|
|
private_message::recipient_id
|
|
|
|
.eq(recipient_id)
|
|
|
|
.or(private_message::creator_id.eq(recipient_id)),
|
2023-08-08 09:07:41 +00:00
|
|
|
);
|
|
|
|
if let Some(i) = options.creator_id {
|
|
|
|
query = query.filter(
|
|
|
|
private_message::creator_id
|
|
|
|
.eq(i)
|
|
|
|
.or(private_message::recipient_id.eq(i)),
|
|
|
|
)
|
|
|
|
}
|
2023-07-28 08:36:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
|
|
|
|
|
|
|
query = query
|
|
|
|
.filter(private_message::deleted.eq(false))
|
|
|
|
.limit(limit)
|
|
|
|
.offset(offset)
|
|
|
|
.order_by(private_message::published.desc());
|
|
|
|
|
|
|
|
debug!(
|
|
|
|
"Private Message View Query: {:?}",
|
|
|
|
debug_query::<Pg, _>(&query)
|
|
|
|
);
|
|
|
|
|
2023-08-31 13:26:10 +00:00
|
|
|
query.load::<PrivateMessageView>(&mut conn).await
|
2023-07-28 08:36:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Queries::new(read, list)
|
|
|
|
}
|
|
|
|
|
2020-12-16 22:16:48 +00:00
|
|
|
impl PrivateMessageView {
|
2023-07-11 13:09:59 +00:00
|
|
|
pub async fn read(
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
private_message_id: PrivateMessageId,
|
2024-09-23 15:26:50 +00:00
|
|
|
) -> Result<Self, Error> {
|
2023-07-28 08:36:50 +00:00
|
|
|
queries().read(pool, private_message_id).await
|
2020-12-16 22:16:48 +00:00
|
|
|
}
|
2021-10-16 10:43:41 +00:00
|
|
|
|
|
|
|
/// Gets the number of unread messages
|
2023-07-11 13:09:59 +00:00
|
|
|
pub async fn get_unread_messages(
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
my_person_id: PersonId,
|
|
|
|
) -> Result<i64, Error> {
|
2022-11-19 04:33:54 +00:00
|
|
|
use diesel::dsl::count;
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2021-10-16 10:43:41 +00:00
|
|
|
private_message::table
|
2024-02-14 09:49:55 +00:00
|
|
|
// Necessary to get the senders instance_id
|
|
|
|
.inner_join(person::table.on(private_message::creator_id.eq(person::id)))
|
2023-10-25 10:01:40 +00:00
|
|
|
.left_join(
|
|
|
|
person_block::table.on(
|
|
|
|
private_message::creator_id
|
|
|
|
.eq(person_block::target_id)
|
|
|
|
.and(person_block::person_id.eq(my_person_id)),
|
|
|
|
),
|
|
|
|
)
|
2024-02-14 09:49:55 +00:00
|
|
|
.left_join(
|
|
|
|
instance_block::table.on(
|
|
|
|
person::instance_id
|
|
|
|
.eq(instance_block::instance_id)
|
|
|
|
.and(instance_block::person_id.eq(my_person_id)),
|
|
|
|
),
|
|
|
|
)
|
2023-10-25 10:01:40 +00:00
|
|
|
// Dont count replies from blocked users
|
|
|
|
.filter(person_block::person_id.is_null())
|
2024-02-14 09:49:55 +00:00
|
|
|
// Dont count replies from blocked instances
|
|
|
|
.filter(instance_block::person_id.is_null())
|
2021-10-16 10:43:41 +00:00
|
|
|
.filter(private_message::read.eq(false))
|
|
|
|
.filter(private_message::recipient_id.eq(my_person_id))
|
|
|
|
.filter(private_message::deleted.eq(false))
|
|
|
|
.select(count(private_message::id))
|
|
|
|
.first::<i64>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2021-10-16 10:43:41 +00:00
|
|
|
}
|
2020-12-16 22:16:48 +00:00
|
|
|
}
|
|
|
|
|
2023-07-17 10:20:25 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct PrivateMessageQuery {
|
2023-08-11 09:13:14 +00:00
|
|
|
pub unread_only: bool,
|
2023-07-17 10:20:25 +00:00
|
|
|
pub page: Option<i64>,
|
|
|
|
pub limit: Option<i64>,
|
2023-08-08 09:07:41 +00:00
|
|
|
pub creator_id: Option<PersonId>,
|
2020-12-16 22:16:48 +00:00
|
|
|
}
|
|
|
|
|
2023-07-17 10:20:25 +00:00
|
|
|
impl PrivateMessageQuery {
|
|
|
|
pub async fn list(
|
|
|
|
self,
|
|
|
|
pool: &mut DbPool<'_>,
|
|
|
|
recipient_id: PersonId,
|
|
|
|
) -> Result<Vec<PrivateMessageView>, Error> {
|
2023-07-28 08:36:50 +00:00
|
|
|
queries().list(pool, (self, recipient_id)).await
|
2020-12-16 22:16:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-08 09:07:41 +00:00
|
|
|
#[cfg(test)]
|
2024-09-24 17:29:02 +00:00
|
|
|
#[expect(clippy::indexing_slicing)]
|
2023-08-08 09:07:41 +00:00
|
|
|
mod tests {
|
|
|
|
|
2023-10-25 10:01:40 +00:00
|
|
|
use crate::{private_message_view::PrivateMessageQuery, structs::PrivateMessageView};
|
2023-08-08 09:07:41 +00:00
|
|
|
use lemmy_db_schema::{
|
2024-01-04 16:51:55 +00:00
|
|
|
assert_length,
|
2024-02-14 09:49:55 +00:00
|
|
|
newtypes::InstanceId,
|
2023-08-08 09:07:41 +00:00
|
|
|
source::{
|
|
|
|
instance::Instance,
|
2024-02-14 09:49:55 +00:00
|
|
|
instance_block::{InstanceBlock, InstanceBlockForm},
|
2023-08-08 09:07:41 +00:00
|
|
|
person::{Person, PersonInsertForm},
|
2023-10-25 10:01:40 +00:00
|
|
|
person_block::{PersonBlock, PersonBlockForm},
|
2023-08-08 09:07:41 +00:00
|
|
|
private_message::{PrivateMessage, PrivateMessageInsertForm},
|
|
|
|
},
|
2023-10-25 10:01:40 +00:00
|
|
|
traits::{Blockable, Crud},
|
2024-02-14 09:49:55 +00:00
|
|
|
utils::{build_db_pool_for_tests, DbPool},
|
2023-08-08 09:07:41 +00:00
|
|
|
};
|
2024-02-14 09:49:55 +00:00
|
|
|
use lemmy_utils::error::LemmyResult;
|
2024-01-04 09:47:18 +00:00
|
|
|
use pretty_assertions::assert_eq;
|
2023-08-08 09:07:41 +00:00
|
|
|
use serial_test::serial;
|
|
|
|
|
2024-02-14 09:49:55 +00:00
|
|
|
struct Data {
|
|
|
|
instance: Instance,
|
|
|
|
timmy: Person,
|
|
|
|
jess: Person,
|
|
|
|
sara: Person,
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn init_data(pool: &mut DbPool<'_>) -> LemmyResult<Data> {
|
2023-08-08 09:07:41 +00:00
|
|
|
let message_content = String::new();
|
|
|
|
|
2024-10-02 12:50:21 +00:00
|
|
|
let instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
|
2023-08-08 09:07:41 +00:00
|
|
|
|
2024-06-06 12:29:18 +00:00
|
|
|
let timmy_form = PersonInsertForm::test_form(instance.id, "timmy_rav");
|
2023-08-08 09:07:41 +00:00
|
|
|
|
2024-10-02 12:50:21 +00:00
|
|
|
let timmy = Person::create(pool, &timmy_form).await?;
|
2023-08-08 09:07:41 +00:00
|
|
|
|
2024-06-06 12:29:18 +00:00
|
|
|
let sara_form = PersonInsertForm::test_form(instance.id, "sara_rav");
|
2023-08-08 09:07:41 +00:00
|
|
|
|
2024-10-02 12:50:21 +00:00
|
|
|
let sara = Person::create(pool, &sara_form).await?;
|
2023-08-08 09:07:41 +00:00
|
|
|
|
2024-06-06 12:29:18 +00:00
|
|
|
let jess_form = PersonInsertForm::test_form(instance.id, "jess_rav");
|
2023-08-08 09:07:41 +00:00
|
|
|
|
2024-10-02 12:50:21 +00:00
|
|
|
let jess = Person::create(pool, &jess_form).await?;
|
2023-08-08 09:07:41 +00:00
|
|
|
|
2024-09-20 12:15:25 +00:00
|
|
|
let sara_timmy_message_form =
|
|
|
|
PrivateMessageInsertForm::new(sara.id, timmy.id, message_content.clone());
|
2024-10-02 12:50:21 +00:00
|
|
|
PrivateMessage::create(pool, &sara_timmy_message_form).await?;
|
2023-08-08 09:07:41 +00:00
|
|
|
|
2024-09-20 12:15:25 +00:00
|
|
|
let sara_jess_message_form =
|
|
|
|
PrivateMessageInsertForm::new(sara.id, jess.id, message_content.clone());
|
2024-10-02 12:50:21 +00:00
|
|
|
PrivateMessage::create(pool, &sara_jess_message_form).await?;
|
2023-08-08 09:07:41 +00:00
|
|
|
|
2024-09-20 12:15:25 +00:00
|
|
|
let timmy_sara_message_form =
|
|
|
|
PrivateMessageInsertForm::new(timmy.id, sara.id, message_content.clone());
|
2024-10-02 12:50:21 +00:00
|
|
|
PrivateMessage::create(pool, &timmy_sara_message_form).await?;
|
2023-08-08 09:07:41 +00:00
|
|
|
|
2024-09-20 12:15:25 +00:00
|
|
|
let jess_timmy_message_form =
|
|
|
|
PrivateMessageInsertForm::new(jess.id, timmy.id, message_content.clone());
|
2024-10-02 12:50:21 +00:00
|
|
|
PrivateMessage::create(pool, &jess_timmy_message_form).await?;
|
2023-08-08 09:07:41 +00:00
|
|
|
|
2024-02-14 09:49:55 +00:00
|
|
|
Ok(Data {
|
|
|
|
instance,
|
|
|
|
timmy,
|
|
|
|
jess,
|
|
|
|
sara,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn cleanup(instance_id: InstanceId, pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
|
|
|
// This also deletes all persons and private messages thanks to sql `on delete cascade`
|
2024-10-02 12:50:21 +00:00
|
|
|
Instance::delete(pool, instance_id).await?;
|
2024-02-14 09:49:55 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
#[serial]
|
|
|
|
async fn read_private_messages() -> LemmyResult<()> {
|
|
|
|
let pool = &build_db_pool_for_tests().await;
|
|
|
|
let pool = &mut pool.into();
|
|
|
|
let Data {
|
|
|
|
timmy,
|
|
|
|
jess,
|
|
|
|
sara,
|
|
|
|
instance,
|
|
|
|
} = init_data(pool).await?;
|
|
|
|
|
2023-08-08 09:07:41 +00:00
|
|
|
let timmy_messages = PrivateMessageQuery {
|
2023-08-11 09:13:14 +00:00
|
|
|
unread_only: false,
|
2023-12-19 10:26:00 +00:00
|
|
|
creator_id: None,
|
2023-08-08 09:07:41 +00:00
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
.list(pool, timmy.id)
|
2024-10-02 12:50:21 +00:00
|
|
|
.await?;
|
2023-08-08 09:07:41 +00:00
|
|
|
|
2024-01-04 16:51:55 +00:00
|
|
|
assert_length!(3, &timmy_messages);
|
2023-08-08 09:07:41 +00:00
|
|
|
assert_eq!(timmy_messages[0].creator.id, jess.id);
|
|
|
|
assert_eq!(timmy_messages[0].recipient.id, timmy.id);
|
|
|
|
assert_eq!(timmy_messages[1].creator.id, timmy.id);
|
|
|
|
assert_eq!(timmy_messages[1].recipient.id, sara.id);
|
|
|
|
assert_eq!(timmy_messages[2].creator.id, sara.id);
|
|
|
|
assert_eq!(timmy_messages[2].recipient.id, timmy.id);
|
|
|
|
|
|
|
|
let timmy_unread_messages = PrivateMessageQuery {
|
2023-08-11 09:13:14 +00:00
|
|
|
unread_only: true,
|
2023-12-19 10:26:00 +00:00
|
|
|
creator_id: None,
|
2023-08-08 09:07:41 +00:00
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
.list(pool, timmy.id)
|
2024-10-02 12:50:21 +00:00
|
|
|
.await?;
|
2023-08-08 09:07:41 +00:00
|
|
|
|
2024-01-04 16:51:55 +00:00
|
|
|
assert_length!(2, &timmy_unread_messages);
|
2023-08-08 09:07:41 +00:00
|
|
|
assert_eq!(timmy_unread_messages[0].creator.id, jess.id);
|
|
|
|
assert_eq!(timmy_unread_messages[0].recipient.id, timmy.id);
|
|
|
|
assert_eq!(timmy_unread_messages[1].creator.id, sara.id);
|
|
|
|
assert_eq!(timmy_unread_messages[1].recipient.id, timmy.id);
|
|
|
|
|
|
|
|
let timmy_sara_messages = PrivateMessageQuery {
|
2023-08-11 09:13:14 +00:00
|
|
|
unread_only: false,
|
2023-08-08 09:07:41 +00:00
|
|
|
creator_id: Some(sara.id),
|
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
.list(pool, timmy.id)
|
2024-10-02 12:50:21 +00:00
|
|
|
.await?;
|
2023-08-08 09:07:41 +00:00
|
|
|
|
2024-01-04 16:51:55 +00:00
|
|
|
assert_length!(2, &timmy_sara_messages);
|
2023-08-08 09:07:41 +00:00
|
|
|
assert_eq!(timmy_sara_messages[0].creator.id, timmy.id);
|
|
|
|
assert_eq!(timmy_sara_messages[0].recipient.id, sara.id);
|
|
|
|
assert_eq!(timmy_sara_messages[1].creator.id, sara.id);
|
|
|
|
assert_eq!(timmy_sara_messages[1].recipient.id, timmy.id);
|
|
|
|
|
|
|
|
let timmy_sara_unread_messages = PrivateMessageQuery {
|
2023-08-11 09:13:14 +00:00
|
|
|
unread_only: true,
|
2023-08-08 09:07:41 +00:00
|
|
|
creator_id: Some(sara.id),
|
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
.list(pool, timmy.id)
|
2024-10-02 12:50:21 +00:00
|
|
|
.await?;
|
2023-08-08 09:07:41 +00:00
|
|
|
|
2024-01-04 16:51:55 +00:00
|
|
|
assert_length!(1, &timmy_sara_unread_messages);
|
2023-08-08 09:07:41 +00:00
|
|
|
assert_eq!(timmy_sara_unread_messages[0].creator.id, sara.id);
|
|
|
|
assert_eq!(timmy_sara_unread_messages[0].recipient.id, timmy.id);
|
2023-10-25 10:01:40 +00:00
|
|
|
|
2024-02-14 09:49:55 +00:00
|
|
|
cleanup(instance.id, pool).await
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
#[serial]
|
|
|
|
async fn ensure_person_block() -> LemmyResult<()> {
|
|
|
|
let pool = &build_db_pool_for_tests().await;
|
|
|
|
let pool = &mut pool.into();
|
|
|
|
let Data {
|
|
|
|
timmy,
|
|
|
|
sara,
|
|
|
|
instance,
|
|
|
|
jess: _,
|
|
|
|
} = init_data(pool).await?;
|
|
|
|
|
2023-10-25 10:01:40 +00:00
|
|
|
// Make sure blocks are working
|
|
|
|
let timmy_blocks_sara_form = PersonBlockForm {
|
|
|
|
person_id: timmy.id,
|
|
|
|
target_id: sara.id,
|
|
|
|
};
|
|
|
|
|
2024-10-02 12:50:21 +00:00
|
|
|
let inserted_block = PersonBlock::block(pool, &timmy_blocks_sara_form).await?;
|
2023-10-25 10:01:40 +00:00
|
|
|
|
|
|
|
let expected_block = PersonBlock {
|
|
|
|
person_id: timmy.id,
|
|
|
|
target_id: sara.id,
|
|
|
|
published: inserted_block.published,
|
|
|
|
};
|
|
|
|
assert_eq!(expected_block, inserted_block);
|
|
|
|
|
|
|
|
let timmy_messages = PrivateMessageQuery {
|
|
|
|
unread_only: true,
|
2023-12-19 10:26:00 +00:00
|
|
|
creator_id: None,
|
2023-10-25 10:01:40 +00:00
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
.list(pool, timmy.id)
|
2024-10-02 12:50:21 +00:00
|
|
|
.await?;
|
2023-10-25 10:01:40 +00:00
|
|
|
|
2024-01-04 16:51:55 +00:00
|
|
|
assert_length!(1, &timmy_messages);
|
2023-10-25 10:01:40 +00:00
|
|
|
|
2024-10-02 12:50:21 +00:00
|
|
|
let timmy_unread_messages = PrivateMessageView::get_unread_messages(pool, timmy.id).await?;
|
2023-10-25 10:01:40 +00:00
|
|
|
assert_eq!(timmy_unread_messages, 1);
|
2023-12-19 10:26:00 +00:00
|
|
|
|
2024-02-14 09:49:55 +00:00
|
|
|
cleanup(instance.id, pool).await
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
#[serial]
|
|
|
|
async fn ensure_instance_block() -> LemmyResult<()> {
|
|
|
|
let pool = &build_db_pool_for_tests().await;
|
|
|
|
let pool = &mut pool.into();
|
|
|
|
let Data {
|
|
|
|
timmy,
|
|
|
|
jess: _,
|
|
|
|
sara,
|
|
|
|
instance,
|
|
|
|
} = init_data(pool).await?;
|
|
|
|
// Make sure instance_blocks are working
|
|
|
|
let timmy_blocks_instance_form = InstanceBlockForm {
|
|
|
|
person_id: timmy.id,
|
|
|
|
instance_id: sara.instance_id,
|
|
|
|
};
|
|
|
|
|
2024-10-02 12:50:21 +00:00
|
|
|
let inserted_instance_block = InstanceBlock::block(pool, &timmy_blocks_instance_form).await?;
|
2024-02-14 09:49:55 +00:00
|
|
|
|
|
|
|
let expected_instance_block = InstanceBlock {
|
|
|
|
person_id: timmy.id,
|
|
|
|
instance_id: sara.instance_id,
|
|
|
|
published: inserted_instance_block.published,
|
|
|
|
};
|
|
|
|
assert_eq!(expected_instance_block, inserted_instance_block);
|
|
|
|
|
|
|
|
let timmy_messages = PrivateMessageQuery {
|
|
|
|
unread_only: true,
|
|
|
|
creator_id: None,
|
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
.list(pool, timmy.id)
|
2024-10-02 12:50:21 +00:00
|
|
|
.await?;
|
2024-02-14 09:49:55 +00:00
|
|
|
|
|
|
|
assert_length!(0, &timmy_messages);
|
|
|
|
|
2024-10-02 12:50:21 +00:00
|
|
|
let timmy_unread_messages = PrivateMessageView::get_unread_messages(pool, timmy.id).await?;
|
2024-02-14 09:49:55 +00:00
|
|
|
assert_eq!(timmy_unread_messages, 0);
|
|
|
|
cleanup(instance.id, pool).await
|
2023-08-08 09:07:41 +00:00
|
|
|
}
|
|
|
|
}
|