2017-09-05 21:53:18 +00:00
|
|
|
using Gee;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
public EncryptionListEntry(StreamInteractor stream_interactor) {
|
|
|
|
this.stream_interactor = stream_interactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Entities.Encryption encryption { get {
|
|
|
|
return Encryption.PGP;
|
|
|
|
}}
|
|
|
|
|
|
|
|
public string name { get {
|
|
|
|
return "OpenPGP";
|
|
|
|
}}
|
|
|
|
|
|
|
|
public bool can_encrypt(Entities.Conversation conversation) {
|
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);
|
2017-10-29 14:15:28 +00:00
|
|
|
try {
|
|
|
|
return key_id != null && GPGHelper.get_keylist(key_id).size > 0;
|
|
|
|
} catch (Error e) { return false; }
|
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);
|
|
|
|
if (key_id == null) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-03-12 01:49:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-14 11:48:43 +00:00
|
|
|
}
|