static void
tp_contact_list_add (EmpathyContactList *list,
		     EmpathyContact     *contact,
		     const gchar        *message)
{
	EmpathyTpContactListPriv *priv = GET_PRIV (list);
	TpHandle handle;
	GArray handles = {(gchar *) &handle, 1};

	handle = empathy_contact_get_handle (contact);

	if (priv->subscribe) {
		tp_cli_channel_interface_group_call_add_members (priv->subscribe,
			-1, &handles, message, NULL, NULL, NULL, NULL);
	}

	if (priv->publish) {
		TpChannelGroupFlags flags = tp_channel_group_get_flags (priv->subscribe);
		if (flags & TP_CHANNEL_GROUP_FLAG_CAN_ADD ||
		    g_hash_table_lookup (priv->pendings, GUINT_TO_POINTER (handle))) {
			tp_cli_channel_interface_group_call_add_members (priv->publish,
				-1, &handles, message, NULL, NULL, NULL, NULL);
		}
	}

	/* We want to unblock the contact */
	if (tp_proxy_has_interface_by_id (priv->connection,
		TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING)) {
		TpContact *tp_contact = empathy_contact_get_tp_contact (contact);

		if (tp_contact != NULL)
			tp_contact_unblock_async (tp_contact, NULL, NULL);
	}
}
/* This function takes ownership of handles array */
static void
tp_contact_list_group_add (EmpathyTpContactList *list,
			   const gchar          *group_name,
			   GArray               *handles)
{
	EmpathyTpContactListPriv *priv = GET_PRIV (list);
	TpChannel                *channel;
	const gchar              *names[] = {group_name, NULL};

	/* Search the channel for that group name */
	channel = g_hash_table_lookup (priv->groups, group_name);
	if (channel) {
		tp_cli_channel_interface_group_call_add_members (channel, -1,
			handles, NULL, NULL, NULL, NULL, NULL);
		g_array_unref (handles);
		return;
	}

	/* That group does not exist yet, we have to:
	 * 1) Request an handle for the group name
	 * 2) Request a channel
	 * 3) When NewChannel is emitted, add handles in members
	 */
	g_hash_table_insert (priv->add_to_group,
			     g_strdup (group_name),
			     handles);
	tp_cli_connection_call_request_handles (priv->connection, -1,
						TP_HANDLE_TYPE_GROUP, names,
						tp_contact_list_group_request_handles_cb,
						NULL, NULL,
						G_OBJECT (list));
}
static void
tp_contact_list_subscribe_group_members_changed_cb (TpChannel     *channel,
						    gchar         *message,
						    GArray        *added,
						    GArray        *removed,
						    GArray        *local_pending,
						    GArray        *remote_pending,
						    guint          actor,
						    guint          reason,
						    EmpathyTpContactList *list)
{
	EmpathyTpContactListPriv *priv = GET_PRIV (list);
	guint i;
	GArray *accept;

	/* We now get the presence of those contacts, add them to members */
	add_to_members (list, added);

	/* Those contacts refuse to send us their presence, remove from members. */
	for (i = 0; i < removed->len; i++) {
		remove_from_member_if_needed (list, g_array_index (removed, TpHandle, i));
	}

	/* We want those contacts in our contact list but we don't get their
	 * presence yet. Add to members anyway. */
	add_to_members (list, remote_pending);

	/* Implicitly accept pending request of contacts which are now members. */
	if (priv->publish == NULL)
		return;

	accept = g_array_new (FALSE, FALSE, sizeof (TpHandle));
	for (i = 0; i < added->len; i++) {
		TpHandle handle = g_array_index (added, TpHandle, i);

		if (g_hash_table_lookup (priv->pendings, GUINT_TO_POINTER (handle)) != NULL)
			g_array_append_val (accept, handle);
	}

	for (i = 0; i < remote_pending->len; i++) {
		TpHandle handle = g_array_index (added, TpHandle, i);

		if (g_hash_table_lookup (priv->pendings, GUINT_TO_POINTER (handle)) != NULL)
			g_array_append_val (accept, handle);
	}

	tp_cli_channel_interface_group_call_add_members (priv->publish,
		-1, accept, NULL, NULL, NULL, NULL, NULL);

	g_array_unref (accept);
}
static void
tp_contact_list_got_local_pending_cb (TpConnection            *connection,
				      guint                    n_contacts,
				      EmpathyContact * const * contacts,
				      guint                    n_failed,
				      const TpHandle          *failed,
				      const GError            *error,
				      gpointer                 user_data,
				      GObject                 *list)
{
	EmpathyTpContactListPriv *priv = GET_PRIV (list);
	guint i;

	if (error) {
		DEBUG ("Error: %s", error->message);
		return;
	}

	for (i = 0; i < n_contacts; i++) {
		EmpathyContact *contact = contacts[i];
		TpHandle handle;
		const gchar *message;
		TpChannelGroupChangeReason reason;
		const TpIntSet *members, *remote_pending;

		handle = empathy_contact_get_handle (contact);
		members = tp_channel_group_get_members (priv->subscribe);
		remote_pending = tp_channel_group_get_remote_pending (priv->subscribe);

		if (tp_intset_is_member (members, handle) ||
		    tp_intset_is_member (remote_pending, handle)) {
			GArray handles = {(gchar *) &handle, 1};

			/* This contact is already subscribed, or user requested
			 * to subscribe, auto accept. */
			tp_cli_channel_interface_group_call_add_members (priv->publish,
				-1, &handles, NULL, NULL, NULL, NULL, NULL);
		}
		else if (tp_channel_group_get_local_pending_info (priv->publish,
								  handle,
								  NULL,
								  &reason,
								  &message)) {
			/* Add contact to pendings */
			g_hash_table_insert (priv->pendings, GUINT_TO_POINTER (handle),
					     g_object_ref (contact));
			g_signal_emit_by_name (list, "pendings-changed", contact,
					       contact, reason, message, TRUE);
		}
	}
}
Example #5
0
static void
tp_chat_add (EmpathyContactList *list,
	     EmpathyContact     *contact,
	     const gchar        *message)
{
	EmpathyTpChatPriv *priv = GET_PRIV (list);
	TpHandle           handle;
	GArray             handles = {(gchar *) &handle, 1};

	g_return_if_fail (EMPATHY_IS_TP_CHAT (list));
	g_return_if_fail (EMPATHY_IS_CONTACT (contact));

	handle = empathy_contact_get_handle (contact);
	tp_cli_channel_interface_group_call_add_members (priv->channel, -1,
							 &handles, NULL,
							 NULL, NULL, NULL,
							 NULL);
}
void
empathy_tp_streamed_media_accept_incoming_call (EmpathyTpStreamedMedia *call)
{
  EmpathyTpStreamedMediaPriv *priv = GET_PRIV (call);
  TpHandle self_handle;
  GArray handles = {(gchar *) &self_handle, 1};

  g_return_if_fail (EMPATHY_IS_TP_STREAMED_MEDIA (call));
  g_return_if_fail (priv->status == EMPATHY_TP_STREAMED_MEDIA_STATUS_PENDING);

  if (!priv->is_incoming)
    return;

  DEBUG ("Accepting incoming call");

  self_handle = tp_channel_group_get_self_handle (priv->channel);
  tp_cli_channel_interface_group_call_add_members (priv->channel, -1,
      &handles, NULL, NULL, NULL, NULL, NULL);
}
NS_IMETHODIMP
csTpChannelInterfaceGroup::CallAddMembers(PRUint32 aContactsCount, PRUint32 *aContacts, const nsACString &aMessage,
    csITpChannelInterfaceGroupAddMembersCB *cb)
{
  if (!m_Proxy)
    return NS_ERROR_NOT_INITIALIZED;

  GArray *cContacts = g_array_new(false, false, sizeof(guint ));
  for (PRUint32 i=0; i<aContactsCount; i++)
    g_array_append_val(cContacts, aContacts[i]);
  char *cMessage = ToNewCString(aMessage);

  NS_IF_ADDREF(cb);
  tp_cli_channel_interface_group_call_add_members(m_Proxy, -1,
      cContacts, cMessage,
      cb? AddMembersResponse: NULL, cb? cb: NULL, NULL, NULL);

  return NS_OK;
}
Example #8
0
void
polari_room_add_member (PolariRoom *room,
                        TpContact  *member)
{
  TpChannel *channel;

  g_return_if_fail (POLARI_IS_ROOM (room));

  channel = room->priv->channel;

  if (!tp_proxy_has_interface_by_id (TP_PROXY (channel),
                                     TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP))
    return;

  {
    TpHandle handle = tp_contact_get_handle (member);
    GArray handles = { (char *)&handle, 1 };

    tp_cli_channel_interface_group_call_add_members (channel,
                                   -1, &handles, NULL, NULL, NULL, NULL, NULL);
  }
}
static void
tp_contact_list_group_ready_cb (TpChannel *channel,
				const GError *error,
				gpointer list)
{
	EmpathyTpContactListPriv *priv = GET_PRIV (list);
	TpChannel *old_group;
	const gchar *group_name;
	const TpIntSet *members;
	GArray *arr;

	if (error) {
		DEBUG ("Error: %s", error->message);
		g_object_unref (channel);
		return;
	}

	group_name = tp_channel_get_identifier (channel);

	/* If there's already a group with this name in the table, we can't
	 * just let it be replaced. Replacing it causes it to be unreffed,
	 * which causes it to be invalidated (see
	 * <https://bugs.freedesktop.org/show_bug.cgi?id=22119>), which causes
	 * it to be removed from the hash table again, which causes it to be
	 * unreffed again.
	 */
	old_group = g_hash_table_lookup (priv->groups, group_name);

	if (old_group != NULL) {
		DEBUG ("Discarding old group %s (%p)", group_name, old_group);
		g_hash_table_steal (priv->groups, group_name);
		tp_contact_list_forget_group (list, old_group);
		g_object_unref (old_group);
	}

	/* Pass the reference on the TpChannel to priv->groups */
	g_hash_table_insert (priv->groups, (gpointer) group_name, channel);
	DEBUG ("Group %s added", group_name);

	g_signal_connect (channel, "group-members-changed",
			  G_CALLBACK (tp_contact_list_group_members_changed_cb),
			  list);

	g_signal_connect (channel, "invalidated",
			  G_CALLBACK (tp_contact_list_group_invalidated_cb),
			  list);

	if (priv->add_to_group) {
		GArray *handles;

		handles = g_hash_table_lookup (priv->add_to_group, group_name);
		if (handles) {
			DEBUG ("Adding initial members to group %s", group_name);
			tp_cli_channel_interface_group_call_add_members (channel,
				-1, handles, NULL, NULL, NULL, NULL, NULL);
			g_hash_table_remove (priv->add_to_group, group_name);
		}
	}

	/* Get initial members of the group */
	members = tp_channel_group_get_members (channel);
	g_assert (members != NULL);
	arr = tp_intset_to_array (members);
	contacts_added_to_group (list, channel, arr);
	g_array_unref (arr);
}