changeset 28371:51d507e6c8f3

jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts. Patch from Eion Robb with minor cleanup. Closes #10413. Refs #3360. committer: Paul Aurich <paul@darkrain42.org>
author eion@robbmob.com
date Mon, 12 Oct 2009 17:36:12 +0000
parents 4a917f91bc05
children 724e77faee1a
files ChangeLog libpurple/protocols/jabber/buddy.c libpurple/protocols/jabber/google.c libpurple/protocols/jabber/google.h
diffstat 4 files changed, 65 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Oct 12 08:27:03 2009 +0000
+++ b/ChangeLog	Mon Oct 12 17:36:12 2009 +0000
@@ -2,6 +2,8 @@
 
 version 2.6.3 (??/??/20??):
 	XMPP:
+	* Users connecting to Google Talk now have an "Initiate Chat" context menu
+	  option for their buddies.  (Eion Robb)
 	* Fix a crash when attempting to validate an invalid JID.
 	* Resolve an issue when connecting to iChat Server when no resource
 	  is specified.
--- a/libpurple/protocols/jabber/buddy.c	Mon Oct 12 08:27:03 2009 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Mon Oct 12 17:36:12 2009 +0000
@@ -38,6 +38,7 @@
 #include "xdata.h"
 #include "pep.h"
 #include "adhoccommands.h"
+#include "google.h"
 
 typedef struct {
 	long idle_seconds;
@@ -1842,6 +1843,13 @@
 		m = g_list_append(m, act);
 	}
 
+	if (js->googletalk) {
+		act = purple_menu_action_new(_("Initiate _Chat"),
+		                           PURPLE_CALLBACK(google_buddy_node_chat),
+		                           NULL, NULL);
+		m = g_list_append(m, act);
+	}
+
 	/*
 	 * This if-condition implements parts of XEP-0100: Gateway Interaction
 	 *
--- a/libpurple/protocols/jabber/google.c	Mon Oct 12 08:27:03 2009 +0000
+++ b/libpurple/protocols/jabber/google.c	Mon Oct 12 17:36:12 2009 +0000
@@ -31,6 +31,7 @@
 #include "jabber.h"
 #include "presence.h"
 #include "iq.h"
+#include "chat.h"
 
 #include "jingle/jingle.h"
 
@@ -1425,3 +1426,53 @@
 	purple_debug_info("jabber", "sending google:jingleinfo query\n");
 	jabber_iq_send(jingle_info);
 }
+
+void google_buddy_node_chat(PurpleBlistNode *node, gpointer data)
+{
+	PurpleBuddy *buddy;
+	PurpleConnection *gc;
+	JabberStream *js;
+	JabberChat *jc;
+	GHashTable *chat_info;
+	gchar *chat_name;
+	gchar *uuid;
+	gchar *room;
+	guint32 tmp, a, b;
+
+	g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
+
+	buddy = PURPLE_BUDDY(node);
+	gc = purple_account_get_connection(purple_buddy_get_account(buddy));
+	js = purple_connection_get_protocol_data(gc);
+
+	tmp = g_random_int();
+	a = 0x4000 | (tmp & 0xFFF); /* 0x4000 to 0x4FFF */
+	tmp >>= 12;
+	b = ((1 << 3) << 12) | (tmp & 0x3FFF); /* 0x8000 to 0xBFFF */
+
+	tmp = g_random_int();
+	uuid = g_strdup_printf("%08x-%04x-%04x-%04x-%04x%08x",
+			g_random_int(),
+			tmp & 0xFFFF,
+			a,
+			b,
+			(tmp >> 16) & 0xFFFF, g_random_int());
+
+	room = g_strdup_printf("private-chat-%s", uuid);
+	chat_name = g_strdup_printf("%s@%s", room, GOOGLE_GROUPCHAT_SERVER);
+	chat_info = jabber_chat_info_defaults(gc, chat_name);
+	if (chat_info) {
+		jabber_chat_join(gc, chat_info);
+		jc = jabber_chat_find(js, room, GOOGLE_GROUPCHAT_SERVER);
+		if (jc)
+		{
+			jc->muc = TRUE;
+			jabber_chat_invite(gc, jc->id, "", buddy->name);
+		}
+		g_hash_table_destroy(chat_info);
+	}
+
+	g_free(room);
+	g_free(uuid);
+	g_free(chat_name);
+}
--- a/libpurple/protocols/jabber/google.h	Mon Oct 12 08:27:03 2009 +0000
+++ b/libpurple/protocols/jabber/google.h	Mon Oct 12 17:36:12 2009 +0000
@@ -31,6 +31,8 @@
 #define GOOGLE_VIDEO_CAP "http://www.google.com/xmpp/protocol/video/v1"
 #define GOOGLE_JINGLE_INFO_NAMESPACE "google:jingleinfo"
 
+#define GOOGLE_GROUPCHAT_SERVER "groupchat.google.com"
+
 void jabber_gmail_init(JabberStream *js);
 void jabber_gmail_poke(JabberStream *js, const char *from, JabberIqType type,
                        const char *id, xmlnode *new_mail);
@@ -59,4 +61,6 @@
                                       xmlnode *child);
 void jabber_google_send_jingle_info(JabberStream *js);
 
+void google_buddy_node_chat(PurpleBlistNode *node, gpointer data);
+
 #endif   /* PURPLE_JABBER_GOOGLE_H_ */