/* roster_manager.c generated by valac 0.56.19, the Vala compiler
 * generated from roster_manager.vala, do not modify */

#include "libdino.h"
#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include "xmpp-vala.h"
#include <stdlib.h>
#include <string.h>
#include "qlite.h"

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	DINO_ROSTER_MANAGER_0_PROPERTY,
	DINO_ROSTER_MANAGER_ID_PROPERTY,
	DINO_ROSTER_MANAGER_NUM_PROPERTIES
};
static GParamSpec* dino_roster_manager_properties[DINO_ROSTER_MANAGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _qlite_database_unref0(var) ((var == NULL) ? NULL : (var = (qlite_database_unref (var), NULL)))
typedef struct _Block43Data Block43Data;
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
typedef struct _Block44Data Block44Data;
#define _xmpp_roster_item_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_roster_item_unref (var), NULL)))
enum  {
	DINO_ROSTER_MANAGER_REMOVED_ROSTER_ITEM_SIGNAL,
	DINO_ROSTER_MANAGER_UPDATED_ROSTER_ITEM_SIGNAL,
	DINO_ROSTER_MANAGER_MUTUAL_SUBSCRIPTION_SIGNAL,
	DINO_ROSTER_MANAGER_NUM_SIGNALS
};
static guint dino_roster_manager_signals[DINO_ROSTER_MANAGER_NUM_SIGNALS] = {0};
enum  {
	DINO_ROSTER_STORE_IMPL_0_PROPERTY,
	DINO_ROSTER_STORE_IMPL_NUM_PROPERTIES
};
static GParamSpec* dino_roster_store_impl_properties[DINO_ROSTER_STORE_IMPL_NUM_PROPERTIES];
#define _qlite_statement_builder_unref0(var) ((var == NULL) ? NULL : (var = (qlite_statement_builder_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _qlite_row_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_unref (var), NULL)))
#define _qlite_row_iterator_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_iterator_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _DinoRosterManagerPrivate {
	DinoStreamInteractor* stream_interactor;
	DinoDatabase* db;
	GeeMap* roster_stores;
};

struct _Block43Data {
	int _ref_count_;
	DinoRosterManager* self;
	DinoDatabase* db;
};

struct _Block44Data {
	int _ref_count_;
	DinoRosterManager* self;
	DinoEntitiesAccount* account;
};

struct _DinoRosterStoreImplPrivate {
	DinoEntitiesAccount* account;
	DinoDatabase* db;
	GeeHashMap* items;
};

static gint DinoRosterManager_private_offset;
static gpointer dino_roster_manager_parent_class = NULL;
DinoModuleIdentity* dino_roster_manager_IDENTITY = NULL;
static DinoStreamInteractionModuleIface * dino_roster_manager_dino_stream_interaction_module_parent_iface = NULL;
static gint DinoRosterStoreImpl_private_offset;
static gpointer dino_roster_store_impl_parent_class = NULL;
static XmppRosterStorageIface * dino_roster_store_impl_xmpp_roster_storage_parent_iface = NULL;

static guint _dino_entities_account_hash_func_gee_hash_data_func (gconstpointer v,
                                                           gpointer self);
static gboolean _dino_entities_account_equals_func_gee_equal_data_func (gconstpointer a,
                                                                 gconstpointer b,
                                                                 gpointer self);
static Block43Data* block43_data_ref (Block43Data* _data43_);
static void block43_data_unref (void * _userdata_);
static void dino_roster_manager_on_account_added (DinoRosterManager* self,
                                           DinoEntitiesAccount* account);
static void _dino_roster_manager_on_account_added_dino_stream_interactor_account_added (DinoStreamInteractor* _sender,
                                                                                 DinoEntitiesAccount* account,
                                                                                 gpointer self);
static void __lambda42_ (Block43Data* _data43_,
                  DinoEntitiesAccount* account,
                  GeeArrayList* modules);
static void ___lambda42__dino_module_manager_initialize_account_modules (DinoModuleManager* _sender,
                                                                  DinoEntitiesAccount* account,
                                                                  GeeArrayList* modules,
                                                                  gpointer self);
static Block44Data* block44_data_ref (Block44Data* _data44_);
static void block44_data_unref (void * _userdata_);
static void __lambda38_ (Block44Data* _data44_,
                  XmppXmppStream* stream,
                  GeeCollection* roster);
static void dino_roster_manager_on_roster_item_updated (DinoRosterManager* self,
                                                 DinoEntitiesAccount* account,
                                                 XmppRosterItem* roster_item);
static void ___lambda38__xmpp_roster_module_received_roster (XmppRosterModule* _sender,
                                                      XmppXmppStream* stream,
                                                      GeeCollection* roster,
                                                      XmppIqStanza* stanza,
                                                      gpointer self);
static void __lambda39_ (Block44Data* _data44_,
                  XmppXmppStream* stream,
                  XmppRosterItem* roster_item);
static void ___lambda39__xmpp_roster_module_item_removed (XmppRosterModule* _sender,
                                                   XmppXmppStream* stream,
                                                   XmppRosterItem* item,
                                                   XmppIqStanza* iq,
                                                   gpointer self);
static void __lambda40_ (Block44Data* _data44_,
                  XmppXmppStream* stream,
                  XmppRosterItem* roster_item);
static void ___lambda40__xmpp_roster_module_item_updated (XmppRosterModule* _sender,
                                                   XmppXmppStream* stream,
                                                   XmppRosterItem* item,
                                                   XmppIqStanza* iq,
                                                   gpointer self);
static void __lambda41_ (Block44Data* _data44_,
                  XmppXmppStream* stream,
                  XmppJid* jid);
static void ___lambda41__xmpp_roster_module_mutual_subscription (XmppRosterModule* _sender,
                                                          XmppXmppStream* stream,
                                                          XmppJid* jid,
                                                          gpointer self);
static void g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID_XMPP_ROSTER_ITEM (GClosure * closure,
                                                                     GValue * return_value,
                                                                     guint n_param_values,
                                                                     const GValue * param_values,
                                                                     gpointer invocation_hint,
                                                                     gpointer marshal_data);
static void g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID (GClosure * closure,
                                                    GValue * return_value,
                                                    guint n_param_values,
                                                    const GValue * param_values,
                                                    gpointer invocation_hint,
                                                    gpointer marshal_data);
static void dino_roster_manager_finalize (GObject * obj);
static GType dino_roster_manager_get_type_once (void);
static void _vala_dino_roster_manager_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec);
static guint _xmpp_jid_hash_bare_func_gee_hash_data_func (gconstpointer v,
                                                   gpointer self);
static gboolean _xmpp_jid_equals_bare_func_gee_equal_data_func (gconstpointer a,
                                                         gconstpointer b,
                                                         gpointer self);
static gchar* dino_roster_store_impl_real_get_roster_version (XmppRosterStorage* base);
static GeeCollection* dino_roster_store_impl_real_get_roster (XmppRosterStorage* base);
static void dino_roster_store_impl_real_set_roster_version (XmppRosterStorage* base,
                                                     const gchar* version);
static void dino_roster_store_impl_real_set_roster (XmppRosterStorage* base,
                                             GeeCollection* items);
static void dino_roster_store_impl_real_set_item (XmppRosterStorage* base,
                                           XmppRosterItem* item);
static void dino_roster_store_impl_real_remove_item (XmppRosterStorage* base,
                                              XmppRosterItem* item);
static void dino_roster_store_impl_finalize (GObject * obj);
static GType dino_roster_store_impl_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_roster_manager_get_instance_private (DinoRosterManager* self)
{
	return G_STRUCT_MEMBER_P (self, DinoRosterManager_private_offset);
}

static guint
_dino_entities_account_hash_func_gee_hash_data_func (gconstpointer v,
                                                     gpointer self)
{
	guint result;
	result = dino_entities_account_hash_func ((DinoEntitiesAccount*) v);
	return result;
}

static gboolean
_dino_entities_account_equals_func_gee_equal_data_func (gconstpointer a,
                                                        gconstpointer b,
                                                        gpointer self)
{
	gboolean result;
	result = dino_entities_account_equals_func ((DinoEntitiesAccount*) a, (DinoEntitiesAccount*) b);
	return result;
}

void
dino_roster_manager_start (DinoStreamInteractor* stream_interactor,
                           DinoDatabase* db)
{
	DinoRosterManager* m = NULL;
	DinoRosterManager* _tmp0_;
	g_return_if_fail (stream_interactor != NULL);
	g_return_if_fail (db != NULL);
	_tmp0_ = dino_roster_manager_new (stream_interactor, db);
	m = _tmp0_;
	dino_stream_interactor_add_module (stream_interactor, (DinoStreamInteractionModule*) m);
	_g_object_unref0 (m);
}

static gpointer
_qlite_database_ref0 (gpointer self)
{
	return self ? qlite_database_ref (self) : NULL;
}

static Block43Data*
block43_data_ref (Block43Data* _data43_)
{
	g_atomic_int_inc (&_data43_->_ref_count_);
	return _data43_;
}

static void
block43_data_unref (void * _userdata_)
{
	Block43Data* _data43_;
	_data43_ = (Block43Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data43_->_ref_count_)) {
		DinoRosterManager* self;
		self = _data43_->self;
		_qlite_database_unref0 (_data43_->db);
		_g_object_unref0 (self);
		g_slice_free (Block43Data, _data43_);
	}
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
_dino_roster_manager_on_account_added_dino_stream_interactor_account_added (DinoStreamInteractor* _sender,
                                                                            DinoEntitiesAccount* account,
                                                                            gpointer self)
{
	dino_roster_manager_on_account_added ((DinoRosterManager*) self, account);
}

static void
__lambda42_ (Block43Data* _data43_,
             DinoEntitiesAccount* account,
             GeeArrayList* modules)
{
	DinoRosterManager* self;
	GeeMap* _tmp0_;
	GeeMap* _tmp4_;
	gpointer _tmp5_;
	DinoRosterStoreImpl* _tmp6_;
	XmppRosterVersioningModule* _tmp7_;
	XmppRosterVersioningModule* _tmp8_;
	self = _data43_->self;
	g_return_if_fail (account != NULL);
	g_return_if_fail (modules != NULL);
	_tmp0_ = self->priv->roster_stores;
	if (!gee_map_has_key (_tmp0_, account)) {
		GeeMap* _tmp1_;
		DinoRosterStoreImpl* _tmp2_;
		DinoRosterStoreImpl* _tmp3_;
		_tmp1_ = self->priv->roster_stores;
		_tmp2_ = dino_roster_store_impl_new (account, _data43_->db);
		_tmp3_ = _tmp2_;
		gee_map_set (_tmp1_, account, _tmp3_);
		_g_object_unref0 (_tmp3_);
	}
	_tmp4_ = self->priv->roster_stores;
	_tmp5_ = gee_map_get (_tmp4_, account);
	_tmp6_ = (DinoRosterStoreImpl*) _tmp5_;
	_tmp7_ = xmpp_roster_versioning_module_new ((XmppRosterStorage*) _tmp6_);
	_tmp8_ = _tmp7_;
	gee_abstract_collection_add ((GeeAbstractCollection*) modules, (XmppXmppStreamModule*) _tmp8_);
	_g_object_unref0 (_tmp8_);
	_g_object_unref0 (_tmp6_);
}

static void
___lambda42__dino_module_manager_initialize_account_modules (DinoModuleManager* _sender,
                                                             DinoEntitiesAccount* account,
                                                             GeeArrayList* modules,
                                                             gpointer self)
{
	__lambda42_ (self, account, modules);
}

DinoRosterManager*
dino_roster_manager_construct (GType object_type,
                               DinoStreamInteractor* stream_interactor,
                               DinoDatabase* db)
{
	DinoRosterManager * self = NULL;
	Block43Data* _data43_;
	DinoDatabase* _tmp0_;
	DinoStreamInteractor* _tmp1_;
	DinoDatabase* _tmp2_;
	DinoModuleManager* _tmp3_;
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	g_return_val_if_fail (db != NULL, NULL);
	_data43_ = g_slice_new0 (Block43Data);
	_data43_->_ref_count_ = 1;
	_tmp0_ = _qlite_database_ref0 (db);
	_qlite_database_unref0 (_data43_->db);
	_data43_->db = _tmp0_;
	self = (DinoRosterManager*) g_object_new (object_type, NULL);
	_data43_->self = g_object_ref (self);
	_tmp1_ = _g_object_ref0 (stream_interactor);
	_g_object_unref0 (self->priv->stream_interactor);
	self->priv->stream_interactor = _tmp1_;
	_tmp2_ = _qlite_database_ref0 (_data43_->db);
	_qlite_database_unref0 (self->priv->db);
	self->priv->db = _tmp2_;
	g_signal_connect_object (stream_interactor, "account-added", (GCallback) _dino_roster_manager_on_account_added_dino_stream_interactor_account_added, self, 0);
	_tmp3_ = stream_interactor->module_manager;
	g_signal_connect_data (_tmp3_, "initialize-account-modules", (GCallback) ___lambda42__dino_module_manager_initialize_account_modules, block43_data_ref (_data43_), (GClosureNotify) block43_data_unref, 0);
	block43_data_unref (_data43_);
	_data43_ = NULL;
	return self;
}

DinoRosterManager*
dino_roster_manager_new (DinoStreamInteractor* stream_interactor,
                         DinoDatabase* db)
{
	return dino_roster_manager_construct (DINO_TYPE_ROSTER_MANAGER, stream_interactor, db);
}

GeeCollection*
dino_roster_manager_get_roster (DinoRosterManager* self,
                                DinoEntitiesAccount* account)
{
	GeeMap* _tmp0_;
	gpointer _tmp1_;
	DinoRosterStoreImpl* _tmp2_;
	gboolean _tmp3_;
	GeeMap* _tmp5_;
	gpointer _tmp6_;
	DinoRosterStoreImpl* _tmp7_;
	GeeCollection* _tmp8_;
	GeeCollection* _tmp9_;
	GeeCollection* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (account != NULL, NULL);
	_tmp0_ = self->priv->roster_stores;
	_tmp1_ = gee_map_get (_tmp0_, account);
	_tmp2_ = (DinoRosterStoreImpl*) _tmp1_;
	_tmp3_ = _tmp2_ == NULL;
	_g_object_unref0 (_tmp2_);
	if (_tmp3_) {
		GeeArrayList* _tmp4_;
		_tmp4_ = gee_array_list_new (XMPP_ROSTER_TYPE_ITEM, (GBoxedCopyFunc) xmpp_roster_item_ref, (GDestroyNotify) xmpp_roster_item_unref, NULL, NULL, NULL);
		result = (GeeCollection*) _tmp4_;
		return result;
	}
	_tmp5_ = self->priv->roster_stores;
	_tmp6_ = gee_map_get (_tmp5_, account);
	_tmp7_ = (DinoRosterStoreImpl*) _tmp6_;
	_tmp8_ = xmpp_roster_storage_get_roster ((XmppRosterStorage*) _tmp7_);
	_tmp9_ = _tmp8_;
	_g_object_unref0 (_tmp7_);
	result = _tmp9_;
	return result;
}

XmppRosterItem*
dino_roster_manager_get_roster_item (DinoRosterManager* self,
                                     DinoEntitiesAccount* account,
                                     XmppJid* jid)
{
	GeeMap* _tmp0_;
	gpointer _tmp1_;
	DinoRosterStoreImpl* _tmp2_;
	gboolean _tmp3_;
	GeeMap* _tmp4_;
	gpointer _tmp5_;
	DinoRosterStoreImpl* _tmp6_;
	XmppRosterItem* _tmp7_;
	XmppRosterItem* _tmp8_;
	XmppRosterItem* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (account != NULL, NULL);
	g_return_val_if_fail (jid != NULL, NULL);
	_tmp0_ = self->priv->roster_stores;
	_tmp1_ = gee_map_get (_tmp0_, account);
	_tmp2_ = (DinoRosterStoreImpl*) _tmp1_;
	_tmp3_ = _tmp2_ == NULL;
	_g_object_unref0 (_tmp2_);
	if (_tmp3_) {
		result = NULL;
		return result;
	}
	_tmp4_ = self->priv->roster_stores;
	_tmp5_ = gee_map_get (_tmp4_, account);
	_tmp6_ = (DinoRosterStoreImpl*) _tmp5_;
	_tmp7_ = dino_roster_store_impl_get_item (_tmp6_, jid);
	_tmp8_ = _tmp7_;
	_g_object_unref0 (_tmp6_);
	result = _tmp8_;
	return result;
}

void
dino_roster_manager_remove_jid (DinoRosterManager* self,
                                DinoEntitiesAccount* account,
                                XmppJid* jid)
{
	XmppXmppStream* stream = NULL;
	DinoStreamInteractor* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppXmppStream* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	_tmp0_ = self->priv->stream_interactor;
	_tmp1_ = dino_stream_interactor_get_stream (_tmp0_, account);
	stream = _tmp1_;
	_tmp2_ = stream;
	if (_tmp2_ != NULL) {
		XmppXmppStream* _tmp3_;
		XmppModuleIdentity* _tmp4_;
		gpointer _tmp5_;
		XmppRosterModule* _tmp6_;
		XmppXmppStream* _tmp7_;
		XmppJid* _tmp8_;
		XmppJid* _tmp9_;
		XmppJid* _tmp10_;
		_tmp3_ = stream;
		_tmp4_ = xmpp_roster_module_IDENTITY;
		_tmp5_ = xmpp_xmpp_stream_get_module (_tmp3_, XMPP_ROSTER_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp4_);
		_tmp6_ = (XmppRosterModule*) _tmp5_;
		_tmp7_ = stream;
		_tmp8_ = xmpp_jid_get_bare_jid (jid);
		_tmp9_ = _tmp8_;
		_tmp10_ = _tmp9_;
		xmpp_roster_module_remove_jid (_tmp6_, _tmp7_, _tmp10_);
		_xmpp_jid_unref0 (_tmp10_);
		_g_object_unref0 (_tmp6_);
	}
	_g_object_unref0 (stream);
}

void
dino_roster_manager_add_jid (DinoRosterManager* self,
                             DinoEntitiesAccount* account,
                             XmppJid* jid,
                             const gchar* handle)
{
	XmppXmppStream* stream = NULL;
	DinoStreamInteractor* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppXmppStream* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	_tmp0_ = self->priv->stream_interactor;
	_tmp1_ = dino_stream_interactor_get_stream (_tmp0_, account);
	stream = _tmp1_;
	_tmp2_ = stream;
	if (_tmp2_ != NULL) {
		XmppXmppStream* _tmp3_;
		XmppModuleIdentity* _tmp4_;
		gpointer _tmp5_;
		XmppRosterModule* _tmp6_;
		XmppXmppStream* _tmp7_;
		XmppJid* _tmp8_;
		XmppJid* _tmp9_;
		XmppJid* _tmp10_;
		_tmp3_ = stream;
		_tmp4_ = xmpp_roster_module_IDENTITY;
		_tmp5_ = xmpp_xmpp_stream_get_module (_tmp3_, XMPP_ROSTER_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp4_);
		_tmp6_ = (XmppRosterModule*) _tmp5_;
		_tmp7_ = stream;
		_tmp8_ = xmpp_jid_get_bare_jid (jid);
		_tmp9_ = _tmp8_;
		_tmp10_ = _tmp9_;
		xmpp_roster_module_add_jid (_tmp6_, _tmp7_, _tmp10_, handle);
		_xmpp_jid_unref0 (_tmp10_);
		_g_object_unref0 (_tmp6_);
	}
	_g_object_unref0 (stream);
}

void
dino_roster_manager_set_jid_handle (DinoRosterManager* self,
                                    DinoEntitiesAccount* account,
                                    XmppJid* jid,
                                    const gchar* handle)
{
	XmppXmppStream* stream = NULL;
	DinoStreamInteractor* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppXmppStream* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	_tmp0_ = self->priv->stream_interactor;
	_tmp1_ = dino_stream_interactor_get_stream (_tmp0_, account);
	stream = _tmp1_;
	_tmp2_ = stream;
	if (_tmp2_ != NULL) {
		XmppXmppStream* _tmp3_;
		XmppModuleIdentity* _tmp4_;
		gpointer _tmp5_;
		XmppRosterModule* _tmp6_;
		XmppXmppStream* _tmp7_;
		XmppJid* _tmp8_;
		XmppJid* _tmp9_;
		XmppJid* _tmp10_;
		_tmp3_ = stream;
		_tmp4_ = xmpp_roster_module_IDENTITY;
		_tmp5_ = xmpp_xmpp_stream_get_module (_tmp3_, XMPP_ROSTER_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp4_);
		_tmp6_ = (XmppRosterModule*) _tmp5_;
		_tmp7_ = stream;
		_tmp8_ = xmpp_jid_get_bare_jid (jid);
		_tmp9_ = _tmp8_;
		_tmp10_ = _tmp9_;
		xmpp_roster_module_set_jid_handle (_tmp6_, _tmp7_, _tmp10_, handle);
		_xmpp_jid_unref0 (_tmp10_);
		_g_object_unref0 (_tmp6_);
	}
	_g_object_unref0 (stream);
}

static Block44Data*
block44_data_ref (Block44Data* _data44_)
{
	g_atomic_int_inc (&_data44_->_ref_count_);
	return _data44_;
}

static void
block44_data_unref (void * _userdata_)
{
	Block44Data* _data44_;
	_data44_ = (Block44Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data44_->_ref_count_)) {
		DinoRosterManager* self;
		self = _data44_->self;
		_g_object_unref0 (_data44_->account);
		_g_object_unref0 (self);
		g_slice_free (Block44Data, _data44_);
	}
}

static void
__lambda38_ (Block44Data* _data44_,
             XmppXmppStream* stream,
             GeeCollection* roster)
{
	DinoRosterManager* self;
	self = _data44_->self;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (roster != NULL);
	{
		GeeIterator* _roster_item_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator ((GeeIterable*) roster);
		_roster_item_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			XmppRosterItem* roster_item = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			XmppRosterItem* _tmp4_;
			_tmp1_ = _roster_item_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _roster_item_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			roster_item = (XmppRosterItem*) _tmp3_;
			_tmp4_ = roster_item;
			dino_roster_manager_on_roster_item_updated (self, _data44_->account, _tmp4_);
			_xmpp_roster_item_unref0 (roster_item);
		}
		_g_object_unref0 (_roster_item_it);
	}
}

static void
___lambda38__xmpp_roster_module_received_roster (XmppRosterModule* _sender,
                                                 XmppXmppStream* stream,
                                                 GeeCollection* roster,
                                                 XmppIqStanza* stanza,
                                                 gpointer self)
{
	__lambda38_ (self, stream, roster);
}

static void
__lambda39_ (Block44Data* _data44_,
             XmppXmppStream* stream,
             XmppRosterItem* roster_item)
{
	DinoRosterManager* self;
	XmppJid* _tmp0_;
	XmppJid* _tmp1_;
	self = _data44_->self;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (roster_item != NULL);
	_tmp0_ = xmpp_roster_item_get_jid (roster_item);
	_tmp1_ = _tmp0_;
	g_signal_emit (self, dino_roster_manager_signals[DINO_ROSTER_MANAGER_REMOVED_ROSTER_ITEM_SIGNAL], 0, _data44_->account, _tmp1_, roster_item);
}

static void
___lambda39__xmpp_roster_module_item_removed (XmppRosterModule* _sender,
                                              XmppXmppStream* stream,
                                              XmppRosterItem* item,
                                              XmppIqStanza* iq,
                                              gpointer self)
{
	__lambda39_ (self, stream, item);
}

static void
__lambda40_ (Block44Data* _data44_,
             XmppXmppStream* stream,
             XmppRosterItem* roster_item)
{
	DinoRosterManager* self;
	self = _data44_->self;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (roster_item != NULL);
	dino_roster_manager_on_roster_item_updated (self, _data44_->account, roster_item);
}

static void
___lambda40__xmpp_roster_module_item_updated (XmppRosterModule* _sender,
                                              XmppXmppStream* stream,
                                              XmppRosterItem* item,
                                              XmppIqStanza* iq,
                                              gpointer self)
{
	__lambda40_ (self, stream, item);
}

static void
__lambda41_ (Block44Data* _data44_,
             XmppXmppStream* stream,
             XmppJid* jid)
{
	DinoRosterManager* self;
	self = _data44_->self;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (jid != NULL);
	g_signal_emit (self, dino_roster_manager_signals[DINO_ROSTER_MANAGER_MUTUAL_SUBSCRIPTION_SIGNAL], 0, _data44_->account, jid);
}

static void
___lambda41__xmpp_roster_module_mutual_subscription (XmppRosterModule* _sender,
                                                     XmppXmppStream* stream,
                                                     XmppJid* jid,
                                                     gpointer self)
{
	__lambda41_ (self, stream, jid);
}

static void
dino_roster_manager_on_account_added (DinoRosterManager* self,
                                      DinoEntitiesAccount* account)
{
	Block44Data* _data44_;
	DinoEntitiesAccount* _tmp0_;
	DinoStreamInteractor* _tmp1_;
	DinoModuleManager* _tmp2_;
	XmppModuleIdentity* _tmp3_;
	gpointer _tmp4_;
	XmppRosterModule* _tmp5_;
	DinoStreamInteractor* _tmp6_;
	DinoModuleManager* _tmp7_;
	XmppModuleIdentity* _tmp8_;
	gpointer _tmp9_;
	XmppRosterModule* _tmp10_;
	DinoStreamInteractor* _tmp11_;
	DinoModuleManager* _tmp12_;
	XmppModuleIdentity* _tmp13_;
	gpointer _tmp14_;
	XmppRosterModule* _tmp15_;
	DinoStreamInteractor* _tmp16_;
	DinoModuleManager* _tmp17_;
	XmppModuleIdentity* _tmp18_;
	gpointer _tmp19_;
	XmppRosterModule* _tmp20_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	_data44_ = g_slice_new0 (Block44Data);
	_data44_->_ref_count_ = 1;
	_data44_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (account);
	_g_object_unref0 (_data44_->account);
	_data44_->account = _tmp0_;
	_tmp1_ = self->priv->stream_interactor;
	_tmp2_ = _tmp1_->module_manager;
	_tmp3_ = xmpp_roster_module_IDENTITY;
	_tmp4_ = dino_module_manager_get_module (_tmp2_, XMPP_ROSTER_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data44_->account, _tmp3_);
	_tmp5_ = (XmppRosterModule*) _tmp4_;
	g_signal_connect_data (_tmp5_, "received-roster", (GCallback) ___lambda38__xmpp_roster_module_received_roster, block44_data_ref (_data44_), (GClosureNotify) block44_data_unref, G_CONNECT_AFTER);
	_g_object_unref0 (_tmp5_);
	_tmp6_ = self->priv->stream_interactor;
	_tmp7_ = _tmp6_->module_manager;
	_tmp8_ = xmpp_roster_module_IDENTITY;
	_tmp9_ = dino_module_manager_get_module (_tmp7_, XMPP_ROSTER_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data44_->account, _tmp8_);
	_tmp10_ = (XmppRosterModule*) _tmp9_;
	g_signal_connect_data (_tmp10_, "item-removed", (GCallback) ___lambda39__xmpp_roster_module_item_removed, block44_data_ref (_data44_), (GClosureNotify) block44_data_unref, G_CONNECT_AFTER);
	_g_object_unref0 (_tmp10_);
	_tmp11_ = self->priv->stream_interactor;
	_tmp12_ = _tmp11_->module_manager;
	_tmp13_ = xmpp_roster_module_IDENTITY;
	_tmp14_ = dino_module_manager_get_module (_tmp12_, XMPP_ROSTER_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data44_->account, _tmp13_);
	_tmp15_ = (XmppRosterModule*) _tmp14_;
	g_signal_connect_data (_tmp15_, "item-updated", (GCallback) ___lambda40__xmpp_roster_module_item_updated, block44_data_ref (_data44_), (GClosureNotify) block44_data_unref, G_CONNECT_AFTER);
	_g_object_unref0 (_tmp15_);
	_tmp16_ = self->priv->stream_interactor;
	_tmp17_ = _tmp16_->module_manager;
	_tmp18_ = xmpp_roster_module_IDENTITY;
	_tmp19_ = dino_module_manager_get_module (_tmp17_, XMPP_ROSTER_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data44_->account, _tmp18_);
	_tmp20_ = (XmppRosterModule*) _tmp19_;
	g_signal_connect_data (_tmp20_, "mutual-subscription", (GCallback) ___lambda41__xmpp_roster_module_mutual_subscription, block44_data_ref (_data44_), (GClosureNotify) block44_data_unref, G_CONNECT_AFTER);
	_g_object_unref0 (_tmp20_);
	block44_data_unref (_data44_);
	_data44_ = NULL;
}

static void
dino_roster_manager_on_roster_item_updated (DinoRosterManager* self,
                                            DinoEntitiesAccount* account,
                                            XmppRosterItem* roster_item)
{
	XmppJid* _tmp0_;
	XmppJid* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (roster_item != NULL);
	_tmp0_ = xmpp_roster_item_get_jid (roster_item);
	_tmp1_ = _tmp0_;
	g_signal_emit (self, dino_roster_manager_signals[DINO_ROSTER_MANAGER_UPDATED_ROSTER_ITEM_SIGNAL], 0, account, _tmp1_, roster_item);
}

static const gchar*
dino_roster_manager_real_get_id (DinoStreamInteractionModule* base)
{
	const gchar* result;
	DinoRosterManager* self;
	DinoModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	self = (DinoRosterManager*) base;
	_tmp0_ = dino_roster_manager_IDENTITY;
	_tmp1_ = dino_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

static void
g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID_XMPP_ROSTER_ITEM (GClosure * closure,
                                                                GValue * return_value,
                                                                guint n_param_values,
                                                                const GValue * param_values,
                                                                gpointer invocation_hint,
                                                                gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__OBJECT_XMPP_JID_XMPP_ROSTER_ITEM) (gpointer data1, gpointer arg_1, gpointer arg_2, gpointer arg_3, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_XMPP_JID_XMPP_ROSTER_ITEM callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 4);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__OBJECT_XMPP_JID_XMPP_ROSTER_ITEM) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), xmpp_value_get_jid (param_values + 2), xmpp_roster_value_get_item (param_values + 3), data2);
}

static void
g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID (GClosure * closure,
                                               GValue * return_value,
                                               guint n_param_values,
                                               const GValue * param_values,
                                               gpointer invocation_hint,
                                               gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__OBJECT_XMPP_JID) (gpointer data1, gpointer arg_1, gpointer arg_2, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_XMPP_JID callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__OBJECT_XMPP_JID) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), xmpp_value_get_jid (param_values + 2), data2);
}

static void
dino_roster_manager_class_init (DinoRosterManagerClass * klass,
                                gpointer klass_data)
{
	DinoModuleIdentity* _tmp0_;
	dino_roster_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoRosterManager_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_roster_manager_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_roster_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_ROSTER_MANAGER_ID_PROPERTY, dino_roster_manager_properties[DINO_ROSTER_MANAGER_ID_PROPERTY] = g_param_spec_string ("id", "id", "id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	dino_roster_manager_signals[DINO_ROSTER_MANAGER_REMOVED_ROSTER_ITEM_SIGNAL] = g_signal_new ("removed-roster-item", DINO_TYPE_ROSTER_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID_XMPP_ROSTER_ITEM, G_TYPE_NONE, 3, DINO_ENTITIES_TYPE_ACCOUNT, XMPP_TYPE_JID, XMPP_ROSTER_TYPE_ITEM);
	dino_roster_manager_signals[DINO_ROSTER_MANAGER_UPDATED_ROSTER_ITEM_SIGNAL] = g_signal_new ("updated-roster-item", DINO_TYPE_ROSTER_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID_XMPP_ROSTER_ITEM, G_TYPE_NONE, 3, DINO_ENTITIES_TYPE_ACCOUNT, XMPP_TYPE_JID, XMPP_ROSTER_TYPE_ITEM);
	dino_roster_manager_signals[DINO_ROSTER_MANAGER_MUTUAL_SUBSCRIPTION_SIGNAL] = g_signal_new ("mutual-subscription", DINO_TYPE_ROSTER_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_XMPP_JID, G_TYPE_NONE, 2, DINO_ENTITIES_TYPE_ACCOUNT, XMPP_TYPE_JID);
	_tmp0_ = dino_module_identity_new (DINO_TYPE_ROSTER_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, "roster_manager");
	dino_roster_manager_IDENTITY = _tmp0_;
}

static void
dino_roster_manager_dino_stream_interaction_module_interface_init (DinoStreamInteractionModuleIface * iface,
                                                                   gpointer iface_data)
{
	dino_roster_manager_dino_stream_interaction_module_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_id = dino_roster_manager_real_get_id;
}

static void
dino_roster_manager_instance_init (DinoRosterManager * self,
                                   gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = dino_roster_manager_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (DINO_ENTITIES_TYPE_ACCOUNT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, DINO_TYPE_ROSTER_STORE_IMPL, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _dino_entities_account_hash_func_gee_hash_data_func, NULL, NULL, _dino_entities_account_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->priv->roster_stores = (GeeMap*) _tmp0_;
}

static void
dino_roster_manager_finalize (GObject * obj)
{
	DinoRosterManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_ROSTER_MANAGER, DinoRosterManager);
	_g_object_unref0 (self->priv->stream_interactor);
	_qlite_database_unref0 (self->priv->db);
	_g_object_unref0 (self->priv->roster_stores);
	G_OBJECT_CLASS (dino_roster_manager_parent_class)->finalize (obj);
}

static GType
dino_roster_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoRosterManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_roster_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoRosterManager), 0, (GInstanceInitFunc) dino_roster_manager_instance_init, NULL };
	static const GInterfaceInfo dino_stream_interaction_module_info = { (GInterfaceInitFunc) dino_roster_manager_dino_stream_interaction_module_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_roster_manager_type_id;
	dino_roster_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoRosterManager", &g_define_type_info, 0);
	g_type_add_interface_static (dino_roster_manager_type_id, DINO_TYPE_STREAM_INTERACTION_MODULE, &dino_stream_interaction_module_info);
	DinoRosterManager_private_offset = g_type_add_instance_private (dino_roster_manager_type_id, sizeof (DinoRosterManagerPrivate));
	return dino_roster_manager_type_id;
}

GType
dino_roster_manager_get_type (void)
{
	static volatile gsize dino_roster_manager_type_id__once = 0;
	if (g_once_init_enter (&dino_roster_manager_type_id__once)) {
		GType dino_roster_manager_type_id;
		dino_roster_manager_type_id = dino_roster_manager_get_type_once ();
		g_once_init_leave (&dino_roster_manager_type_id__once, dino_roster_manager_type_id);
	}
	return dino_roster_manager_type_id__once;
}

static void
_vala_dino_roster_manager_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec)
{
	DinoRosterManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_TYPE_ROSTER_MANAGER, DinoRosterManager);
	switch (property_id) {
		case DINO_ROSTER_MANAGER_ID_PROPERTY:
		g_value_set_string (value, dino_stream_interaction_module_get_id ((DinoStreamInteractionModule*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
dino_roster_store_impl_get_instance_private (DinoRosterStoreImpl* self)
{
	return G_STRUCT_MEMBER_P (self, DinoRosterStoreImpl_private_offset);
}

static guint
_xmpp_jid_hash_bare_func_gee_hash_data_func (gconstpointer v,
                                             gpointer self)
{
	guint result;
	result = xmpp_jid_hash_bare_func ((XmppJid*) v);
	return result;
}

static gboolean
_xmpp_jid_equals_bare_func_gee_equal_data_func (gconstpointer a,
                                                gconstpointer b,
                                                gpointer self)
{
	gboolean result;
	result = xmpp_jid_equals_bare_func ((XmppJid*) a, (XmppJid*) b);
	return result;
}

DinoRosterStoreImpl*
dino_roster_store_impl_construct (GType object_type,
                                  DinoEntitiesAccount* account,
                                  DinoDatabase* db)
{
	DinoRosterStoreImpl * self = NULL;
	DinoEntitiesAccount* _tmp0_;
	DinoDatabase* _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (account != NULL, NULL);
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoRosterStoreImpl*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (account);
	_g_object_unref0 (self->priv->account);
	self->priv->account = _tmp0_;
	_tmp1_ = _qlite_database_ref0 (db);
	_qlite_database_unref0 (self->priv->db);
	self->priv->db = _tmp1_;
	{
		QliteRowIterator* _row_it = NULL;
		DinoDatabaseRosterTable* _tmp2_;
		DinoDatabaseRosterTable* _tmp3_;
		QliteQueryBuilder* _tmp4_;
		QliteQueryBuilder* _tmp5_;
		DinoDatabaseRosterTable* _tmp6_;
		DinoDatabaseRosterTable* _tmp7_;
		QliteColumn* _tmp8_;
		gint _tmp9_;
		gint _tmp10_;
		QliteQueryBuilder* _tmp11_;
		QliteQueryBuilder* _tmp12_;
		QliteRowIterator* _tmp13_;
		QliteRowIterator* _tmp14_;
		_tmp2_ = dino_database_get_roster (db);
		_tmp3_ = _tmp2_;
		_tmp4_ = qlite_table_select ((QliteTable*) _tmp3_, NULL, (gint) 0);
		_tmp5_ = _tmp4_;
		_tmp6_ = dino_database_get_roster (db);
		_tmp7_ = _tmp6_;
		_tmp8_ = _tmp7_->account_id;
		_tmp9_ = dino_entities_account_get_id (account);
		_tmp10_ = _tmp9_;
		_tmp11_ = qlite_query_builder_with (_tmp5_, G_TYPE_INT, NULL, NULL, _tmp8_, "=", (gpointer) ((gintptr) _tmp10_));
		_tmp12_ = _tmp11_;
		_tmp13_ = qlite_query_builder_iterator (_tmp12_);
		_tmp14_ = _tmp13_;
		_qlite_statement_builder_unref0 (_tmp12_);
		_qlite_statement_builder_unref0 (_tmp5_);
		_row_it = _tmp14_;
		while (TRUE) {
			QliteRowIterator* _tmp15_;
			QliteRow* row = NULL;
			QliteRowIterator* _tmp16_;
			QliteRow* _tmp17_;
			_tmp15_ = _row_it;
			if (!qlite_row_iterator_next (_tmp15_)) {
				break;
			}
			_tmp16_ = _row_it;
			_tmp17_ = qlite_row_iterator_get (_tmp16_);
			row = _tmp17_;
			{
				XmppRosterItem* item = NULL;
				XmppRosterItem* _tmp18_;
				XmppJid* _tmp19_ = NULL;
				QliteRow* _tmp20_;
				DinoDatabaseRosterTable* _tmp21_;
				DinoDatabaseRosterTable* _tmp22_;
				QliteColumn* _tmp23_;
				gpointer _tmp24_;
				gchar* _tmp25_;
				XmppJid* _tmp26_;
				XmppJid* _tmp27_;
				XmppRosterItem* _tmp28_;
				XmppRosterItem* _tmp29_;
				QliteRow* _tmp30_;
				DinoDatabaseRosterTable* _tmp31_;
				DinoDatabaseRosterTable* _tmp32_;
				QliteColumn* _tmp33_;
				gpointer _tmp34_;
				gchar* _tmp35_;
				XmppRosterItem* _tmp36_;
				QliteRow* _tmp37_;
				DinoDatabaseRosterTable* _tmp38_;
				DinoDatabaseRosterTable* _tmp39_;
				QliteColumn* _tmp40_;
				gpointer _tmp41_;
				gchar* _tmp42_;
				GeeHashMap* _tmp43_;
				XmppRosterItem* _tmp44_;
				XmppJid* _tmp45_;
				XmppJid* _tmp46_;
				XmppRosterItem* _tmp47_;
				_tmp18_ = xmpp_roster_item_new ();
				item = _tmp18_;
				_tmp20_ = row;
				_tmp21_ = dino_database_get_roster (db);
				_tmp22_ = _tmp21_;
				_tmp23_ = _tmp22_->jid;
				_tmp24_ = qlite_row_get (_tmp20_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp23_);
				_tmp25_ = (gchar*) _tmp24_;
				_tmp26_ = xmpp_jid_new (_tmp25_, &_inner_error0_);
				_tmp27_ = _tmp26_;
				_g_free0 (_tmp25_);
				_tmp19_ = _tmp27_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					_xmpp_roster_item_unref0 (item);
					if (_inner_error0_->domain == XMPP_INVALID_JID_ERROR) {
						goto __catch0_xmpp_invalid_jid_error;
					}
					_qlite_row_unref0 (row);
					_qlite_row_iterator_unref0 (_row_it);
					g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return NULL;
				}
				_tmp28_ = item;
				xmpp_roster_item_set_jid (_tmp28_, _tmp19_);
				_tmp29_ = item;
				_tmp30_ = row;
				_tmp31_ = dino_database_get_roster (db);
				_tmp32_ = _tmp31_;
				_tmp33_ = _tmp32_->handle;
				_tmp34_ = qlite_row_get (_tmp30_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp33_);
				_tmp35_ = (gchar*) _tmp34_;
				xmpp_roster_item_set_name (_tmp29_, _tmp35_);
				_g_free0 (_tmp35_);
				_tmp36_ = item;
				_tmp37_ = row;
				_tmp38_ = dino_database_get_roster (db);
				_tmp39_ = _tmp38_;
				_tmp40_ = _tmp39_->subscription;
				_tmp41_ = qlite_row_get (_tmp37_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp40_);
				_tmp42_ = (gchar*) _tmp41_;
				xmpp_roster_item_set_subscription (_tmp36_, _tmp42_);
				_g_free0 (_tmp42_);
				_tmp43_ = self->priv->items;
				_tmp44_ = item;
				_tmp45_ = xmpp_roster_item_get_jid (_tmp44_);
				_tmp46_ = _tmp45_;
				_tmp47_ = item;
				gee_abstract_map_set ((GeeAbstractMap*) _tmp43_, _tmp46_, _tmp47_);
				_xmpp_jid_unref0 (_tmp19_);
				_xmpp_roster_item_unref0 (item);
			}
			goto __finally0;
			__catch0_xmpp_invalid_jid_error:
			{
				GError* e = NULL;
				GError* _tmp48_;
				const gchar* _tmp49_;
				e = _inner_error0_;
				_inner_error0_ = NULL;
				_tmp48_ = e;
				_tmp49_ = _tmp48_->message;
				g_warning ("roster_manager.vala:101: Ignoring roster entry with invalid Jid: %s", _tmp49_);
				_g_error_free0 (e);
			}
			__finally0:
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_qlite_row_unref0 (row);
				_qlite_row_iterator_unref0 (_row_it);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return NULL;
			}
			_qlite_row_unref0 (row);
		}
		_qlite_row_iterator_unref0 (_row_it);
	}
	return self;
}

DinoRosterStoreImpl*
dino_roster_store_impl_new (DinoEntitiesAccount* account,
                            DinoDatabase* db)
{
	return dino_roster_store_impl_construct (DINO_TYPE_ROSTER_STORE_IMPL, account, db);
}

static gchar*
dino_roster_store_impl_real_get_roster_version (XmppRosterStorage* base)
{
	DinoRosterStoreImpl * self;
	DinoEntitiesAccount* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	self = (DinoRosterStoreImpl*) base;
	_tmp0_ = self->priv->account;
	_tmp1_ = dino_entities_account_get_roster_version (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	result = _tmp3_;
	return result;
}

static GeeCollection*
dino_roster_store_impl_real_get_roster (XmppRosterStorage* base)
{
	DinoRosterStoreImpl * self;
	GeeHashMap* _tmp0_;
	GeeCollection* _tmp1_;
	GeeCollection* _tmp2_;
	GeeCollection* result;
	self = (DinoRosterStoreImpl*) base;
	_tmp0_ = self->priv->items;
	_tmp1_ = gee_abstract_map_get_values ((GeeAbstractMap*) _tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

XmppRosterItem*
dino_roster_store_impl_get_item (DinoRosterStoreImpl* self,
                                 XmppJid* jid)
{
	XmppRosterItem* _tmp0_ = NULL;
	GeeHashMap* _tmp1_;
	XmppRosterItem* _tmp4_;
	XmppRosterItem* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (jid != NULL, NULL);
	_tmp1_ = self->priv->items;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp1_, jid)) {
		GeeHashMap* _tmp2_;
		gpointer _tmp3_;
		_tmp2_ = self->priv->items;
		_tmp3_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp2_, jid);
		_xmpp_roster_item_unref0 (_tmp0_);
		_tmp0_ = (XmppRosterItem*) _tmp3_;
	} else {
		_xmpp_roster_item_unref0 (_tmp0_);
		_tmp0_ = NULL;
	}
	_tmp4_ = _tmp0_;
	_tmp0_ = NULL;
	result = _tmp4_;
	_xmpp_roster_item_unref0 (_tmp0_);
	return result;
}

static void
dino_roster_store_impl_real_set_roster_version (XmppRosterStorage* base,
                                                const gchar* version)
{
	DinoRosterStoreImpl * self;
	DinoEntitiesAccount* _tmp0_;
	self = (DinoRosterStoreImpl*) base;
	g_return_if_fail (version != NULL);
	_tmp0_ = self->priv->account;
	dino_entities_account_set_roster_version (_tmp0_, version);
}

static void
dino_roster_store_impl_real_set_roster (XmppRosterStorage* base,
                                        GeeCollection* items)
{
	DinoRosterStoreImpl * self;
	DinoDatabase* _tmp0_;
	DinoDatabaseRosterTable* _tmp1_;
	DinoDatabaseRosterTable* _tmp2_;
	QliteDeleteBuilder* _tmp3_;
	QliteDeleteBuilder* _tmp4_;
	DinoDatabase* _tmp5_;
	DinoDatabaseRosterTable* _tmp6_;
	DinoDatabaseRosterTable* _tmp7_;
	QliteColumn* _tmp8_;
	DinoEntitiesAccount* _tmp9_;
	gint _tmp10_;
	gint _tmp11_;
	QliteDeleteBuilder* _tmp12_;
	QliteDeleteBuilder* _tmp13_;
	self = (DinoRosterStoreImpl*) base;
	g_return_if_fail (items != NULL);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_database_get_roster (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = qlite_table_delete ((QliteTable*) _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = self->priv->db;
	_tmp6_ = dino_database_get_roster (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = _tmp7_->account_id;
	_tmp9_ = self->priv->account;
	_tmp10_ = dino_entities_account_get_id (_tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = qlite_delete_builder_with (_tmp4_, G_TYPE_INT, NULL, NULL, _tmp8_, "=", (gpointer) ((gintptr) _tmp11_));
	_tmp13_ = _tmp12_;
	qlite_delete_builder_perform (_tmp13_);
	_qlite_statement_builder_unref0 (_tmp13_);
	_qlite_statement_builder_unref0 (_tmp4_);
	{
		GeeIterator* _item_it = NULL;
		GeeIterator* _tmp14_;
		_tmp14_ = gee_iterable_iterator ((GeeIterable*) items);
		_item_it = _tmp14_;
		while (TRUE) {
			GeeIterator* _tmp15_;
			XmppRosterItem* item = NULL;
			GeeIterator* _tmp16_;
			gpointer _tmp17_;
			XmppRosterItem* _tmp18_;
			_tmp15_ = _item_it;
			if (!gee_iterator_next (_tmp15_)) {
				break;
			}
			_tmp16_ = _item_it;
			_tmp17_ = gee_iterator_get (_tmp16_);
			item = (XmppRosterItem*) _tmp17_;
			_tmp18_ = item;
			xmpp_roster_storage_set_item ((XmppRosterStorage*) self, _tmp18_);
			_xmpp_roster_item_unref0 (item);
		}
		_g_object_unref0 (_item_it);
	}
}

static void
dino_roster_store_impl_real_set_item (XmppRosterStorage* base,
                                      XmppRosterItem* item)
{
	DinoRosterStoreImpl * self;
	GeeHashMap* _tmp0_;
	XmppJid* _tmp1_;
	XmppJid* _tmp2_;
	DinoDatabase* _tmp3_;
	DinoDatabaseRosterTable* _tmp4_;
	DinoDatabaseRosterTable* _tmp5_;
	QliteUpsertBuilder* _tmp6_;
	QliteUpsertBuilder* _tmp7_;
	DinoDatabase* _tmp8_;
	DinoDatabaseRosterTable* _tmp9_;
	DinoDatabaseRosterTable* _tmp10_;
	QliteColumn* _tmp11_;
	DinoEntitiesAccount* _tmp12_;
	gint _tmp13_;
	gint _tmp14_;
	QliteUpsertBuilder* _tmp15_;
	QliteUpsertBuilder* _tmp16_;
	DinoDatabase* _tmp17_;
	DinoDatabaseRosterTable* _tmp18_;
	DinoDatabaseRosterTable* _tmp19_;
	QliteColumn* _tmp20_;
	XmppJid* _tmp21_;
	XmppJid* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	QliteUpsertBuilder* _tmp25_;
	QliteUpsertBuilder* _tmp26_;
	DinoDatabase* _tmp27_;
	DinoDatabaseRosterTable* _tmp28_;
	DinoDatabaseRosterTable* _tmp29_;
	QliteColumn* _tmp30_;
	const gchar* _tmp31_;
	const gchar* _tmp32_;
	QliteUpsertBuilder* _tmp33_;
	QliteUpsertBuilder* _tmp34_;
	DinoDatabase* _tmp35_;
	DinoDatabaseRosterTable* _tmp36_;
	DinoDatabaseRosterTable* _tmp37_;
	QliteColumn* _tmp38_;
	const gchar* _tmp39_;
	const gchar* _tmp40_;
	QliteUpsertBuilder* _tmp41_;
	QliteUpsertBuilder* _tmp42_;
	DinoDatabase* _tmp43_;
	DinoDatabaseRosterTable* _tmp44_;
	DinoDatabaseRosterTable* _tmp45_;
	QliteColumn* _tmp46_;
	const gchar* _tmp47_;
	const gchar* _tmp48_;
	QliteUpsertBuilder* _tmp49_;
	QliteUpsertBuilder* _tmp50_;
	self = (DinoRosterStoreImpl*) base;
	g_return_if_fail (item != NULL);
	_tmp0_ = self->priv->items;
	_tmp1_ = xmpp_roster_item_get_jid (item);
	_tmp2_ = _tmp1_;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp0_, _tmp2_, item);
	_tmp3_ = self->priv->db;
	_tmp4_ = dino_database_get_roster (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = qlite_table_upsert ((QliteTable*) _tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = self->priv->db;
	_tmp9_ = dino_database_get_roster (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = _tmp10_->account_id;
	_tmp12_ = self->priv->account;
	_tmp13_ = dino_entities_account_get_id (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = qlite_upsert_builder_value (_tmp7_, G_TYPE_INT, NULL, NULL, _tmp11_, (gpointer) ((gintptr) _tmp14_), TRUE);
	_tmp16_ = _tmp15_;
	_tmp17_ = self->priv->db;
	_tmp18_ = dino_database_get_roster (_tmp17_);
	_tmp19_ = _tmp18_;
	_tmp20_ = _tmp19_->jid;
	_tmp21_ = xmpp_roster_item_get_jid (item);
	_tmp22_ = _tmp21_;
	_tmp23_ = xmpp_jid_to_string (_tmp22_);
	_tmp24_ = _tmp23_;
	_tmp25_ = qlite_upsert_builder_value (_tmp16_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp20_, _tmp24_, TRUE);
	_tmp26_ = _tmp25_;
	_tmp27_ = self->priv->db;
	_tmp28_ = dino_database_get_roster (_tmp27_);
	_tmp29_ = _tmp28_;
	_tmp30_ = _tmp29_->handle;
	_tmp31_ = xmpp_roster_item_get_name (item);
	_tmp32_ = _tmp31_;
	_tmp33_ = qlite_upsert_builder_value (_tmp26_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp30_, _tmp32_, FALSE);
	_tmp34_ = _tmp33_;
	_tmp35_ = self->priv->db;
	_tmp36_ = dino_database_get_roster (_tmp35_);
	_tmp37_ = _tmp36_;
	_tmp38_ = _tmp37_->subscription;
	_tmp39_ = xmpp_roster_item_get_subscription (item);
	_tmp40_ = _tmp39_;
	_tmp41_ = qlite_upsert_builder_value (_tmp34_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp38_, _tmp40_, FALSE);
	_tmp42_ = _tmp41_;
	_tmp43_ = self->priv->db;
	_tmp44_ = dino_database_get_roster (_tmp43_);
	_tmp45_ = _tmp44_;
	_tmp46_ = _tmp45_->ask;
	_tmp47_ = xmpp_roster_item_get_ask (item);
	_tmp48_ = _tmp47_;
	_tmp49_ = qlite_upsert_builder_value (_tmp42_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp46_, _tmp48_, FALSE);
	_tmp50_ = _tmp49_;
	qlite_upsert_builder_perform (_tmp50_);
	_qlite_statement_builder_unref0 (_tmp50_);
	_qlite_statement_builder_unref0 (_tmp42_);
	_qlite_statement_builder_unref0 (_tmp34_);
	_qlite_statement_builder_unref0 (_tmp26_);
	_g_free0 (_tmp24_);
	_qlite_statement_builder_unref0 (_tmp16_);
	_qlite_statement_builder_unref0 (_tmp7_);
}

static void
dino_roster_store_impl_real_remove_item (XmppRosterStorage* base,
                                         XmppRosterItem* item)
{
	DinoRosterStoreImpl * self;
	GeeHashMap* _tmp0_;
	XmppJid* _tmp1_;
	XmppJid* _tmp2_;
	DinoDatabase* _tmp3_;
	DinoDatabaseRosterTable* _tmp4_;
	DinoDatabaseRosterTable* _tmp5_;
	QliteDeleteBuilder* _tmp6_;
	QliteDeleteBuilder* _tmp7_;
	DinoDatabase* _tmp8_;
	DinoDatabaseRosterTable* _tmp9_;
	DinoDatabaseRosterTable* _tmp10_;
	QliteColumn* _tmp11_;
	DinoEntitiesAccount* _tmp12_;
	gint _tmp13_;
	gint _tmp14_;
	QliteDeleteBuilder* _tmp15_;
	QliteDeleteBuilder* _tmp16_;
	DinoDatabase* _tmp17_;
	DinoDatabaseRosterTable* _tmp18_;
	DinoDatabaseRosterTable* _tmp19_;
	QliteColumn* _tmp20_;
	XmppJid* _tmp21_;
	XmppJid* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	QliteDeleteBuilder* _tmp25_;
	QliteDeleteBuilder* _tmp26_;
	self = (DinoRosterStoreImpl*) base;
	g_return_if_fail (item != NULL);
	_tmp0_ = self->priv->items;
	_tmp1_ = xmpp_roster_item_get_jid (item);
	_tmp2_ = _tmp1_;
	gee_abstract_map_unset ((GeeAbstractMap*) _tmp0_, _tmp2_, NULL);
	_tmp3_ = self->priv->db;
	_tmp4_ = dino_database_get_roster (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = qlite_table_delete ((QliteTable*) _tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = self->priv->db;
	_tmp9_ = dino_database_get_roster (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = _tmp10_->account_id;
	_tmp12_ = self->priv->account;
	_tmp13_ = dino_entities_account_get_id (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = qlite_delete_builder_with (_tmp7_, G_TYPE_INT, NULL, NULL, _tmp11_, "=", (gpointer) ((gintptr) _tmp14_));
	_tmp16_ = _tmp15_;
	_tmp17_ = self->priv->db;
	_tmp18_ = dino_database_get_roster (_tmp17_);
	_tmp19_ = _tmp18_;
	_tmp20_ = _tmp19_->jid;
	_tmp21_ = xmpp_roster_item_get_jid (item);
	_tmp22_ = _tmp21_;
	_tmp23_ = xmpp_jid_to_string (_tmp22_);
	_tmp24_ = _tmp23_;
	_tmp25_ = qlite_delete_builder_with (_tmp16_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp20_, "=", _tmp24_);
	_tmp26_ = _tmp25_;
	qlite_delete_builder_perform (_tmp26_);
	_qlite_statement_builder_unref0 (_tmp26_);
	_g_free0 (_tmp24_);
	_qlite_statement_builder_unref0 (_tmp16_);
	_qlite_statement_builder_unref0 (_tmp7_);
}

static void
dino_roster_store_impl_class_init (DinoRosterStoreImplClass * klass,
                                   gpointer klass_data)
{
	dino_roster_store_impl_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoRosterStoreImpl_private_offset);
	G_OBJECT_CLASS (klass)->finalize = dino_roster_store_impl_finalize;
}

static void
dino_roster_store_impl_xmpp_roster_storage_interface_init (XmppRosterStorageIface * iface,
                                                           gpointer iface_data)
{
	dino_roster_store_impl_xmpp_roster_storage_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_roster_version = (gchar* (*) (XmppRosterStorage*)) dino_roster_store_impl_real_get_roster_version;
	iface->get_roster = (GeeCollection* (*) (XmppRosterStorage*)) dino_roster_store_impl_real_get_roster;
	iface->set_roster_version = (void (*) (XmppRosterStorage*, const gchar*)) dino_roster_store_impl_real_set_roster_version;
	iface->set_roster = (void (*) (XmppRosterStorage*, GeeCollection*)) dino_roster_store_impl_real_set_roster;
	iface->set_item = (void (*) (XmppRosterStorage*, XmppRosterItem*)) dino_roster_store_impl_real_set_item;
	iface->remove_item = (void (*) (XmppRosterStorage*, XmppRosterItem*)) dino_roster_store_impl_real_remove_item;
}

static void
dino_roster_store_impl_instance_init (DinoRosterStoreImpl * self,
                                      gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = dino_roster_store_impl_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, XMPP_ROSTER_TYPE_ITEM, (GBoxedCopyFunc) xmpp_roster_item_ref, (GDestroyNotify) xmpp_roster_item_unref, _xmpp_jid_hash_bare_func_gee_hash_data_func, NULL, NULL, _xmpp_jid_equals_bare_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->priv->items = _tmp0_;
}

static void
dino_roster_store_impl_finalize (GObject * obj)
{
	DinoRosterStoreImpl * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_ROSTER_STORE_IMPL, DinoRosterStoreImpl);
	_g_object_unref0 (self->priv->account);
	_qlite_database_unref0 (self->priv->db);
	_g_object_unref0 (self->priv->items);
	G_OBJECT_CLASS (dino_roster_store_impl_parent_class)->finalize (obj);
}

static GType
dino_roster_store_impl_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoRosterStoreImplClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_roster_store_impl_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoRosterStoreImpl), 0, (GInstanceInitFunc) dino_roster_store_impl_instance_init, NULL };
	static const GInterfaceInfo xmpp_roster_storage_info = { (GInterfaceInitFunc) dino_roster_store_impl_xmpp_roster_storage_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_roster_store_impl_type_id;
	dino_roster_store_impl_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoRosterStoreImpl", &g_define_type_info, 0);
	g_type_add_interface_static (dino_roster_store_impl_type_id, XMPP_ROSTER_TYPE_STORAGE, &xmpp_roster_storage_info);
	DinoRosterStoreImpl_private_offset = g_type_add_instance_private (dino_roster_store_impl_type_id, sizeof (DinoRosterStoreImplPrivate));
	return dino_roster_store_impl_type_id;
}

GType
dino_roster_store_impl_get_type (void)
{
	static volatile gsize dino_roster_store_impl_type_id__once = 0;
	if (g_once_init_enter (&dino_roster_store_impl_type_id__once)) {
		GType dino_roster_store_impl_type_id;
		dino_roster_store_impl_type_id = dino_roster_store_impl_get_type_once ();
		g_once_init_leave (&dino_roster_store_impl_type_id__once, dino_roster_store_impl_type_id);
	}
	return dino_roster_store_impl_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

