pidgin: febb4e31: jabber: Add an "Initiate Chat" blist con...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Mon Oct 12 14:33:08 EDT 2009


-----------------------------------------------------------------
Revision: febb4e314c57a724a7f639f226ee40790dabc56c
Ancestor: e342d10b415f6261ea20d408d825bc2603dc2e66
Author: eion at robbmob.com
Date: 2009-10-12T17:36:12
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/febb4e314c57a724a7f639f226ee40790dabc56c

Modified files:
        ChangeLog libpurple/protocols/jabber/buddy.c
        libpurple/protocols/jabber/google.c
        libpurple/protocols/jabber/google.h

ChangeLog: 

jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.

Patch from Eion Robb with minor cleanup.  Closes #10413. Refs #3360.

-------------- next part --------------
============================================================
--- ChangeLog	adaf21fe344ffdc4bf30087a64ac30cdb3323baf
+++ ChangeLog	721beef75bff88db44c283ae6056838c88bbe5c9
@@ -2,6 +2,8 @@ version 2.6.3 (??/??/20??):
 
 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.
============================================================
--- libpurple/protocols/jabber/buddy.c	1172c8eb8ee1a015269056dfbdbabcdceccaa193
+++ libpurple/protocols/jabber/buddy.c	ffe60fdaf2eaf7ba230b59239c92080dc7ba9392
@@ -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 @@ static GList *jabber_buddy_menu(PurpleBu
 		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
 	 *
============================================================
--- libpurple/protocols/jabber/google.c	5c0ce14647fde25a1bc8d119a58de540af020aae
+++ libpurple/protocols/jabber/google.c	a1f6f23d223d8571e39ede2b5c86898d94c3954d
@@ -31,6 +31,7 @@
 #include "jabber.h"
 #include "presence.h"
 #include "iq.h"
+#include "chat.h"
 
 #include "jingle/jingle.h"
 
@@ -1425,3 +1426,53 @@ jabber_google_send_jingle_info(JabberStr
 	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);
+}
============================================================
--- libpurple/protocols/jabber/google.h	7c3fbd371479a0b8cd7ab1661dc925d1d84fd8c8
+++ libpurple/protocols/jabber/google.h	16ab49c5168cf8b70727bb35227825ddb7c0d5f1
@@ -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 @@ void jabber_google_send_jingle_info(Jabb
                                       xmlnode *child);
 void jabber_google_send_jingle_info(JabberStream *js);
 
+void google_buddy_node_chat(PurpleBlistNode *node, gpointer data);
+
 #endif   /* PURPLE_JABBER_GOOGLE_H_ */


More information about the Commits mailing list