From e64351f6b8c06e0ef5ef36fb6ec0f5cc8a114710 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Thu, 21 Apr 2022 20:36:10 -0700 Subject: [PATCH] fixes --- src/imp.rs | 74 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/src/imp.rs b/src/imp.rs index 0fdbf6d..98189d5 100644 --- a/src/imp.rs +++ b/src/imp.rs @@ -145,7 +145,6 @@ impl Imp { Ok(p) => p, Err(e) => panic!("error parsing profile: {}", e), }; - print!("profile: {:?}", profile); // Share profile image match self.settings.as_ref() { Some(_settings) => { @@ -156,6 +155,17 @@ impl Imp { self.cwtch.set_profile_attribute(&profile.handle, "profile.name", &self.behaviour.profile_name); + for (_id, conversation) in &profile.conversations { + match self.behaviour.default_contant_policy { + DefaultContactPolicy::Accept => { + self.cwtch.accept_conversation(&profile.handle.clone(), conversation.identifier); + }, + DefaultContactPolicy::Block => + self.cwtch.block_contact(&profile.handle.clone(), conversation.identifier), + DefaultContactPolicy::Ignore => (), + } + } + self.profile = Some(profile); } Event::AppError => { @@ -164,41 +174,43 @@ impl Imp { } } Event::ContactCreated => { - if event.data["ConnectionState"] == "Authenticated" { - let profile_onion = event.data["RemotePeer"].to_string(); - let convo_id = event.data["ConversationID"].parse::().unwrap(); + println!("Contact Created"); + let convo_handle = event.data["RemotePeer"].to_string(); + let convo_id = event.data["ConversationID"].parse::().unwrap(); - let acl: ACL = serde_json::from_str(&event.data["accessControlList"]) - .expect("Error parsing conversation"); + let acl: ACL = serde_json::from_str(&event.data["accessControlList"]) + .expect("Error parsing conversation"); - let conversation = Conversation { - handle: profile_onion.clone(), - identifier: event.data["ConversationID"].parse::().unwrap(), - name: event.data["nick"].to_string(), - status: ConnectionState::new(&event.data["status"]), - blocked: event.data["blocked"] == "true", - accepted: event.data["accepted"] == "true", - access_control_list: acl, - is_group: false, // by definition - }; + let conversation = Conversation { + handle: convo_handle.clone(), + identifier: event.data["ConversationID"].parse::().unwrap(), + name: event.data["nick"].to_string(), + status: ConnectionState::new(&event.data["status"]), + blocked: event.data["blocked"] == "true", + accepted: event.data["accepted"] == "true", + access_control_list: acl, + is_group: false, // by definition + }; - match self.behaviour.default_contant_policy { - DefaultContactPolicy::Accept => - self.cwtch.accept_conversation(&conversation.handle.clone(), convo_id), - DefaultContactPolicy::Block => - self.cwtch.block_contact(&conversation.handle.clone(), convo_id), - DefaultContactPolicy::Ignore => (), - } + match self.profile.as_mut() { + Some(profile) => { + profile + .conversations + .insert(event.data["RemotePeer"].to_string(), conversation); - match self.profile.as_mut() { - Some(profile) => { - profile - .conversations - .insert(event.data["RemotePeer"].to_string(), conversation); + match self.behaviour.default_contant_policy { + DefaultContactPolicy::Accept => { + self.cwtch.accept_conversation(&profile.handle.clone(), convo_id); + }, + DefaultContactPolicy::Block => + self.cwtch.block_contact(&profile.handle.clone(), convo_id), + DefaultContactPolicy::Ignore => (), } - None => (), - }; - } + } + None => (), + }; + } + Event::PeerStateChange => { } Event::ErrUnhandled(err) => eprintln!("unhandled event: {}!", err), _ => (),