/pidgin/main: 4951752ad038: Split PurpleMessage into incoming, o...

Tomasz Wasilczyk twasilczyk at pidgin.im
Fri May 23 03:20:51 EDT 2014


Changeset: 4951752ad038d087989c9975a28590bb4d18a2de
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-05-23 09:20 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/4951752ad038

Description:

Split PurpleMessage into incoming, outgoing and system

diffstat:

 finch/gntconv.c                                |    4 +-
 finch/gntpounce.c                              |    2 +-
 finch/gntsound.c                               |    2 +-
 libpurple/conversation.c                       |    6 +-
 libpurple/conversationtypes.c                  |   10 +-
 libpurple/message.c                            |  134 +++++++++++++++++-------
 libpurple/message.h                            |   18 ++-
 libpurple/plugins/offlinemsg.c                 |    6 +-
 libpurple/plugins/signals-test.c               |    4 +-
 libpurple/plugins/tcl/tcl_cmds.c               |   13 +-
 libpurple/protocols/bonjour/bonjour.c          |    4 +-
 libpurple/protocols/gg/message-prpl.c          |   12 +-
 libpurple/protocols/irc/cmds.c                 |   15 +-
 libpurple/protocols/irc/irc.c                  |    2 +-
 libpurple/protocols/jabber/jabber.c            |    2 +-
 libpurple/protocols/jabber/message.c           |   10 +-
 libpurple/protocols/msn/msn.c                  |   24 ++--
 libpurple/protocols/mxit/mxit.c                |    2 +-
 libpurple/protocols/novell/novell.c            |    2 +-
 libpurple/protocols/null/nullprpl.c            |    2 +-
 libpurple/protocols/oscar/oscar.c              |    2 +-
 libpurple/protocols/sametime/sametime.c        |    2 +-
 libpurple/protocols/silc/silc.c                |   28 ++--
 libpurple/protocols/simple/simple.c            |    2 +-
 libpurple/protocols/yahoo/libymsg.c            |   32 ++--
 libpurple/protocols/zephyr/zephyr.c            |    2 +-
 libpurple/server.c                             |   19 +--
 pidgin/gtkconv.c                               |    2 +-
 pidgin/gtkpounce.c                             |    2 +-
 pidgin/gtksound.c                              |    2 +-
 pidgin/plugins/musicmessaging/musicmessaging.c |    8 +-
 pidgin/plugins/notify.c                        |    2 +-
 32 files changed, 221 insertions(+), 156 deletions(-)

diffs (truncated from 1120 to 300 lines):

diff --git a/finch/gntconv.c b/finch/gntconv.c
--- a/finch/gntconv.c
+++ b/finch/gntconv.c
@@ -1093,7 +1093,7 @@ static void
 finch_write_chat(PurpleChatConversation *chat, PurpleMessage *msg)
 {
 	purple_conversation_write(PURPLE_CONVERSATION(chat),
-		purple_message_get_who(msg),
+		purple_message_get_author(msg),
 		purple_message_get_contents(msg),
 		purple_message_get_flags(msg),
 		purple_message_get_time(msg));
@@ -1105,7 +1105,7 @@ finch_write_im(PurpleIMConversation *im,
 	PurpleConversation *conv = PURPLE_CONVERSATION(im);
 	PurpleAccount *account = purple_conversation_get_account(conv);
 	PurpleMessageFlags flags = purple_message_get_flags(msg);
-	const gchar *who = purple_message_get_who(msg);
+	const gchar *who = purple_message_get_author(msg);
 
 	if (flags & PURPLE_MESSAGE_SEND)
 	{
diff --git a/finch/gntpounce.c b/finch/gntpounce.c
--- a/finch/gntpounce.c
+++ b/finch/gntpounce.c
@@ -875,7 +875,7 @@ pounce_cb(PurplePounce *pounce, PurplePo
 			if (im == NULL)
 				im = purple_im_conversation_new(account, pouncee);
 
-			pmsg = purple_message_new(pouncee, message, PURPLE_MESSAGE_SEND);
+			pmsg = purple_message_new_outgoing(pouncee, message, 0);
 			purple_serv_send_im(purple_account_get_connection(account), pmsg);
 			purple_conversation_write_message(PURPLE_CONVERSATION(im), pmsg);
 		}
diff --git a/finch/gntsound.c b/finch/gntsound.c
--- a/finch/gntsound.c
+++ b/finch/gntsound.c
@@ -208,7 +208,7 @@ im_msg_sent_cb(PurpleAccount *account, P
 	PurpleSoundEventID event)
 {
 	PurpleIMConversation *im = purple_conversations_find_im_with_account(
-		purple_message_get_who(msg), account);
+		purple_message_get_recipient(msg), account);
 	play_conv_event(PURPLE_CONVERSATION(im), event);
 }
 
diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -134,8 +134,8 @@ common_send(PurpleConversation *conv, co
 	msgflags |= PURPLE_MESSAGE_SEND;
 
 	if (PURPLE_IS_IM_CONVERSATION(conv)) {
-		msg = purple_message_new(purple_conversation_get_name(conv),
-			sent, msgflags);
+		msg = purple_message_new_outgoing(
+			purple_conversation_get_name(conv), sent, msgflags);
 
 		purple_signal_emit(purple_conversations_get_handle(), "sending-im-msg",
 			account, msg);
@@ -154,7 +154,7 @@ common_send(PurpleConversation *conv, co
 	else if (PURPLE_IS_CHAT_CONVERSATION(conv)) {
 		int id = purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION(conv));
 
-		msg = purple_message_new(NULL, sent, msgflags);
+		msg = purple_message_new_outgoing(NULL, sent, msgflags);
 
 		purple_signal_emit(purple_conversations_get_handle(),
 			"sending-chat-msg", account, msg, id);
diff --git a/libpurple/conversationtypes.c b/libpurple/conversationtypes.c
--- a/libpurple/conversationtypes.c
+++ b/libpurple/conversationtypes.c
@@ -357,13 +357,15 @@ im_conversation_write_message(PurpleConv
 {
 	PurpleConversationUiOps *ops;
 	PurpleIMConversation *im = PURPLE_IM_CONVERSATION(conv);
+	gboolean is_recv;
 
 	g_return_if_fail(im != NULL);
 	g_return_if_fail(msg != NULL);
 
 	ops = purple_conversation_get_ui_ops(conv);
+	is_recv = (purple_message_get_flags(msg) & PURPLE_MESSAGE_RECV);
 
-	if (purple_message_get_flags(msg) & PURPLE_MESSAGE_RECV)
+	if (is_recv)
 		purple_im_conversation_set_typing_state(im, PURPLE_IM_NOT_TYPING);
 
 	/* Pass this on to either the ops structure or the default write func. */
@@ -371,7 +373,7 @@ im_conversation_write_message(PurpleConv
 		ops->write_im(im, msg);
 	else {
 		purple_conversation_write(conv,
-			purple_message_get_who(msg),
+			purple_message_get_author(msg),
 			purple_message_get_contents(msg),
 			purple_message_get_flags(msg),
 			purple_message_get_time(msg));
@@ -812,7 +814,7 @@ chat_conversation_write_message(PurpleCo
 
 	/* Don't display this if the person who wrote it is ignored. */
 	if (purple_chat_conversation_is_ignored_user(
-		PURPLE_CHAT_CONVERSATION(conv), purple_message_get_who(msg)))
+		PURPLE_CHAT_CONVERSATION(conv), purple_message_get_author(msg)))
 	{
 		return;
 	}
@@ -840,7 +842,7 @@ chat_conversation_write_message(PurpleCo
 		ops->write_chat(PURPLE_CHAT_CONVERSATION(conv), msg);
 	else {
 		purple_conversation_write(conv,
-			purple_message_get_who(msg),
+			purple_message_get_author(msg),
 			purple_message_get_contents(msg),
 			purple_message_get_flags(msg),
 			purple_message_get_time(msg));
diff --git a/libpurple/message.c b/libpurple/message.c
--- a/libpurple/message.c
+++ b/libpurple/message.c
@@ -32,8 +32,9 @@
 
 typedef struct {
 	guint id;
-	gchar *who;
-	gchar *alias;
+	gchar *author;
+	gchar *author_alias;
+	gchar *recipient;
 	gchar *contents;
 	guint64 msgtime;
 	PurpleMessageFlags flags;
@@ -43,8 +44,9 @@ enum
 {
 	PROP_0,
 	PROP_ID,
-	PROP_WHO,
-	PROP_ALIAS,
+	PROP_AUTHOR,
+	PROP_AUTHOR_ALIAS,
+	PROP_RECIPIENT,
 	PROP_CONTENTS,
 	PROP_TIME,
 	PROP_FLAGS,
@@ -61,20 +63,57 @@ static GHashTable *messages = NULL;
  ******************************************************************************/
 
 PurpleMessage *
-purple_message_new(const gchar *who, const gchar *contents,
+purple_message_new_outgoing(const gchar *who, const gchar *contents,
 	PurpleMessageFlags flags)
 {
-	if (!(flags & (PURPLE_MESSAGE_SEND |
-		PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_SYSTEM)))
-	{
-		purple_debug_warning("message", "Invalid flags %#x", flags);
-	}
+	g_warn_if_fail(!(flags & PURPLE_MESSAGE_RECV));
+	g_warn_if_fail(!(flags & PURPLE_MESSAGE_SYSTEM));
+
+	flags |= PURPLE_MESSAGE_SEND;
+
+	/* who may be NULL for outgoing MUC messages */
+	return g_object_new(PURPLE_TYPE_MESSAGE,
+		"author-alias", _("Me"),
+		"recipient", who,
+		"contents", contents,
+		"time", (guint64)time(NULL),
+		"flags", flags,
+		NULL);
+}
+
+PurpleMessage *
+purple_message_new_incoming(const gchar *who, const gchar *contents,
+	PurpleMessageFlags flags, guint64 timestamp)
+{
+	g_warn_if_fail(!(flags & PURPLE_MESSAGE_SEND));
+	g_warn_if_fail(!(flags & PURPLE_MESSAGE_SYSTEM));
+
+	flags |= PURPLE_MESSAGE_RECV;
+
+	if (timestamp == 0)
+		timestamp = time(NULL);
 
 	return g_object_new(PURPLE_TYPE_MESSAGE,
-		"who", who,
+		"author", who,
+		"author-alias", who,
 		"contents", contents,
+		"time", timestamp,
 		"flags", flags,
+		NULL);
+}
+
+PurpleMessage *
+purple_message_new_system(const gchar *contents, PurpleMessageFlags flags)
+{
+	g_warn_if_fail(!(flags & PURPLE_MESSAGE_SEND));
+	g_warn_if_fail(!(flags & PURPLE_MESSAGE_RECV));
+
+	flags |= PURPLE_MESSAGE_SYSTEM;
+
+	return g_object_new(PURPLE_TYPE_MESSAGE,
+		"contents", contents,
 		"time", (guint64)time(NULL),
+		"flags", flags,
 		NULL);
 }
 
@@ -97,29 +136,39 @@ purple_message_find_by_id(guint id)
 }
 
 const gchar *
-purple_message_get_who(PurpleMessage *msg)
+purple_message_get_author(PurpleMessage *msg)
 {
 	PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg);
 
 	g_return_val_if_fail(priv != NULL, NULL);
 
-	return priv->who;
-}
-
-void
-purple_message_set_alias(PurpleMessage *msg, const gchar *alias)
-{
-	g_object_set(msg, "alias", alias, NULL);
+	return priv->author;
 }
 
 const gchar *
-purple_message_get_alias(PurpleMessage *msg)
+purple_message_get_recipient(PurpleMessage *msg)
 {
 	PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg);
 
 	g_return_val_if_fail(priv != NULL, NULL);
 
-	return priv->alias;
+	return priv->recipient;
+}
+
+void
+purple_message_set_author_alias(PurpleMessage *msg, const gchar *alias)
+{
+	g_object_set(msg, "author-alias", alias, NULL);
+}
+
+const gchar *
+purple_message_get_author_alias(PurpleMessage *msg)
+{
+	PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg);
+
+	g_return_val_if_fail(priv != NULL, NULL);
+
+	return priv->author_alias;
 }
 
 void
@@ -201,8 +250,9 @@ purple_message_finalize(GObject *obj)
 	PurpleMessage *message = PURPLE_MESSAGE(obj);
 	PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(message);
 
-	g_free(priv->who);
-	g_free(priv->alias);
+	g_free(priv->author);
+	g_free(priv->author_alias);
+	g_free(priv->recipient);
 	g_free(priv->contents);
 
 	G_OBJECT_CLASS(parent_class)->finalize(obj);
@@ -219,11 +269,14 @@ purple_message_get_property(GObject *obj
 		case PROP_ID:
 			g_value_set_uint(value, priv->id);
 			break;
-		case PROP_WHO:
-			g_value_set_string(value, priv->who);
+		case PROP_AUTHOR:
+			g_value_set_string(value, priv->author);
 			break;
-		case PROP_ALIAS:
-			g_value_set_string(value, priv->alias);
+		case PROP_AUTHOR_ALIAS:
+			g_value_set_string(value, priv->author_alias);
+			break;
+		case PROP_RECIPIENT:
+			g_value_set_string(value, priv->recipient);
 			break;
 		case PROP_CONTENTS:
 			g_value_set_string(value, priv->contents);
@@ -248,13 +301,17 @@ purple_message_set_property(GObject *obj
 	PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(message);
 
 	switch (par_id) {
-		case PROP_WHO:
-			g_free(priv->who);
-			priv->who = g_strdup(g_value_get_string(value));
+		case PROP_AUTHOR:
+			g_free(priv->author);
+			priv->author = g_strdup(g_value_get_string(value));
 			break;
-		case PROP_ALIAS:



More information about the Commits mailing list