aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-tp-chatroom.c
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2007-05-21 06:34:10 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2007-05-21 06:34:10 +0800
commite9da37418519e89f8489491310b5f3ca3ef59f76 (patch)
tree1c071ef8c6bbbd3922dc5d70888bd30074313d1c /libempathy/empathy-tp-chatroom.c
parent03d20e55433ca5d11633dec62435ea66ebdaf1ae (diff)
downloadgsoc2013-empathy-e9da37418519e89f8489491310b5f3ca3ef59f76.tar
gsoc2013-empathy-e9da37418519e89f8489491310b5f3ca3ef59f76.tar.gz
gsoc2013-empathy-e9da37418519e89f8489491310b5f3ca3ef59f76.tar.bz2
gsoc2013-empathy-e9da37418519e89f8489491310b5f3ca3ef59f76.tar.lz
gsoc2013-empathy-e9da37418519e89f8489491310b5f3ca3ef59f76.tar.xz
gsoc2013-empathy-e9da37418519e89f8489491310b5f3ca3ef59f76.tar.zst
gsoc2013-empathy-e9da37418519e89f8489491310b5f3ca3ef59f76.zip
Implementing basic chatroom support. Actually it works only if we get
2007-05-21 Xavier Claessens <xclaesse@gmail.com> * libempathy-gtk/gossip-group-chat.c: * libempathy-gtk/gossip-group-chat.h: * libempathy-gtk/gossip-private-chat.c: * libempathy-gtk/gossip-private-chat.h: * libempathy-gtk/gossip-group-chat.glade: * libempathy-gtk/Makefile.am: * src/empathy-chat-main.c: * libempathy/empathy-tp-contact-list.c: * libempathy/gossip-telepathy-group.c: * libempathy/gossip-telepathy-group.h: * libempathy/empathy-tp-chatroom.c: * libempathy/empathy-tp-chatroom.h: Implementing basic chatroom support. Actually it works only if we get invited in a chatroom. svn path=/trunk/; revision=87
Diffstat (limited to 'libempathy/empathy-tp-chatroom.c')
-rw-r--r--libempathy/empathy-tp-chatroom.c163
1 files changed, 160 insertions, 3 deletions
diff --git a/libempathy/empathy-tp-chatroom.c b/libempathy/empathy-tp-chatroom.c
index 6feef549d..34875c10c 100644
--- a/libempathy/empathy-tp-chatroom.c
+++ b/libempathy/empathy-tp-chatroom.c
@@ -30,6 +30,7 @@
#include "empathy-contact-manager.h"
#include "gossip-telepathy-group.h"
#include "gossip-utils.h"
+#include "gossip-debug.h"
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
EMPATHY_TYPE_TP_CHATROOM, EmpathyTpChatroomPriv))
@@ -40,12 +41,28 @@ struct _EmpathyTpChatroomPriv {
EmpathyContactManager *manager;
EmpathyTpContactList *list;
GossipTelepathyGroup *group;
+
+ gboolean is_invited;
+ GossipContact *invitor;
+ gchar *invit_message;
};
static void empathy_tp_chatroom_class_init (EmpathyTpChatroomClass *klass);
static void tp_chatroom_iface_init (EmpathyContactListIface *iface);
static void empathy_tp_chatroom_init (EmpathyTpChatroom *chatroom);
static void tp_chatroom_finalize (GObject *object);
+static void tp_chatroom_members_added_cb (GossipTelepathyGroup *group,
+ GArray *handles,
+ guint actor_handle,
+ guint reason,
+ const gchar *message,
+ EmpathyTpChatroom *list);
+static void tp_chatroom_members_removed_cb (GossipTelepathyGroup *group,
+ GArray *handles,
+ guint actor_handle,
+ guint reason,
+ const gchar *message,
+ EmpathyTpChatroom *list);
static void tp_chatroom_setup (EmpathyContactList *list);
static GossipContact * tp_chatroom_find (EmpathyContactList *list,
const gchar *id);
@@ -97,7 +114,12 @@ tp_chatroom_finalize (GObject *object)
g_object_unref (priv->group);
g_object_unref (priv->manager);
- g_object_unref (priv->list);
+
+ if (priv->invitor) {
+ g_object_unref (priv->invitor);
+ }
+
+ g_free (priv->invit_message);
G_OBJECT_CLASS (empathy_tp_chatroom_parent_class)->finalize (object);
}
@@ -110,6 +132,8 @@ empathy_tp_chatroom_new (McAccount *account,
EmpathyTpChatroom *chatroom;
TpConn *tp_conn;
MissionControl *mc;
+ GList *members, *l;
+ guint self_handle;
g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL);
@@ -124,18 +148,139 @@ empathy_tp_chatroom_new (McAccount *account,
mc = gossip_mission_control_new ();
tp_conn = mission_control_get_connection (mc, account, NULL);
priv->manager = empathy_contact_manager_new ();
- priv->group = gossip_telepathy_group_new (tp_chan, tp_conn);
priv->list = empathy_contact_manager_get_list (priv->manager, account);
+ priv->group = gossip_telepathy_group_new (tp_chan, tp_conn);
+
+ g_signal_connect (priv->group, "members-added",
+ G_CALLBACK (tp_chatroom_members_added_cb),
+ chatroom);
+ g_signal_connect (priv->group, "members-removed",
+ G_CALLBACK (tp_chatroom_members_removed_cb),
+ chatroom);
+
+ /* Check if we are invited to join the chat */
+ self_handle = gossip_telepathy_group_get_self_handle (priv->group);
+ members = gossip_telepathy_group_get_local_pending_members_with_info (priv->group);
+ for (l = members; l; l = l->next) {
+ GossipTpGroupInfo *info;
+ info = l->data;
+
+ if (info->member != self_handle) {
+ continue;
+ }
+
+ priv->invitor = empathy_tp_contact_list_get_from_handle (priv->list,
+ info->actor);
+ priv->invit_message = g_strdup (info->message);
+ priv->is_invited = TRUE;
+
+ gossip_debug (DEBUG_DOMAIN, "We are invited to join by %s: %s",
+ gossip_contact_get_name (priv->invitor),
+ priv->invit_message);
+ }
+
+ gossip_telepathy_group_info_list_free (members);
g_object_unref (mc);
g_object_unref (tp_conn);
return chatroom;
}
+gboolean
+empathy_tp_chatroom_get_invitation (EmpathyTpChatroom *chatroom,
+ GossipContact **contact,
+ const gchar **message)
+{
+ EmpathyTpChatroomPriv *priv;
+
+ g_return_val_if_fail (EMPATHY_IS_TP_CHATROOM (chatroom), FALSE);
+
+ priv = GET_PRIV (chatroom);
+
+ if (*contact) {
+ *contact = priv->invitor;
+ }
+ if (*message) {
+ *message = priv->invit_message;
+ }
+
+ return priv->is_invited;
+}
+
+void
+empathy_tp_chatroom_accept_invitation (EmpathyTpChatroom *chatroom)
+{
+ EmpathyTpChatroomPriv *priv;
+ guint self_handle;
+
+ g_return_if_fail (EMPATHY_IS_TP_CHATROOM (chatroom));
+
+ priv = GET_PRIV (chatroom);
+
+ /* Clear invitation data */
+ priv->is_invited = FALSE;
+ if (priv->invitor) {
+ g_object_unref (priv->invitor);
+ priv->invitor = NULL;
+ }
+ g_free (priv->invit_message);
+ priv->invit_message = NULL;
+
+ /* Add ourself in the members of the room */
+ self_handle = gossip_telepathy_group_get_self_handle (priv->group);
+ gossip_telepathy_group_add_member (priv->group, self_handle,
+ "Just for fun");
+}
+
+void
+empathy_tp_chatroom_set_topic (EmpathyTpChatroom *chatroom,
+ const gchar *topic)
+{
+}
+
+static void
+tp_chatroom_members_added_cb (GossipTelepathyGroup *group,
+ GArray *handles,
+ guint actor_handle,
+ guint reason,
+ const gchar *message,
+ EmpathyTpChatroom *chatroom)
+{
+ EmpathyTpChatroomPriv *priv;
+ GList *contacts, *l;
+
+ g_return_if_fail (EMPATHY_IS_TP_CHATROOM (chatroom));
+
+ priv = GET_PRIV (chatroom);
+
+ contacts = empathy_tp_contact_list_get_from_handles (priv->list, handles);
+ for (l = contacts; l; l = l->next) {
+ GossipContact *contact;
+
+ contact = l->data;
+
+ g_signal_emit_by_name (chatroom, "contact-added", contact);
+
+ g_object_unref (contact);
+ }
+ g_list_free (contacts);
+}
+
+static void
+tp_chatroom_members_removed_cb (GossipTelepathyGroup *group,
+ GArray *handles,
+ guint actor_handle,
+ guint reason,
+ const gchar *message,
+ EmpathyTpChatroom *chatroom)
+{
+}
+
static void
tp_chatroom_setup (EmpathyContactList *list)
{
+ /* Nothing to do */
}
static GossipContact *
@@ -162,6 +307,18 @@ tp_chatroom_remove (EmpathyContactList *list,
static GList *
tp_chatroom_get_contacts (EmpathyContactList *list)
{
- return NULL;
+ EmpathyTpChatroomPriv *priv;
+ GArray *members;
+ GList *contacts;
+
+ g_return_val_if_fail (EMPATHY_IS_TP_CHATROOM (list), NULL);
+
+ priv = GET_PRIV (list);
+
+ members = gossip_telepathy_group_get_members (priv->group);
+ contacts = empathy_tp_contact_list_get_from_handles (priv->list, members);
+ g_array_free (members, TRUE);
+
+ return contacts;
}