aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-12-14 02:01:55 +0100
committerfiaxh <git@mx.ax.lt>2017-12-30 13:10:06 +0100
commitb4bb0912fc328bc44b13e190f59b347eb5d4310a (patch)
treea18f680f8349eb758dd54fd44321837bcd228545 /libdino
parentf25fadde2d6c9492b9cafe2cddbcc7b966942e47 (diff)
downloaddino-b4bb0912fc328bc44b13e190f59b347eb5d4310a.tar.gz
dino-b4bb0912fc328bc44b13e190f59b347eb5d4310a.zip
Show subscription request in conversation summary
Diffstat (limited to 'libdino')
-rw-r--r--libdino/src/application.vala13
-rw-r--r--libdino/src/service/presence_manager.vala25
2 files changed, 33 insertions, 5 deletions
diff --git a/libdino/src/application.vala b/libdino/src/application.vala
index 55913a99..f6e651a4 100644
--- a/libdino/src/application.vala
+++ b/libdino/src/application.vala
@@ -38,6 +38,8 @@ public interface Dino.Application : GLib.Application {
ChatInteraction.start(stream_interactor);
FileManager.start(stream_interactor, db);
+ create_actions();
+
activate.connect(() => {
stream_interactor.connection_manager.log_options = print_xmpp;
Idle.add(() => {
@@ -93,6 +95,17 @@ public interface Dino.Application : GLib.Application {
return (Dino.Application) GLib.Application.get_default();
}
+ public void create_actions() {
+ SimpleAction accept_subscription_action = new SimpleAction("accept-subscription", VariantType.INT32);
+ accept_subscription_action.activate.connect((variant) => {
+ Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32());
+ if (conversation == null) return;
+ stream_interactor.get_module(PresenceManager.IDENTITY).approve_subscription(conversation.account, conversation.counterpart);
+ stream_interactor.get_module(PresenceManager.IDENTITY).request_subscription(conversation.account, conversation.counterpart);
+ });
+ add_action(accept_subscription_action);
+ }
+
protected void add_connection(Account account) {
stream_interactor.connect(account);
}
diff --git a/libdino/src/service/presence_manager.vala b/libdino/src/service/presence_manager.vala
index 298fa234..7e74f125 100644
--- a/libdino/src/service/presence_manager.vala
+++ b/libdino/src/service/presence_manager.vala
@@ -14,6 +14,7 @@ public class PresenceManager : StreamInteractionModule, Object {
private StreamInteractor stream_interactor;
private HashMap<Jid, HashMap<Jid, ArrayList<Show>>> shows = new HashMap<Jid, HashMap<Jid, ArrayList<Show>>>(Jid.hash_bare_func, Jid.equals_bare_func);
private HashMap<Jid, ArrayList<Jid>> resources = new HashMap<Jid, ArrayList<Jid>>(Jid.hash_bare_func, Jid.equals_bare_func);
+ private Gee.List<Jid> subscription_requests = new ArrayList<Jid>(Jid.equals_func);
public static void start(StreamInteractor stream_interactor) {
PresenceManager m = new PresenceManager(stream_interactor);
@@ -59,6 +60,10 @@ public class PresenceManager : StreamInteractionModule, Object {
return null;
}
+ public bool exists_subscription_request(Account account, Jid jid) {
+ return subscription_requests.contains(jid);
+ }
+
public void request_subscription(Account account, Jid jid) {
Core.XmppStream stream = stream_interactor.get_stream(account);
if (stream != null) stream.get_module(Xmpp.Presence.Module.IDENTITY).request_subscription(stream, jid.bare_jid.to_string());
@@ -66,12 +71,18 @@ public class PresenceManager : StreamInteractionModule, Object {
public void approve_subscription(Account account, Jid jid) {
Core.XmppStream stream = stream_interactor.get_stream(account);
- if (stream != null) stream.get_module(Xmpp.Presence.Module.IDENTITY).approve_subscription(stream, jid.bare_jid.to_string());
+ if (stream != null) {
+ stream.get_module(Xmpp.Presence.Module.IDENTITY).approve_subscription(stream, jid.bare_jid.to_string());
+ subscription_requests.remove(jid);
+ }
}
public void deny_subscription(Account account, Jid jid) {
Core.XmppStream stream = stream_interactor.get_stream(account);
- if (stream != null) stream.get_module(Xmpp.Presence.Module.IDENTITY).deny_subscription(stream, jid.bare_jid.to_string());
+ if (stream != null) {
+ stream.get_module(Xmpp.Presence.Module.IDENTITY).deny_subscription(stream, jid.bare_jid.to_string());
+ subscription_requests.remove(jid);
+ }
}
public void cancel_subscription(Account account, Jid jid) {
@@ -86,9 +97,13 @@ public class PresenceManager : StreamInteractionModule, Object {
stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_unavailable.connect((stream, presence) =>
on_received_unavailable(account, new Jid(presence.from))
);
- stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_subscription_request.connect((stream, jid) =>
- received_subscription_request(new Jid(jid), account)
- );
+ stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_subscription_request.connect((stream, jid_str) => {
+ Jid jid = new Jid(jid_str);
+ if (!subscription_requests.contains(jid)) {
+ subscription_requests.add(jid);
+ }
+ received_subscription_request(jid, account);
+ });
}
private void on_received_available_show(Account account, Jid jid, string show) {