Make the protocol advertise a requestable channel

Without this, telepathy-glib/empathy doesn't believe the protocol is
bonafide (i.e., implementing TP_PROTOCOL_FEATURE_CORE). Adding a dummy
gets empathy to display the protocol without needing to be patched \o/.
This commit is contained in:
2020-05-10 00:33:15 +01:00
parent c643c42fa5
commit ffb190385e
3 changed files with 67 additions and 21 deletions

View File

@@ -1,4 +1,5 @@
[ConnectionManager]
Interfaces=
Name=padfoot
BusName=org.freedesktop.Telepathy.ConnectionManager.padfoot
ObjectPath=/org/freedesktop/Telepathy/ConnectionManager/padfoot
@@ -6,6 +7,16 @@ ObjectPath=/org/freedesktop/Telepathy/ConnectionManager/padfoot
[Protocol delta]
param-account=s required
param-password=s required secret
AuthenticationTypes=org.freedesktop.Telepathy.Channel.Type.ServerTLSConnection;
ConnectionInterfaces=org.freedesktop.Telepathy.Connection.Interface.Requests;org.freedesktop.Telepathy.Connection.Interface.Contacts;
EnglishName=Delta Chat
VCardField=email
Icon=im-delta
Interfaces=
RequestableChannelClasses=text;
VCardField=email
[text]
org.freedesktop.Telepathy.Channel.ChannelType s=org.freedesktop.Telepathy.Channel.Type.Text
org.freedesktop.Telepathy.Channel.TargetHandleType u=1
allowed=org.freedesktop.Telepathy.Channel.TargetHandle;org.freedesktop.Telepathy.Channel.TargetID;

View File

@@ -45,12 +45,17 @@ impl telepathy::ConnectionManager for ConnectionManager {
props.insert(
"org.freedesktop.Telepathy.Protocol.AuthenticationTypes".to_string(),
arg::Variant(Box::new(Vec::<String>::new())),
arg::Variant(Box::new(vec![
"org.freedesktop.Telepathy.Channel.Type.ServerTLSConnection".to_string(),
])),
);
props.insert(
"org.freedesktop.Telepathy.Protocol.ConnectionInterfaces".to_string(),
arg::Variant(Box::new(Vec::<String>::new())),
arg::Variant(Box::new(vec![
"org.freedesktop.Telepathy.Connection.Interface.Contacts".to_string(),
"org.freedesktop.Telepathy.Connection.Interface.Requests".to_string(),
])),
);
props.insert(
"org.freedesktop.Telepathy.Protocol.EnglishName".to_string(),
@@ -70,7 +75,7 @@ impl telepathy::ConnectionManager for ConnectionManager {
);
props.insert(
"org.freedesktop.Telepathy.Protocol.RequestableChannelClasses".to_string(),
arg::Variant(Box::new(Vec::<String>::new())),
arg::Variant(Box::new(protocol::requestables())),
);
props.insert(
"org.freedesktop.Telepathy.Protocol.VCardField".to_string(),

View File

@@ -5,14 +5,20 @@ use std::collections::HashMap;
#[derive(Debug)]
pub struct Protocol {}
pub type Variant = arg::Variant<Box<dyn arg::RefArg + 'static>>;
pub type ParamSpec = (
String, // Name
u32, // Flags (Conn_Mgr_Param_Flags)
String, // Signature
arg::Variant<Box<dyn arg::RefArg + 'static>>, // Default
Variant, // Default
);
pub type Variant = arg::Variant<Box<dyn arg::RefArg + 'static>>;
pub type RequestableChannelSpec = (
// Requestable_Channel_Class
HashMap<String, Variant>, // Fixed properties
Vec<String>, // Allowed properties
);
pub const NAME: &'static str = "delta";
@@ -41,6 +47,29 @@ pub fn parameters() -> Vec<ParamSpec> {
]
}
pub fn requestables() -> Vec<RequestableChannelSpec> {
let mut rf = HashMap::<String, Variant>::new();
rf.insert(
"org.freedesktop.Telepathy.Channel.ChannelType".to_string(),
arg::Variant(Box::new(
"org.freedesktop.Telepathy.Channel.Type.Text".to_string(),
)),
);
rf.insert(
"org.freedesktop.Telepathy.Channel.TargetHandleType".to_string(),
arg::Variant(Box::new(1)),
);
let ra = vec![
"org.freedesktop.Telepathy.Channel.TargetHandle".to_string(),
"org.freedesktop.Telepathy.Channel.TargetID".to_string(),
];
vec![(rf, ra)]
}
impl telepathy::Protocol for Protocol {
fn identify_account(&self, params: HashMap<&str, Variant>) -> Result<String, tree::MethodErr> {
println!("Protocol::identify_account({:?})", params);
@@ -68,39 +97,40 @@ impl telepathy::Protocol for Protocol {
fn connection_interfaces(&self) -> Result<Vec<String>, tree::MethodErr> {
println!("Protocol::connection_interfaces()");
Ok(vec![])
Ok(vec![
"org.freedesktop.Telepathy.Connection.Interface.Contacts".to_string(),
"org.freedesktop.Telepathy.Connection.Interface.Requests".to_string(),
])
}
fn requestable_channel_classes(
&self,
) -> Result<
Vec<(
::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg + 'static>>>,
Vec<String>,
)>,
tree::MethodErr,
> {
fn requestable_channel_classes(&self) -> Result<Vec<RequestableChannelSpec>, tree::MethodErr> {
println!("Protocol::requestable_channel_classes()");
Ok(vec![])
Ok(requestables())
}
fn vcard_field(&self) -> Result<String, tree::MethodErr> {
println!("Protocol::vcard_field()");
Ok("email".to_string())
}
fn english_name(&self) -> Result<String, tree::MethodErr> {
println!("Protocol::english_name()");
Ok("Delta Chat".to_string())
}
fn icon(&self) -> Result<String, tree::MethodErr> {
println!("Protocol::icon()");
Ok("im-delta".to_string())
}
fn authentication_types(&self) -> Result<Vec<String>, tree::MethodErr> {
println!("Protocol::authentication_types()");
Ok(vec![])
Ok(vec![
"org.freedesktop.Telepathy.Channel.Type.ServerTLSConnection".to_string(),
])
}
}