]> git.0d.be Git - empathy.git/commitdiff
Ack received messages from ourself.
authorWill Thompson <will.thompson@collabora.co.uk>
Mon, 31 Aug 2009 00:15:41 +0000 (01:15 +0100)
committerWill Thompson <will.thompson@collabora.co.uk>
Mon, 31 Aug 2009 00:18:14 +0000 (01:18 +0100)
Sumana Harihareswara reported that she had started a conversation with
herself, sent a message, and then tried to close the window, but
whenever she did so it reappeared.

This was because Empathy did not acknowledge "incoming" messages from
the user themself; hence, when it Close()d the channel, Gabble respawned
it, because it still had pending messages.

libempathy/empathy-message.c
libempathy/empathy-message.h
libempathy/empathy-tp-chat.c

index 34a4667525790d95fc1142f5e8d4de45bcfae80a..4b9413b1b21c90e99216e34462c0082c85e1bb70 100644 (file)
@@ -41,6 +41,7 @@ typedef struct {
        time_t                    timestamp;
        gboolean                  is_backlog;
        guint                     id;
+       gboolean                  incoming;
 } EmpathyMessagePriv;
 
 static void empathy_message_finalize   (GObject            *object);
@@ -63,12 +64,14 @@ enum {
        PROP_BODY,
        PROP_TIMESTAMP,
        PROP_IS_BACKLOG,
+       PROP_INCOMING,
 };
 
 static void
 empathy_message_class_init (EmpathyMessageClass *class)
 {
        GObjectClass *object_class;
+       GParamSpec *pspec;
 
        object_class = G_OBJECT_CLASS (class);
        object_class->finalize     = empathy_message_finalize;
@@ -123,6 +126,13 @@ empathy_message_class_init (EmpathyMessageClass *class)
                                                               G_PARAM_READWRITE));
 
 
+       pspec = g_param_spec_boolean ("incoming",
+                                     "Incoming",
+                                     "If this is an incoming (as opposed to sent) message",
+                                     FALSE,
+                                     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+       g_object_class_install_property (object_class, PROP_INCOMING, pspec);
+
        g_type_class_add_private (object_class, sizeof (EmpathyMessagePriv));
 
 }
@@ -179,6 +189,9 @@ message_get_property (GObject    *object,
        case PROP_BODY:
                g_value_set_string (value, priv->body);
                break;
+       case PROP_INCOMING:
+               g_value_set_boolean (value, priv->incoming);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                break;
@@ -212,6 +225,9 @@ message_set_property (GObject      *object,
                empathy_message_set_body (EMPATHY_MESSAGE (object),
                                         g_value_get_string (value));
                break;
+       case PROP_INCOMING:
+               priv->incoming = g_value_get_boolean (value);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                break;
@@ -579,6 +595,22 @@ empathy_message_set_id (EmpathyMessage *message, guint id)
        priv->id = id;
 }
 
+void
+empathy_message_set_incoming (EmpathyMessage *message, gboolean incoming)
+{
+       g_object_set (message, "incoming", incoming, NULL);
+}
+
+gboolean
+empathy_message_is_incoming (EmpathyMessage *message)
+{
+       EmpathyMessagePriv *priv = GET_PRIV (message);
+
+       g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE);
+
+       return priv->incoming;
+}
+
 gboolean
 empathy_message_equal (EmpathyMessage *message1, EmpathyMessage *message2)
 {
index f9a4887033a12476865603a6533512c8b6462e6f..7ca624031539b34f1835dd5c7be200b7042c2a2b 100644 (file)
@@ -72,6 +72,10 @@ void                     empathy_message_set_timestamp     (EmpathyMessage
 gboolean                 empathy_message_is_backlog        (EmpathyMessage           *message);
 void                     empathy_message_set_is_backlog    (EmpathyMessage           *message,
                                                            gboolean                 is_backlog);
+gboolean                 empathy_message_is_incoming       (EmpathyMessage           *message);
+void                     empathy_message_set_incoming      (EmpathyMessage           *message,
+                                                           gboolean                 incoming);
+
 gboolean                 empathy_message_should_highlight  (EmpathyMessage           *message);
 TpChannelTextMessageType empathy_message_type_from_str     (const gchar              *type_str);
 const gchar *            empathy_message_type_to_str       (TpChannelTextMessageType  type);
index 7429e1ddc85f69b54f64fd8893dcaaf34ae30e0f..a64f06a2fbc151dc557de86a396156398d5e26c8 100644 (file)
@@ -227,6 +227,7 @@ tp_chat_got_sender_cb (EmpathyTpContactFactory *factory,
 
 static void
 tp_chat_build_message (EmpathyTpChat *chat,
+                      gboolean       incoming,
                       guint          id,
                       guint          type,
                       guint          timestamp,
@@ -243,6 +244,8 @@ tp_chat_build_message (EmpathyTpChat *chat,
        empathy_message_set_receiver (message, priv->user);
        empathy_message_set_timestamp (message, timestamp);
        empathy_message_set_id (message, id);
+       empathy_message_set_incoming (message, incoming);
+
        g_queue_push_tail (priv->messages_queue, message);
 
        if (from_handle == 0) {
@@ -294,6 +297,7 @@ tp_chat_received_cb (TpChannel   *channel,
        }
 
        tp_chat_build_message (chat,
+                              TRUE,
                               message_id,
                               message_type,
                               timestamp,
@@ -318,6 +322,7 @@ tp_chat_sent_cb (TpChannel   *channel,
        DEBUG ("Message sent: %s", message_body);
 
        tp_chat_build_message (chat,
+                              FALSE,
                               0,
                               message_type,
                               timestamp,
@@ -456,6 +461,7 @@ tp_chat_list_pending_messages_cb (TpChannel       *channel,
                }
 
                tp_chat_build_message (chat,
+                                      TRUE,
                                       message_id,
                                       message_type,
                                       timestamp,
@@ -1369,7 +1375,7 @@ empathy_tp_chat_acknowledge_message (EmpathyTpChat *chat,
        g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
        g_return_if_fail (priv->ready);
 
-       if (empathy_message_get_sender (message) == priv->user)
+       if (!empathy_message_is_incoming (message))
                goto out;
 
        message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
@@ -1415,7 +1421,7 @@ empathy_tp_chat_acknowledge_messages (EmpathyTpChat *chat,
                g_assert (m != NULL);
                g_queue_delete_link (priv->pending_messages_queue, m);
 
-               if (empathy_message_get_sender (message) != priv->user) {
+               if (empathy_message_is_incoming (message)) {
                        guint id = empathy_message_get_id (message);
                        g_array_append_val (message_ids, id);
                }