Skip to content

Commit

Permalink
refactor: provide a reference from structs where possible (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 authored Nov 14, 2024
1 parent 406197e commit 1614235
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 104 deletions.
46 changes: 23 additions & 23 deletions extensions/warp-ipfs/examples/identity-interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ async fn main() -> anyhow::Result<()> {
warp::multipass::MultiPassEventKind::FriendRequestReceived { from: did, .. } => {
let username = account
.get_identity(Identifier::did_key(did.clone())).await
.map(|ident| ident.username())
.map(|ident| ident.username().to_owned())
.unwrap_or_else(|_| did.to_string());

if !opt.autoaccept_friend {
Expand All @@ -218,39 +218,39 @@ async fn main() -> anyhow::Result<()> {
warp::multipass::MultiPassEventKind::FriendRequestSent { to: did, .. } => {
let username = account
.get_identity(Identifier::did_key(did.clone())).await
.map(|ident| ident.username())
.map(|ident| ident.username().to_owned())
.unwrap_or_else(|_| did.to_string());

writeln!(stdout, "> A request has been sent to {username}. Do \"request close {did}\" to if you wish to close the request")?;
}
warp::multipass::MultiPassEventKind::IncomingFriendRequestRejected { did } => {
let username = account
.get_identity(Identifier::did_key(did.clone())).await
.map(|ident| ident.username())
.map(|ident| ident.username().to_owned())
.unwrap_or_else(|_| did.to_string());

writeln!(stdout, "> You've rejected {username} request")?;
},
warp::multipass::MultiPassEventKind::OutgoingFriendRequestRejected { did } => {
let username = account
.get_identity(Identifier::did_key(did.clone())).await
.map(|ident| ident.username())
.map(|ident| ident.username().to_owned())
.unwrap_or_else(|_| did.to_string());

writeln!(stdout, "> {username} rejected your request")?;
},
warp::multipass::MultiPassEventKind::IncomingFriendRequestClosed { did } => {
let username = account
.get_identity(Identifier::did_key(did.clone())).await
.map(|ident| ident.username())
.map(|ident| ident.username().to_owned())
.unwrap_or_else(|_| did.to_string());

writeln!(stdout, "> {username} has retracted their request")?;
},
warp::multipass::MultiPassEventKind::OutgoingFriendRequestClosed { did } => {
let username = account
.get_identity(Identifier::did_key(did.clone())).await
.map(|ident| ident.username())
.map(|ident| ident.username().to_owned())
.unwrap_or_else(|_| did.to_string());


Expand All @@ -259,55 +259,55 @@ async fn main() -> anyhow::Result<()> {
warp::multipass::MultiPassEventKind::FriendAdded { did } => {
let username = account
.get_identity(Identifier::did_key(did.clone())).await
.map(|ident| ident.username())
.map(|ident| ident.username().to_owned())
.unwrap_or_else(|_| did.to_string());

writeln!(stdout, "> You are now friends with {username}")?;
},
warp::multipass::MultiPassEventKind::FriendRemoved { did } => {
let username = account
.get_identity(Identifier::did_key(did.clone())).await
.map(|ident| ident.username())
.map(|ident| ident.username().to_owned())
.unwrap_or_else(|_| did.to_string());

writeln!(stdout, "> {username} has been removed from friends list")?;
},
warp::multipass::MultiPassEventKind::IdentityOnline { did } => {
let username = account
.get_identity(Identifier::did_key(did.clone())).await
.map(|ident| ident.username())
.map(|ident| ident.username().to_owned())
.unwrap_or_else(|_| did.to_string());

writeln!(stdout, "> {username} has came online")?;
},
warp::multipass::MultiPassEventKind::IdentityOffline { did } => {
let username = account
.get_identity(Identifier::did_key(did.clone())).await
.map(|ident| ident.username())
.map(|ident| ident.username().to_owned())
.unwrap_or_else(|_| did.to_string());

writeln!(stdout, "> {username} went offline")?;
},
warp::multipass::MultiPassEventKind::Blocked { did } => {
let username = account
.get_identity(Identifier::did_key(did.clone())).await
.map(|ident| ident.username())
.map(|ident| ident.username().to_owned())
.unwrap_or_else(|_| did.to_string());

writeln!(stdout, "> {username} was blocked")?;
},
warp::multipass::MultiPassEventKind::Unblocked { did } => {
let username = account
.get_identity(Identifier::did_key(did.clone())).await
.map(|ident| ident.username())
.map(|ident| ident.username().to_owned())
.unwrap_or_else(|_| did.to_string());

writeln!(stdout, "> {username} was unblocked")?;
},
warp::multipass::MultiPassEventKind::UnblockedBy { did } => {
let username = account
.get_identity(Identifier::did_key(did.clone())).await
.map(|ident| ident.username())
.map(|ident| ident.username().to_owned())
.unwrap_or_else(|_| did.to_string());


Expand All @@ -316,7 +316,7 @@ async fn main() -> anyhow::Result<()> {
warp::multipass::MultiPassEventKind::BlockedBy { did } => {
let username = account
.get_identity(Identifier::did_key(did.clone())).await
.map(|ident| ident.username())
.map(|ident| ident.username().to_owned())
.unwrap_or_else(|_| did.to_string());


Expand All @@ -325,7 +325,7 @@ async fn main() -> anyhow::Result<()> {
warp::multipass::MultiPassEventKind::IdentityUpdate { did } => {
let username = account
.get_identity(Identifier::did_key(did.clone())).await
.map(|ident| ident.username())
.map(|ident| ident.username().to_owned())
.unwrap_or_else(|_| did.to_string());

writeln!(stdout, "> {username} has been updated ")?;
Expand Down Expand Up @@ -364,7 +364,7 @@ async fn main() -> anyhow::Result<()> {
};
for friend in friends.iter() {
let username = match account.get_identity(Identifier::did_key(friend.clone())).await {
Ok(ident) => ident.username(),
Ok(ident) => ident.username().to_owned(),
Err(_) => String::from("N/A")
};
table.add_row(vec![
Expand All @@ -386,7 +386,7 @@ async fn main() -> anyhow::Result<()> {
};
for item in block_list.iter() {
let username = match account.get_identity(Identifier::did_key(item.clone())).await {
Ok(ident) => ident.username(),
Ok(ident) => ident.username().to_owned(),
Err(_) => String::from("N/A")
};
table.add_row(vec![
Expand Down Expand Up @@ -633,7 +633,7 @@ async fn main() -> anyhow::Result<()> {
for request in list.iter() {
let identity = request.identity();
let username = match account.get_identity(Identifier::did_key(identity.clone())).await {
Ok(ident) => ident.username(),
Ok(ident) => ident.username().to_owned(),
Err(_) => String::from("N/A")
};
table.add_row(vec![
Expand All @@ -656,7 +656,7 @@ async fn main() -> anyhow::Result<()> {
for request in list.iter() {
let identity = request.identity();
let username = match account.get_identity(Identifier::did_key(identity.clone())).await {
Ok(ident) => ident.username(),
Ok(ident) => ident.username().to_owned(),
Err(_) => String::from("N/A")
};
table.add_row(vec![
Expand Down Expand Up @@ -774,11 +774,11 @@ async fn main() -> anyhow::Result<()> {
let meta = identity.metadata();

table.add_row(vec![
identity.username(),
identity.username().to_owned(),
identity.did_key().to_string(),
created.to_string(),
modified.to_string(),
identity.status_message().unwrap_or_default(),
identity.status_message().map(ToOwned::to_owned).unwrap_or_default(),
(!profile_banner.data().is_empty()).to_string(),
(!profile_picture.data().is_empty()).to_string(),
platform.to_string(),
Expand Down Expand Up @@ -811,11 +811,11 @@ async fn main() -> anyhow::Result<()> {
let meta = identity.metadata();

table.add_row(vec![
identity.username(),
identity.username().to_string(),
identity.did_key().to_string(),
created.to_string(),
modified.to_string(),
identity.status_message().unwrap_or_default(),
identity.status_message().map(ToOwned::to_owned).unwrap_or_default(),
(!profile_banner.data().is_empty()).to_string(),
(!profile_picture.data().is_empty()).to_string(),
platform.to_string(),
Expand Down
4 changes: 2 additions & 2 deletions extensions/warp-ipfs/examples/ipfs-friends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ async fn main() -> anyhow::Result<()> {
Some(ev) = subscribe_a.next() => {
match ev {
MultiPassEventKind::FriendRequestSent { .. } => sent = true,
MultiPassEventKind::IdentityUpdate { did } if did == ident_b.did_key() => seen_b = true,
MultiPassEventKind::IdentityUpdate { did } if did.eq(ident_b.did_key()) => seen_b = true,
_ => {}
}
}
Some(ev) = subscribe_b.next() => {
match ev {
MultiPassEventKind::FriendRequestReceived { .. } => received = true,
MultiPassEventKind::IdentityUpdate { did } if did == ident_a.did_key() => seen_a = true,
MultiPassEventKind::IdentityUpdate { did } if did.eq(ident_a.did_key()) => seen_a = true,
_ => {}
}
}
Expand Down
Loading

0 comments on commit 1614235

Please sign in to comment.