2017-09-05 21:53:18 +00:00
using Gee ;
2020-03-28 13:46:51 +00:00
using Gtk ;
2017-09-05 21:53:18 +00:00
2017-03-12 01:49:53 +00:00
using Dino.Entities ;
2018-01-12 20:03:09 +00:00
using Xmpp ;
2017-03-12 01:49:53 +00:00
namespace Dino.Plugins.OpenPgp {
private class EncryptionListEntry : Plugins . EncryptionListEntry , Object {
private StreamInteractor stream_interactor ;
2019-08-02 01:15:12 +00:00
private Database db ;
2017-03-12 01:49:53 +00:00
2019-08-02 01:15:12 +00:00
public EncryptionListEntry ( StreamInteractor stream_interactor , Database db ) {
2017-03-12 01:49:53 +00:00
this . stream_interactor = stream_interactor ;
2019-08-02 01:15:12 +00:00
this . db = db ;
2017-03-12 01:49:53 +00:00
}
public Entities . Encryption encryption { get {
return Encryption . PGP ;
} }
public string name { get {
return " OpenPGP " ;
} }
2020-03-28 13:46:51 +00:00
public Object ? get_encryption_icon ( Entities . Conversation conversation , ContentItem content_item ) {
return null ;
}
2022-02-14 13:55:59 +00:00
public string ? get_encryption_icon_name ( Entities . Conversation conversation , ContentItem content_item ) {
return null ;
}
2019-08-02 01:15:12 +00:00
public void encryption_activated ( Entities . Conversation conversation , Plugins . SetInputFieldStatus input_status_callback ) {
try {
GPGHelper . get_public_key ( db . get_account_key ( conversation . account ) ? ? " " ) ;
} catch ( Error e ) {
input_status_callback ( new Plugins . InputFieldStatus ( " You didn't configure OpenPGP for this account. You can do that in the Accounts Dialog. " , Plugins . InputFieldStatus . MessageType . ERROR , Plugins . InputFieldStatus . InputState . NO_SEND ) ) ;
return ;
}
2017-09-05 21:53:18 +00:00
if ( conversation . type_ = = Conversation . Type . CHAT ) {
string ? key_id = stream_interactor . get_module ( Manager . IDENTITY ) . get_key_id ( conversation . account , conversation . counterpart ) ;
2019-08-02 01:15:12 +00:00
if ( key_id = = null ) {
input_status_callback ( new Plugins . InputFieldStatus ( " This contact does not support %s encryption. " . printf ( " OpenPGP " ) , Plugins . InputFieldStatus . MessageType . ERROR , Plugins . InputFieldStatus . InputState . NO_SEND ) ) ;
return ;
}
2017-10-29 14:15:28 +00:00
try {
2019-08-02 01:15:12 +00:00
GPGHelper . get_keylist ( key_id ) ;
} catch ( Error e ) {
input_status_callback ( new Plugins . InputFieldStatus ( " This contact's OpenPGP key is not in your keyring. " , Plugins . InputFieldStatus . MessageType . ERROR , Plugins . InputFieldStatus . InputState . NO_SEND ) ) ;
}
2017-09-05 21:53:18 +00:00
} else if ( conversation . type_ = = Conversation . Type . GROUPCHAT ) {
Gee . List < Jid > muc_jids = new Gee . ArrayList < Jid > ( ) ;
Gee . List < Jid > ? occupants = stream_interactor . get_module ( MucManager . IDENTITY ) . get_occupants ( conversation . counterpart , conversation . account ) ;
if ( occupants ! = null ) muc_jids . add_all ( occupants ) ;
Gee . List < Jid > ? offline_members = stream_interactor . get_module ( MucManager . IDENTITY ) . get_offline_members ( conversation . counterpart , conversation . account ) ;
2018-08-03 17:45:07 +00:00
if ( offline_members ! = null ) muc_jids . add_all ( offline_members ) ;
2017-09-05 21:53:18 +00:00
foreach ( Jid jid in muc_jids ) {
string ? key_id = stream_interactor . get_module ( Manager . IDENTITY ) . get_key_id ( conversation . account , jid ) ;
2019-08-02 01:15:12 +00:00
if ( key_id = = null ) {
input_status_callback ( new Plugins . InputFieldStatus ( " A member's OpenPGP key is not in your keyring: %s / %s. " . printf ( jid . to_string ( ) , key_id ) , Plugins . InputFieldStatus . MessageType . ERROR , Plugins . InputFieldStatus . InputState . NO_SEND ) ) ;
return ;
}
2017-09-05 21:53:18 +00:00
}
}
2017-03-12 01:49:53 +00:00
}
}
2017-08-14 11:48:43 +00:00
}