aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorJonny Lamb <jonnylamb@gnome.org>2011-05-17 16:36:33 +0800
committerJonny Lamb <jonnylamb@gnome.org>2011-05-17 16:36:33 +0800
commit2950825a4452bc984c0dd356c5bf17c3a674c451 (patch)
treec562a901727f1548105acf75884f350d9dfd7192 /libempathy
parent38e5925b90ca5864907aaef09cbaa4c963b1be98 (diff)
parent9e1914959b7e26e82ca4042ad5f7f042cb5a34a2 (diff)
downloadgsoc2013-empathy-2950825a4452bc984c0dd356c5bf17c3a674c451.tar
gsoc2013-empathy-2950825a4452bc984c0dd356c5bf17c3a674c451.tar.gz
gsoc2013-empathy-2950825a4452bc984c0dd356c5bf17c3a674c451.tar.bz2
gsoc2013-empathy-2950825a4452bc984c0dd356c5bf17c3a674c451.tar.lz
gsoc2013-empathy-2950825a4452bc984c0dd356c5bf17c3a674c451.tar.xz
gsoc2013-empathy-2950825a4452bc984c0dd356c5bf17c3a674c451.tar.zst
gsoc2013-empathy-2950825a4452bc984c0dd356c5bf17c3a674c451.zip
Merge branch 'ack'
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-message.c55
-rw-r--r--libempathy/empathy-message.h4
-rw-r--r--libempathy/empathy-tp-chat.c113
3 files changed, 98 insertions, 74 deletions
diff --git a/libempathy/empathy-message.c b/libempathy/empathy-message.c
index 076a10053..25ec498ce 100644
--- a/libempathy/empathy-message.c
+++ b/libempathy/empathy-message.c
@@ -40,6 +40,7 @@
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyMessage)
typedef struct {
+ TpMessage *tp_message;
TpChannelTextMessageType type;
EmpathyContact *sender;
EmpathyContact *receiver;
@@ -73,6 +74,7 @@ enum {
PROP_IS_BACKLOG,
PROP_INCOMING,
PROP_FLAGS,
+ PROP_TP_MESSAGE,
};
static void
@@ -153,6 +155,15 @@ empathy_message_class_init (EmpathyMessageClass *class)
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class,
+ PROP_TP_MESSAGE,
+ g_param_spec_object ("tp-message",
+ "TpMessage",
+ "The TpMessage of this message",
+ TP_TYPE_MESSAGE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
+ G_PARAM_CONSTRUCT_ONLY));
+
g_type_class_add_private (object_class, sizeof (EmpathyMessagePriv));
}
@@ -181,6 +192,10 @@ empathy_message_finalize (GObject *object)
g_object_unref (priv->receiver);
}
+ if (priv->tp_message) {
+ g_object_unref (priv->tp_message);
+ }
+
g_free (priv->body);
G_OBJECT_CLASS (empathy_message_parent_class)->finalize (object);
@@ -221,6 +236,9 @@ message_get_property (GObject *object,
case PROP_FLAGS:
g_value_set_uint (value, priv->flags);
break;
+ case PROP_TP_MESSAGE:
+ g_value_set_object (value, priv->tp_message);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -267,6 +285,9 @@ message_set_property (GObject *object,
case PROP_FLAGS:
priv->flags = g_value_get_uint (value);
break;
+ case PROP_TP_MESSAGE:
+ priv->tp_message = g_value_dup_object (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -342,6 +363,18 @@ empathy_message_from_tpl_log_event (TplEvent *logevent)
return retval;
}
+TpMessage *
+empathy_message_get_tp_message (EmpathyMessage *message)
+{
+ EmpathyMessagePriv *priv;
+
+ g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), NULL);
+
+ priv = GET_PRIV (message);
+
+ return priv->tp_message;
+}
+
TpChannelTextMessageType
empathy_message_get_tptype (EmpathyMessage *message)
{
@@ -563,16 +596,6 @@ empathy_message_type_to_str (TpChannelTextMessageType type)
}
}
-guint
-empathy_message_get_id (EmpathyMessage *message)
-{
- EmpathyMessagePriv *priv = GET_PRIV (message);
-
- g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), 0);
-
- return priv->id;
-}
-
gboolean
empathy_message_is_incoming (EmpathyMessage *message)
{
@@ -618,10 +641,8 @@ empathy_message_new_from_tp_message (TpMessage *tp_msg,
gboolean incoming)
{
EmpathyMessage *message;
- EmpathyMessagePriv *priv;
gchar *body;
TpChannelTextMessageFlags flags;
- guint id;
g_return_val_if_fail (TP_IS_MESSAGE (tp_msg), NULL);
@@ -634,17 +655,9 @@ empathy_message_new_from_tp_message (TpMessage *tp_msg,
"flags", flags,
"is-backlog", flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_SCROLLBACK,
"incoming", incoming,
+ "tp-message", tp_msg,
NULL);
- priv = GET_PRIV (message);
-
- /* FIXME: this is pretty low level, ideally we shouldn't have to use the
- * ID directly but we don't use TpTextChannel's ack API everywhere yet. */
- id = tp_asv_get_uint32 (tp_message_peek (tp_msg, 0),
- "pending-message-id", NULL);
-
- priv->id = id;
-
g_free (body);
return message;
}
diff --git a/libempathy/empathy-message.h b/libempathy/empathy-message.h
index 7508cb08e..b20ceca16 100644
--- a/libempathy/empathy-message.h
+++ b/libempathy/empathy-message.h
@@ -59,6 +59,8 @@ EmpathyMessage * empathy_message_from_tpl_log_event (TplEvent
EmpathyMessage * empathy_message_new_from_tp_message (TpMessage *tp_msg,
gboolean incoming);
+TpMessage * empathy_message_get_tp_message (EmpathyMessage *message);
+
TpChannelTextMessageType empathy_message_get_tptype (EmpathyMessage *message);
EmpathyContact * empathy_message_get_sender (EmpathyMessage *message);
void empathy_message_set_sender (EmpathyMessage *message,
@@ -75,8 +77,6 @@ gboolean empathy_message_should_highlight (EmpathyMessage
TpChannelTextMessageType empathy_message_type_from_str (const gchar *type_str);
const gchar * empathy_message_type_to_str (TpChannelTextMessageType type);
-guint empathy_message_get_id (EmpathyMessage *message);
-
gboolean empathy_message_equal (EmpathyMessage *message1, EmpathyMessage *message2);
TpChannelTextMessageFlags empathy_message_get_flags (EmpathyMessage *message);
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index 8e6672eee..0541943b9 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -84,6 +84,7 @@ enum {
CHAT_STATE_CHANGED,
PROPERTY_CHANGED,
DESTROY,
+ MESSAGE_ACKNOWLEDGED,
LAST_SIGNAL
};
@@ -93,8 +94,6 @@ G_DEFINE_TYPE_WITH_CODE (EmpathyTpChat, empathy_tp_chat, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CONTACT_LIST,
tp_chat_iface_init));
-static void acknowledge_messages (EmpathyTpChat *chat, GArray *ids);
-
static void
tp_chat_set_delivery_status (EmpathyTpChat *self,
const gchar *token,
@@ -453,6 +452,39 @@ message_received_cb (TpTextChannel *channel,
handle_incoming_message (chat, message, FALSE);
}
+static gboolean
+find_pending_message_func (gconstpointer a,
+ gconstpointer b)
+{
+ EmpathyMessage *msg = (EmpathyMessage *) a;
+ TpMessage *message = (TpMessage *) b;
+
+ if (empathy_message_get_tp_message (msg) == message)
+ return 0;
+
+ return -1;
+}
+
+static void
+pending_message_removed_cb (TpTextChannel *channel,
+ TpMessage *message,
+ EmpathyTpChat *chat)
+{
+ EmpathyTpChatPriv *priv = GET_PRIV (chat);
+ GList *m;
+
+ m = g_queue_find_custom (priv->pending_messages_queue, message,
+ find_pending_message_func);
+
+ if (m == NULL)
+ return;
+
+ g_signal_emit (chat, signals[MESSAGE_ACKNOWLEDGED], 0, m->data);
+
+ g_object_unref (m->data);
+ g_queue_delete_link (priv->pending_messages_queue, m);
+}
+
static void
message_sent_cb (TpTextChannel *channel,
TpMessage *message,
@@ -911,6 +943,8 @@ check_almost_ready (EmpathyTpChat *chat)
tp_g_signal_connect_object (priv->channel, "message-received",
G_CALLBACK (message_received_cb), chat, 0);
+ tp_g_signal_connect_object (priv->channel, "pending-message-removed",
+ G_CALLBACK (pending_message_removed_cb), chat, 0);
list_pending_messages (chat);
@@ -1632,6 +1666,16 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
G_TYPE_NONE,
0);
+ signals[MESSAGE_ACKNOWLEDGED] =
+ g_signal_new ("message-acknowledged",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1, EMPATHY_TYPE_MESSAGE);
+
g_type_class_add_private (object_class, sizeof (EmpathyTpChatPriv));
}
@@ -1793,84 +1837,51 @@ empathy_tp_chat_get_pending_messages (EmpathyTpChat *chat)
return priv->pending_messages_queue->head;
}
-static void
-acknowledge_messages (EmpathyTpChat *chat, GArray *ids) {
- EmpathyTpChatPriv *priv = GET_PRIV (chat);
-
- tp_cli_channel_type_text_call_acknowledge_pending_messages (
- priv->channel, -1, ids, tp_chat_async_cb,
- "acknowledging received message", NULL, G_OBJECT (chat));
-}
-
void
empathy_tp_chat_acknowledge_message (EmpathyTpChat *chat,
EmpathyMessage *message) {
EmpathyTpChatPriv *priv = GET_PRIV (chat);
- GArray *message_ids;
- GList *m;
- guint id;
+ TpMessage *tp_msg;
g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
g_return_if_fail (priv->ready);
if (!empathy_message_is_incoming (message))
- goto out;
-
- message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
-
- id = empathy_message_get_id (message);
- g_array_append_val (message_ids, id);
- acknowledge_messages (chat, message_ids);
- g_array_free (message_ids, TRUE);
+ return;
-out:
- m = g_queue_find (priv->pending_messages_queue, message);
- g_assert (m != NULL);
- g_queue_delete_link (priv->pending_messages_queue, m);
- g_object_unref (message);
+ tp_msg = empathy_message_get_tp_message (message);
+ tp_text_channel_ack_message_async (TP_TEXT_CHANNEL (priv->channel),
+ tp_msg, NULL, NULL);
}
void
empathy_tp_chat_acknowledge_messages (EmpathyTpChat *chat,
const GSList *messages) {
EmpathyTpChatPriv *priv = GET_PRIV (chat);
- /* Copy messages as the messges list (probably is) our own */
- GSList *msgs = g_slist_copy ((GSList *) messages);
- GSList *l;
- guint length;
- GArray *message_ids;
+ const GSList *l;
+ GList *messages_to_ack = NULL;
g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
g_return_if_fail (priv->ready);
- length = g_slist_length ((GSList *) messages);
-
- if (length == 0)
+ if (messages == NULL)
return;
- message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), length);
-
- for (l = msgs; l != NULL; l = g_slist_next (l)) {
- GList *m;
-
+ for (l = messages; l != NULL; l = g_slist_next (l)) {
EmpathyMessage *message = EMPATHY_MESSAGE (l->data);
- m = g_queue_find (priv->pending_messages_queue, message);
- g_assert (m != NULL);
- g_queue_delete_link (priv->pending_messages_queue, m);
-
if (empathy_message_is_incoming (message)) {
- guint id = empathy_message_get_id (message);
- g_array_append_val (message_ids, id);
+ TpMessage *tp_msg = empathy_message_get_tp_message (message);
+ messages_to_ack = g_list_append (messages_to_ack, tp_msg);
}
- g_object_unref (message);
}
- if (message_ids->len > 0)
- acknowledge_messages (chat, message_ids);
+ if (messages_to_ack != NULL) {
+ tp_text_channel_ack_messages_async (TP_TEXT_CHANNEL (priv->channel),
+ messages_to_ack, NULL, NULL);
+ }
- g_array_free (message_ids, TRUE);
- g_slist_free (msgs);
+ g_list_free (messages_to_ack);
}
void