From bd751c69ef2e0a9928b4853a8657e1cea376531e Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Tue, 5 Apr 2011 16:37:37 +0200 Subject: emulate '/me' command if CM doesn't support Action messages (#622118) --- libempathy-gtk/empathy-chat.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index dae0239c2..b7c5192a8 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -869,9 +869,33 @@ chat_command_me (EmpathyChat *chat, { EmpathyChatPriv *priv = GET_PRIV (chat); EmpathyMessage *message; + TpChannel *channel; + + channel = empathy_tp_chat_get_channel (priv->tp_chat); + + /* Strictly speaking we don't depend yet on Messages so best to check that + * the channel is actually a TpTextChannel before casting it. */ + if (TP_IS_TEXT_CHANNEL (channel) && + !tp_text_channel_supports_message_type (TP_TEXT_CHANNEL (channel), + TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION)) { + /* Action message are not supported, 'simulate' the action */ + EmpathyContact *self_contact; + gchar *tmp; + + self_contact = empathy_tp_chat_get_self_contact (priv->tp_chat); + /* The TpChat can't be ready if it doesn't have the self contact */ + g_assert (self_contact != NULL); + + tmp = g_strdup_printf ("%s %s", empathy_contact_get_alias (self_contact), + strv[1]); + message = empathy_message_new (tmp); + g_free (tmp); + } + else { + message = empathy_message_new (strv[1]); + empathy_message_set_tptype (message, TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION); + } - message = empathy_message_new (strv[1]); - empathy_message_set_tptype (message, TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION); empathy_tp_chat_send (priv->tp_chat, message); g_object_unref (message); } -- cgit v1.2.3