Пример #1
0
static void
handle_channels (TpSimpleHandler *handler,
    TpAccount *account,
    TpConnection *connection,
    GList *channels,
    GList *requests_satisfied,
    gint64 user_action_time,
    TpHandleChannelsContext *context,
    gpointer user_data)
{
  EmpathyChatManager *self = (EmpathyChatManager *) user_data;
  GList *l;

  for (l = channels; l != NULL; l = g_list_next (l))
    {
      EmpathyTpChat *tp_chat = l->data;

      if (tp_proxy_get_invalidated (tp_chat) != NULL)
        continue;

      if (!EMPATHY_IS_TP_CHAT (tp_chat))
        {
          DEBUG ("Channel %s doesn't implement Messages; can't handle it",
              tp_proxy_get_object_path (tp_chat));
          continue;
        }

      DEBUG ("Now handling channel %s", tp_proxy_get_object_path (tp_chat));

      process_tp_chat (self, tp_chat, account, user_action_time);
    }

  tp_handle_channels_context_accept (context);
}
Пример #2
0
void
empathy_tp_chat_acknowledge_message (EmpathyTpChat *chat,
				     EmpathyMessage *message) {
	EmpathyTpChatPriv *priv = GET_PRIV (chat);
	GArray *message_ids;
	GList *m;
	guint id;

	g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
	g_return_if_fail (priv->ready);

	if (empathy_message_get_sender (message) == priv->user)
		goto out;

	message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);

	id = empathy_message_get_id (message);
	g_array_append_val (message_ids, id);
	acknowledge_messages (chat, message_ids);
	g_array_free (message_ids, TRUE);

out:
	m = g_queue_find (priv->pending_messages_queue, message);
	g_assert (m != NULL);
	g_queue_delete_link (priv->pending_messages_queue, m);
	g_object_unref (message);
}
Пример #3
0
gboolean
empathy_tp_chat_is_ready (EmpathyTpChat *chat)
{
	EmpathyTpChatPriv *priv = GET_PRIV (chat);

	g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), FALSE);

	return priv->ready;
}
Пример #4
0
TpConnection *
empathy_tp_chat_get_connection (EmpathyTpChat *chat)
{
	EmpathyTpChatPriv *priv = GET_PRIV (chat);

	g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);

	return tp_channel_borrow_connection (priv->channel);
}
Пример #5
0
TpChannel *
empathy_tp_chat_get_channel (EmpathyTpChat *chat)
{
	EmpathyTpChatPriv *priv = GET_PRIV (chat);

	g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);

	return priv->channel;
}
Пример #6
0
const gchar *
empathy_tp_chat_get_id (EmpathyTpChat *chat)
{
	EmpathyTpChatPriv *priv = GET_PRIV (chat);

	g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);

	return tp_channel_get_identifier (priv->channel);
}
Пример #7
0
const GList *
empathy_tp_chat_get_pending_messages (EmpathyTpChat *chat)
{
	EmpathyTpChatPriv *priv = GET_PRIV (chat);

	g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
	g_return_val_if_fail (priv->ready, NULL);

	return priv->pending_messages_queue->head;
}
Пример #8
0
EmpathyContact *
empathy_tp_chat_get_remote_contact (EmpathyTpChat *chat)
{
	EmpathyTpChatPriv *priv = GET_PRIV (chat);

	g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
	g_return_val_if_fail (priv->ready, NULL);

	return priv->remote_contact;
}
Пример #9
0
static EmpathyContactMonitor *
tp_chat_get_monitor (EmpathyContactList *list)
{
	EmpathyTpChatPriv *priv;

	g_return_val_if_fail (EMPATHY_IS_TP_CHAT (list), NULL);

	priv = GET_PRIV (list);

	if (priv->contact_monitor == NULL) {
		priv->contact_monitor = empathy_contact_monitor_new_for_iface (list);
	}

	return priv->contact_monitor;
}
Пример #10
0
void
empathy_tp_chat_set_state (EmpathyTpChat      *chat,
			   TpChannelChatState  state)
{
	EmpathyTpChatPriv *priv = GET_PRIV (chat);

	g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
	g_return_if_fail (priv->ready);

	DEBUG ("Set state: %d", state);
	tp_cli_channel_interface_chat_state_call_set_chat_state (priv->channel, -1,
								 state,
								 tp_chat_async_cb,
								 "setting chat state",
								 NULL,
								 G_OBJECT (chat));
}
static void
observe_channels_cb (TpSimpleObserver *observer,
    TpAccount *account,
    TpConnection *connection,
    GList *channels,
    TpChannelDispatchOperation *dispatch_operation,
    GList *requests,
    TpObserveChannelsContext *context,
    gpointer user_data)
{
  EmpathyChatroomManager *self = user_data;
  GList *l;

  for (l = channels; l != NULL; l = g_list_next (l))
    {
      EmpathyTpChat *tp_chat = l->data;
      const gchar *roomname;
      EmpathyChatroom *chatroom;

      if (tp_proxy_get_invalidated ((TpChannel *) tp_chat) != NULL)
        continue;

      if (!EMPATHY_IS_TP_CHAT (tp_chat))
        continue;

      roomname = empathy_tp_chat_get_id (tp_chat);
      chatroom = empathy_chatroom_manager_find (self, account, roomname);

      if (chatroom == NULL)
        {
          chatroom = empathy_chatroom_new_full (account, roomname, roomname,
            FALSE);
          empathy_chatroom_manager_add (self, chatroom);
          g_object_unref (chatroom);
        }

      empathy_chatroom_set_tp_chat (chatroom, tp_chat);

      g_signal_connect (tp_chat, "invalidated",
        G_CALLBACK (chatroom_manager_chat_invalidated_cb),
        self);
    }

  tp_observe_channels_context_accept (context);
}
Пример #12
0
static GList *
tp_chat_get_members (EmpathyContactList *list)
{
	EmpathyTpChatPriv *priv = GET_PRIV (list);
	GList             *members = NULL;

	g_return_val_if_fail (EMPATHY_IS_TP_CHAT (list), NULL);

	if (priv->members) {
		members = g_list_copy (priv->members);
		g_list_foreach (members, (GFunc) g_object_ref, NULL);
	} else {
		members = g_list_prepend (members, g_object_ref (priv->user));
		members = g_list_prepend (members, g_object_ref (priv->remote_contact));
	}

	return members;
}
Пример #13
0
static void
tp_chat_remove (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_remove_members (priv->channel, -1,
							    &handles, NULL,
							    NULL, NULL, NULL,
							    NULL);
}
Пример #14
0
void
empathy_tp_chat_acknowledge_messages (EmpathyTpChat *chat,
				      const GList *messages) {
	EmpathyTpChatPriv *priv = GET_PRIV (chat);
	/* Copy messages as the messges list (probably is) our own */
	GList *msgs = g_list_copy ((GList *) messages);
	GList *l;
	guint length;
	GArray *message_ids;

	g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
	g_return_if_fail (priv->ready);

	length = g_list_length ((GList *) messages);

	if (length == 0)
		return;

	message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), length);

	for (l = msgs; l != NULL; l = g_list_next (l)) {
		GList *m;

		EmpathyMessage *message = EMPATHY_MESSAGE (l->data);

		m = g_queue_find (priv->pending_messages_queue, message);
		g_assert (m != NULL);
		g_queue_delete_link (priv->pending_messages_queue, m);

		if (empathy_message_get_sender (message) != priv->user) {
			guint id = empathy_message_get_id (message);
			g_array_append_val (message_ids, id);
		}
		g_object_unref (message);
	}

	if (message_ids->len > 0)
		acknowledge_messages (chat, message_ids);

	g_array_free (message_ids, TRUE);
	g_list_free (msgs);
}
Пример #15
0
void
empathy_chatroom_set_tp_chat (EmpathyChatroom *chatroom,
			      EmpathyTpChat   *tp_chat)
{
	EmpathyChatroomPriv *priv;

	g_return_if_fail (EMPATHY_IS_CHATROOM (chatroom));
	g_return_if_fail (tp_chat == NULL || EMPATHY_IS_TP_CHAT (tp_chat));

	priv = GET_PRIV (chatroom);

	if (priv->tp_chat == tp_chat) {
		return;
	}

	if (priv->tp_chat != NULL) {
		g_object_unref (priv->tp_chat);
	}

	priv->tp_chat = tp_chat ? g_object_ref (tp_chat) : NULL;
	g_object_notify (G_OBJECT (chatroom), "tp-chat");
}
Пример #16
0
void
empathy_tp_chat_send (EmpathyTpChat *chat,
		      EmpathyMessage *message)
{
	EmpathyTpChatPriv        *priv = GET_PRIV (chat);
	const gchar              *message_body;
	TpChannelTextMessageType  message_type;

	g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
	g_return_if_fail (EMPATHY_IS_MESSAGE (message));
	g_return_if_fail (priv->ready);

	message_body = empathy_message_get_body (message);
	message_type = empathy_message_get_tptype (message);

	DEBUG ("Sending message: %s", message_body);
	tp_cli_channel_type_text_call_send (priv->channel, -1,
					    message_type,
					    message_body,
					    tp_chat_send_cb,
					    g_object_ref (message),
					    (GDestroyNotify) g_object_unref,
					    G_OBJECT (chat));
}