about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-08-18 00:10:15 +0100
committerJames Booth <boothj5@gmail.com>2016-08-18 00:10:15 +0100
commit4de570b1ee34bad2e7565df6a426e497485a5708 (patch)
tree928fbaa7ff94457654862da284a532355fc5c48c /src/xmpp
parent41acaee9558c4989bebdd99b3f3c577715db756c (diff)
downloadprofani-tty-4de570b1ee34bad2e7565df6a426e497485a5708.tar.gz
Only include receipts feature in disco responses when enabled
issue #829
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/capabilities.c42
-rw-r--r--src/xmpp/xmpp.h3
2 files changed, 44 insertions, 1 deletions
diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c
index f528e05c..17d60e36 100644
--- a/src/xmpp/capabilities.c
+++ b/src/xmpp/capabilities.c
@@ -54,8 +54,10 @@
 
 #include "common.h"
 #include "log.h"
+#include "event/client_events.h"
 #include "plugins/plugins.h"
 #include "config/files.h"
+#include "config/preferences.h"
 #include "xmpp/xmpp.h"
 #include "xmpp/stanza.h"
 #include "xmpp/form.h"
@@ -100,12 +102,50 @@ caps_init(void)
     g_hash_table_add(prof_features, strdup(STANZA_NS_VERSION));
     g_hash_table_add(prof_features, strdup(STANZA_NS_CHATSTATES));
     g_hash_table_add(prof_features, strdup(STANZA_NS_PING));
-    g_hash_table_add(prof_features, strdup(STANZA_NS_RECEIPTS));
+    if (prefs_get_boolean(PREF_RECEIPTS_SEND)) {
+        g_hash_table_add(prof_features, strdup(STANZA_NS_RECEIPTS));
+    }
     g_hash_table_add(prof_features, strdup(STANZA_NS_LASTACTIVITY));
 
     my_sha1 = NULL;
 }
 
+void
+caps_add_feature(char *feature)
+{
+    if (g_hash_table_contains(prof_features, feature)) {
+        return;
+    }
+
+    g_hash_table_add(prof_features, strdup(feature));
+
+    caps_reset_ver();
+
+    // resend presence to update server's disco info data for this client
+    if (connection_get_status() == JABBER_CONNECTED) {
+        resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name());
+        cl_ev_presence_send(last_presence, connection_get_presence_msg(), 0);
+    }
+}
+
+void
+caps_remove_feature(char *feature)
+{
+    if (!g_hash_table_contains(prof_features, feature)) {
+        return;
+    }
+
+    g_hash_table_remove(prof_features, feature);
+
+    caps_reset_ver();
+
+    // resend presence to update server's disco info data for this client
+    if (connection_get_status() == JABBER_CONNECTED) {
+        resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name());
+        cl_ev_presence_send(last_presence, connection_get_presence_msg(), 0);
+    }
+}
+
 GList*
 caps_get_features(void)
 {
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 93b02cb2..821abfd6 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -56,6 +56,7 @@
 #define JABBER_PRIORITY_MAX 127
 
 #define XMPP_FEATURE_BLOCKING "urn:xmpp:blocking"
+#define XMPP_FEATURE_RECEIPTS "urn:xmpp:receipts"
 
 typedef enum {
     JABBER_CONNECTING,
@@ -179,6 +180,8 @@ EntityCapabilities* caps_lookup(const char *const jid);
 void caps_close(void);
 void caps_destroy(EntityCapabilities *caps);
 void caps_reset_ver(void);
+void caps_add_feature(char *feature);
+void caps_remove_feature(char *feature);
 
 gboolean bookmark_add(const char *jid, const char *nick, const char *password, const char *autojoin_str);
 gboolean bookmark_update(const char *jid, const char *nick, const char *password, const char *autojoin_str);