]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-request-util.c
Move the code ensuring a requested sms channel to empathy-request-util
[empathy.git] / libempathy / empathy-request-util.c
index ea885dacc273f9d1a9c61fe3b506b17fcbdc8e25..6472230ab30604f4fdeeade433c8de344ecde395 100644 (file)
@@ -58,9 +58,11 @@ ensure_text_channel_cb (GObject *source,
     }
 }
 
-void
-empathy_chat_with_contact_id (TpAccount *account,
-    const gchar *contact_id,
+static void
+create_text_channel (TpAccount *account,
+    TpHandleType target_handle_type,
+    const gchar *target_id,
+    gboolean sms_channel,
     gint64 timestamp)
 {
   GHashTable *request;
@@ -69,39 +71,46 @@ empathy_chat_with_contact_id (TpAccount *account,
   request = tp_asv_new (
       TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
         TP_IFACE_CHANNEL_TYPE_TEXT,
-      TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
-      TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, contact_id,
+      TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, target_handle_type,
+      TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, target_id,
       NULL);
 
+  if (sms_channel)
+    tp_asv_set_boolean (request,
+        TP_PROP_CHANNEL_INTERFACE_SMS_SMS_CHANNEL, TRUE);
+
   req = tp_account_channel_request_new (account, request, timestamp);
 
-  tp_account_channel_request_ensure_channel_async (req, EMPATHY_CHAT_BUS_NAME,
-      NULL, ensure_text_channel_cb, NULL);
+  tp_account_channel_request_ensure_channel_async (req, NULL, NULL,
+      ensure_text_channel_cb, NULL);
 
   g_hash_table_unref (request);
   g_object_unref (req);
 }
 
+void
+empathy_chat_with_contact_id (TpAccount *account,
+    const gchar *contact_id,
+    gint64 timestamp)
+{
+       create_text_channel (account, TP_HANDLE_TYPE_CONTACT,
+        contact_id, FALSE, timestamp);
+}
+
 void
 empathy_join_muc (TpAccount *account,
     const gchar *room_name,
     gint64 timestamp)
 {
-  GHashTable *request;
-  TpAccountChannelRequest *req;
-
-  request = tp_asv_new (
-      TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
-        TP_IFACE_CHANNEL_TYPE_TEXT,
-      TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_ROOM,
-      TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, room_name,
-      NULL);
-
-  req = tp_account_channel_request_new (account, request, timestamp);
-
-  tp_account_channel_request_ensure_channel_async (req, EMPATHY_CHAT_BUS_NAME,
-      NULL, ensure_text_channel_cb, NULL);
+       create_text_channel (account, TP_HANDLE_TYPE_ROOM,
+        room_name, FALSE, timestamp);
+}
 
-  g_hash_table_unref (request);
-  g_object_unref (req);
+void
+empathy_sms_contact_id (TpAccount *account,
+    const gchar *contact_id,
+    gint64 timestamp)
+{
+  create_text_channel (account, TP_HANDLE_TYPE_CONTACT,
+      contact_id, TRUE, timestamp);
 }