Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sugyan committed Jun 5, 2024
1 parent cefa4a4 commit a1df2c3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 19 deletions.
33 changes: 28 additions & 5 deletions bsky-sdk/src/moderation/decision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub(crate) enum ModerationBehaviorSeverity {
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum Priority {
pub enum Priority {
Priority1,
Priority2,
Priority3,
Expand Down Expand Up @@ -68,7 +68,7 @@ impl ModerationDecision {
match cause {
ModerationCause::Blocking(b)
| ModerationCause::BlockedBy(b)
| ModerationCause::BlockOther(b) => {
/* | ModerationCause::BlockOther(b) */ => {
if self.is_me {
continue;
}
Expand Down Expand Up @@ -171,8 +171,24 @@ impl ModerationDecision {
}
}
}
ModerationCause::Hidden(_) => {
todo!();
ModerationCause::Hidden(hidden) => {
if matches!(context, DecisionContext::ProfileList | DecisionContext::ContentList) {
ui.filters.push(cause.clone())
}
if !hidden.downgraded {
match ModerationBehavior::HIDE_BEHAVIOR.behavior_for(context) {
Some(BehaviorValue::Blur) => {
ui.blurs.push(cause.clone());
}
Some(BehaviorValue::Alert) => {
ui.alerts.push(cause.clone());
}
Some(BehaviorValue::Inform) => {
ui.informs.push(cause.clone());
}
_ => {}
}
}
}
}
}
Expand All @@ -186,7 +202,7 @@ impl ModerationDecision {
c,
ModerationCause::Blocking(_)
| ModerationCause::BlockedBy(_)
| ModerationCause::BlockOther(_)
/* | ModerationCause::BlockOther(_) */
)
})
}
Expand Down Expand Up @@ -353,6 +369,13 @@ impl ModerationDecision {
downgraded: false,
})));
}
pub(crate) fn add_hidden(&mut self) {
self.causes
.push(ModerationCause::Hidden(Box::new(ModerationCauseOther {
source: ModerationCauseSource::User,
downgraded: false,
})));
}
pub(crate) fn downgrade(&mut self) {
for cause in self.causes.iter_mut() {
cause.downgrade()
Expand Down
30 changes: 29 additions & 1 deletion bsky-sdk/src/moderation/subjects/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ impl Moderator {
acc.add_label(LabelTarget::Content, label, self);
}
}
// TODO: hidden?
if check_hidden_post(subject, &self.prefs.hidden_posts) {
acc.add_hidden();
}
if !is_me && check_muted_words(subject, &self.prefs.muted_words) {
acc.add_muted_word();
}
Expand Down Expand Up @@ -112,6 +114,32 @@ impl Moderator {
}
}

fn check_hidden_post(subject: &SubjectPost, hidden_posts: &[String]) -> bool {
if hidden_posts.is_empty() {
return false;
}
if hidden_posts.contains(&subject.uri) {
return true;
}
match &subject.embed {
Some(Union::Refs(PostViewEmbedRefs::AppBskyEmbedRecordView(view))) => {
if let Union::Refs(ViewRecordRefs::ViewRecord(record)) = &view.record {
if hidden_posts.contains(&record.uri) {
return true;
}
}
}
Some(Union::Refs(PostViewEmbedRefs::AppBskyEmbedRecordWithMediaView(view))) => {
if let Union::Refs(ViewRecordRefs::ViewRecord(record)) = &view.record.record {
if hidden_posts.contains(&record.uri) {
return true;
}
}
}
_ => {}
}
false
}
fn check_muted_words(subject: &SubjectPost, muted_words: &[MutedWord]) -> bool {
if muted_words.is_empty() {
return false;
Expand Down
28 changes: 19 additions & 9 deletions bsky-sdk/src/moderation/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,18 @@ impl ModerationBehavior {
avatar: None,
banner: None,
display_name: None,
content_list: Some(ContentListBehavior::Inform),
content_view: Some(ContentViewBehavior::Inform),
content_list: Some(ContentListBehavior::Blur),
content_view: Some(ContentViewBehavior::Blur),
content_media: None,
};
pub(crate) const HIDE_BEHAVIOR: Self = Self {
profile_list: None,
profile_view: None,
avatar: None,
banner: None,
display_name: None,
content_list: Some(ContentListBehavior::Blur),
content_view: Some(ContentViewBehavior::Blur),
content_media: None,
};
pub(crate) fn behavior_for(&self, context: DecisionContext) -> Option<BehaviorValue> {
Expand Down Expand Up @@ -509,10 +519,10 @@ impl From<ProfileViewDetailed> for SubjectProfile {
pub type SubjectPost = PostView;

#[derive(Debug, Clone)]
pub(crate) enum ModerationCause {
pub enum ModerationCause {
Blocking(Box<ModerationCauseOther>),
BlockedBy(Box<ModerationCauseOther>),
BlockOther(Box<ModerationCauseOther>),
// BlockOther(Box<ModerationCauseOther>),
Label(Box<ModerationCauseLabel>),
Muted(Box<ModerationCauseOther>),
MuteWord(Box<ModerationCauseOther>),
Expand All @@ -527,7 +537,7 @@ impl ModerationCause {
Self::Label(label) => label.priority,
Self::Muted(_) => Priority::Priority6,
Self::MuteWord(_) => Priority::Priority6,
_ => todo!(),
Self::Hidden(_) => Priority::Priority6,
}
}
pub fn downgrade(&mut self) {
Expand All @@ -537,20 +547,20 @@ impl ModerationCause {
Self::Label(label) => label.downgraded = true,
Self::Muted(muted) => muted.downgraded = true,
Self::MuteWord(mute_word) => mute_word.downgraded = true,
_ => todo!(),
Self::Hidden(hidden) => hidden.downgraded = true,
}
}
}

#[derive(Debug, Clone)]
pub(crate) enum ModerationCauseSource {
pub enum ModerationCauseSource {
User,
List(Box<ListViewBasic>),
Labeler(Did),
}

#[derive(Debug, Clone)]
pub(crate) struct ModerationCauseLabel {
pub struct ModerationCauseLabel {
pub source: ModerationCauseSource,
pub label: Label,
pub label_def: InterpretedLabelValueDefinition,
Expand All @@ -563,7 +573,7 @@ pub(crate) struct ModerationCauseLabel {
}

#[derive(Debug, Clone)]
pub(crate) struct ModerationCauseOther {
pub struct ModerationCauseOther {
pub source: ModerationCauseSource,
pub downgraded: bool,
}
Expand Down
8 changes: 4 additions & 4 deletions bsky-sdk/src/moderation/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use super::types::ModerationCause;

pub struct ModerationUi {
pub no_override: bool,
pub(crate) filters: Vec<ModerationCause>,
pub(crate) blurs: Vec<ModerationCause>,
pub(crate) alerts: Vec<ModerationCause>,
pub(crate) informs: Vec<ModerationCause>,
pub filters: Vec<ModerationCause>,
pub blurs: Vec<ModerationCause>,
pub alerts: Vec<ModerationCause>,
pub informs: Vec<ModerationCause>,
}

impl ModerationUi {
Expand Down

0 comments on commit a1df2c3

Please sign in to comment.