/soc/2015/igor.gajowiak/chatlog: e61c25e3a66f: Hooked marking me...

Igor Gajowiak igor.gajowiak at gmail.com
Mon Jul 27 16:02:31 EDT 2015


Changeset: e61c25e3a66f384e14b0ecbd0dfd455fdb7a5c2e
Author:	 Igor Gajowiak <igor.gajowiak at gmail.com>
Date:	 2015-07-27 22:02 +0200
Branch:	 default
URL: https://hg.pidgin.im/soc/2015/igor.gajowiak/chatlog/rev/e61c25e3a66f

Description:

Hooked marking messages as seen to the UI.

diffstat:

 pidgin/gtkconv.c |  50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 pidgin/gtkconv.h |   2 ++
 2 files changed, 51 insertions(+), 1 deletions(-)

diffs (108 lines):

diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -6032,6 +6032,8 @@ private_gtkconv_new(PurpleConversation *
 	gtkconv->convs = g_list_prepend(gtkconv->convs, conv);
 	gtkconv->send_history = g_list_append(NULL, NULL);
 
+	gtkconv->unseen_messages = NULL;
+
 	gtkconv->edited_message_id = PURPLE_MESSAGE_ID_NONE;
 
 	/* Setup some initial variables. */
@@ -6255,6 +6257,8 @@ pidgin_conv_destroy(PurpleConversation *
 		g_free(gtkconv->u.chat);
 	}
 
+	g_list_free_full(gtkconv->unseen_messages, g_object_unref);
+
 	gtkconv->send_history = g_list_first(gtkconv->send_history);
 	g_list_foreach(gtkconv->send_history, (GFunc)g_free, NULL);
 	g_list_free(gtkconv->send_history);
@@ -7078,6 +7082,22 @@ pidgin_conv_write_conv(PurpleConversatio
 
 #endif
 
+	// Mark message as seen immediately if the conversation has focus
+	if (pidgin_conv_has_focus(conv)) {
+		GError *error;
+		if (!purple_genericlog_mark_as_seen(pmsg, &error)) {
+			purple_debug_error("gtkconv",
+				"Marking message as seen failed: %s (code=%d)",
+				error->message, error->code);
+			g_error_free(error);
+		}
+	}
+	else { // Otherwise push message to unseen_messages
+		g_object_ref(G_OBJECT(pmsg));
+		gtkconv->unseen_messages = g_list_prepend(
+			gtkconv->unseen_messages, pmsg);
+	}
+
 	/* Tab highlighting stuff */
 	if (!(flags & PURPLE_MESSAGE_SEND) && !pidgin_conv_has_focus(conv))
 	{
@@ -9512,6 +9532,31 @@ gtkconv_set_unseen(PidginConversation *g
 	purple_conversation_update(gtkconv->active_conv, PURPLE_CONVERSATION_UPDATE_UNSEEN);
 }
 
+static void
+mark_all_messages_as_seen(PidginConversation *gtkconv)
+{
+	g_assert(gtkconv);
+
+	GList *it = gtkconv->unseen_messages;
+	while (it != NULL) {
+		PurpleMessage *msg = PURPLE_MESSAGE(it->data);
+
+		GError *error;
+		if (!purple_genericlog_mark_as_seen(msg, &error)) {
+			purple_debug_error("gtkconv",
+				"Marking message as seen failed: %s (code=%d)",
+				error->message, error->code);
+			g_error_free(error);
+		}
+
+		g_object_unref(G_OBJECT(msg));
+
+		it = g_list_delete_link(it, it);
+	}
+
+	gtkconv->unseen_messages = NULL;
+}
+
 /*
  * When a conversation window is focused, we know the user
  * has looked at it so we know there are no longer unseen
@@ -9523,8 +9568,10 @@ focus_win_cb(GtkWidget *w, GdkEventFocus
 	PidginConvWindow *win = d;
 	PidginConversation *gtkconv = pidgin_conv_window_get_active_gtkconv(win);
 
-	if (gtkconv)
+	if (gtkconv) {
 		gtkconv_set_unseen(gtkconv, PIDGIN_UNSEEN_NONE);
+		mark_all_messages_as_seen(gtkconv);
+	}
 
 	return FALSE;
 }
@@ -10289,6 +10336,7 @@ switch_conv_cb(GtkNotebook *notebook, Gt
 	/* clear unseen flag if conversation is not hidden */
 	if(!pidgin_conv_is_hidden(gtkconv)) {
 		gtkconv_set_unseen(gtkconv, PIDGIN_UNSEEN_NONE);
+		mark_all_messages_as_seen(gtkconv);
 	}
 
 	/* Update the menubar */
diff --git a/pidgin/gtkconv.h b/pidgin/gtkconv.h
--- a/pidgin/gtkconv.h
+++ b/pidgin/gtkconv.h
@@ -96,6 +96,8 @@ struct _PidginConversation
 	GList *convs;
 	GList *send_history;
 
+	GList *unseen_messages;
+
 	guint edited_message_id;
 
 	PidginConvWindow *win;



More information about the Commits mailing list