/soc/2015/igor.gajowiak/chatlog: 4343775d809a: Some fixes in mes...

Igor Gajowiak igor.gajowiak at gmail.com
Fri Aug 21 15:24:07 EDT 2015


Changeset: 4343775d809ac3a9cba1ab71a62d3bd023232bdb
Author:	 Igor Gajowiak <igor.gajowiak at gmail.com>
Date:	 2015-08-21 21:23 +0200
Branch:	 default
URL: https://hg.pidgin.im/soc/2015/igor.gajowiak/chatlog/rev/4343775d809a

Description:

Some fixes in message replacing feature.

diffstat:

 libpurple/conversation.c             |  56 ++++++++++++++++----------------
 libpurple/conversation.h             |  61 +++++++++++++++++++----------------
 libpurple/conversationtypes.c        |  10 +++--
 libpurple/internal.h                 |   5 +-
 libpurple/protocol.c                 |   7 ++-
 libpurple/protocol.h                 |  11 ++---
 libpurple/protocols/jabber/message.c |  51 +++++++++++++++++------------
 libpurple/protocols/jabber/message.h |   3 +-
 libpurple/server.c                   |  39 +++++++++++-----------
 libpurple/server.h                   |  41 ++++++++++++-----------
 pidgin/gtkconv.c                     |  36 +++++++++++---------
 pidgin/gtkconv.h                     |   2 +-
 pidgin/gtkwebview.c                  |   4 ++
 13 files changed, 177 insertions(+), 149 deletions(-)

diffs (truncated from 820 to 300 lines):

diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -669,8 +669,8 @@ void
 
 // TODO: Implemenatation copied from _purple_conversation_write_common, try to refactor
 void
-_purple_conversation_replace_common(PurpleConversation *conv, guint replaced_msg_id,
-									PurpleMessage *pmsg)
+_purple_conversation_replace_common(PurpleConversation *conv,
+	PurpleMessage *old_msg, PurpleMessage *new_msg)
 {
 	PurpleProtocol *protocol = NULL;
 	PurpleConnection *gc = NULL;
@@ -682,7 +682,7 @@ void
 	/* int logging_font_options = 0; */
 
 	g_return_if_fail(priv != NULL);
-	g_return_if_fail(pmsg != NULL);
+	g_return_if_fail(new_msg != NULL);
 
 	ops = purple_conversation_get_ui_ops(conv);
 
@@ -702,9 +702,9 @@ void
 	plugin_return = GPOINTER_TO_INT(purple_signal_emit_return_1(
 		purple_conversations_get_handle(),
 		(PURPLE_IS_IM_CONVERSATION(conv) ? "writing-im-msg" : "writing-chat-msg"),
-		conv, pmsg));
+		conv, new_msg));
 
-	if (purple_message_is_empty(pmsg))
+	if (purple_message_is_empty(new_msg))
 		return;
 
 	if (plugin_return)
@@ -716,7 +716,7 @@ void
 		if (PURPLE_IS_IM_CONVERSATION(conv) ||
 			!(purple_protocol_get_options(protocol) & OPT_PROTO_UNIQUE_CHATNAME)) {
 
-			if (purple_message_get_flags(pmsg) & PURPLE_MESSAGE_SEND) {
+			if (purple_message_get_flags(new_msg) & PURPLE_MESSAGE_SEND) {
 				const gchar *alias;
 
 				b = purple_blist_find_buddy(account,
@@ -733,51 +733,51 @@ void
 				else
 					alias = purple_account_get_username(account);
 
-				purple_message_set_author_alias(pmsg, alias);
+				purple_message_set_author_alias(new_msg, alias);
 			}
-			else if (purple_message_get_flags(pmsg) & PURPLE_MESSAGE_RECV)
+			else if (purple_message_get_flags(new_msg) & PURPLE_MESSAGE_RECV)
 			{
 				/* TODO: PurpleDude - folks not on the buddy list */
 				b = purple_blist_find_buddy(account,
-					purple_message_get_author(pmsg));
+					purple_message_get_author(new_msg));
 
 				if (b != NULL) {
-					purple_message_set_author_alias(pmsg,
+					purple_message_set_author_alias(new_msg,
 						purple_buddy_get_contact_alias(b));
 				}
 			}
 		}
 	}
 
-	if (!(purple_message_get_flags(pmsg) & PURPLE_MESSAGE_NO_LOG) && purple_conversation_is_logging(conv)) {
+	if (!(purple_message_get_flags(new_msg) & PURPLE_MESSAGE_NO_LOG) && purple_conversation_is_logging(conv)) {
 		GList *log;
 
 		log = priv->logs;
 		while (log != NULL) {
 			purple_log_write((PurpleLog *)log->data,
-				purple_message_get_flags(pmsg),
-				purple_message_get_author_alias(pmsg),
-				purple_message_get_time(pmsg),
-				purple_message_get_contents(pmsg));
+				purple_message_get_flags(new_msg),
+				purple_message_get_author_alias(new_msg),
+				purple_message_get_time(new_msg),
+				purple_message_get_contents(new_msg));
 			log = log->next;
 		}
 	}
 
 	if (ops) {
 		if (PURPLE_IS_CHAT_CONVERSATION(conv) && ops->replace_chat)
-			ops->replace_chat(PURPLE_CHAT_CONVERSATION(conv), replaced_msg_id, pmsg);
+			ops->replace_chat(PURPLE_CHAT_CONVERSATION(conv), old_msg, new_msg);
 		else if (PURPLE_IS_IM_CONVERSATION(conv) && ops->replace_im)
-			ops->replace_im(PURPLE_IM_CONVERSATION(conv), replaced_msg_id, pmsg);
+			ops->replace_im(PURPLE_IM_CONVERSATION(conv), old_msg, new_msg);
 		else if (ops->replace_conv)
-			ops->replace_conv(conv, replaced_msg_id, pmsg);
+			ops->replace_conv(conv, old_msg, new_msg);
 	}
 
 	// TODO: replace instead of add?
-	add_message_to_history(conv, pmsg);
+	add_message_to_history(conv, new_msg);
 
 	purple_signal_emit(purple_conversations_get_handle(),
 		(PURPLE_IS_IM_CONVERSATION(conv) ? "wrote-im-msg" : "wrote-chat-msg"),
-		conv, pmsg);
+		conv, new_msg);
 }
 
 static void
@@ -915,18 +915,18 @@ purple_conversation_write_message(Purple
 
 void
 purple_conversation_replace_message(PurpleConversation *conv,
-	guint replaced_msg_id, PurpleMessage *msg)
+	PurpleMessage *old_msg, PurpleMessage *new_msg)
 {
 	PurpleConversationClass *klass = NULL;
 
 	g_return_if_fail(PURPLE_IS_CONVERSATION(conv));
-	g_return_if_fail(replaced_msg_id != PURPLE_MESSAGE_ID_NONE);
-	g_return_if_fail(msg != NULL);
+	g_return_if_fail(old_msg != NULL);
+	g_return_if_fail(new_msg != NULL);
 
 	klass = PURPLE_CONVERSATION_GET_CLASS(conv);
 
 	if (klass && klass->replace_message)
-		klass->replace_message(conv, replaced_msg_id, msg);
+		klass->replace_message(conv, old_msg, new_msg);
 }
 
 static void
@@ -1012,11 +1012,11 @@ purple_conversation_send_with_flags(Purp
 
 void
 purple_conversation_send_replace_message_with_flags(
-	PurpleConversation *conv, guint replaced_msg_id,
+	PurpleConversation *conv, PurpleMessage *old_msg,
 	const char *new_message, PurpleMessageFlags flags)
 {
 	g_return_if_fail(PURPLE_IS_CONVERSATION(conv));
-	g_return_if_fail(replaced_msg_id != PURPLE_MESSAGE_ID_NONE);
+	g_return_if_fail(old_msg != NULL);
 	g_return_if_fail(new_message != NULL);
 
 	PurpleAccount *account;
@@ -1036,8 +1036,8 @@ purple_conversation_send_replace_message
 			purple_conversation_get_name(conv), new_message, flags);
 
 		// Replace message in conversation if sending succeeded
-		if (purple_serv_send_replace_im(gc, replaced_msg_id, msg))
-			purple_conversation_replace_message(conv, replaced_msg_id, msg);
+		if (purple_serv_send_replace_im(gc, old_msg, msg))
+			purple_conversation_replace_message(conv, old_msg, msg);
 
 		g_object_unref(G_OBJECT(msg));
 	}
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        = 0x00001,
+	PURPLE_MESSAGE_RECV        = 0x00002,
+	PURPLE_MESSAGE_SYSTEM      = 0x00004,
+	PURPLE_MESSAGE_AUTO_RESP   = 0x00008,
+	PURPLE_MESSAGE_ACTIVE_ONLY = 0x00010,
+	PURPLE_MESSAGE_NICK        = 0x00020,
+	PURPLE_MESSAGE_NO_LOG      = 0x00040,
+	PURPLE_MESSAGE_ERROR       = 0x00200,
+	PURPLE_MESSAGE_DELAYED     = 0x00400,
+	PURPLE_MESSAGE_RAW         = 0x00800,
+	PURPLE_MESSAGE_IMAGES      = 0x01000,
+	PURPLE_MESSAGE_NOTIFY      = 0x02000,
+	PURPLE_MESSAGE_NO_LINKIFY  = 0x04000,
+	PURPLE_MESSAGE_INVISIBLE   = 0x08000,
+	PURPLE_MESSAGE_REPLACABLE  = 0x10000
 } PurpleMessageFlags;
 
 #include <glib.h>
@@ -180,7 +181,8 @@ struct _PurpleConversationClass {
 
 	void (*write_message)(PurpleConversation *conv, PurpleMessage *msg);
 
-	void (*replace_message)(PurpleConversation *conv, guint replaced_msg_id, PurpleMessage *msg);
+	void (*replace_message)(PurpleConversation *conv, PurpleMessage *old_msg,
+		PurpleMessage *new_msg);
 
 	void (*prepend_message)(PurpleConversation *conv, PurpleMessage *msg);
 
@@ -256,9 +258,12 @@ struct _PurpleConversationUiOps
 	void (*write_im)(PurpleIMConversation *im, PurpleMessage *msg);
 	void (*write_conv)(PurpleConversation *conv, PurpleMessage *msg);
 
-	void (*replace_chat)(PurpleChatConversation *chat, guint replaced_msg_id, PurpleMessage *msg);
-	void (*replace_im)(PurpleIMConversation *im, guint replaced_msg_id, PurpleMessage *msg);
-	void (*replace_conv)(PurpleConversation *conv, guint replaced_msg_id, PurpleMessage *msg);
+	void (*replace_chat)(PurpleChatConversation *chat, PurpleMessage *old_msg,
+		PurpleMessage *new_msg);
+	void (*replace_im)(PurpleIMConversation *im, PurpleMessage *old_msg,
+		PurpleMessage *new_msg);
+	void (*replace_conv)(PurpleConversation *conv, PurpleMessage *old_msg,
+		PurpleMessage *new_msg);
 
 	void (*prepend_chat)(PurpleChatConversation *conv, PurpleMessage *msg);
 	void (*prepend_im)(PurpleIMConversation *conv, PurpleMessage *msg);
@@ -487,12 +492,12 @@ void purple_conversation_write_message(P
 
 /**
  * purple_conversation_replace_message:
- * @conv:            The conversation.
- * @replaced_msg_id: The id of purple message to be replaced
- * @msg:             The new message
+ * @conv:    The conversation.
+ * @old_msg: The old message.
+ * @new_msg: The new message.
  */
 void purple_conversation_replace_message(PurpleConversation *conv,
-	guint replaced_msg_id, PurpleMessage *msg);
+	PurpleMessage *old_msg, PurpleMessage *new_msg);
 
 /**
  * purple_conversation_load_older_msgs:
@@ -539,14 +544,14 @@ void purple_conversation_send_with_flags
 
 /**
  * purple_conversation_send_replace_message_with_flags:
- * @conv:            The conversation.
- * @replaced_msg_id: The id of the PurpleMessage to replace.
- * @new_message:     The new message data.
- * @flags:           The PurpleMessageFlags flags to use in addition to
- *                   PURPLE_MESSAGE_SEND.
+ * @conv:        The conversation.
+ * @old_msg:     The old message.
+ * @new_message: The new message data.
+ * @flags:       The PurpleMessageFlags flags to use in addition to
+ *               PURPLE_MESSAGE_SEND.
  */
 void purple_conversation_send_replace_message_with_flags(
-	PurpleConversation *conv, guint replaced_msg_id,
+	PurpleConversation *conv, PurpleMessage *old_msg,
 	const char *new_message, PurpleMessageFlags flags);
 
 /**
diff --git a/libpurple/conversationtypes.c b/libpurple/conversationtypes.c
--- a/libpurple/conversationtypes.c
+++ b/libpurple/conversationtypes.c
@@ -370,20 +370,22 @@ im_conversation_write_message(PurpleConv
 }
 
 static void
-im_conversation_replace_message(PurpleConversation *conv, guint replaced_msg_id, PurpleMessage *msg)
+im_conversation_replace_message(PurpleConversation *conv,
+	PurpleMessage *old_msg, PurpleMessage *new_msg)
 {
 	PurpleIMConversation *im = PURPLE_IM_CONVERSATION(conv);
 	gboolean is_recv;
 
 	g_return_if_fail(im != NULL);
-	g_return_if_fail(msg != NULL);
+	g_return_if_fail(old_msg != NULL);
+	g_return_if_fail(new_msg != NULL);
 
-	is_recv = (purple_message_get_flags(msg) & PURPLE_MESSAGE_RECV);
+	is_recv = (purple_message_get_flags(new_msg) & PURPLE_MESSAGE_RECV);
 
 	if (is_recv)
 		purple_im_conversation_set_typing_state(im, PURPLE_IM_NOT_TYPING);
 
-	_purple_conversation_replace_common(conv, replaced_msg_id, msg);
+	_purple_conversation_replace_common(conv, old_msg, new_msg);
 }
 
 static void
diff --git a/libpurple/internal.h b/libpurple/internal.h
--- a/libpurple/internal.h
+++ b/libpurple/internal.h
@@ -432,8 +432,9 @@ void
 _purple_conversation_write_common(PurpleConversation *conv, PurpleMessage *msg);
 
 void
-_purple_conversation_replace_common(PurpleConversation *conv, guint replaced_msg_id,
-									PurpleMessage *pmsg);



More information about the Commits mailing list