/pidgin/main: 69b4fce85ffa: Switch _purple_conversation_write_co...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Thu Jun 12 12:45:29 EDT 2014
Changeset: 69b4fce85ffa00d737d5293df7660c351c3bffce
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-06-12 18:45 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/69b4fce85ffa
Description:
Switch _purple_conversation_write_common and (writing|wrote)-(chat|im)-msg to PurpleMessage
diffstat:
finch/plugins/gnttinyurl.c | 9 ++-
libpurple/conversation.c | 88 ++++++++++++++++++++---------------
libpurple/conversations.c | 22 +++-----
libpurple/conversationtypes.c | 27 ++++------
libpurple/internal.h | 11 +---
libpurple/message.c | 3 +
libpurple/plugins/signals-test.c | 14 ++--
libpurple/protocols/jabber/message.c | 2 +-
libpurple/server.c | 7 ++-
pidgin/gtkblist.c | 16 ++++--
pidgin/gtkconv.c | 11 +++-
11 files changed, 113 insertions(+), 97 deletions(-)
diffs (truncated from 467 to 300 lines):
diff --git a/finch/plugins/gnttinyurl.c b/finch/plugins/gnttinyurl.c
--- a/finch/plugins/gnttinyurl.c
+++ b/finch/plugins/gnttinyurl.c
@@ -297,13 +297,16 @@ static gboolean writing_msg(PurpleAccoun
return FALSE;
}
-static void wrote_msg(PurpleAccount *account, char *sender, char *message,
- PurpleConversation *conv, PurpleMessageFlags flags)
+static void wrote_msg(PurpleConversation *conv, PurpleMessage *pmsg,
+ gpointer _unused)
{
GList *urls;
+ if (purple_message_get_flags(pmsg) & PURPLE_MESSAGE_SEND)
+ return;
+
urls = g_object_get_data(G_OBJECT(conv), "TinyURLs");
- if ((flags & PURPLE_MESSAGE_SEND) || urls == NULL)
+ if (urls == NULL)
return;
process_urls(conv, urls);
diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -578,23 +578,19 @@ purple_conversation_close_logs(PurpleCon
}
void
-_purple_conversation_write_common(PurpleConversation *conv, const char *who,
- const char *message, PurpleMessageFlags flags,
- time_t mtime)
+_purple_conversation_write_common(PurpleConversation *conv, PurpleMessage *pmsg)
{
PurplePluginProtocolInfo *prpl_info = NULL;
PurpleConnection *gc = NULL;
PurpleAccount *account;
PurpleConversationUiOps *ops;
- const char *alias;
- char *displayed = NULL;
PurpleBuddy *b;
int plugin_return;
PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
/* int logging_font_options = 0; */
- g_return_if_fail(priv != NULL);
- g_return_if_fail(message != NULL);
+ g_return_if_fail(priv != NULL);
+ g_return_if_fail(pmsg != NULL);
ops = purple_conversation_get_ui_ops(conv);
@@ -611,25 +607,16 @@ void
!g_list_find(purple_conversations_get_all(), conv))
return;
- displayed = g_strdup(message);
+ 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));
- if (who == NULL || *who == '\0')
- who = purple_conversation_get_name(conv);
- alias = who;
-
- 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"),
- account, who, &displayed, conv, flags));
-
- if (displayed == NULL)
+ if (purple_message_is_empty(pmsg))
return;
- if (plugin_return) {
- g_free(displayed);
+ if (plugin_return)
return;
- }
if (account != NULL) {
prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_find_prpl(purple_account_get_protocol_id(account)));
@@ -637,49 +624,72 @@ void
if (PURPLE_IS_IM_CONVERSATION(conv) ||
!(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) {
- if (flags & PURPLE_MESSAGE_SEND) {
+ if (purple_message_get_flags(pmsg) & PURPLE_MESSAGE_SEND) {
+ const gchar *alias;
+
b = purple_blist_find_buddy(account,
- purple_account_get_username(account));
+ purple_account_get_username(account));
if (purple_account_get_private_alias(account) != NULL)
alias = purple_account_get_private_alias(account);
- else if (b != NULL && !purple_strequal(purple_buddy_get_name(b), purple_buddy_get_contact_alias(b)))
+ else if (b != NULL && !purple_strequal(purple_buddy_get_name(b),
+ purple_buddy_get_contact_alias(b)))
+ {
alias = purple_buddy_get_contact_alias(b);
- else if (purple_connection_get_display_name(gc) != NULL)
+ } else if (purple_connection_get_display_name(gc) != NULL)
alias = purple_connection_get_display_name(gc);
else
alias = purple_account_get_username(account);
+
+ purple_message_set_author_alias(pmsg, alias);
}
else
{
- b = purple_blist_find_buddy(account, who);
+ /* TODO: PurpleDude - folks not on the buddy list */
+ b = purple_blist_find_buddy(account,
+ purple_message_get_author(pmsg));
- if (b != NULL)
- alias = purple_buddy_get_contact_alias(b);
+ if (b != NULL) {
+ purple_message_set_author_alias(pmsg,
+ purple_buddy_get_contact_alias(b));
+ }
}
}
}
- if (!(flags & PURPLE_MESSAGE_NO_LOG) && purple_conversation_is_logging(conv)) {
+ if (!(purple_message_get_flags(pmsg) & PURPLE_MESSAGE_NO_LOG) && purple_conversation_is_logging(conv)) {
GList *log;
log = priv->logs;
while (log != NULL) {
- purple_log_write((PurpleLog *)log->data, flags, alias, mtime, displayed);
+ 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));
log = log->next;
}
}
- if (ops && ops->write_conv)
- ops->write_conv(conv, who, alias, displayed, flags, mtime);
+ if (ops && ops->write_conv) {
+ ops->write_conv(conv,
+ (purple_message_get_flags(pmsg) & PURPLE_MESSAGE_SEND) ? purple_message_get_recipient(pmsg) : purple_message_get_author(pmsg),
+ purple_message_get_author_alias(pmsg),
+ purple_message_get_contents(pmsg),
+ purple_message_get_flags(pmsg),
+ purple_message_get_time(pmsg));
+ }
- add_message_to_history(conv, who, alias, message, flags, mtime);
+ add_message_to_history(conv,
+ (purple_message_get_flags(pmsg) & PURPLE_MESSAGE_SEND) ? purple_message_get_recipient(pmsg) : purple_message_get_author(pmsg),
+ purple_message_get_author_alias(pmsg),
+ purple_message_get_contents(pmsg),
+ purple_message_get_flags(pmsg),
+ purple_message_get_time(pmsg));
purple_signal_emit(purple_conversations_get_handle(),
(PURPLE_IS_IM_CONVERSATION(conv) ? "wrote-im-msg" : "wrote-chat-msg"),
- account, who, displayed, conv, flags);
-
- g_free(displayed);
+ conv, pmsg);
}
void
@@ -698,8 +708,8 @@ purple_conversation_write_message(Purple
void purple_conversation_write_system_message(PurpleConversation *conv,
const gchar *message, PurpleMessageFlags flags)
{
- _purple_conversation_write_common(conv, NULL, message,
- flags | PURPLE_MESSAGE_SYSTEM, time(NULL));
+ _purple_conversation_write_common(conv,
+ purple_message_new_system(message, flags));
}
void
diff --git a/libpurple/conversations.c b/libpurple/conversations.c
--- a/libpurple/conversations.c
+++ b/libpurple/conversations.c
@@ -284,15 +284,12 @@ purple_conversations_init(void)
* Register signals
**********************************************************************/
purple_signal_register(handle, "writing-im-msg",
- purple_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER_UINT,
- G_TYPE_BOOLEAN, 5, PURPLE_TYPE_ACCOUNT, G_TYPE_STRING,
- G_TYPE_POINTER, /* pointer to a string */
- PURPLE_TYPE_IM_CONVERSATION, G_TYPE_UINT);
+ purple_marshal_BOOLEAN__POINTER_POINTER, G_TYPE_BOOLEAN, 2,
+ PURPLE_TYPE_IM_CONVERSATION, PURPLE_TYPE_MESSAGE);
purple_signal_register(handle, "wrote-im-msg",
- purple_marshal_VOID__POINTER_POINTER_POINTER_POINTER_UINT,
- G_TYPE_NONE, 5, PURPLE_TYPE_ACCOUNT, G_TYPE_STRING,
- G_TYPE_STRING, PURPLE_TYPE_IM_CONVERSATION, G_TYPE_UINT);
+ purple_marshal_VOID__POINTER_POINTER, G_TYPE_NONE, 2,
+ PURPLE_TYPE_IM_CONVERSATION, PURPLE_TYPE_MESSAGE);
purple_signal_register(handle, "sent-attention",
purple_marshal_VOID__POINTER_POINTER_POINTER_UINT,
@@ -331,15 +328,12 @@ purple_conversations_init(void)
G_TYPE_STRING, G_TYPE_UINT, G_TYPE_UINT);
purple_signal_register(handle, "writing-chat-msg",
- purple_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER_UINT,
- G_TYPE_BOOLEAN, 5, PURPLE_TYPE_ACCOUNT, G_TYPE_STRING,
- G_TYPE_POINTER, /* pointer to a string */
- PURPLE_TYPE_CHAT_CONVERSATION, G_TYPE_UINT);
+ purple_marshal_BOOLEAN__POINTER_POINTER, G_TYPE_BOOLEAN, 2,
+ PURPLE_TYPE_IM_CONVERSATION, PURPLE_TYPE_MESSAGE);
purple_signal_register(handle, "wrote-chat-msg",
- purple_marshal_VOID__POINTER_POINTER_POINTER_POINTER_UINT,
- G_TYPE_NONE, 5, PURPLE_TYPE_ACCOUNT, G_TYPE_STRING,
- G_TYPE_STRING, PURPLE_TYPE_CHAT_CONVERSATION, G_TYPE_UINT);
+ purple_marshal_VOID__POINTER_POINTER, G_TYPE_NONE, 2,
+ PURPLE_TYPE_IM_CONVERSATION, PURPLE_TYPE_MESSAGE);
purple_signal_register(handle, "sending-chat-msg",
purple_marshal_VOID__POINTER_POINTER_UINT, G_TYPE_NONE,
diff --git a/libpurple/conversationtypes.c b/libpurple/conversationtypes.c
--- a/libpurple/conversationtypes.c
+++ b/libpurple/conversationtypes.c
@@ -55,6 +55,8 @@ struct _PurpleChatConversationPrivate
char *nick; /* Your nick in this chat. */
gboolean left; /* We left the chat and kept the window open */
GHashTable *users; /* Hash table of the users in the room. */
+
+ gboolean is_finalizing; /* The object is being destroyed. */
};
/* Chat Property enums */
@@ -371,13 +373,8 @@ im_conversation_write_message(PurpleConv
/* Pass this on to either the ops structure or the default write func. */
if (ops != NULL && ops->write_im != NULL)
ops->write_im(im, msg);
- else {
- _purple_conversation_write_common(conv,
- purple_message_get_author(msg),
- purple_message_get_contents(msg),
- purple_message_get_flags(msg),
- purple_message_get_time(msg));
- }
+ else
+ _purple_conversation_write_common(conv, msg);
}
/**************************************************************************
@@ -813,7 +810,7 @@ chat_conversation_write_message(PurpleCo
g_return_if_fail(msg != NULL);
/* Don't display this if the person who wrote it is ignored. */
- if (purple_chat_conversation_is_ignored_user(
+ if (purple_message_get_author(msg) && purple_chat_conversation_is_ignored_user(
PURPLE_CHAT_CONVERSATION(conv), purple_message_get_author(msg)))
{
return;
@@ -840,13 +837,8 @@ chat_conversation_write_message(PurpleCo
/* Pass this on to either the ops structure or the default write func. */
if (ops != NULL && ops->write_chat != NULL)
ops->write_chat(PURPLE_CHAT_CONVERSATION(conv), msg);
- else {
- _purple_conversation_write_common(conv,
- purple_message_get_author(msg),
- purple_message_get_contents(msg),
- purple_message_get_flags(msg),
- purple_message_get_time(msg));
- }
+ else
+ _purple_conversation_write_common(conv, msg);
}
void
@@ -1299,7 +1291,8 @@ purple_chat_conversation_leave(PurpleCha
priv->left = TRUE;
- g_object_notify_by_pspec(G_OBJECT(chat), chat_properties[CHAT_PROP_LEFT]);
+ if (!priv->is_finalizing)
+ g_object_notify_by_pspec(G_OBJECT(chat), chat_properties[CHAT_PROP_LEFT]);
purple_conversation_update(PURPLE_CONVERSATION(chat), PURPLE_CONVERSATION_UPDATE_CHATLEFT);
}
@@ -1474,6 +1467,8 @@ purple_chat_conversation_finalize(GObjec
PurpleConnection *gc = purple_conversation_get_connection(PURPLE_CONVERSATION(chat));
PurpleChatConversationPrivate *priv = PURPLE_CHAT_CONVERSATION_GET_PRIVATE(chat);
+ priv->is_finalizing = TRUE;
+
if (gc != NULL)
{
/* Still connected */
diff --git a/libpurple/internal.h b/libpurple/internal.h
More information about the Commits
mailing list