/soc/2015/igor.gajowiak/chatlog: 25e01227b21a: Add incoming mess...
Igor Gajowiak
igor.gajowiak at gmail.com
Wed Jun 24 13:31:31 EDT 2015
Changeset: 25e01227b21a6c4348d3e7f216dd1912bd674b91
Author: Igor Gajowiak <igor.gajowiak at gmail.com>
Date: 2015-06-15 10:49 +0200
Branch: default
URL: https://hg.pidgin.im/soc/2015/igor.gajowiak/chatlog/rev/25e01227b21a
Description:
Add incoming message replacing. TODO: fix problems mentioned in comments
diffstat:
finch/gntconv.c | 3 +
libpurple/conversation.c | 128 ++++++++++
libpurple/conversation.h | 15 +
libpurple/conversationtypes.c | 19 +
libpurple/internal.h | 4 +
libpurple/message.c | 16 +-
libpurple/message.h | 1 +
libpurple/protocols/jabber/jabber.c | 5 +
libpurple/protocols/jabber/message.c | 44 +++-
libpurple/protocols/jabber/message.h | 4 +
libpurple/protocols/jabber/namespaces.h | 3 +
libpurple/server.c | 166 +++++++++++++-
libpurple/server.h | 19 +-
pidgin/gtkconv.c | 203 ++++++++++++++++-
pidgin/themes/Contents/Resources/Incoming/Content.html | 2 +-
pidgin/themes/Contents/Resources/Outgoing/Content.html | 13 +
pidgin/themes/Makefile.am | 3 +
pidgin/themes/Template.html | 47 +++
18 files changed, 681 insertions(+), 14 deletions(-)
diffs (truncated from 1059 to 300 lines):
diff --git a/finch/gntconv.c b/finch/gntconv.c
--- a/finch/gntconv.c
+++ b/finch/gntconv.c
@@ -1217,6 +1217,9 @@ static PurpleConversationUiOps conv_ui_o
NULL, /* write_chat */
NULL, /* write_im */
finch_write_conv,
+ NULL, /* replace_chat */
+ NULL, /* replace_im */
+ NULL, /* replace_conv */
finch_chat_add_users,
finch_chat_rename_user,
finch_chat_remove_users,
diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -639,6 +639,119 @@ void
conv, pmsg);
}
+// TODO: Implemenatation copied from _purple_conversation_write_common, try to refactor
+void
+_purple_conversation_replace_common(PurpleConversation *conv, guint replaced_msg_id,
+ PurpleMessage *pmsg)
+{
+ PurpleProtocol *protocol = NULL;
+ PurpleConnection *gc = NULL;
+ PurpleAccount *account;
+ PurpleConversationUiOps *ops;
+ 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(pmsg != NULL);
+
+ ops = purple_conversation_get_ui_ops(conv);
+
+ account = purple_conversation_get_account(conv);
+
+ if (account != NULL)
+ gc = purple_account_get_connection(account);
+
+ if (PURPLE_IS_CHAT_CONVERSATION(conv) &&
+ (gc != NULL && !g_slist_find(purple_connection_get_active_chats(gc), conv)))
+ return;
+
+ if (PURPLE_IS_IM_CONVERSATION(conv) &&
+ !g_list_find(purple_conversations_get_all(), conv))
+ return;
+
+ 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 (purple_message_is_empty(pmsg))
+ return;
+
+ if (plugin_return)
+ return;
+
+ if (account != NULL) {
+ protocol = purple_protocols_find(purple_account_get_protocol_id(account));
+
+ if (PURPLE_IS_IM_CONVERSATION(conv) ||
+ !(purple_protocol_get_options(protocol) & OPT_PROTO_UNIQUE_CHATNAME)) {
+
+ if (purple_message_get_flags(pmsg) & PURPLE_MESSAGE_SEND) {
+ const gchar *alias;
+
+ b = purple_blist_find_buddy(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)))
+ {
+ alias = purple_buddy_get_contact_alias(b);
+ } 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 if (purple_message_get_flags(pmsg) & PURPLE_MESSAGE_RECV)
+ {
+ /* TODO: PurpleDude - folks not on the buddy list */
+ b = purple_blist_find_buddy(account,
+ purple_message_get_author(pmsg));
+
+ if (b != NULL) {
+ purple_message_set_author_alias(pmsg,
+ purple_buddy_get_contact_alias(b));
+ }
+ }
+ }
+ }
+
+ 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,
+ 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) {
+ if (PURPLE_IS_CHAT_CONVERSATION(conv) && ops->replace_chat)
+ ops->replace_chat(PURPLE_CHAT_CONVERSATION(conv), replaced_msg_id, pmsg);
+ else if (PURPLE_IS_IM_CONVERSATION(conv) && ops->replace_im)
+ ops->replace_im(PURPLE_IM_CONVERSATION(conv), replaced_msg_id, pmsg);
+ else if (ops->replace_conv)
+ ops->replace_conv(conv, replaced_msg_id, pmsg);
+ }
+
+ // TODO: replace instead of add?
+ add_message_to_history(conv, pmsg);
+
+ purple_signal_emit(purple_conversations_get_handle(),
+ (PURPLE_IS_IM_CONVERSATION(conv) ? "wrote-im-msg" : "wrote-chat-msg"),
+ conv, pmsg);
+}
+
void
purple_conversation_write_message(PurpleConversation *conv, PurpleMessage *msg)
{
@@ -652,6 +765,21 @@ purple_conversation_write_message(Purple
klass->write_message(conv, msg);
}
+void
+purple_conversation_replace_message(PurpleConversation *conv,
+ guint replaced_msg_id, PurpleMessage *msg)
+{
+ PurpleConversationClass *klass = NULL;
+
+ g_return_if_fail(PURPLE_IS_CONVERSATION(conv));
+ g_return_if_fail(msg != NULL);
+
+ klass = PURPLE_CONVERSATION_GET_CLASS(conv);
+
+ if (klass && klass->replace_message)
+ klass->replace_message(conv, replaced_msg_id, msg);
+}
+
void purple_conversation_write_system_message(PurpleConversation *conv,
const gchar *message, PurpleMessageFlags flags)
{
diff --git a/libpurple/conversation.h b/libpurple/conversation.h
--- a/libpurple/conversation.h
+++ b/libpurple/conversation.h
@@ -180,6 +180,8 @@ struct _PurpleConversationClass {
void (*write_message)(PurpleConversation *conv, PurpleMessage *msg);
+ void (*replace_message)(PurpleConversation *conv, guint replaced_msg_id, PurpleMessage *msg);
+
/*< private >*/
void (*_purple_reserved1)(void);
void (*_purple_reserved2)(void);
@@ -252,6 +254,10 @@ 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 (*chat_add_users)(PurpleChatConversation *chat,
GList *cbuddies,
gboolean new_arrivals);
@@ -477,6 +483,15 @@ void purple_conversation_write_message(P
PurpleMessage *msg);
/**
+ * purple_conversation_replace_message:
+ * @conv: The conversation.
+ * @replaced_msg_id: The id of purple message to be replaced
+ * @msg: The new message
+ */
+void purple_conversation_replace_message(PurpleConversation *conv,
+ guint replaced_msg_id, PurpleMessage *msg);
+
+/**
* purple_conversation_write_system_message:
* @conv: The conversation.
* @message: The message to write.
diff --git a/libpurple/conversationtypes.c b/libpurple/conversationtypes.c
--- a/libpurple/conversationtypes.c
+++ b/libpurple/conversationtypes.c
@@ -369,6 +369,23 @@ im_conversation_write_message(PurpleConv
_purple_conversation_write_common(conv, msg);
}
+static void
+im_conversation_replace_message(PurpleConversation *conv, guint replaced_msg_id, PurpleMessage *msg)
+{
+ PurpleIMConversation *im = PURPLE_IM_CONVERSATION(conv);
+ gboolean is_recv;
+
+ g_return_if_fail(im != NULL);
+ g_return_if_fail(msg != NULL);
+
+ is_recv = (purple_message_get_flags(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);
+}
+
/**************************************************************************
* GObject code for IMs
**************************************************************************/
@@ -509,6 +526,7 @@ static void purple_im_conversation_class
obj_class->set_property = purple_im_conversation_set_property;
conv_class->write_message = im_conversation_write_message;
+ conv_class->replace_message = im_conversation_replace_message;
g_type_class_add_private(klass, sizeof(PurpleIMConversationPrivate));
@@ -1534,6 +1552,7 @@ static void purple_chat_conversation_cla
obj_class->set_property = purple_chat_conversation_set_property;
conv_class->write_message = chat_conversation_write_message;
+ // TODO: initialize replace_message here
g_type_class_add_private(klass, sizeof(PurpleChatConversationPrivate));
diff --git a/libpurple/internal.h b/libpurple/internal.h
--- a/libpurple/internal.h
+++ b/libpurple/internal.h
@@ -431,4 +431,8 @@ void
void
_purple_conversation_write_common(PurpleConversation *conv, PurpleMessage *msg);
+void
+_purple_conversation_replace_common(PurpleConversation *conv, guint replaced_msg_id,
+ PurpleMessage *pmsg);
+
#endif /* _PURPLE_INTERNAL_H_ */
diff --git a/libpurple/message.c b/libpurple/message.c
--- a/libpurple/message.c
+++ b/libpurple/message.c
@@ -234,17 +234,25 @@ purple_message_get_flags(const PurpleMes
* Object stuff
******************************************************************************/
+static guint
+generate_next_id()
+{
+ static guint id = PURPLE_MESSAGE_ID_NONE;
+
+ if(id == PURPLE_MESSAGE_ID_NONE)
+ ++id;
+ return id++;
+}
+
static void
purple_message_init(GTypeInstance *instance, gpointer klass)
{
- static guint max_id = 0;
-
PurpleMessage *msg = PURPLE_MESSAGE(instance);
PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg);
PURPLE_DBUS_REGISTER_POINTER(msg, PurpleMessage);
- priv->id = ++max_id;
- g_hash_table_insert(messages, GINT_TO_POINTER(max_id), msg);
+ priv->id = generate_next_id();
+ g_hash_table_insert(messages, GINT_TO_POINTER(priv->id), msg);
}
static void
diff --git a/libpurple/message.h b/libpurple/message.h
--- a/libpurple/message.h
+++ b/libpurple/message.h
@@ -45,6 +45,7 @@ typedef struct _PurpleMessageClass Purpl
#define PURPLE_IS_MESSAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_MESSAGE))
#define PURPLE_MESSAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_MESSAGE, PurpleMessageClass))
+#define PURPLE_MESSAGE_ID_NONE 0
/**
* PurpleMessage:
*
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
@@ -3941,6 +3941,7 @@ jabber_do_init(void)
More information about the Commits
mailing list