diff options
author | Xavier Claessens <xclaesse@gmail.com> | 2009-10-11 21:25:52 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2009-11-01 22:36:45 +0800 |
commit | 06f81e690da1a60ee385c9486bf59e221259fd1a (patch) | |
tree | 831175c1b740a8e16e9f8fe94b05e3cb3110e6f8 /libempathy-gtk | |
parent | a24f350a5e3423913f3456ddf7d5f5c6d3ad3300 (diff) | |
download | gsoc2013-empathy-06f81e690da1a60ee385c9486bf59e221259fd1a.tar gsoc2013-empathy-06f81e690da1a60ee385c9486bf59e221259fd1a.tar.gz gsoc2013-empathy-06f81e690da1a60ee385c9486bf59e221259fd1a.tar.bz2 gsoc2013-empathy-06f81e690da1a60ee385c9486bf59e221259fd1a.tar.lz gsoc2013-empathy-06f81e690da1a60ee385c9486bf59e221259fd1a.tar.xz gsoc2013-empathy-06f81e690da1a60ee385c9486bf59e221259fd1a.tar.zst gsoc2013-empathy-06f81e690da1a60ee385c9486bf59e221259fd1a.zip |
Add support for /msg command
https://bugzilla.gnome.org/show_bug.cgi?id=573407
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/empathy-chat.c | 76 |
1 files changed, 74 insertions, 2 deletions
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index 8c38e5bf7..b598afb38 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -404,12 +404,57 @@ chat_query_command_cb (EmpathyDispatchOperation *dispatch, } } +typedef struct { + EmpathyChat *chat; + gchar *msg; +} ChatMsgCommandData; + +static void +chat_msg_command_cb (EmpathyDispatchOperation *dispatch, + const GError *error, + gpointer user_data) +{ + ChatMsgCommandData *data = user_data; + EmpathyTpChat *tpchat; + + if (error != NULL) { + empathy_chat_view_append_event (data->chat->view, + _("Failed to msg contact")); + goto OUT; + } + + tpchat = EMPATHY_TP_CHAT ( + empathy_dispatch_operation_get_channel_wrapper (dispatch)); + + if (empathy_dispatch_operation_claim (dispatch)) { + EmpathyMessage *message; + gchar *event; + + message = empathy_message_new (data->msg); + empathy_tp_chat_send (tpchat, message); + g_object_unref (message); + + event = g_strdup_printf (_("[%s]: %s"), + empathy_tp_chat_get_id (tpchat), + data->msg); + empathy_chat_view_append_event (data->chat->view, event); + g_free (event); + + empathy_tp_chat_close (tpchat); + } + +OUT: + g_free (data->msg); + g_slice_free (ChatMsgCommandData, data); +} + static void chat_send (EmpathyChat *chat, const gchar *msg) { EmpathyChatPriv *priv; EmpathyMessage *message; + TpConnection *connection; gchar *join = NULL; if (EMP_STR_EMPTY (msg)) { @@ -420,6 +465,7 @@ chat_send (EmpathyChat *chat, chat_sent_message_add (chat, msg); + connection = empathy_tp_chat_get_connection (priv->tp_chat); if (strcmp (msg, "/clear") == 0) { empathy_chat_view_clear (chat->view); return; @@ -453,18 +499,44 @@ chat_send (EmpathyChat *chat, } else if (g_str_has_prefix (msg, "/j ")) { join = g_strstrip (g_strdup (msg + strlen ("/j "))); } else if (g_str_has_prefix (msg, "/query ")) { - TpConnection *connection; gchar *id; /* FIXME: We should probably search in members alias. But this * is enough for IRC */ id = g_strstrip (g_strdup (msg + strlen ("/query "))); - connection = empathy_tp_chat_get_connection (priv->tp_chat); empathy_dispatcher_chat_with_contact_id (connection, id, chat_query_command_cb, chat); g_free (id); return; + } else if (g_str_has_prefix (msg, "/msg ")) { + gchar *id, *index; + ChatMsgCommandData *data; + + id = g_strstrip (g_strdup (msg + strlen ("/msg "))); + index = strchr (id, ' '); + if (index != NULL) { + *index = '\0'; + g_strstrip (++index); + } + + if (EMP_STR_EMPTY (id) || EMP_STR_EMPTY (index)) { + empathy_chat_view_append_event (chat->view, + _("Usage: /msg pseudo message")); + g_free (id); + return; + } + + /* FIXME: We should probably search in members alias. But this + * is enough for IRC */ + data = g_slice_new (ChatMsgCommandData); + data->chat = chat; + data->msg = g_strdup (index); + empathy_dispatcher_chat_with_contact_id (connection, id, + chat_msg_command_cb, + data); + g_free (id); + return; } if (join != NULL) { |