/soc/2015/koosha/main: b82a143becf7: XEP-0308: update receiving ...

Koosha Khajehmoogahi koosha at posteo.de
Mon Jun 29 20:43:59 EDT 2015


Changeset: b82a143becf73ea7ce09ab9d0c1158acdd0bd09f
Author:	 Koosha Khajehmoogahi <koosha at posteo.de>
Date:	 2015-06-30 02:42 +0200
Branch:	 default
URL: https://hg.pidgin.im/soc/2015/koosha/main/rev/b82a143becf7

Description:

XEP-0308: update receiving side conversation window in Pidgin


The sending side is still missing

diffstat:

 libpurple/conversation.h             |  29 +++++++++++----------
 libpurple/protocols/jabber/jabber.c  |   1 +
 libpurple/protocols/jabber/message.c |  47 +++++++++++++++++++++++++++++------
 libpurple/protocols/jabber/message.h |   1 +
 pidgin/gtkconv.c                     |   4 +++
 5 files changed, 59 insertions(+), 23 deletions(-)

diffs (191 lines):

diff --git a/libpurple/conversation.h b/libpurple/conversation.h
--- a/libpurple/conversation.h
+++ b/libpurple/conversation.h
@@ -122,20 +122,21 @@ typedef enum
  */
 typedef enum /*< flags >*/
 {
-	PURPLE_MESSAGE_SEND        = 0x0001,
-	PURPLE_MESSAGE_RECV        = 0x0002,
-	PURPLE_MESSAGE_SYSTEM      = 0x0004,
-	PURPLE_MESSAGE_AUTO_RESP   = 0x0008,
-	PURPLE_MESSAGE_ACTIVE_ONLY = 0x0010,
-	PURPLE_MESSAGE_NICK        = 0x0020,
-	PURPLE_MESSAGE_NO_LOG      = 0x0040,
-	PURPLE_MESSAGE_ERROR       = 0x0200,
-	PURPLE_MESSAGE_DELAYED     = 0x0400,
-	PURPLE_MESSAGE_RAW         = 0x0800,
-	PURPLE_MESSAGE_IMAGES      = 0x1000,
-	PURPLE_MESSAGE_NOTIFY      = 0x2000,
-	PURPLE_MESSAGE_NO_LINKIFY  = 0x4000,
-	PURPLE_MESSAGE_INVISIBLE   = 0x8000
+	PURPLE_MESSAGE_SEND         = 1 << 0,
+	PURPLE_MESSAGE_RECV         = 1 << 1,
+	PURPLE_MESSAGE_SYSTEM       = 1 << 2,
+	PURPLE_MESSAGE_AUTO_RESP    = 1 << 3,
+	PURPLE_MESSAGE_ACTIVE_ONLY  = 1 << 4,
+	PURPLE_MESSAGE_NICK         = 1 << 5,
+	PURPLE_MESSAGE_NO_LOG       = 1 << 6,
+	PURPLE_MESSAGE_ERROR        = 1 << 7,
+	PURPLE_MESSAGE_DELAYED      = 1 << 8,
+	PURPLE_MESSAGE_RAW          = 1 << 9,
+	PURPLE_MESSAGE_IMAGES       = 1 << 10,
+	PURPLE_MESSAGE_NOTIFY       = 1 << 11,
+	PURPLE_MESSAGE_NO_LINKIFY   = 1 << 12,
+	PURPLE_MESSAGE_INVISIBLE    = 1 << 13,
+	PURPLE_MESSAGE_REPLACE_LAST = 1 << 14,
 } PurpleMessageFlags;
 
 #include <glib.h>
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
@@ -3237,6 +3237,7 @@ jabber_cmd_replace(PurpleConversation *c
 	}
 
 	msg = purple_xmlnode_new("message");
+	purple_xmlnode_set_attrib(msg, "type", "chat");
 
 	to = g_strdup_printf("%s/%s", username, jbr->name);
 	purple_xmlnode_set_attrib(msg, "to", to);
diff --git a/libpurple/protocols/jabber/message.c b/libpurple/protocols/jabber/message.c
--- a/libpurple/protocols/jabber/message.c
+++ b/libpurple/protocols/jabber/message.c
@@ -101,12 +101,28 @@ static void handle_receipt_request(Jabbe
 	jabber_message_send(response);
 }
 
+static GHashTable *last_recv_im_ids = NULL;
+static const char *jabber_get_last_recv_im_ids(JabberStream *js)
+{
+	const char *id;
+	if (!js)
+		return NULL;
+
+	if (!last_recv_im_ids)
+		last_recv_im_ids = g_hash_table_new(NULL, NULL);
+
+	id = (const char *)g_hash_table_lookup(last_recv_im_ids, js);
+	return id;
+}
+
+
 static void handle_chat(JabberMessage *jm)
 {
 	JabberID *jid = jabber_id_new(jm->from);
 
 	PurpleConnection *gc;
 	PurpleAccount *account;
+	PurpleMessageFlags flags;
 	JabberBuddy *jb;
 	JabberBuddyResource *jbr;
 
@@ -118,7 +134,7 @@ static void handle_chat(JabberMessage *j
 
 	jb = jabber_buddy_find(jm->js, jm->from, TRUE);
 	jbr = jabber_buddy_find_resource(jb, jid->resource);
-
+	flags = 0;
 	if(!jm->xhtml && !jm->body) {
 		if (jbr && jm->chat_state != JM_STATE_NONE)
 			jbr->chat_states = JABBER_CHAT_STATES_SUPPORTED;
@@ -195,15 +211,23 @@ static void handle_chat(JabberMessage *j
 			jbr->thread_id = g_strdup(jbr->thread_id);
 		}
 
+		if (last_recv_im_ids == NULL)
+			last_recv_im_ids = g_hash_table_new(NULL, NULL);
+
 		if (jm->receipt)
 			handle_receipt_request(jm);
 
+		if (jm->replace_last)
+			flags |= PURPLE_MESSAGE_REPLACE_LAST;
+		else
+			g_hash_table_insert(last_recv_im_ids, jm->js, g_strdup(jm->id));
+
 		if (jm->js->googletalk && jm->xhtml == NULL) {
 			char *tmp = jm->body;
 			jm->body = jabber_google_format_to_html(jm->body);
 			g_free(tmp);
 		}
-		purple_serv_got_im(gc, jm->from, jm->xhtml ? jm->xhtml : jm->body, 0, jm->sent);
+		purple_serv_got_im(gc, jm->from, jm->xhtml ? jm->xhtml : jm->body, flags, jm->sent);
 	}
 
 	jabber_id_free(jid);
@@ -796,6 +820,11 @@ void jabber_message_parse(JabberStream *
 			const char *msg_id = purple_xmlnode_get_attrib(child, "id");
 			if (msg_id)
 				remove_pending_receipt(jm);
+		} else if(!strcmp(child->name, "replace") && !strcmp(xmlns, NS_MSG_REPLACE)) {
+			const char *msg_id = purple_xmlnode_get_attrib(child, "id");
+			const char *last_id = jabber_get_last_recv_im_ids(jm->js);
+			if (msg_id && *msg_id && last_id && g_strcmp0(msg_id, last_id) == 0)
+				jm->replace_last = TRUE;
 		} else if(!strcmp(child->name, "delay") && !strcmp(xmlns, NS_DELAYED_DELIVERY)) {
 			const char *timestamp = purple_xmlnode_get_attrib(child, "stamp");
 			jm->delayed = TRUE;
@@ -1186,17 +1215,17 @@ jabber_xhtml_plain_equal(const char *xht
 	return ret;
 }
 
-static GHashTable *last_im_ids = NULL;
+static GHashTable *last_sent_im_ids = NULL;
 const char *jabber_get_last_sent_im_id(JabberStream *js)
 {
 	const char *id;
 	if (!js)
 		return NULL;
 
-	if (!last_im_ids)
-		last_im_ids = g_hash_table_new(NULL, NULL);
+	if (!last_sent_im_ids)
+		last_sent_im_ids = g_hash_table_new(NULL, NULL);
 
-	id = (const char *)g_hash_table_lookup(last_im_ids, js);
+	id = (const char *)g_hash_table_lookup(last_sent_im_ids, js);
 	return id;
 }
 
@@ -1260,12 +1289,12 @@ int jabber_message_send_im(PurpleConnect
 			jm->xhtml = g_strdup_printf("<html xmlns='" NS_XHTML_IM "'><body xmlns='" NS_XHTML "'><p>%s</p></body></html>", xhtml);
 	}
 
-	if (!last_im_ids)
-		last_im_ids = g_hash_table_new_full(NULL, NULL, NULL, g_free);
+	if (!last_sent_im_ids)
+		last_sent_im_ids = g_hash_table_new_full(NULL, NULL, NULL, g_free);
 
 	g_free(xhtml);
 
-	g_hash_table_insert(last_im_ids, jm->js, g_strdup(jm->id));
+	g_hash_table_insert(last_sent_im_ids, jm->js, g_strdup(jm->id));
 	jabber_message_send(jm);
 	jabber_message_free(jm);
 	return 1;
diff --git a/libpurple/protocols/jabber/message.h b/libpurple/protocols/jabber/message.h
--- a/libpurple/protocols/jabber/message.h
+++ b/libpurple/protocols/jabber/message.h
@@ -44,6 +44,7 @@ typedef struct _JabberMessage {
 	gboolean delayed;
 	gboolean hasBuzz;
 	gboolean receipt;
+	gboolean replace_last;
 	char *id;
 	char *from;
 	char *to;
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -6792,6 +6792,10 @@ pidgin_conv_write_conv(PurpleConversatio
 		message_html = pidgin_conversation_theme_get_template(gtkconv->theme,
 			PIDGIN_CONVERSATION_THEME_TEMPLATE_STATUS);
 	}
+
+	if (flags & PURPLE_MESSAGE_REPLACE_LAST)
+		func = "replaceLastMessage";
+
 	gtkconv->last_flags = flags;
 	gtkconv->last_conversed = conv;
 



More information about the Commits mailing list