Blocking setting in Contact Details
This commit is contained in:
parent
a8d06e634b
commit
7e83529afc
|
@ -29,6 +29,7 @@ SOURCES
|
||||||
|
|
||||||
src/service/avatar_manager.vala
|
src/service/avatar_manager.vala
|
||||||
src/service/avatar_storage.vala
|
src/service/avatar_storage.vala
|
||||||
|
src/service/blocking_manager.vala
|
||||||
src/service/chat_interaction.vala
|
src/service/chat_interaction.vala
|
||||||
src/service/connection_manager.vala
|
src/service/connection_manager.vala
|
||||||
src/service/conversation_manager.vala
|
src/service/conversation_manager.vala
|
||||||
|
|
|
@ -31,6 +31,7 @@ public interface Dino.Application : GLib.Application {
|
||||||
MessageStorage.start(stream_interactor, db);
|
MessageStorage.start(stream_interactor, db);
|
||||||
CounterpartInteractionManager.start(stream_interactor);
|
CounterpartInteractionManager.start(stream_interactor);
|
||||||
PresenceManager.start(stream_interactor);
|
PresenceManager.start(stream_interactor);
|
||||||
|
BlockingManager.start(stream_interactor);
|
||||||
MucManager.start(stream_interactor);
|
MucManager.start(stream_interactor);
|
||||||
RosterManager.start(stream_interactor, db);
|
RosterManager.start(stream_interactor, db);
|
||||||
ConversationManager.start(stream_interactor, db);
|
ConversationManager.start(stream_interactor, db);
|
||||||
|
|
44
libdino/src/service/blocking_manager.vala
Normal file
44
libdino/src/service/blocking_manager.vala
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
using Gee;
|
||||||
|
|
||||||
|
using Xmpp;
|
||||||
|
using Dino.Entities;
|
||||||
|
|
||||||
|
namespace Dino {
|
||||||
|
|
||||||
|
public class BlockingManager : StreamInteractionModule, Object {
|
||||||
|
public static ModuleIdentity<BlockingManager> IDENTITY = new ModuleIdentity<BlockingManager>("blocking_manager");
|
||||||
|
public string id { get { return IDENTITY.id; } }
|
||||||
|
|
||||||
|
private StreamInteractor stream_interactor;
|
||||||
|
|
||||||
|
public static void start(StreamInteractor stream_interactor) {
|
||||||
|
BlockingManager m = new BlockingManager(stream_interactor);
|
||||||
|
stream_interactor.add_module(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BlockingManager(StreamInteractor stream_interactor) {
|
||||||
|
this.stream_interactor = stream_interactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool is_blocked(Account account, Jid jid) {
|
||||||
|
Core.XmppStream stream = stream_interactor.get_stream(account);
|
||||||
|
return stream != null && stream.get_module(Xmpp.Xep.BlockingCommand.Module.IDENTITY).is_blocked(stream, jid.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void block(Account account, Jid jid) {
|
||||||
|
Core.XmppStream stream = stream_interactor.get_stream(account);
|
||||||
|
stream.get_module(Xmpp.Xep.BlockingCommand.Module.IDENTITY).block(stream, new ArrayList<string>.wrap(new string[] {jid.to_string()}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unblock(Account account, Jid jid) {
|
||||||
|
Core.XmppStream stream = stream_interactor.get_stream(account);
|
||||||
|
stream.get_module(Xmpp.Xep.BlockingCommand.Module.IDENTITY).unblock(stream, new ArrayList<string>.wrap(new string[] {jid.to_string()}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool is_supported(Account account) {
|
||||||
|
Core.XmppStream stream = stream_interactor.get_stream(account);
|
||||||
|
return stream != null && stream.get_module(Xmpp.Xep.BlockingCommand.Module.IDENTITY).is_supported(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -88,6 +88,7 @@ SOURCES
|
||||||
src/ui/chat_input/occupants_tab_completer.vala
|
src/ui/chat_input/occupants_tab_completer.vala
|
||||||
src/ui/chat_input/smiley_converter.vala
|
src/ui/chat_input/smiley_converter.vala
|
||||||
src/ui/chat_input/view.vala
|
src/ui/chat_input/view.vala
|
||||||
|
src/ui/contact_details/blocking_provider.vala
|
||||||
src/ui/contact_details/settings_provider.vala
|
src/ui/contact_details/settings_provider.vala
|
||||||
src/ui/contact_details/dialog.vala
|
src/ui/contact_details/dialog.vala
|
||||||
src/ui/contact_details/muc_config_form_provider.vala
|
src/ui/contact_details/muc_config_form_provider.vala
|
||||||
|
|
36
main/src/ui/contact_details/blocking_provider.vala
Normal file
36
main/src/ui/contact_details/blocking_provider.vala
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
using Gtk;
|
||||||
|
|
||||||
|
using Dino.Entities;
|
||||||
|
|
||||||
|
namespace Dino.Ui.ContactDetails {
|
||||||
|
|
||||||
|
public class BlockingProvider : Plugins.ContactDetailsProvider, Object {
|
||||||
|
public string id { get { return "blocking"; } }
|
||||||
|
|
||||||
|
private StreamInteractor stream_interactor;
|
||||||
|
|
||||||
|
public BlockingProvider(StreamInteractor stream_interactor) {
|
||||||
|
this.stream_interactor = stream_interactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void populate(Conversation conversation, Plugins.ContactDetails contact_details, Plugins.WidgetType type) {
|
||||||
|
if (type != Plugins.WidgetType.GTK) return;
|
||||||
|
if (conversation.type_ != Conversation.Type.CHAT) return;
|
||||||
|
|
||||||
|
if (stream_interactor.get_module(BlockingManager.IDENTITY).is_supported(conversation.account)) {
|
||||||
|
bool is_blocked = stream_interactor.get_module(BlockingManager.IDENTITY).is_blocked(conversation.account, conversation.counterpart);
|
||||||
|
Switch sw = new Switch() { active=is_blocked, valign=Align.CENTER, visible=true };
|
||||||
|
sw.state_set.connect((state) => {
|
||||||
|
if (state) {
|
||||||
|
stream_interactor.get_module(BlockingManager.IDENTITY).block(conversation.account, conversation.counterpart);
|
||||||
|
} else {
|
||||||
|
stream_interactor.get_module(BlockingManager.IDENTITY).unblock(conversation.account, conversation.counterpart);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
contact_details.add(_("Settings"), _("Block"), _("Communication and status updates in either direction are blocked"), sw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -42,6 +42,7 @@ public class Dialog : Gtk.Dialog {
|
||||||
|
|
||||||
Application app = GLib.Application.get_default() as Application;
|
Application app = GLib.Application.get_default() as Application;
|
||||||
app.plugin_registry.register_contact_details_entry(new SettingsProvider(stream_interactor));
|
app.plugin_registry.register_contact_details_entry(new SettingsProvider(stream_interactor));
|
||||||
|
app.plugin_registry.register_contact_details_entry(new BlockingProvider(stream_interactor));
|
||||||
app.plugin_registry.register_contact_details_entry(new MucConfigFormProvider(stream_interactor));
|
app.plugin_registry.register_contact_details_entry(new MucConfigFormProvider(stream_interactor));
|
||||||
|
|
||||||
foreach (Plugins.ContactDetailsProvider provider in app.plugin_registry.contact_details_entries) {
|
foreach (Plugins.ContactDetailsProvider provider in app.plugin_registry.contact_details_entries) {
|
||||||
|
|
|
@ -14,13 +14,15 @@ public class Module : XmppStreamModule, Iq.Handler {
|
||||||
public signal void unblock_all_received(XmppStream stream);
|
public signal void unblock_all_received(XmppStream stream);
|
||||||
|
|
||||||
public bool is_blocked(XmppStream stream, string jid) {
|
public bool is_blocked(XmppStream stream, string jid) {
|
||||||
return stream.get_flag(Flag.IDENTITY).blocklist.contains(jid);
|
foreach (string blocked in stream.get_flag(Flag.IDENTITY).blocklist) {
|
||||||
|
if (blocked.contains(jid)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool block(XmppStream stream, Gee.List<string> jids) {
|
public bool block(XmppStream stream, Gee.List<string> jids) {
|
||||||
// This would otherwise be a bad-request error.
|
if (jids.size == 0) return false; // This would otherwise be a bad-request error.
|
||||||
if (jids.size == 0)
|
|
||||||
return false;
|
|
||||||
StanzaNode block_node = new StanzaNode.build("block", NS_URI).add_self_xmlns();
|
StanzaNode block_node = new StanzaNode.build("block", NS_URI).add_self_xmlns();
|
||||||
fill_node_with_items(block_node, jids);
|
fill_node_with_items(block_node, jids);
|
||||||
Iq.Stanza iq = new Iq.Stanza.set(block_node);
|
Iq.Stanza iq = new Iq.Stanza.set(block_node);
|
||||||
|
@ -29,9 +31,8 @@ public class Module : XmppStreamModule, Iq.Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool unblock(XmppStream stream, Gee.List<string> jids) {
|
public bool unblock(XmppStream stream, Gee.List<string> jids) {
|
||||||
// This would otherwise unblock all blocked JIDs.
|
if (jids.size == 0) return false; // This would otherwise unblock all blocked JIDs.
|
||||||
if (jids.size == 0)
|
|
||||||
return false;
|
|
||||||
StanzaNode unblock_node = new StanzaNode.build("unblock", NS_URI).add_self_xmlns();
|
StanzaNode unblock_node = new StanzaNode.build("unblock", NS_URI).add_self_xmlns();
|
||||||
fill_node_with_items(unblock_node, jids);
|
fill_node_with_items(unblock_node, jids);
|
||||||
Iq.Stanza iq = new Iq.Stanza.set(unblock_node);
|
Iq.Stanza iq = new Iq.Stanza.set(unblock_node);
|
||||||
|
@ -45,6 +46,10 @@ public class Module : XmppStreamModule, Iq.Handler {
|
||||||
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, null);
|
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool is_supported(XmppStream stream) {
|
||||||
|
return stream.has_flag(Flag.IDENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
private void on_iq_get(XmppStream stream, Iq.Stanza iq) { }
|
private void on_iq_get(XmppStream stream, Iq.Stanza iq) { }
|
||||||
private void on_iq_set(XmppStream stream, Iq.Stanza iq) {
|
private void on_iq_set(XmppStream stream, Iq.Stanza iq) {
|
||||||
StanzaNode? block_node = iq.stanza.get_subnode("block", NS_URI);
|
StanzaNode? block_node = iq.stanza.get_subnode("block", NS_URI);
|
||||||
|
@ -81,7 +86,7 @@ public class Module : XmppStreamModule, Iq.Handler {
|
||||||
public override string get_id() { return IDENTITY.id; }
|
public override string get_id() { return IDENTITY.id; }
|
||||||
|
|
||||||
private void on_stream_negotiated(XmppStream stream) {
|
private void on_stream_negotiated(XmppStream stream) {
|
||||||
stream.get_module(Xep.ServiceDiscovery.Module.IDENTITY).request_info(stream, "jabberfr.org", (stream, info_result) => {
|
stream.get_module(Xep.ServiceDiscovery.Module.IDENTITY).request_info(stream, stream.remote_name, (stream, info_result) => {
|
||||||
if (info_result.features.contains(NS_URI)) {
|
if (info_result.features.contains(NS_URI)) {
|
||||||
stream.add_flag(new Flag());
|
stream.add_flag(new Flag());
|
||||||
get_blocklist(stream, (stream, jids) => {
|
get_blocklist(stream, (stream, jids) => {
|
||||||
|
@ -110,9 +115,10 @@ public class Module : XmppStreamModule, Iq.Handler {
|
||||||
Gee.List<string> jids = new ArrayList<string>();
|
Gee.List<string> jids = new ArrayList<string>();
|
||||||
foreach (StanzaNode item_node in item_nodes) {
|
foreach (StanzaNode item_node in item_nodes) {
|
||||||
string? jid = item_node.get_attribute("jid", NS_URI);
|
string? jid = item_node.get_attribute("jid", NS_URI);
|
||||||
if (jid != null)
|
if (jid != null) {
|
||||||
jids.add(jid);
|
jids.add(jid);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return jids;
|
return jids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue