]> git.0d.be Git - empathy.git/blob - libempathy/empathy-request-util.c
rename empathy-dispatcher to empathy-request-util
[empathy.git] / libempathy / empathy-request-util.c
1 /* * Copyright (C) 2007-2010 Collabora Ltd.
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16  *
17  * Authors: Xavier Claessens <xclaesse@gmail.com>
18  *          Sjoerd Simons <sjoerd.simons@collabora.co.uk>
19  *          Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
20  */
21
22 #include <config.h>
23
24 #include <string.h>
25
26 #include <glib/gi18n-lib.h>
27
28 #include <telepathy-glib/telepathy-glib.h>
29
30 #include "empathy-request-util.h"
31 #include "empathy-utils.h"
32 #include "empathy-utils.h"
33
34 #define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
35 #include <libempathy/empathy-debug.h>
36
37 void
38 empathy_chat_with_contact (EmpathyContact *contact,
39     gint64 timestamp)
40 {
41   empathy_chat_with_contact_id (
42       empathy_contact_get_account (contact), empathy_contact_get_id (contact),
43       timestamp);
44 }
45
46 static void
47 ensure_text_channel_cb (GObject *source,
48     GAsyncResult *result,
49     gpointer user_data)
50 {
51   GError *error = NULL;
52
53   if (!tp_account_channel_request_ensure_channel_finish (
54         TP_ACCOUNT_CHANNEL_REQUEST (source), result, &error))
55     {
56       DEBUG ("Failed to ensure text channel: %s", error->message);
57       g_error_free (error);
58     }
59 }
60
61 void
62 empathy_chat_with_contact_id (TpAccount *account,
63     const gchar *contact_id,
64     gint64 timestamp)
65 {
66   GHashTable *request;
67   TpAccountChannelRequest *req;
68
69   request = tp_asv_new (
70       TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
71         TP_IFACE_CHANNEL_TYPE_TEXT,
72       TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
73       TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, contact_id,
74       NULL);
75
76   req = tp_account_channel_request_new (account, request, timestamp);
77
78   tp_account_channel_request_ensure_channel_async (req, NULL, NULL,
79       ensure_text_channel_cb, NULL);
80
81   g_hash_table_unref (request);
82   g_object_unref (req);
83 }
84
85 void
86 empathy_join_muc (TpAccount *account,
87     const gchar *room_name,
88     gint64 timestamp)
89 {
90   GHashTable *request;
91   TpAccountChannelRequest *req;
92
93   request = tp_asv_new (
94       TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
95         TP_IFACE_CHANNEL_TYPE_TEXT,
96       TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_ROOM,
97       TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, room_name,
98       NULL);
99
100   req = tp_account_channel_request_new (account, request, timestamp);
101
102   tp_account_channel_request_ensure_channel_async (req, NULL, NULL,
103       ensure_text_channel_cb, NULL);
104
105   g_hash_table_unref (request);
106   g_object_unref (req);
107 }