]> git.0d.be Git - empathy.git/commitdiff
Fix support for /me and /say commands.
authorXavier Claessens <xclaesse@gmail.com>
Fri, 10 Apr 2009 17:31:39 +0000 (17:31 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Fri, 10 Apr 2009 17:31:39 +0000 (17:31 +0000)
From: Xavier Claessens <xclaesse@gmail.com>

svn path=/trunk/; revision=2809

libempathy-gtk/empathy-chat.c

index d11f331610670887e24a875e44bc85733acd60f5..5f54c12ebb3d123d0231ae76abaa8af67f0ba050 100644 (file)
@@ -349,6 +349,7 @@ chat_send (EmpathyChat  *chat,
           const gchar *msg)
 {
        EmpathyChatPriv *priv;
+       EmpathyMessage  *message;
 
        if (EMP_STR_EMPTY (msg)) {
                return;
@@ -358,24 +359,25 @@ chat_send (EmpathyChat  *chat,
 
        chat_sent_message_add (chat, msg);
 
-       /* If this is not a command, send the message */
-       if (msg[0] != '/') {
-               EmpathyMessage  *message;
-
-               message = empathy_message_new (msg);
-               empathy_tp_chat_send (priv->tp_chat, message);
-               g_object_unref (message);
+       if (g_str_has_prefix (msg, "/clear")) {
+               empathy_chat_view_clear (chat->view);
                return;
        }
 
-       /* Check for all supported commands */
-       if (g_str_has_prefix (msg, "/clear")) {
-               empathy_chat_view_clear (chat->view);
+       /* Blacklist messages begining by '/', except for "/me" and "/say"
+        * because they are handled in EmpathyMessage */
+       if (msg[0] == '/' &&
+           !g_str_has_prefix (msg, "/me") &&
+           !g_str_has_prefix (msg, "/say")) {
+               empathy_chat_view_append_event (chat->view,
+                       _("Unsupported command"));
                return;
        }
 
-       /* This is an unknown command, display a message to the user */
-       empathy_chat_view_append_event (chat->view, _("Unsupported command"));
+       /* We can send the message */
+       message = empathy_message_new (msg);
+       empathy_tp_chat_send (priv->tp_chat, message);
+       g_object_unref (message);
 }
 
 static void
@@ -567,28 +569,6 @@ chat_property_changed_cb (EmpathyTpChat *tp_chat,
        }
 }
 
-static gboolean
-chat_get_is_command (const gchar *str)
-{
-       g_return_val_if_fail (str != NULL, FALSE);
-
-       if (str[0] != '/') {
-               return FALSE;
-       }
-
-       if (g_str_has_prefix (str, "/me")) {
-               return TRUE;
-       }
-       else if (g_str_has_prefix (str, "/nick")) {
-               return TRUE;
-       }
-       else if (g_str_has_prefix (str, "/topic")) {
-               return TRUE;
-       }
-
-       return FALSE;
-}
-
 static void
 chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
                                   EmpathyChat    *chat)
@@ -648,8 +628,8 @@ chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
 
                str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
 
-               /* spell check string */
-               if (!chat_get_is_command (str)) {
+               /* spell check string if not a command */
+               if (str[0] != '/') {
                        correct = empathy_spell_check (str);
                } else {
                        correct = TRUE;