25
25
#include "salut-muc-manager.h"
26
26
#include "salut-muc-manager-signals-marshal.h"
28
#include "salut-muc-connection.h"
28
#include <gibber/gibber-muc-connection.h>
30
30
#include "salut-muc-channel.h"
31
31
#include "salut-contact-manager.h"
206
_get_connection(SalutMucManager *mgr, const gchar *name,
207
const gchar *protocol, GHashTable *parameters, GError **error) {
208
SalutMucConnection *connection;
205
GibberMucConnection *
206
_get_connection(SalutMucManager *mgr, const gchar *protocol,
207
GHashTable *parameters, GError **error) {
208
SalutMucManagerPrivate *priv = SALUT_MUC_MANAGER_GET_PRIVATE(mgr);
210
connection = salut_muc_connection_new(name, protocol, parameters, error);
211
return connection == NULL ? NULL : G_OBJECT(connection);
210
return gibber_muc_connection_new(priv->connection->name,
211
protocol, parameters, error);
215
215
_get_connection_parameters(SalutMucManager *mgr, const gchar *protocol) {
216
return salut_muc_connection_get_required_parameters(protocol);
216
return gibber_muc_connection_get_required_parameters(protocol);
219
219
static SalutMucChannel *
220
220
salut_muc_manager_new_channel(SalutMucManager *mgr, TpHandle handle,
221
GObject *connection) {
221
GibberMucConnection *connection) {
222
222
SalutMucManagerPrivate *priv = SALUT_MUC_MANAGER_GET_PRIVATE(mgr);
223
223
TpBaseConnection *base_connection = TP_BASE_CONNECTION(priv->connection);
224
224
TpHandleRepoIface *room_repo =
232
232
DEBUG("Requested channel for handle: %d", handle);
234
/* FIXME The name of the muc and the handel might need to be different at
234
/* FIXME The name of the muc and the handle might need to be different at
235
235
* some point.. E.g. if two rooms are called the same */
236
236
name = tp_handle_inspect(room_repo, handle);
237
237
path = g_strdup_printf("%s/MucChannel/%u",
267
267
TpHandleRepoIface *room_repo =
268
268
tp_base_connection_get_handles(base_connection, TP_HANDLE_TYPE_ROOM);
269
269
SalutMucChannel *chan;
270
gboolean created = FALSE;
270
TpChannelFactoryRequestStatus status;
272
272
DEBUG("Muc request");
289
289
chan = g_hash_table_lookup(priv->channels, GINT_TO_POINTER(handle));
290
291
if (chan != NULL) {
291
292
*ret = TP_CHANNEL_IFACE(chan);
293
status = TP_CHANNEL_FACTORY_REQUEST_STATUS_EXISTING;
294
GObject *connection = _get_connection(mgr,
295
priv->connection->name,
295
GibberMucConnection *connection = _get_connection(mgr,
296
296
NULL, NULL, NULL);
297
status = TP_CHANNEL_FACTORY_REQUEST_STATUS_CREATED;
298
298
if (connection == NULL) {
299
299
return TP_CHANNEL_FACTORY_REQUEST_STATUS_NOT_AVAILABLE;
301
chan = salut_muc_manager_new_channel(mgr, handle, connection);
302
302
/* We requested the channel, so invite ourselves to it */
304
salut_muc_channel_invited(chan, base_connection->self_handle, "");
304
GError *cerror = NULL;
305
if (!gibber_muc_connection_connect(connection, &cerror)) {
306
DEBUG("Connect failed: %s", cerror->message);
307
status = TP_CHANNEL_FACTORY_REQUEST_STATUS_ERROR;
308
g_set_error(error, TP_ERRORS,
309
TP_ERROR_NETWORK_ERROR, cerror->message);
310
g_error_free(cerror);
311
g_object_unref(connection);
314
DEBUG("Connect succeeded");
316
chan = salut_muc_manager_new_channel(mgr, handle, connection);
317
/* Inviting ourselves to a connected channel should always succeed */
318
g_assert(salut_muc_channel_invited(chan, base_connection->self_handle,
305
320
*ret = TP_CHANNEL_IFACE(chan);
307
g_assert(chan != NULL);
323
g_assert(chan != NULL);
310
return created ? TP_CHANNEL_FACTORY_REQUEST_STATUS_CREATED
311
: TP_CHANNEL_FACTORY_REQUEST_STATUS_EXISTING;
314
329
static void salut_muc_manager_factory_iface_init(gpointer *g_iface,
408
423
chan = g_hash_table_lookup(priv->channels, GINT_TO_POINTER(room_handle));
410
425
if (chan == NULL) {
411
transport = _get_connection(self, room, protocol, params_hash, NULL);
412
if (transport == NULL) {
426
connection = _get_connection(self, protocol, params_hash, NULL);
427
if (connection == NULL) {
413
428
DEBUG("Invalid invitation, (wrong protocol parameters) discarding");
417
if (transport == NULL) {
432
if (connection == NULL) {
418
433
tp_handle_unref(room_repo, room_handle);
419
434
/* FIXME some kinda error to the user maybe ? Ignore for now */
422
437
/* Need to create a new one */
423
chan = salut_muc_manager_new_channel(self, room_handle, transport);
438
chan = salut_muc_manager_new_channel(self, room_handle, connection);
425
440
/* FIXME handle properly */
426
441
g_assert(chan != NULL);
428
443
g_object_get(G_OBJECT(imchannel), "handle", &invitor_handle, NULL);
429
salut_muc_channel_invited(chan, invitor_handle, reason);
444
salut_muc_channel_invited(chan, invitor_handle, reason, NULL);
431
446
g_hash_table_destroy(params_hash);