This commit is contained in:
Dan Ballard 2022-04-21 20:36:10 -07:00
parent e8f9088c85
commit e64351f6b8
1 changed files with 43 additions and 31 deletions

View File

@ -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::<i32>().unwrap();
println!("Contact Created");
let convo_handle = event.data["RemotePeer"].to_string();
let convo_id = event.data["ConversationID"].parse::<i32>().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::<i32>().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::<i32>().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),
_ => (),