Merge branch 'main' into imp-fixes
This commit is contained in:
commit
611f803880
70
src/imp.rs
70
src/imp.rs
|
@ -3,10 +3,9 @@ use libcwtch::CwtchLib;
|
||||||
use crate::event::Event;
|
use crate::event::Event;
|
||||||
|
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use crate::imp::DefaultContactPolicy::Accept;
|
|
||||||
|
|
||||||
/// How new contacts should be treated
|
/// How new contacts should be treated
|
||||||
pub enum DefaultContactPolicy {
|
pub enum NewContactPolicy {
|
||||||
/// Do not react, leave it for the custom event handler
|
/// Do not react, leave it for the custom event handler
|
||||||
Ignore,
|
Ignore,
|
||||||
/// Block all new contacts
|
/// Block all new contacts
|
||||||
|
@ -28,19 +27,48 @@ pub struct Behaviour {
|
||||||
pub profile_pic_path: Option<String>,
|
pub profile_pic_path: Option<String>,
|
||||||
|
|
||||||
/// Policy dictacting how the bot should automatically handle ContactCreated events
|
/// Policy dictacting how the bot should automatically handle ContactCreated events
|
||||||
pub default_contant_policy: DefaultContactPolicy,
|
pub new_contant_policy: NewContactPolicy,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Behaviour {
|
pub struct BehaviourBuilder {
|
||||||
/// Returns a named, profile pic using, always accepting conversations bot
|
behaviour: Behaviour
|
||||||
pub fn new_default_acceptor(name: String, profile_pic_path: String) -> Self {
|
}
|
||||||
return Behaviour{
|
|
||||||
proto_experiments: true,
|
impl BehaviourBuilder {
|
||||||
proto_experiment_fileshare: true,
|
pub fn new() -> Self {
|
||||||
default_contant_policy: Accept,
|
return BehaviourBuilder{ behaviour: Behaviour {
|
||||||
profile_name: name,
|
proto_experiments: false,
|
||||||
profile_pic_path: Some(profile_pic_path),
|
proto_experiment_fileshare: false,
|
||||||
}
|
new_contant_policy: NewContactPolicy::Ignore,
|
||||||
|
profile_name: "".to_string(),
|
||||||
|
profile_pic_path: None,
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn build(self) -> Behaviour {
|
||||||
|
self.behaviour
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn fileshare(mut self, val: bool) -> Self {
|
||||||
|
self.behaviour.proto_experiment_fileshare = val;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn profile_pic_path(mut self, val: String) -> Self {
|
||||||
|
self.behaviour.profile_pic_path = Some(val);
|
||||||
|
self.behaviour.proto_experiment_fileshare = true;
|
||||||
|
self.behaviour.proto_experiments = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn name(mut self, val: String) -> Self {
|
||||||
|
self.behaviour.profile_name = val;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_contact_policy(mut self, val: NewContactPolicy) -> Self {
|
||||||
|
self.behaviour.new_contant_policy = val;
|
||||||
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,13 +184,13 @@ impl Imp {
|
||||||
self.cwtch.set_profile_attribute(&profile.handle, "profile.name", &self.behaviour.profile_name);
|
self.cwtch.set_profile_attribute(&profile.handle, "profile.name", &self.behaviour.profile_name);
|
||||||
|
|
||||||
for (_id, conversation) in &profile.conversations {
|
for (_id, conversation) in &profile.conversations {
|
||||||
match self.behaviour.default_contant_policy {
|
match self.behaviour.new_contant_policy {
|
||||||
DefaultContactPolicy::Accept => {
|
NewContactPolicy::Accept => {
|
||||||
self.cwtch.accept_conversation(&profile.handle.clone(), conversation.identifier);
|
self.cwtch.accept_conversation(&profile.handle.clone(), conversation.identifier);
|
||||||
},
|
},
|
||||||
DefaultContactPolicy::Block =>
|
NewContactPolicy::Block =>
|
||||||
self.cwtch.block_contact(&profile.handle.clone(), conversation.identifier),
|
self.cwtch.block_contact(&profile.handle.clone(), conversation.identifier),
|
||||||
DefaultContactPolicy::Ignore => (),
|
NewContactPolicy::Ignore => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,13 +226,13 @@ impl Imp {
|
||||||
.conversations
|
.conversations
|
||||||
.insert(event.data["RemotePeer"].to_string(), conversation);
|
.insert(event.data["RemotePeer"].to_string(), conversation);
|
||||||
|
|
||||||
match self.behaviour.default_contant_policy {
|
match self.behaviour.new_contant_policy {
|
||||||
DefaultContactPolicy::Accept => {
|
NewContactPolicy::Accept => {
|
||||||
self.cwtch.accept_conversation(&profile.handle.clone(), convo_id);
|
self.cwtch.accept_conversation(&profile.handle.clone(), convo_id);
|
||||||
},
|
},
|
||||||
DefaultContactPolicy::Block =>
|
NewContactPolicy::Block =>
|
||||||
self.cwtch.block_contact(&profile.handle.clone(), convo_id),
|
self.cwtch.block_contact(&profile.handle.clone(), convo_id),
|
||||||
DefaultContactPolicy::Ignore => (),
|
NewContactPolicy::Ignore => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => (),
|
None => (),
|
||||||
|
|
Loading…
Reference in New Issue