/pidgin/main: 4c386387f6f3: Switch purple_conversation_write_mes...
Tomasz Wasilczyk <[email protected]>
| Newsgroups | gmane.comp.gnome.gaim.cvs |
|---|---|
| Message-ID | <[email protected]> |
Changeset: 4c386387f6f31e48fc36e17d35830b12a26efa84 Author: Tomasz Wasilczyk <[email protected]> Date: 2014-05-22 20:20 +0200 Branch: default URL: https://hg.pidgin.im/pidgin/main/rev/4c386387f6f3 Description: Switch purple_conversation_write_message to PurpleMessage diffstat: finch/gntconv.c | 18 ++++-- libpurple/conversation.c | 9 +- libpurple/conversation.h | 16 +---- libpurple/conversationtypes.c | 69 ++++++++++++++------------ libpurple/message.c | 10 +++ libpurple/message.h | 3 + libpurple/plugins/offlinemsg.c | 5 +- libpurple/plugins/perl/common/Conversation.xs | 9 --- libpurple/plugins/tcl/tcl_cmds.c | 2 +- libpurple/protocols/irc/cmds.c | 14 +++-- libpurple/protocols/irc/msgs.c | 24 ++++---- libpurple/protocols/jabber/presence.c | 9 ++- libpurple/protocols/silc/ops.c | 26 ++++----- libpurple/protocols/silc/silc.c | 18 +++--- libpurple/server.c | 16 +++-- pidgin/gtkconv.c | 9 +- 16 files changed, 137 insertions(+), 120 deletions(-) diffs (truncated from 670 to 300 lines): diff --git a/finch/gntconv.c b/finch/gntconv.c --- a/finch/gntconv.c +++ b/finch/gntconv.c @@ -1083,18 +1083,23 @@ finch_write_common(PurpleConversation *c } static void -finch_write_chat(PurpleChatConversation *chat, const char *who, const char *message, - PurpleMessageFlags flags, time_t mtime) +finch_write_chat(PurpleChatConversation *chat, PurpleMessage *msg) { - purple_conversation_write(PURPLE_CONVERSATION(chat), who, message, flags, mtime); + purple_conversation_write(PURPLE_CONVERSATION(chat), + purple_message_get_who(msg), + purple_message_get_contents(msg), + purple_message_get_flags(msg), + purple_message_get_time(msg)); } static void -finch_write_im(PurpleIMConversation *im, const char *who, const char *message, - PurpleMessageFlags flags, time_t mtime) +finch_write_im(PurpleIMConversation *im, PurpleMessage *msg) { 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); + if (flags & PURPLE_MESSAGE_SEND) { who = purple_connection_get_display_name(purple_account_get_connection(account)); @@ -1112,7 +1117,8 @@ finch_write_im(PurpleIMConversation *im, who = purple_buddy_get_contact_alias(buddy); } - purple_conversation_write(conv, who, message, flags, mtime); + purple_conversation_write(conv, who, purple_message_get_contents(msg), + flags, purple_message_get_time(msg)); } static void diff --git a/libpurple/conversation.c b/libpurple/conversation.c --- a/libpurple/conversation.c +++ b/libpurple/conversation.c @@ -144,8 +144,8 @@ common_send(PurpleConversation *conv, co err = purple_serv_send_im(gc, msg); - if ((err > 0) && (displayed != NULL)) /* TODO: use msg! */ - purple_conversation_write_message(conv, NULL, displayed, msgflags, time(NULL)); + if ((err > 0) && (displayed != NULL)) + purple_conversation_write_message(conv, msg); purple_signal_emit(purple_conversations_get_handle(), "sent-im-msg", account, msg); @@ -683,8 +683,7 @@ purple_conversation_write(PurpleConversa } void -purple_conversation_write_message(PurpleConversation *conv, const char *who, - const char *message, PurpleMessageFlags flags, time_t mtime) +purple_conversation_write_message(PurpleConversation *conv, PurpleMessage *msg) { PurpleConversationClass *klass = NULL; @@ -693,7 +692,7 @@ purple_conversation_write_message(Purple klass = PURPLE_CONVERSATION_GET_CLASS(conv); if (klass && klass->write_message) - klass->write_message(conv, who, message, flags, mtime); + klass->write_message(conv, msg); } void purple_conversation_write_system_message(PurpleConversation *conv, diff --git a/libpurple/conversation.h b/libpurple/conversation.h --- a/libpurple/conversation.h +++ b/libpurple/conversation.h @@ -142,6 +142,7 @@ typedef enum /*< flags >*/ #include <glib.h> #include <glib-object.h> +#include "message.h" /**************************************************************************/ /** PurpleConversation */ @@ -179,8 +180,7 @@ struct _PurpleConversation struct _PurpleConversationClass { GObjectClass parent_class; - void (*write_message)(PurpleConversation *conv, const char *who, - const char *message, PurpleMessageFlags flags, time_t mtime); + void (*write_message)(PurpleConversation *conv, PurpleMessage *msg); /*< private >*/ void (*_purple_reserved1)(void); @@ -250,13 +250,8 @@ struct _PurpleConversationUiOps void (*create_conversation)(PurpleConversation *conv); void (*destroy_conversation)(PurpleConversation *conv); - void (*write_chat)(PurpleChatConversation *chat, const char *who, - const char *message, PurpleMessageFlags flags, - time_t mtime); - - void (*write_im)(PurpleIMConversation *im, const char *who, - const char *message, PurpleMessageFlags flags, - time_t mtime); + void (*write_chat)(PurpleChatConversation *chat, PurpleMessage *msg); + void (*write_im)(PurpleIMConversation *im, PurpleMessage *msg); void (*write_conv)(PurpleConversation *conv, const char *name, @@ -512,8 +507,7 @@ void purple_conversation_write(PurpleCon * Writes to a chat or an IM. */ void purple_conversation_write_message(PurpleConversation *conv, - const char *who, const char *message, - PurpleMessageFlags flags, time_t mtime); + PurpleMessage *msg); /** * purple_conversation_write_system_message: diff --git a/libpurple/conversationtypes.c b/libpurple/conversationtypes.c --- a/libpurple/conversationtypes.c +++ b/libpurple/conversationtypes.c @@ -353,25 +353,29 @@ purple_im_conversation_update_typing(Pur } static void -im_conversation_write_message(PurpleConversation *conv, const char *who, const char *message, - PurpleMessageFlags flags, time_t mtime) +im_conversation_write_message(PurpleConversation *conv, PurpleMessage *msg) { PurpleConversationUiOps *ops; PurpleIMConversation *im = PURPLE_IM_CONVERSATION(conv); g_return_if_fail(im != NULL); - g_return_if_fail(message != NULL); + g_return_if_fail(msg != NULL); ops = purple_conversation_get_ui_ops(conv); - if ((flags & PURPLE_MESSAGE_RECV) == PURPLE_MESSAGE_RECV) + if (purple_message_get_flags(msg) & PURPLE_MESSAGE_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. */ if (ops != NULL && ops->write_im != NULL) - ops->write_im(im, who, message, flags, mtime); - else - purple_conversation_write(conv, who, message, flags, mtime); + ops->write_im(im, msg); + else { + purple_conversation_write(conv, + purple_message_get_who(msg), + purple_message_get_contents(msg), + purple_message_get_flags(msg), + purple_message_get_time(msg)); + } } /************************************************************************** @@ -797,43 +801,37 @@ purple_chat_conversation_get_id(const Pu } static void -chat_conversation_write_message(PurpleConversation *conv, const char *who, const char *message, - PurpleMessageFlags flags, time_t mtime) +chat_conversation_write_message(PurpleConversation *conv, PurpleMessage *msg) { PurpleAccount *account; PurpleConversationUiOps *ops; PurpleChatConversationPrivate *priv = PURPLE_CHAT_CONVERSATION_GET_PRIVATE(conv); + PurpleMessageFlags flags; g_return_if_fail(priv != NULL); - g_return_if_fail(who != NULL); - g_return_if_fail(message != NULL); + g_return_if_fail(msg != NULL); account = purple_conversation_get_account(conv); /* Don't display this if the person who wrote it is ignored. */ - if (purple_chat_conversation_is_ignored_user(PURPLE_CHAT_CONVERSATION(conv), who)) + if (purple_chat_conversation_is_ignored_user( + PURPLE_CHAT_CONVERSATION(conv), purple_message_get_who(msg))) + { return; - - if (mtime < 0) { - purple_debug_error("conversation", - "purple_conv_chat_write ignoring negative timestamp\n"); - /* TODO: Would be more appropriate to use a value that indicates - that the timestamp is unknown, and surface that in the UI. */ - mtime = time(NULL); } - if (TRUE) { - const char *str; +#if 0 + /* XXX: this should not be necessary */ + if (purple_strequal(purple_normalize(account, who), priv->nick)) { + flags |= PURPLE_MESSAGE_SEND; + } +#endif - str = purple_normalize(account, who); - - if (purple_strequal(str, priv->nick)) { - flags |= PURPLE_MESSAGE_SEND; - } else { - flags |= PURPLE_MESSAGE_RECV; - - if (purple_utf8_has_word(message, priv->nick)) - flags |= PURPLE_MESSAGE_NICK; + flags = purple_message_get_flags(msg); + if (flags & PURPLE_MESSAGE_RECV) { + if (purple_utf8_has_word(purple_message_get_contents(msg), priv->nick)) { + flags |= PURPLE_MESSAGE_NICK; + purple_message_set_flags(msg, flags); } } @@ -841,9 +839,14 @@ 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), who, message, flags, mtime); - else - purple_conversation_write(conv, who, message, flags, mtime); + ops->write_chat(PURPLE_CHAT_CONVERSATION(conv), msg); + else { + purple_conversation_write(conv, + purple_message_get_who(msg), + purple_message_get_contents(msg), + purple_message_get_flags(msg), + purple_message_get_time(msg)); + } } void diff --git a/libpurple/message.c b/libpurple/message.c --- a/libpurple/message.c +++ b/libpurple/message.c @@ -142,6 +142,16 @@ purple_message_get_time(PurpleMessage *m return priv->msgtime; } +void +purple_message_set_flags(PurpleMessage *msg, PurpleMessageFlags flags) +{ + PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg); + + g_return_if_fail(priv != NULL); + + priv->flags = flags; +} + PurpleMessageFlags purple_message_get_flags(PurpleMessage *msg) { diff --git a/libpurple/message.h b/libpurple/message.h --- a/libpurple/message.h +++ b/libpurple/message.h @@ -110,6 +110,9 @@ purple_message_set_time(PurpleMessage *m guint64 purple_message_get_time(PurpleMessage *msg); +void +purple_message_set_flags(PurpleMessage *msg, PurpleMessageFlags flags); + PurpleMessageFlags purple_message_get_flags(PurpleMessage *msg); diff --git a/libpurple/plugins/offlinemsg.c b/libpurple/plugins/offlinemsg.c --- a/libpurple/plugins/offlinemsg.c +++ b/libpurple/plugins/offlinemsg.c @@ -105,8 +105,9 @@ record_pounce(OfflineMsg *offline) g_object_set_data(G_OBJECT(conv), "plugin_pack:offlinemsg", GINT_TO_POINTER(OFFLINE_MSG_YES)); - purple_conversation_write_message(conv, offline->who, offline->message, - PURPLE_MESSAGE_SEND, time(NULL)); + /* TODO: use a reference to a PurpleMessage */ + purple_conversation_write_message(conv, purple_message_new(offline->who, + offline->message, PURPLE_MESSAGE_SEND)); discard_data(offline); } diff --git a/libpurple/plugins/perl/common/Conversation.xs b/libpurple/plugins/perl/common/Conversation.xs --- a/libpurple/plugins/perl/common/Conversation.xs +++ b/libpurple/plugins/perl/common/Conversation.xs @@ -47,7 +47,6 @@ BOOT: const_iv(ACTIVE_ONLY), const_iv(NICK), const_iv(NO_LOG), - const_iv(WHISPER), const_iv(ERROR), const_iv(DELAYED), const_iv(RAW),