-
-
Notifications
You must be signed in to change notification settings - Fork 869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blank out extra info for deleted or removed content. Fixes #1679 #1680
Conversation
impl DeleteableOrRemoveable for Post { | ||
fn blank_out_deleted_or_removed_info(mut self) -> Self { | ||
self.name = "".into(); | ||
self.url = None; | ||
self.body = None; | ||
self.embed_title = None; | ||
self.embed_description = None; | ||
self.embed_html = None; | ||
self.thumbnail_url = None; | ||
|
||
self | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main thing, adding a trait for these types that allows you to blank out some fields.
// Blank out deleted or removed info | ||
for pv in posts | ||
.iter_mut() | ||
.filter(|p| p.post.deleted || p.post.removed) | ||
{ | ||
pv.post = pv.to_owned().post.blank_out_deleted_or_removed_info(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The vector versions of these are a bit verbose, but I can't think of a good way to do them without using maybe another trait with an associated type.
Its certainly not the most elegant solution, and its easy to forget the blank_out call somewhere. I guess we could make these fields optional, or make a separate struct for |
I don't particularly like this solution, as this blanking happens after the database calls, so requires some in-code manipulation, when I'd really rather have the DB be able to do it. But there's no way that I can think of to do that, IE blanking other columns if one is a certain result.
The vector looping if probably fast enough that it's not an issue.