Skip to content

Commit

Permalink
feat: Update BskyAgent (#197)
Browse files Browse the repository at this point in the history
* Fix BskyAgent::get_preferences

* Remove SDK enforcement of max labelers
  • Loading branch information
sugyan committed Jul 3, 2024
1 parent f1bf1c7 commit 18ee562
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bsky-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ anyhow.workspace = true
async-trait.workspace = true
atrium-api.workspace = true
atrium-xrpc-client = { workspace = true, optional = true }
ipld-core.workspace = true
psl = { version = "2.1.42", optional = true }
regex.workspace = true
serde = { workspace = true, features = ["derive"] }
Expand All @@ -26,6 +25,7 @@ toml = { version = "0.8.13", optional = true }
unicode-segmentation = { version = "1.11.0", optional = true }

[dev-dependencies]
ipld-core.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

[features]
Expand Down
16 changes: 7 additions & 9 deletions bsky-sdk/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ use crate::moderation::{ModerationPrefsLabeler, Moderator};
use crate::preference::{FeedViewPreferenceData, Preferences, ThreadViewPreferenceData};
use atrium_api::agent::store::MemorySessionStore;
use atrium_api::agent::{store::SessionStore, AtpAgent};
use atrium_api::app::bsky::actor::defs::{LabelersPref, PreferencesItem};
use atrium_api::app::bsky::actor::defs::PreferencesItem;
use atrium_api::types::{Object, Union};
use atrium_api::xrpc::XrpcClient;
#[cfg(feature = "default-client")]
use atrium_xrpc_client::reqwest::ReqwestClient;
use ipld_core::serde::from_ipld;
use std::collections::HashMap;
use std::ops::Deref;
use std::sync::Arc;
Expand Down Expand Up @@ -160,11 +159,12 @@ where
Union::Refs(PreferencesItem::HiddenPostsPref(p)) => {
prefs.moderation_prefs.hidden_posts = p.data.items;
}
Union::Unknown(u) => {
if u.r#type == "app.bsky.actor.defs#labelersPref" {
prefs.moderation_prefs.labelers.extend(
from_ipld::<LabelersPref>(u.data)?
.data
Union::Refs(PreferencesItem::LabelersPref(p)) => {
prefs
.moderation_prefs
.labelers
.extend(
p.data
.labelers
.into_iter()
.map(|item| ModerationPrefsLabeler {
Expand All @@ -173,7 +173,6 @@ where
is_default_labeler: false,
}),
);
}
}
_ => {
// TODO
Expand Down Expand Up @@ -214,7 +213,6 @@ where
.labelers
.iter()
.map(|labeler| (labeler.did.clone(), labeler.is_default_labeler))
.take(10)
.collect(),
));
}
Expand Down
2 changes: 0 additions & 2 deletions bsky-sdk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ pub enum Error {
#[error("saving config error: {0}")]
ConfigSave(Box<dyn std::error::Error + Send + Sync + 'static>),
#[error(transparent)]
IpldSerde(#[from] ipld_core::serde::SerdeError),
#[error(transparent)]
Moderation(#[from] crate::moderation::Error),
}

Expand Down

0 comments on commit 18ee562

Please sign in to comment.