soc.2009.telepathy: e7b69f9a: Can now accept or reject chat invitation...
sttwister at soc.pidgin.im
sttwister at soc.pidgin.im
Wed Jul 15 08:10:54 EDT 2009
-----------------------------------------------------------------
Revision: e7b69f9a618f67ed09b9f10c1528bbd35636c1f6
Ancestor: 5bdf03b3bf73f48c3caaf85774829fa5192d7b6b
Author: sttwister at soc.pidgin.im
Date: 2009-07-15T12:00:07
Branch: im.pidgin.soc.2009.telepathy
URL: http://d.pidgin.im/viewmtn/revision/info/e7b69f9a618f67ed09b9f10c1528bbd35636c1f6
Modified files:
libpurple/protocols/telepathy/telepathy.c
libpurple/protocols/telepathy/telepathy_channel_list.c
libpurple/protocols/telepathy/telepathy_channel_list.h
libpurple/protocols/telepathy/telepathy_channel_text.c
libpurple/protocols/telepathy/telepathy_channel_text.h
libpurple/protocols/telepathy/telepathy_connection.c
libpurple/protocols/telepathy/telepathy_connection.h
ChangeLog:
Can now accept or reject chat invitations
-------------- next part --------------
============================================================
--- libpurple/protocols/telepathy/telepathy.c 230b03cb2f465888bb27b32651ad1052215a45d5
+++ libpurple/protocols/telepathy/telepathy.c 0bd98450536240f36256809747153818ad680f6d
@@ -561,19 +561,41 @@ telepathy_join_chat (PurpleConnection *g
telepathy_join_chat (PurpleConnection *gc, GHashTable *components)
{
telepathy_connection *data = purple_connection_get_protocol_data(gc);
+
const gchar *name = g_hash_table_lookup(components, "room");
+ telepathy_room_channel *tp_channel = g_hash_table_lookup(components, "tp_channel");
- /* Request a room text channel */
- GHashTable *map = tp_asv_new (
- TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
- TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_UINT, TP_HANDLE_TYPE_ROOM,
- TP_IFACE_CHANNEL ".TargetID", G_TYPE_STRING, name,
- NULL);
+ /* Is this a channel the user requested? */
+ if (tp_channel == NULL)
+ {
+ /* Request a room text channel */
+ GHashTable *map = tp_asv_new (
+ TP_IFACE_CHANNEL ".ChannelType",G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
+ TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_UINT, TP_HANDLE_TYPE_ROOM,
+ TP_IFACE_CHANNEL ".TargetID", G_TYPE_STRING, name,
+ NULL);
- purple_debug_info("telepathy", "Requesting room text channel for %s\n", name);
+ purple_debug_info("telepathy", "Requesting room text channel for %s\n", name);
- tp_cli_connection_interface_requests_call_ensure_channel(data->connection, -1,
- map, ensure_channel_cb, data, NULL, NULL);
+ tp_cli_connection_interface_requests_call_ensure_channel(data->connection, -1,
+ map, ensure_channel_cb, data, NULL, NULL);
+ }
+ else
+ {
+ /* This is an invitation request confirmation */
+ GArray *arr = g_array_new(FALSE, FALSE, sizeof(TpHandle));
+
+ g_array_append_val(arr, tp_channel->self_handle);
+
+ purple_debug_info("telepathy", "Adding self handle to chatroom group\n");
+
+ tp_cli_channel_interface_group_call_add_members(tp_channel->channel, -1,
+ arr, NULL, add_members_cb, data, NULL, NULL);
+
+ g_array_free(arr, TRUE);
+
+ handle_room_text_channel(tp_channel->channel, data, TRUE);
+ }
}
static void
@@ -617,6 +639,17 @@ static void
}
static void
+telepathy_reject_chat (PurpleConnection *gc, GHashTable *components)
+{
+ telepathy_room_channel *tp_channel = g_hash_table_lookup(components, "tp_channel");
+
+ if (tp_channel != NULL)
+ {
+ tp_cli_channel_call_close(tp_channel->channel, -1, NULL, NULL, NULL, NULL);
+ }
+}
+
+static void
telepathy_chat_invite (PurpleConnection *gc, int id, const char *message, const char *who)
{
telepathy_connection *data = purple_connection_get_protocol_data(gc);
@@ -793,7 +826,7 @@ static PurplePluginProtocolInfo telepath
NULL, /* rem_deny */
NULL, /* set_permit_deny */
telepathy_join_chat, /* join_chat */
- NULL, /* reject_chat */
+ telepathy_reject_chat, /* reject_chat */
NULL, /* get_chat_name */
telepathy_chat_invite, /* chat_invite */
telepathy_chat_leave, /* chat_leave */
============================================================
--- libpurple/protocols/telepathy/telepathy_channel_list.c e8fb56172c408c679aa5fc403e6b4d42751879ce
+++ libpurple/protocols/telepathy/telepathy_channel_list.c f8613678f3af018933633f221413e57faea08272
@@ -51,7 +51,7 @@ create_group_channel_cb (TpConnection *p
purple_debug_info("telepathy", "Group channel created: %s\n", out_Channel);
}
-static void
+void
add_members_cb (TpChannel *proxy,
const GError *error,
gpointer user_data,
============================================================
--- libpurple/protocols/telepathy/telepathy_channel_list.h 46e660896f8b1bf76a8b0d1f75325918a785fc10
+++ libpurple/protocols/telepathy/telepathy_channel_list.h 0690f27c3f2865a95c691c94942fe2c8ee454c95
@@ -53,6 +53,12 @@ void
GObject *weak_object);
void
+add_members_cb (TpChannel *proxy,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object);
+
+void
handle_list_channel (TpChannel *channel,
telepathy_connection *data);
============================================================
--- libpurple/protocols/telepathy/telepathy_channel_text.c 019a77759f8acbcbd6f7223cc97d12bc078a2777
+++ libpurple/protocols/telepathy/telepathy_channel_text.c ff45dcfcec60d351fa7c5bddf43108418a2afdd8
@@ -336,19 +336,23 @@ chat_get_contacts_cb (TpConnection *conn
tp_channel_get_handle(tp_channel->channel, NULL));
for (i = 0; i<n_contacts; ++i)
{
+ TpHandle handle = tp_contact_get_handle(contacts[i]);
+
purple_debug_info("telepathy", " %s (%s)\n",
tp_contact_get_identifier(contacts[i]),
tp_contact_get_alias(contacts[i]));
- purple_conv_chat_add_user(PURPLE_CONV_CHAT(conv),
- tp_contact_get_alias(contacts[i]), NULL,
- PURPLE_CBFLAGS_NONE, FALSE);
+ /* Make sure we are not duplicating any contact */
+ if (!g_hash_table_lookup(tp_channel->contacts, (gpointer)handle))
+ {
+ purple_conv_chat_add_user(PURPLE_CONV_CHAT(conv),
+ tp_contact_get_alias(contacts[i]), NULL,
+ PURPLE_CBFLAGS_NONE, FALSE);
- g_object_ref(contacts[i]);
+ g_object_ref(contacts[i]);
- g_hash_table_insert(tp_channel->contacts,
- (gpointer)tp_contact_get_handle(contacts[i]),
- contacts[i]);
+ g_hash_table_insert(tp_channel->contacts, (gpointer)handle, contacts[i]);
+ }
}
/* Only after we got the member list are we ready to receive messages */
@@ -395,6 +399,30 @@ chat_get_all_members_cb (TpChannel *prox
G_N_ELEMENTS (features), features,
chat_get_contacts_cb, user_data,
NULL, NULL);
+
+ if (out_Local_Pending->len > 0)
+ {
+ purple_debug_info("telepathy", "Got %u local pending members\n",
+ out_Local_Pending->len);
+
+ for (i = 0; i<out_Local_Pending->len; ++i)
+ {
+ purple_debug_info("telepathy", " %u\n",
+ g_array_index(out_Local_Pending, TpHandle, i));
+ }
+ }
+
+ if (out_Remote_Pending->len > 0)
+ {
+ purple_debug_info("telepathy", "Got %u remote pending members\n",
+ out_Remote_Pending->len);
+
+ for (i = 0; i<out_Remote_Pending->len; ++i)
+ {
+ purple_debug_info("telepathy", " %u\n",
+ g_array_index(out_Remote_Pending, TpHandle, i));
+ }
+ }
}
static void
@@ -552,20 +580,63 @@ chat_members_changed_cb (TpChannel *prox
}
}
-static void
+void
handle_room_text_channel (TpChannel *channel,
- telepathy_connection *data)
+ telepathy_connection *data,
+ gboolean invitation)
{
GError *error = NULL;
GHashTable *properties = tp_channel_borrow_immutable_properties(channel);
+
gchar *who = (gchar *)tp_asv_get_string(properties, TP_IFACE_CHANNEL ".TargetID");
+
+ TpHandle initiator_handle = tp_asv_get_uint32(properties,
+ TP_IFACE_CHANNEL ".InitiatorHandle", NULL);
+
TpHandle handle = tp_channel_get_handle(channel, NULL);
telepathy_room_channel *tp_channel;
tp_channel = g_hash_table_lookup(data->room_Channels, (gpointer)handle);
+
+ /* Is this an invitation we have not yet handled? */
+ if (initiator_handle != data->self_handle && !invitation)
+ {
+ gchar *initiator_id = (gchar *)tp_asv_get_string(properties,
+ TP_IFACE_CHANNEL ".InitiatorID");
+
+ /* Create a hash table for prompting the user */
+ GHashTable *chat_data = g_hash_table_new(g_str_hash, g_str_equal);
+
+ purple_debug_info("telepathy", "We have been invited by %s\n",
+ initiator_id);
+
+ /* Include information about the channel */
+ tp_channel = g_new0(telepathy_room_channel, 1);
+
+ tp_channel->channel = channel;
+ tp_channel->connection_data = data;
+ tp_channel->self_handle = tp_channel_group_get_self_handle(channel);
+
+ g_hash_table_insert(data->room_Channels, (gpointer)handle, tp_channel);
+
+ /* Fill in the actual information */
+ g_hash_table_insert(chat_data, "room", g_strdup(who));
+ g_hash_table_insert(chat_data, "tp_channel", tp_channel);
+
+ /* Prompt the user. Depending on his action, telepathy_join_chat() or
+ * telepathy_reject_chat() will be called along with the hash table
+ */
+ serv_got_chat_invite(data->gc, who, initiator_id, NULL, chat_data);
+
+ /* Return to wait for user input. If he accepts the invitation, this function
+ * will be called again with the invitation flag set.
+ */
+ return;
+ }
+
/* if tp_channel exists, then we requested this channel
* else it's an incoming request so we must cache it
*/
@@ -575,12 +646,15 @@ handle_room_text_channel (TpChannel *cha
who, handle);
tp_channel = g_new0(telepathy_room_channel, 1);
+
+ tp_channel->channel = channel;
+ tp_channel->connection_data = data;
+ tp_channel->self_handle = tp_channel_group_get_self_handle(channel);
+
g_hash_table_insert(data->room_Channels, (gpointer)handle, tp_channel);
- serv_got_joined_chat(data->gc, handle, who);
}
- tp_channel->channel = channel;
- tp_channel->connection_data = data;
+ serv_got_joined_chat(data->gc, handle, who);
tp_channel->contacts = g_hash_table_new(g_direct_hash, g_direct_equal);
/* This will notify us of users joining or leaving */
@@ -1021,7 +1095,7 @@ handle_text_channel (TpChannel *channel,
break;
case TP_HANDLE_TYPE_ROOM:
- handle_room_text_channel(channel, data);
+ handle_room_text_channel(channel, data, FALSE);
break;
default:
============================================================
--- libpurple/protocols/telepathy/telepathy_channel_text.h 7e8a8c93605497685bd8b7e913ceb0eddbaa1124
+++ libpurple/protocols/telepathy/telepathy_channel_text.h 696d427959ccb30ad4dd15acccd53766efcaf072
@@ -35,6 +35,8 @@ typedef struct
GHashTable *contacts;
+ TpHandle self_handle;
+
} telepathy_room_channel;
void
@@ -60,6 +62,11 @@ void
destroy_text_channel(telepathy_text_channel *tp_channel);
void
+handle_room_text_channel (TpChannel *channel,
+ telepathy_connection *data,
+ gboolean invitation);
+
+void
chat_send_cb (TpChannel *proxy,
const GError *error,
gpointer user_data,
============================================================
--- libpurple/protocols/telepathy/telepathy_connection.c 8ea204f815444131c2c39411766b906b616d6249
+++ libpurple/protocols/telepathy/telepathy_connection.c b8ddc2df04dd497e1b61250d4702f584e82a5bd0
@@ -311,6 +311,15 @@ connection_ready_cb (TpConnection *conne
}
g_strfreev(interfaces);
+
+ /* The self handle is useful in a number of possible scenarios,
+ * we need to keep track of it.
+ */
+ data->self_handle = tp_connection_get_self_handle(connection);
+
+ purple_debug_info("telepathy", "Self Handle: %u\n", data->self_handle);
+
+
tp_cli_connection_interface_requests_connect_to_new_channels(connection, new_channels_cb, user_data, NULL, NULL, &error);
if (error != NULL)
============================================================
--- libpurple/protocols/telepathy/telepathy_connection.h 6e2cd4cd44114f9d93f7c2102b42ba3752a9b548
+++ libpurple/protocols/telepathy/telepathy_connection.h 8b140f11430d17aae0cb0b556a9be5d56a1a2265
@@ -36,6 +36,8 @@ typedef struct
PurpleConnection *gc;
PurpleAccount *acct;
+ TpHandle self_handle;
+
/* This flag avoids having a channel processed twice via both NewChannels and quering the Channels property */
gboolean listing_channels;
More information about the Commits
mailing list