Ejemplo n.º 1
0
static void
chatroom_manager_observe_channel_cb (EmpathyDispatcher *dispatcher,
  EmpathyDispatchOperation *operation, gpointer manager)
{
  EmpathyChatroomManagerPriv *priv = GET_PRIV (manager);
  EmpathyChatroom *chatroom;
  TpChannel *channel;
  EmpathyTpChat *chat;
  const gchar *roomname;
  GQuark channel_type;
  TpHandleType handle_type;
  EmpathyAccount *account;
  TpConnection *connection;

  channel_type = empathy_dispatch_operation_get_channel_type_id (operation);

  /* Observe Text channels to rooms only */
  if (channel_type != TP_IFACE_QUARK_CHANNEL_TYPE_TEXT)
    return;

  channel = empathy_dispatch_operation_get_channel (operation);
  tp_channel_get_handle (channel, &handle_type);

  if (handle_type != TP_HANDLE_TYPE_ROOM)
    return;

  chat = EMPATHY_TP_CHAT (
    empathy_dispatch_operation_get_channel_wrapper (operation));
  connection = empathy_tp_chat_get_connection (chat);
  account = empathy_account_manager_get_account_for_connection (
      priv->account_manager, connection);

  roomname = empathy_tp_chat_get_id (chat);

  chatroom = empathy_chatroom_manager_find (manager, account, roomname);

  if (chatroom == NULL)
    {
      chatroom = empathy_chatroom_new_full (account, roomname, roomname,
        FALSE);
      empathy_chatroom_set_tp_chat (chatroom, chat);
      empathy_chatroom_manager_add (manager, chatroom);
      g_object_unref (chatroom);
    }
  else
    {
        empathy_chatroom_set_tp_chat (chatroom, chat);
    }

  /* A TpChat is always destroyed as it only gets unreffed after the channel
   * has been invalidated in the dispatcher..  */
  g_signal_connect (chat, "destroy",
    G_CALLBACK (chatroom_manager_chat_destroyed_cb),
    manager);
}
Ejemplo n.º 2
0
static void
dispatch_cb (EmpathyDispatcher *dispatcher,
    EmpathyDispatchOperation *operation,
    gpointer user_data)
{
  GQuark channel_type;

  channel_type = empathy_dispatch_operation_get_channel_type_id (operation);

  if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT)
    {
      EmpathyTpChat *tp_chat;
      EmpathyChat   *chat = NULL;
      const gchar   *id;

      tp_chat = EMPATHY_TP_CHAT
        (empathy_dispatch_operation_get_channel_wrapper (operation));

      id = empathy_tp_chat_get_id (tp_chat);
      if (!EMP_STR_EMPTY (id))
        {
          TpConnection *connection;
          TpAccount *account;

          connection = empathy_tp_chat_get_connection (tp_chat);
          account = empathy_get_account_for_connection (connection);
          chat = empathy_chat_window_find_chat (account, id);
        }

      if (chat)
        {
          empathy_chat_set_tp_chat (chat, tp_chat);
        }
      else
        {
          chat = empathy_chat_new (tp_chat);
          /* empathy_chat_new returns a floating reference as EmpathyChat is
           * a GtkWidget. This reference will be taken by a container
           * (a GtkNotebook) when we'll call empathy_chat_window_present_chat */
        }

      empathy_chat_window_present_chat (chat);

      empathy_dispatch_operation_claim (operation);
    }
  else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
    {
      EmpathyCallFactory *factory;

      factory = empathy_call_factory_get ();
      empathy_call_factory_claim_channel (factory, operation);
    }
  else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER)
    {
      EmpathyFTFactory *factory;

      factory = empathy_ft_factory_dup_singleton ();

      /* if the operation is not incoming, don't claim it,
       * as it might have been triggered by another client, and
       * we are observing it.
       */
      if (empathy_dispatch_operation_is_incoming (operation))
        empathy_ft_factory_claim_channel (factory, operation);
    }
}