]> git.0d.be Git - empathy.git/commitdiff
Implementation of /PART command for MUCs
authorChandni Verma <chandniverma2112@gmail.com>
Wed, 23 Feb 2011 06:25:25 +0000 (11:55 +0530)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Fri, 25 Feb 2011 09:25:01 +0000 (10:25 +0100)
Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=604348
libempathy-gtk/empathy-chat.c
libempathy-gtk/empathy-chat.h

index fbe2425b656f69c8ca54c07fc1f450fadfdca920..2aa94af06f185a83add4a212ea885268e4af46de 100644 (file)
@@ -44,6 +44,8 @@
 #include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-dispatcher.h>
 #include <libempathy/empathy-marshal.h>
+#include <libempathy/empathy-chatroom-manager.h>
+#include <src/empathy-chat-window.h>
 
 #include "empathy-chat.h"
 #include "empathy-spell.h"
@@ -684,6 +686,17 @@ nick_command_supported (EmpathyChat *chat)
                EMP_IFACE_QUARK_CONNECTION_INTERFACE_RENAMING);
 }
 
+static gboolean
+part_command_supported (EmpathyChat *chat)
+{
+       EmpathyChatPriv * priv = GET_PRIV (chat);
+       TpChannel *channel;
+
+       channel = empathy_tp_chat_get_channel (priv->tp_chat);
+       return tp_proxy_has_interface_by_id (channel,
+                       TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP);
+}
+
 static void
 chat_command_clear (EmpathyChat *chat,
                    GStrv        strv)
@@ -718,12 +731,21 @@ chat_command_topic (EmpathyChat *chat,
        g_value_unset (&value);
 }
 
+void
+empathy_chat_join_muc (EmpathyChat *chat,
+                  const gchar   *room)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+
+       empathy_dispatcher_join_muc (priv->account, room,
+               gtk_get_current_event_time ());
+}
+
 static void
 chat_command_join (EmpathyChat *chat,
                   GStrv        strv)
 {
        guint i = 0;
-       EmpathyChatPriv *priv = GET_PRIV (chat);
 
        GStrv rooms = g_strsplit_set (strv[1], ", ", -1);
 
@@ -733,17 +755,41 @@ chat_command_join (EmpathyChat *chat,
        while (rooms[i] != NULL) {
                /* ignore empty strings */
                if (!EMP_STR_EMPTY (rooms[i])) {
-                       TpConnection *connection;
-
-                       connection = empathy_tp_chat_get_connection (priv->tp_chat);
-                       empathy_dispatcher_join_muc (priv->account, rooms[i],
-                               gtk_get_current_event_time ());
+                       empathy_chat_join_muc (chat, rooms[i]);
                }
                i++;
        }
        g_strfreev (rooms);
 }
 
+void
+empathy_chat_leave_chat (EmpathyChat *chat)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+
+       empathy_tp_chat_leave (priv->tp_chat, "");
+}
+
+static void
+chat_command_part (EmpathyChat *chat,
+                          GStrv        strv)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       EmpathyChat *chat_to_be_parted;
+
+       if (strv[1] == NULL) {
+               empathy_tp_chat_leave (priv->tp_chat, "");
+               return;
+       }
+       chat_to_be_parted = empathy_chat_window_find_chat (priv->account, strv[1]);
+
+       if (chat_to_be_parted != NULL) {
+               empathy_tp_chat_leave (empathy_chat_get_tp_chat (chat_to_be_parted), strv[2]);
+       } else {
+               empathy_tp_chat_leave (priv->tp_chat, strv[1]);
+       }
+}
+
 static void
 chat_command_msg_internal (EmpathyChat *chat,
                           const gchar *contact_id,
@@ -867,6 +913,10 @@ static ChatCommandItem commands[] = {
        {"j", 2, 2, chat_command_join, NULL,
         N_("/j <chat room ID>: join a new chat room")},
 
+       {"part", 1, 3, chat_command_part, part_command_supported,
+        N_("/part [<chat room ID>] [<reason>]: leave the chat room, "
+           "by default the current one")},
+
        {"query", 2, 3, chat_command_query, NULL,
         N_("/query <contact ID> [<message>]: open a private chat")},
 
index 01b7a737bdc2b621466339aa8775681491ff3141..77122f7c873dc7343047a854aea4ecb0c0037d8d 100644 (file)
@@ -83,6 +83,9 @@ void               empathy_chat_correct_word         (EmpathyChat   *chat,
                                                      GtkTextIter   *start,
                                                      GtkTextIter   *end,
                                                      const gchar   *new_word);
+void               empathy_chat_join_muc             (EmpathyChat   *chat,
+                                                     const gchar   *room);
+void               empathy_chat_leave_chat           (EmpathyChat *chat);
 gboolean           empathy_chat_is_room              (EmpathyChat   *chat);
 void               empathy_chat_set_show_contacts    (EmpathyChat *chat,
                                                       gboolean     show);