/soc/2015/koosha/main: e0b121d88637: XEP-0280: add a protocol ac...

Koosha Khajehmoogahi koosha at posteo.de
Fri Jul 31 14:51:51 EDT 2015


Changeset: e0b121d88637537a9a88b5ee5c59dfd572abb208
Author:	 Koosha Khajehmoogahi <koosha at posteo.de>
Date:	 2015-07-31 20:50 +0200
Branch:	 default
URL: https://hg.pidgin.im/soc/2015/koosha/main/rev/e0b121d88637

Description:

XEP-0280: add a protocol action for enabling/disabling carbons

diffstat:

 libpurple/protocols/jabber/disco.c  |  10 ++++++++++
 libpurple/protocols/jabber/jabber.c |  24 +++++++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletions(-)

diffs (68 lines):

diff --git a/libpurple/protocols/jabber/disco.c b/libpurple/protocols/jabber/disco.c
--- a/libpurple/protocols/jabber/disco.c
+++ b/libpurple/protocols/jabber/disco.c
@@ -390,6 +390,16 @@ jabber_disco_finish_server_info_result_c
 		jabber_request_block_list(js);
 	}
 
+	/* If the server supports message carbons and the user pref is set to use them, ask the server to handle them */
+	if ((js->server_caps & JABBER_CAP_CARBONS) &&
+			purple_account_get_bool(purple_connection_get_account(js->gc), "carbons", FALSE))
+	{
+		JabberIq *iq    = jabber_iq_new(js, JABBER_IQ_SET);
+		PurpleXmlNode *enable = purple_xmlnode_new_child(iq->node, "enable");
+		purple_xmlnode_set_namespace(enable, NS_CARBONS);
+		jabber_iq_send(iq);
+	}
+
 	/* If there are manually specified bytestream proxies, query them */
 	ft_proxies = purple_account_get_string(purple_connection_get_account(js->gc), "ft_proxies", NULL);
 	if (ft_proxies) {
diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -2566,6 +2566,21 @@ static void jabber_password_change(Purpl
 			purple_request_cpar_from_connection(gc), js);
 }
 
+static void jabber_toggle_carbons(PurpleProtocolAction *action)
+{
+	PurpleConnection *gc   = (PurpleConnection *) action->connection;
+	PurpleAccount *account = purple_connection_get_account(gc);
+	JabberStream *js       = purple_connection_get_protocol_data(gc);
+	JabberIq *iq           = jabber_iq_new(js, JABBER_IQ_SET);
+	gboolean has_carbons   = purple_account_get_bool(account, "carbons", FALSE);
+	PurpleXmlNode *value   = purple_xmlnode_new_child(iq->node, has_carbons ? "disable" : "enable");
+	purple_xmlnode_set_namespace(value, NS_CARBONS);
+	jabber_iq_send(iq);
+	purple_account_set_bool(account, "carbons", !has_carbons);
+	/* Reload account actions */
+	purple_protocol_got_account_actions(account);
+}
+
 GList *jabber_get_actions(PurpleConnection *gc)
 {
 	JabberStream *js = purple_connection_get_protocol_data(gc);
@@ -2586,7 +2601,7 @@ GList *jabber_get_actions(PurpleConnecti
 	                             jabber_user_search_begin);
 	m = g_list_append(m, act);
 
-	purple_debug_info("jabber", "jabber_get_actions: have pep: %s\n", js->pep?"YES":"NO");
+	purple_debug_info("jabber", "jabber_get_actions: have pep: %s\n", js->pep? "YES" : "NO");
 
 	if(js->pep)
 		jabber_pep_init_actions(&m);
@@ -2594,6 +2609,13 @@ GList *jabber_get_actions(PurpleConnecti
 	if(js->commands)
 		jabber_adhoc_init_server_commands(js, &m);
 
+	if (js->server_caps & JABBER_CAP_CARBONS) {
+		gboolean has_carbons = purple_account_get_bool(purple_connection_get_account(gc), "carbons", FALSE);
+		act = purple_protocol_action_new(has_carbons ? _("Disable Message Carbons") :
+							       _("Enable Message Carbons") , jabber_toggle_carbons);
+		m = g_list_append(m, act);
+	}
+
 	return m;
 }
 



More information about the Commits mailing list