static void polari_room_set_channel (PolariRoom *room, TpChannel *channel) { PolariRoomPrivate *priv; g_return_if_fail (POLARI_IS_ROOM (room)); g_return_if_fail (channel == NULL || TP_IS_TEXT_CHANNEL (channel)); priv = room->priv; if (priv->channel == channel) return; if (priv->channel) { g_signal_handler_disconnect (priv->channel, priv->identifier_notify_id); g_signal_handler_disconnect (priv->channel, priv->group_contacts_changed_id); tp_proxy_signal_connection_disconnect (priv->properties_changed_id); g_clear_object (&priv->channel); } if (channel) { priv->channel = g_object_ref (channel); if (priv->id == NULL) priv->id = g_strdup (tp_proxy_get_object_path (TP_PROXY (channel))); tp_cli_dbus_properties_call_get_all (channel, -1, TP_IFACE_CHANNEL_INTERFACE_SUBJECT, (tp_properties_get_all_cb)subject_get_all, room, NULL, NULL); priv->identifier_notify_id = g_signal_connect (channel, "notify::identifier", G_CALLBACK (on_identifier_notify), room); priv->group_contacts_changed_id = g_signal_connect (channel, "group-contacts-changed", G_CALLBACK (on_group_contacts_changed), room); priv->properties_changed_id = tp_cli_dbus_properties_connect_to_properties_changed ( channel, (tp_properties_changed_cb) properties_changed, room, NULL, NULL, NULL); } g_object_freeze_notify (G_OBJECT (room)); update_identifier (room); update_icon (room); g_object_notify_by_pspec (G_OBJECT (room), props[PROP_CHANNEL]); g_object_thaw_notify (G_OBJECT (room)); }
static void channel_ready (GObject *source, GAsyncResult *result, gpointer user_data) { ChVisitor *visitor = (ChVisitor*) user_data; TpChannel *channel; const gchar *ident; TpMessage *message; GError *error = NULL; if (!tp_proxy_prepare_finish (source, result, &error)) { g_printerr ("error loading channel: %s\n", error->message); return; } channel = TP_CHANNEL (source); ident = tp_channel_get_identifier (channel); if (verbose > 0) { g_printerr ("channel ready \"%s\" (type %s)\n", ident, tp_channel_get_channel_type (channel)); } GList *messages, *iter; if (TP_IS_TEXT_CHANNEL (channel)) { messages = tp_text_channel_dup_pending_messages ( TP_TEXT_CHANNEL (channel)); for (iter = messages; iter; iter = iter->next) { TpMessage *message = TP_MESSAGE (iter->data); message_cb (message); } if (acknowledge) { tp_text_channel_ack_messages_async (TP_TEXT_CHANNEL (channel), messages, ack_messages_cb, NULL); } g_list_free_full (messages, g_object_unref); if (send_message && !has_sent_message_to (ident)) { message = tp_client_message_new_text(0, msg_buffer); g_ptr_array_add (messages_sent, g_strdup (ident)); ch_visitor_incref (visitor); tp_text_channel_send_message_async (TP_TEXT_CHANNEL (channel), message, 0, send_message_cb, visitor); } } else { g_printerr ("error loading channel: %s is not a text channel\n", tp_channel_get_identifier (channel)); } ch_visitor_decref (visitor); }