Skip to content

Add ability delete received private messages#6378

Merged
Nutomic merged 17 commits intoLemmyNet:mainfrom
smorks:delete-priv-msgs
Mar 9, 2026
Merged

Add ability delete received private messages#6378
Nutomic merged 17 commits intoLemmyNet:mainfrom
smorks:delete-priv-msgs

Conversation

@smorks
Copy link
Copy Markdown
Contributor

@smorks smorks commented Mar 4, 2026

This should fix #4120.

It also required PR's in lemmy-ui and lemmy-js-client, that I will open shortly too.

There are some issues with this but I figure I'd get this into a PR before I forget about it again, haha.

The only remaining issue that I know about is that this also causes the message to stop showing for the sender too. Pretty sure it just needs the view modified so it only filters the message for when the recipient of the message matches the current user, but I haven't looked to hard into doing that yet.

Edit: Oops, I just noticed that I should update the timestamp of the migration file too.

.and(not(private_message::deleted))
.and(not(private_message::removed)),
.and(not(private_message::removed))
.and(not(private_message::deleted_by_recipient)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be something like this, so that these messages are only excluded if current user is not the creator (best write a unit test to ensure it works correctly).

Suggested change
.and(not(private_message::deleted_by_recipient)),
.and(private_message::creator_id.eq(person_id).or(not(private_message::deleted_by_recipient))),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that code and it appears to crash the server process with a stack overflow error. I can get the exact error message (& stack trace), but I remember running into this before too. Will poke around to see why that's happening, but any insight would be appreciated!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the error I receive, tried with RUST_BACKTRACE=1 which didn't seem to give any useful information either:

thread 'actix-server worker 3' (19510) has overflowed its stack
fatal runtime error: stack overflow, aborting

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here isn't the right place to try to extract the creator. We have two options:

  • Do it like you've done here, and don't show messages you've sent that the recipient deleted
  • Add the deleted_by_recipient logic somewhere inside this function. That does have access to the creator and recipient.

I spose it might be important for message creators to still view their past messages, so the 2nd option is maybe better.

This also needs a unit test in crates/api/api_utils/src/notify.rs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I managed to get it working, but I had to in-memory filtering, which is probably not ideal?

I couldn't add on to the existing filter you mentioned because as far as I can tell, I have no way of getting to the deleted_by_recipient field of the private message, from the notification?

I also added a unit test, hopefully it's sufficient.

@smorks smorks force-pushed the delete-priv-msgs branch 4 times, most recently from d3d60b0 to 08fdba7 Compare March 4, 2026 20:34
Copy link
Copy Markdown
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there, nice job so far. I'd def add a unit test somewhere in crates/api/api_utils/src/notify.rs . There are other tests for private messages in there already.

.and(not(private_message::deleted))
.and(not(private_message::removed)),
.and(not(private_message::removed))
.and(not(private_message::deleted_by_recipient)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here isn't the right place to try to extract the creator. We have two options:

  • Do it like you've done here, and don't show messages you've sent that the recipient deleted
  • Add the deleted_by_recipient logic somewhere inside this function. That does have access to the creator and recipient.

I spose it might be important for message creators to still view their past messages, so the 2nd option is maybe better.

This also needs a unit test in crates/api/api_utils/src/notify.rs

@smorks smorks force-pushed the delete-priv-msgs branch from 08fdba7 to d923e31 Compare March 5, 2026 18:38
Comment on lines +191 to +195
.filter(|r| {
r.private_message
.as_ref()
.is_none_or(|pm| !(pm.deleted_by_recipient && pm.recipient_id == my_person.id))
})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works but we should really be doing this on the query side somewhere. I'll take a look and see if I can figure out where.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I poked around a bit to try and do it in the query part you referenced before, but couldn't figure it out. I'll take another look later today too.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can probably be done with query = query.filter(...) just before the let paginated_query. You check if private message is null (none) by checking if one column is null. Probably notification::private_message_id.is_null() if such a column exists.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it out I think: smorks#1

Unfortunately I had to remove one join (post image details) because with notifications, we're hitting the limits of diesel's joins. That's for us to deal with tho.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhh ok, so that explains the stack overflow I was getting when doing it that way too.

Thanks for looking into that!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No probs, ya sry about that, its a diesel related bug because we have too many joins there.

.left_join(instance_join)
// This causes a stack overflow currently, due to diesel join limitations.
// image_details aren't critical for for post notifications anyway.
// .left_join(image_details_join())
Copy link
Copy Markdown
Member

@Nutomic Nutomic Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are only 20 joins here. I tried to uncomment these lines and it works just fine with cargo 1.93

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It failed on my local machine for 1.92, but I'll try it for that one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still getting the same overflowed stack error, even on 1.94

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, had it added at the wrong place. I'll try again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also got overflows on both 1.93 and 1.94, with that line uncommented.

Copy link
Copy Markdown
Member

@dessalines dessalines Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it, I had to change the position of the join to make it earlier.

Normally diesel isn't this finicky, its just with the large amount of joins there.

Once I get CI passing, I'll push directly to this branch. Won't be any logical changes, just clippy fixes.

@dessalines
Copy link
Copy Markdown
Member

I'll handle the clippy errors and such, and push directly to your branch to handle them.

@dessalines
Copy link
Copy Markdown
Member

Added back in the image_details_join, needed to add Box::pin to appease clippy, and upgraded to rust 1.94 to fix the diesel join. Once this passes it can be merged.

@@ -173,12 +173,17 @@ impl NotificationQuery {
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the definition of this function to:

pub  fn list(...) -> impl Future<Output = LemmyResult<PagedResponse<NotificationView>>> {
    Box::pin(async move {
        ...
    })

Then its not necessary to use Box::pin for every single function call.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try it out.

@Nutomic
Copy link
Copy Markdown
Member

Nutomic commented Mar 9, 2026

Thanks @smorks!

@Nutomic Nutomic enabled auto-merge (squash) March 9, 2026 14:31
@Nutomic Nutomic disabled auto-merge March 9, 2026 15:17
@Nutomic Nutomic enabled auto-merge (squash) March 9, 2026 15:22
@Nutomic Nutomic merged commit 2a696c5 into LemmyNet:main Mar 9, 2026
1 check passed
@smorks
Copy link
Copy Markdown
Contributor Author

smorks commented Mar 9, 2026

Thanks @smorks!

No problem! I'll look at getting those UI changes done soon as well so this can be completely done. thanks to both of you for helping me out with this one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Delete received private messages

4 participants