pidgin/pidgin

09387009bb17
Parents 97ea8574aeea
Children e1f9a50effbc
Drop PurpleConversationMessage in favor of PurpleMessage
--- a/libpurple/conversation.c Thu Jun 12 21:43:10 2014 +0200
+++ b/libpurple/conversation.c Fri Jun 13 23:42:59 2014 +0200
@@ -56,8 +56,7 @@
PurpleConversationUiOps *ui_ops; /* UI-specific operations. */
PurpleConnectionFlags features; /* The supported features */
- GList *message_history; /* Message history, as a GList of
- PurpleConversationMessage's */
+ GList *message_history; /* Message history, as a GList of PurpleMessages */
PurpleE2eeState *e2ee_state; /* End-to-end encryption state. */
@@ -67,19 +66,6 @@
PurpleSmileyList *remote_smileys;
};
-/*
- * Description of a conversation message
- */
-struct _PurpleConversationMessage
-{
- char *who;
- char *what;
- PurpleMessageFlags flags;
- time_t when;
- PurpleConversation *conv;
- char *alias;
-};
-
/* GObject Property enums */
enum
{
@@ -216,58 +202,20 @@
conv, time(NULL), NULL));
}
-/* Functions that deal with PurpleConversationMessage */
+/* Functions that deal with PurpleMessage history */
static void
-add_message_to_history(PurpleConversation *conv, const char *who, const char *alias,
- const char *message, PurpleMessageFlags flags, time_t when)
+add_message_to_history(PurpleConversation *conv, PurpleMessage *msg)
{
PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
- PurpleConversationMessage *msg;
- PurpleConnection *gc;
g_return_if_fail(priv != NULL);
-
- gc = purple_account_get_connection(priv->account);
-
- if (flags & PURPLE_MESSAGE_SEND) {
- const char *me = NULL;
- if (gc)
- me = purple_connection_get_display_name(gc);
- if (!me)
- me = purple_account_get_username(priv->account);
- who = me;
- }
+ g_return_if_fail(msg != NULL);
- msg = g_new0(PurpleConversationMessage, 1);
- PURPLE_DBUS_REGISTER_POINTER(msg, PurpleConversationMessage);
- msg->who = g_strdup(who);
- msg->alias = g_strdup(alias);
- msg->flags = flags;
- msg->what = g_strdup(message);
- msg->when = when;
- msg->conv = conv;
-
+ g_object_ref(msg);
priv->message_history = g_list_prepend(priv->message_history, msg);
}
-static void
-free_conv_message(PurpleConversationMessage *msg)
-{
- g_free(msg->who);
- g_free(msg->alias);
- g_free(msg->what);
- PURPLE_DBUS_UNREGISTER_POINTER(msg);
- g_free(msg);
-}
-
-static void
-message_history_free(GList *list)
-{
- g_list_foreach(list, (GFunc)free_conv_message, NULL);
- g_list_free(list);
-}
-
/**************************************************************************
* Conversation API
**************************************************************************/
@@ -681,12 +629,7 @@
ops->write_conv(conv, pmsg);
}
- 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));
+ add_message_to_history(conv, pmsg);
purple_signal_emit(purple_conversations_get_handle(),
(PURPLE_IS_IM_CONVERSATION(conv) ? "wrote-im-msg" : "wrote-chat-msg"),
@@ -835,7 +778,7 @@
g_return_if_fail(priv != NULL);
list = priv->message_history;
- message_history_free(list);
+ g_list_free_full(list, g_object_unref);
priv->message_history = NULL;
purple_signal_emit(purple_conversations_get_handle(),
@@ -851,74 +794,6 @@
return priv->message_history;
}
-const char *purple_conversation_message_get_sender(const PurpleConversationMessage *msg)
-{
- g_return_val_if_fail(msg, NULL);
- return msg->who;
-}
-
-const char *purple_conversation_message_get_message(const PurpleConversationMessage *msg)
-{
- g_return_val_if_fail(msg, NULL);
- return msg->what;
-}
-
-PurpleMessageFlags purple_conversation_message_get_flags(const PurpleConversationMessage *msg)
-{
- g_return_val_if_fail(msg, 0);
- return msg->flags;
-}
-
-time_t purple_conversation_message_get_timestamp(const PurpleConversationMessage *msg)
-{
- g_return_val_if_fail(msg, 0);
- return msg->when;
-}
-
-const char *purple_conversation_message_get_alias(const PurpleConversationMessage *msg)
-{
- g_return_val_if_fail(msg, NULL);
- return msg->alias;
-}
-
-PurpleConversation *purple_conversation_message_get_conversation(const PurpleConversationMessage *msg)
-{
- g_return_val_if_fail(msg, NULL);
- return msg->conv;
-}
-
-static PurpleConversationMessage *
-copy_conv_message(PurpleConversationMessage *msg)
-{
- PurpleConversationMessage *newmsg;
-
- g_return_val_if_fail(msg != NULL, NULL);
-
- newmsg = g_new(PurpleConversationMessage, 1);
- PURPLE_DBUS_REGISTER_POINTER(newmsg, PurpleConversationMessage);
-
- *newmsg = *msg;
- newmsg->who = g_strdup(msg->who);
- newmsg->what = g_strdup(msg->what);
- newmsg->alias = g_strdup(msg->alias);
-
- return newmsg;
-}
-
-GType
-purple_conversation_message_get_type(void)
-{
- static GType type = 0;
-
- if (type == 0) {
- type = g_boxed_type_register_static("PurpleConversationMessage",
- (GBoxedCopyFunc)copy_conv_message,
- (GBoxedFreeFunc)free_conv_message);
- }
-
- return type;
-}
-
void purple_conversation_set_ui_data(PurpleConversation *conv, gpointer ui_data)
{
g_return_if_fail(PURPLE_IS_CONVERSATION(conv));
--- a/libpurple/conversation.h Thu Jun 12 21:43:10 2014 +0200
+++ b/libpurple/conversation.h Fri Jun 13 23:42:59 2014 +0200
@@ -48,8 +48,6 @@
typedef struct _PurpleConversationUiOps PurpleConversationUiOps;
-typedef struct _PurpleConversationMessage PurpleConversationMessage;
-
/**
* PurpleConversationUpdateType:
* @PURPLE_CONVERSATION_UPDATE_ADD: The buddy associated with the
@@ -556,9 +554,9 @@
*
* Retrieve the message history of a conversation.
*
- * Returns: A GList of PurpleConversationMessage's. The must not modify the
- * list or the data within. The list contains the newest message at
- * the beginning, and the oldest message at the end.
+ * Returns: (transfer none): A GList of PurpleMessage's. You must not modify the
+ * list or the data within. The list contains the newest message at
+ * the beginning, and the oldest message at the end.
*/
GList *purple_conversation_get_message_history(PurpleConversation *conv);
@@ -714,77 +712,6 @@
*/
gboolean purple_conversation_present_error(const char *who, PurpleAccount *account, const char *what);
-/**************************************************************************/
-/* Conversation Message API */
-/**************************************************************************/
-
-/**
- * purple_conversation_message_get_type:
- *
- * Returns: The #GType for the #PurpleConversationMessage boxed structure.
- */
-GType purple_conversation_message_get_type(void);
-
-/**
- * purple_conversation_message_get_sender:
- * @msg: A PurpleConversationMessage
- *
- * Get the sender from a PurpleConversationMessage
- *
- * Returns: The name of the sender of the message
- */
-const char *purple_conversation_message_get_sender(const PurpleConversationMessage *msg);
-
-/**
- * purple_conversation_message_get_message:
- * @msg: A PurpleConversationMessage
- *
- * Get the message from a PurpleConversationMessage
- *
- * Returns: The name of the sender of the message
- */
-const char *purple_conversation_message_get_message(const PurpleConversationMessage *msg);
-
-/**
- * purple_conversation_message_get_flags:
- * @msg: A PurpleConversationMessage
- *
- * Get the message-flags of a PurpleConversationMessage
- *
- * Returns: The message flags
- */
-PurpleMessageFlags purple_conversation_message_get_flags(const PurpleConversationMessage *msg);
-
-/**
- * purple_conversation_message_get_timestamp:
- * @msg: A PurpleConversationMessage
- *
- * Get the timestamp of a PurpleConversationMessage
- *
- * Returns: The timestamp of the message
- */
-time_t purple_conversation_message_get_timestamp(const PurpleConversationMessage *msg);
-
-/**
- * purple_conversation_message_get_alias:
- * @msg: A PurpleConversationMessage
- *
- * Get the alias from a PurpleConversationMessage
- *
- * Returns: The alias of the sender of the message
- */
-const char *purple_conversation_message_get_alias(const PurpleConversationMessage *msg);
-
-/**
- * purple_conversation_message_get_conversation:
- * @msg: A PurpleConversationMessage
- *
- * Get the conversation associated with the PurpleConversationMessage
- *
- * Returns: The conversation
- */
-PurpleConversation *purple_conversation_message_get_conversation(const PurpleConversationMessage *msg);
-
G_END_DECLS
#endif /* _PURPLE_CONVERSATION_H_ */
--- a/libpurple/message.c Thu Jun 12 21:43:10 2014 +0200
+++ b/libpurple/message.c Fri Jun 13 23:42:59 2014 +0200
@@ -118,7 +118,7 @@
}
guint
-purple_message_get_id(PurpleMessage *msg)
+purple_message_get_id(const PurpleMessage *msg)
{
PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg);
@@ -136,7 +136,7 @@
}
const gchar *
-purple_message_get_author(PurpleMessage *msg)
+purple_message_get_author(const PurpleMessage *msg)
{
PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg);
@@ -146,7 +146,7 @@
}
const gchar *
-purple_message_get_recipient(PurpleMessage *msg)
+purple_message_get_recipient(const PurpleMessage *msg)
{
PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg);
@@ -162,7 +162,7 @@
}
const gchar *
-purple_message_get_author_alias(PurpleMessage *msg)
+purple_message_get_author_alias(const PurpleMessage *msg)
{
PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg);
@@ -181,7 +181,7 @@
}
const gchar *
-purple_message_get_contents(PurpleMessage *msg)
+purple_message_get_contents(const PurpleMessage *msg)
{
PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg);
@@ -191,7 +191,7 @@
}
gboolean
-purple_message_is_empty(PurpleMessage *msg)
+purple_message_is_empty(const PurpleMessage *msg)
{
const gchar *cont = purple_message_get_contents(msg);
@@ -205,7 +205,7 @@
}
guint64
-purple_message_get_time(PurpleMessage *msg)
+purple_message_get_time(const PurpleMessage *msg)
{
PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg);
@@ -221,7 +221,7 @@
}
PurpleMessageFlags
-purple_message_get_flags(PurpleMessage *msg)
+purple_message_get_flags(const PurpleMessage *msg)
{
PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg);
--- a/libpurple/message.h Thu Jun 12 21:43:10 2014 +0200
+++ b/libpurple/message.h Fri Jun 13 23:42:59 2014 +0200
@@ -94,43 +94,43 @@
purple_message_new_system(const gchar *contents, PurpleMessageFlags flags);
guint
-purple_message_get_id(PurpleMessage *msg);
+purple_message_get_id(const PurpleMessage *msg);
PurpleMessage *
purple_message_find_by_id(guint id);
const gchar *
-purple_message_get_author(PurpleMessage *msg);
+purple_message_get_author(const PurpleMessage *msg);
const gchar *
-purple_message_get_recipient(PurpleMessage *msg);
+purple_message_get_recipient(const PurpleMessage *msg);
void
purple_message_set_author_alias(PurpleMessage *msg, const gchar *alias);
const gchar *
-purple_message_get_author_alias(PurpleMessage *msg);
+purple_message_get_author_alias(const PurpleMessage *msg);
void
purple_message_set_contents(PurpleMessage *msg, const gchar *cont);
const gchar *
-purple_message_get_contents(PurpleMessage *msg);
+purple_message_get_contents(const PurpleMessage *msg);
gboolean
-purple_message_is_empty(PurpleMessage *msg);
+purple_message_is_empty(const PurpleMessage *msg);
void
purple_message_set_time(PurpleMessage *msg, guint64 msgtime);
guint64
-purple_message_get_time(PurpleMessage *msg);
+purple_message_get_time(const PurpleMessage *msg);
void
purple_message_set_flags(PurpleMessage *msg, PurpleMessageFlags flags);
PurpleMessageFlags
-purple_message_get_flags(PurpleMessage *msg);
+purple_message_get_flags(const PurpleMessage *msg);
void
_purple_message_init(void);
--- a/pidgin/gtkconv.c Thu Jun 12 21:43:10 2014 +0200
+++ b/pidgin/gtkconv.c Fri Jun 13 23:42:59 2014 +0200
@@ -70,6 +70,8 @@
#define GTK_TOOLTIPS_VAR gtkconv->tooltips
#include "gtk3compat.h"
+#define ADD_MESSAGE_HISTORY_AT_ONCE 100
+
/*
* A GTK+ Instant Message pane.
*/
@@ -6767,13 +6769,13 @@
} else if ((flags & PURPLE_MESSAGE_RECV) && (old_flags & PURPLE_MESSAGE_RECV)) {
GList *history = purple_conversation_get_message_history(gtkconv->last_conversed);
- PurpleConversationMessage *last_msg = history ? (PurpleConversationMessage *)history->data : NULL;
+ PurpleMessage *last_msg = history ? history->data : NULL;
g_assert(history != NULL);
g_assert(last_msg != NULL);
/* If the senders are the same, use appendNextMessage */
- if (purple_strequal(purple_conversation_message_get_sender(last_msg), purple_message_get_author(pmsg))) {
+ if (purple_strequal(purple_message_get_author(last_msg), purple_message_get_author(pmsg))) {
message_html = pidgin_conversation_theme_get_template(gtkconv->theme,
PIDGIN_CONVERSATION_THEME_TEMPLATE_INCOMING_NEXT_CONTENT);
func = "appendNextMessage";
@@ -8482,12 +8484,12 @@
/* Message history stuff */
-/* Compare two PurpleConversationMessage's, according to time in ascending order. */
+/* Compare two PurpleMessages, according to time in ascending order. */
static int
message_compare(gconstpointer p1, gconstpointer p2)
{
- const PurpleConversationMessage *m1 = p1, *m2 = p2;
- return (purple_conversation_message_get_timestamp(m1) > purple_conversation_message_get_timestamp(m2));
+ const PurpleMessage *m1 = p1, *m2 = p2;
+ return (purple_message_get_time(m1) > purple_message_get_time(m2));
}
/* Adds some message history to the gtkconv. This happens in a idle-callback. */
@@ -8502,23 +8504,15 @@
gboolean im = (PURPLE_IS_IM_CONVERSATION(gtkconv->active_conv));
gtkconv->attach_timer = 0;
- while (gtkconv->attach_current && count < 100) { /* XXX: 100 is a random value here */
- PurpleConversationMessage *msg = gtkconv->attach_current->data;
- if (!im && when && when < purple_conversation_message_get_timestamp(msg)) {
+ while (gtkconv->attach_current && count < ADD_MESSAGE_HISTORY_AT_ONCE) {
+ PurpleMessage *msg = gtkconv->attach_current->data;
+ if (!im && when && (guint64)when < purple_message_get_time(msg)) {
pidgin_webview_append_html(webview, "<BR><HR>");
pidgin_webview_scroll_to_end(webview, TRUE);
g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", NULL);
}
-#if 0
- /* TODO */
- pidgin_conv_write_conv(
- purple_conversation_message_get_conversation(msg),
- purple_conversation_message_get_sender(msg),
- purple_conversation_message_get_alias(msg),
- purple_conversation_message_get_message(msg),
- purple_conversation_message_get_flags(msg),
- purple_conversation_message_get_timestamp(msg));
-#endif
+ /* XXX: should it be gtkconv->active_conv? */
+ pidgin_conv_write_conv(gtkconv->active_conv, msg);
if (im) {
gtkconv->attach_current = g_list_delete_link(gtkconv->attach_current, gtkconv->attach_current);
} else {
@@ -8540,24 +8534,16 @@
PurpleConversation *conv = iter->data;
GList *history = purple_conversation_get_message_history(conv);
for (; history; history = history->next) {
- PurpleConversationMessage *msg = history->data;
- if (purple_conversation_message_get_timestamp(msg) > when)
+ PurpleMessage *msg = history->data;
+ if (purple_message_get_time(msg) > (guint64)when)
msgs = g_list_prepend(msgs, msg);
}
}
msgs = g_list_sort(msgs, message_compare);
for (; msgs; msgs = g_list_delete_link(msgs, msgs)) {
-#if 0
- /* TODO */
- PurpleConversationMessage *msg = msgs->data;
- pidgin_conv_write_conv(
- purple_conversation_message_get_conversation(msg),
- purple_conversation_message_get_sender(msg),
- purple_conversation_message_get_alias(msg),
- purple_conversation_message_get_message(msg),
- purple_conversation_message_get_flags(msg),
- purple_conversation_message_get_timestamp(msg));
-#endif
+ PurpleMessage *msg = msgs->data;
+ /* XXX: see above - should it be active_conv? */
+ pidgin_conv_write_conv(gtkconv->active_conv, msg);
}
pidgin_webview_append_html(webview, "<BR><HR>");
pidgin_webview_scroll_to_end(webview, TRUE);
@@ -8628,9 +8614,9 @@
} else if (PURPLE_IS_CHAT_CONVERSATION(conv)) {
gtkconv->attach_current = g_list_last(list);
}
-
+
g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time",
- GINT_TO_POINTER(purple_conversation_message_get_timestamp((PurpleConversationMessage*)(list->data))));
+ GINT_TO_POINTER(purple_message_get_time(list->data)));
gtkconv->attach_timer = g_idle_add(add_message_history_to_gtkconv, gtkconv);
} else {
purple_signal_emit(pidgin_conversations_get_handle(),