Skip to content

Commit

Permalink
chore: Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Oct 22, 2023
1 parent 5478c4e commit 3e83c78
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions extensions/warp-ipfs/src/store/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ use crate::spam_filter::SpamFilter;
use crate::store::payload::Payload;
use crate::store::{
connected_to_peer, ecdh_decrypt, ecdh_encrypt, get_keypair_did, sign_serde,
ConversationRequestKind, ConversationRequestResponse, ConversationResponseKind, PeerTopic,
ConversationRequestKind, ConversationRequestResponse, ConversationResponseKind, DidExt,
PeerTopic,
};

use super::conversation::{ConversationDocument, MessageDocument};
use super::discovery::Discovery;
use super::document::conversation::Conversations;
use super::identity::IdentityStore;
use super::keystore::Keystore;
use super::{did_to_libp2p_pub, verify_serde_sig, ConversationEvents, MessagingEvents};
use super::{verify_serde_sig, ConversationEvents, MessagingEvents};

type ConversationSender =
UnboundedSender<(MessagingEvents, Option<OneshotSender<Result<(), Error>>>)>;
Expand Down Expand Up @@ -549,8 +550,8 @@ impl MessageStore {
.ipfs
.pubsub_peers(Some(topic.clone()))
.await?;
let peer_id = did_to_libp2p_pub(&sender)
.map(|pk| pk.to_peer_id())?;

let peer_id = sender.to_peer_id()?;

let bytes = payload.to_bytes()?;

Expand Down Expand Up @@ -711,7 +712,7 @@ impl MessageStore {
let topic = conversation.reqres_topic(did);

let peers = self.ipfs.pubsub_peers(Some(topic.clone())).await?;
let peer_id = did_to_libp2p_pub(did).map(|pk| pk.to_peer_id())?;
let peer_id = did.to_peer_id()?;

if !peers.contains(&peer_id)
|| (peers.contains(&peer_id)
Expand Down Expand Up @@ -798,7 +799,6 @@ impl MessageStore {
Cipher::direct_decrypt(data.data(), &key)
}
};
drop(conversation);

let bytes = match bytes_results {
Ok(b) => b,
Expand Down Expand Up @@ -1745,7 +1745,7 @@ impl MessageStore {

self.start_task(convo_id, stream).await;

let peer_id = did_to_libp2p_pub(did_key)?.to_peer_id();
let peer_id = did_key.to_peer_id()?;

let event = ConversationEvents::NewConversation {
recipient: own_did.clone(),
Expand Down Expand Up @@ -1870,8 +1870,7 @@ impl MessageStore {
.iter()
.filter(|did| own_did.ne(did))
.map(|did| (did.clone(), did))
.filter_map(|(a, b)| did_to_libp2p_pub(b).map(|pk| (a, pk)).ok())
.map(|(did, pk)| (did, pk.to_peer_id()))
.filter_map(|(a, b)| b.to_peer_id().map(|pk| (a, pk)).ok())
.collect::<Vec<_>>();

let conversation = self.conversations.get(convo_id).await?;
Expand Down Expand Up @@ -1980,8 +1979,8 @@ impl MessageStore {
.iter()
.filter(|did| own_did.ne(did))
.map(|did| (did.clone(), did))
.filter_map(|(a, b)| did_to_libp2p_pub(b).map(|pk| (a, pk)).ok())
.map(|(did, pk)| (did, pk.to_peer_id()))
.filter_map(|(a, b)| b.to_peer_id().map(|pk| (a, pk)).ok())
.map(|(did, pk)| (did, pk))
.collect::<Vec<_>>();

let event = serde_json::to_vec(&ConversationEvents::DeleteConversation {
Expand Down Expand Up @@ -2140,7 +2139,7 @@ impl MessageStore {

let payload = Payload::new(own_did, &bytes, &signature);

let peer_id = did_to_libp2p_pub(did_key)?.to_peer_id();
let peer_id = did_key.to_peer_id()?;
let peers = self.ipfs.pubsub_peers(Some(did_key.messaging())).await?;

let mut time = true;
Expand Down Expand Up @@ -3327,7 +3326,7 @@ impl MessageStore {
.iter()
.filter(|did| own_did.ne(did))
{
let peer_id = did_to_libp2p_pub(recipient)?.to_peer_id();
let peer_id = recipient.to_peer_id()?;

// We want to confirm that there is atleast one peer subscribed before attempting to send a message
match peers.contains(&peer_id) {
Expand Down

0 comments on commit 3e83c78

Please sign in to comment.