Skip to content

Commit

Permalink
refactor: Add check for Platform::Web and remove configuration option (
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 authored Nov 12, 2024
1 parent 4f7f69e commit 4118bd6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 47 deletions.
4 changes: 0 additions & 4 deletions extensions/warp-ipfs/examples/identity-interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ struct Opt {
#[clap(long)]
bootstrap: Option<bool>,
#[clap(long)]
provide_platform_info: bool,
#[clap(long)]
autoaccept_friend: bool,
#[clap(long)]
wait: Option<u64>,
Expand Down Expand Up @@ -99,8 +97,6 @@ async fn account(
config.ipfs_setting_mut().portmapping = true;
}

config.store_setting_mut().share_platform = opt.provide_platform_info;

if let Some(oride) = opt.r#override {
config.store_setting_mut().fetch_over_bitswap = oride;
}
Expand Down
4 changes: 0 additions & 4 deletions extensions/warp-ipfs/examples/messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ struct Opt {
#[clap(long)]
bootstrap: Option<bool>,
#[clap(long)]
provide_platform_info: bool,
#[clap(long)]
wait: Option<u64>,
#[clap(long)]
phrase: Option<String>,
Expand Down Expand Up @@ -113,8 +111,6 @@ async fn setup<P: AsRef<Path>>(
config.ipfs_setting_mut().portmapping = true;
}

config.store_setting_mut().share_platform = opt.provide_platform_info;

if let Some(oride) = opt.r#override {
config.store_setting_mut().fetch_over_bitswap = oride;
}
Expand Down
3 changes: 0 additions & 3 deletions extensions/warp-ipfs/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ pub struct StoreSetting {

/// Fetch data over bitswap instead of pubsub
pub fetch_over_bitswap: bool,
/// Enables sharing platform (Desktop, Mobile, Web) information to another user
pub share_platform: bool,
/// Waits for a response from peer for a specific duration
pub friend_request_response_duration: Option<Duration>,
/// Disable providing images for identities
Expand All @@ -156,7 +154,6 @@ impl Default for StoreSetting {
discovery_type: Default::default(),
},
fetch_over_bitswap: false,
share_platform: false,
friend_request_response_duration: None,
disable_images: false,
with_friends: false,
Expand Down
51 changes: 16 additions & 35 deletions extensions/warp-ipfs/src/store/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,28 +999,11 @@ impl IdentityStore {

let is_blocked_by = self.is_blocked_by(out_did).await.unwrap_or_default();

let share_platform = self.config.store_setting().share_platform;

let platform =
(share_platform && (!is_blocked || !is_blocked_by)).then_some(self.own_platform());

identity.metadata.platform = platform;

let mut metadata = identity.metadata;
metadata.platform = platform;
identity.metadata.platform = Some(self.own_platform());

let metadata = identity.metadata;
identity.metadata = Default::default();

/*
(matches!(
self.config.store_setting().update_events,
UpdateEvents::Enabled
) || matches!(
self.config.store_setting().update_events,
UpdateEvents::FriendsOnly
) && is_friend)
&& */

let include_meta = is_friend || (!is_blocked && !is_blocked_by);

tracing::debug!(?metadata, included = include_meta);
Expand Down Expand Up @@ -1626,22 +1609,20 @@ impl IdentityStore {
}

fn own_platform(&self) -> Platform {
if self.config.store_setting().share_platform {
if cfg!(any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd"
)) {
Platform::Desktop
} else if cfg!(any(target_os = "android", target_os = "ios")) {
Platform::Mobile
} else {
Platform::Unknown
}
if cfg!(any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd"
)) {
Platform::Desktop
} else if cfg!(any(target_os = "android", target_os = "ios")) {
Platform::Mobile
} else if cfg!(any(target_arch = "wasm32", target_os = "unknown")) {
Platform::Web
} else {
Platform::Unknown
}
Expand Down
1 change: 0 additions & 1 deletion extensions/warp-ipfs/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ pub async fn create_account(
*config.listen_on_mut() = vec![Multiaddr::empty().with(Protocol::Memory(0))];
config.ipfs_setting_mut().memory_transport = true;
config.store_setting_mut().discovery = Discovery::None;
config.store_setting_mut().share_platform = true;
config.ipfs_setting_mut().relay_client.relay_address = vec![];
config.ipfs_setting_mut().mdns.enable = false;
config.store_setting_mut().announce_to_mesh = true;
Expand Down

0 comments on commit 4118bd6

Please sign in to comment.