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

#include "libdino.h"
#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include "qlite.h"
#include <stdlib.h>
#include <string.h>
#include "xmpp-vala.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_CONTENT_ITEM_STORE_0_PROPERTY,
	DINO_CONTENT_ITEM_STORE_ID_PROPERTY,
	DINO_CONTENT_ITEM_STORE_NUM_PROPERTIES
};
static GParamSpec* dino_content_item_store_properties[DINO_CONTENT_ITEM_STORE_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)))
#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_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#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_option_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_option_unref (var), NULL)))
enum  {
	DINO_CONTENT_ITEM_STORE_NEW_ITEM_SIGNAL,
	DINO_CONTENT_ITEM_STORE_NUM_SIGNALS
};
static guint dino_content_item_store_signals[DINO_CONTENT_ITEM_STORE_NUM_SIGNALS] = {0};
enum  {
	DINO_CONTENT_ITEM_0_PROPERTY,
	DINO_CONTENT_ITEM_ID_PROPERTY,
	DINO_CONTENT_ITEM_TYPE__PROPERTY,
	DINO_CONTENT_ITEM_JID_PROPERTY,
	DINO_CONTENT_ITEM_TIME_PROPERTY,
	DINO_CONTENT_ITEM_ENCRYPTION_PROPERTY,
	DINO_CONTENT_ITEM_MARK_PROPERTY,
	DINO_CONTENT_ITEM_NUM_PROPERTIES
};
static GParamSpec* dino_content_item_properties[DINO_CONTENT_ITEM_NUM_PROPERTIES];
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
enum  {
	DINO_MESSAGE_ITEM_0_PROPERTY,
	DINO_MESSAGE_ITEM_NUM_PROPERTIES
};
static GParamSpec* dino_message_item_properties[DINO_MESSAGE_ITEM_NUM_PROPERTIES];
enum  {
	DINO_FILE_ITEM_0_PROPERTY,
	DINO_FILE_ITEM_NUM_PROPERTIES
};
static GParamSpec* dino_file_item_properties[DINO_FILE_ITEM_NUM_PROPERTIES];
enum  {
	DINO_CALL_ITEM_0_PROPERTY,
	DINO_CALL_ITEM_NUM_PROPERTIES
};
static GParamSpec* dino_call_item_properties[DINO_CALL_ITEM_NUM_PROPERTIES];

struct _DinoContentItemStorePrivate {
	DinoStreamInteractor* stream_interactor;
	DinoDatabase* db;
	GeeHashMap* collection_conversations;
};

struct _DinoContentItemPrivate {
	gint _id;
	gchar* _type_;
	XmppJid* _jid;
	GDateTime* _time;
	DinoEntitiesEncryption _encryption;
	DinoEntitiesMessageMarked _mark;
};

static gint DinoContentItemStore_private_offset;
static gpointer dino_content_item_store_parent_class = NULL;
DinoModuleIdentity* dino_content_item_store_IDENTITY = NULL;
static DinoStreamInteractionModuleIface * dino_content_item_store_dino_stream_interaction_module_parent_iface = NULL;
static gint DinoContentItem_private_offset;
static gpointer dino_content_item_parent_class = NULL;
static gpointer dino_message_item_parent_class = NULL;
static gpointer dino_file_item_parent_class = NULL;
static gpointer dino_call_item_parent_class = NULL;

static guint _dino_entities_conversation_hash_func_gee_hash_data_func (gconstpointer v,
                                                                gpointer self);
static gboolean _dino_entities_conversation_equals_func_gee_equal_data_func (gconstpointer a,
                                                                      gconstpointer b,
                                                                      gpointer self);
static void dino_content_item_store_insert_file_transfer (DinoContentItemStore* self,
                                                   DinoEntitiesFileTransfer* file_transfer,
                                                   DinoEntitiesConversation* conversation);
static void _dino_content_item_store_insert_file_transfer_dino_file_manager_received_file (DinoFileManager* _sender,
                                                                                    DinoEntitiesFileTransfer* file_transfer,
                                                                                    DinoEntitiesConversation* conversation,
                                                                                    gpointer self);
static void dino_content_item_store_announce_message (DinoContentItemStore* self,
                                               DinoEntitiesMessage* message,
                                               DinoEntitiesConversation* conversation);
static void _dino_content_item_store_announce_message_dino_message_processor_message_received (DinoMessageProcessor* _sender,
                                                                                        DinoEntitiesMessage* message,
                                                                                        DinoEntitiesConversation* conversation,
                                                                                        gpointer self);
static void _dino_content_item_store_announce_message_dino_message_processor_message_sent (DinoMessageProcessor* _sender,
                                                                                    DinoEntitiesMessage* message,
                                                                                    DinoEntitiesConversation* conversation,
                                                                                    gpointer self);
static void dino_content_item_store_insert_call (DinoContentItemStore* self,
                                          DinoEntitiesCall* call,
                                          DinoCallState* call_state,
                                          DinoEntitiesConversation* conversation);
static void _dino_content_item_store_insert_call_dino_calls_call_incoming (DinoCalls* _sender,
                                                                    DinoEntitiesCall* call,
                                                                    DinoCallState* state,
                                                                    DinoEntitiesConversation* conversation,
                                                                    gboolean video,
                                                                    gboolean multiparty,
                                                                    gpointer self);
static void _dino_content_item_store_insert_call_dino_calls_call_outgoing (DinoCalls* _sender,
                                                                    DinoEntitiesCall* call,
                                                                    DinoCallState* state,
                                                                    DinoEntitiesConversation* conversation,
                                                                    gpointer self);
static GeeList* dino_content_item_store_get_items_from_query (DinoContentItemStore* self,
                                                       QliteQueryBuilder* select,
                                                       DinoEntitiesConversation* conversation);
static gint _dino_content_item_compare_func_gcompare_data_func (gconstpointer a,
                                                         gconstpointer b,
                                                         gpointer self);
static DinoContentItem* dino_content_item_store_get_item_from_row (DinoContentItemStore* self,
                                                            QliteRow* row,
                                                            DinoEntitiesConversation* conversation,
                                                            GError** error);
static DinoContentItem* dino_content_item_store_get_item (DinoContentItemStore* self,
                                                   DinoEntitiesConversation* conversation,
                                                   gint id,
                                                   gint content_type,
                                                   gint foreign_id,
                                                   GDateTime* time,
                                                   GError** error);
static QliteRow* dino_content_item_store_get_content_item_row_for_message_id (DinoContentItemStore* self,
                                                                       DinoEntitiesConversation* conversation,
                                                                       const gchar* message_id);
static void g_cclosure_user_marshal_VOID__OBJECT_OBJECT (GClosure * closure,
                                                  GValue * return_value,
                                                  guint n_param_values,
                                                  const GValue * param_values,
                                                  gpointer invocation_hint,
                                                  gpointer marshal_data);
static void dino_content_item_store_finalize (GObject * obj);
static GType dino_content_item_store_get_type_once (void);
static void _vala_dino_content_item_store_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec);
static GType dino_content_item_collection_get_type_once (void);
static DinoContentItem* dino_content_item_construct (GType object_type,
                                              gint id,
                                              const gchar* ty,
                                              XmppJid* jid,
                                              GDateTime* time,
                                              DinoEntitiesEncryption encryption,
                                              DinoEntitiesMessageMarked mark);
static void dino_content_item_finalize (GObject * obj);
static GType dino_content_item_get_type_once (void);
static void _vala_dino_content_item_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec);
static void _vala_dino_content_item_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec);
static void dino_message_item_finalize (GObject * obj);
static GType dino_message_item_get_type_once (void);
static DinoEntitiesMessageMarked dino_file_item_file_to_message_state (DinoEntitiesFileTransferState state);
static gboolean ____lambda47_ (DinoFileItem* self,
                        GBinding* _,
                        GValue* from_value,
                        GValue* to_value);
static gboolean _____lambda47__gbinding_transform_func (GBinding* binding,
                                                 GValue* from_value,
                                                 GValue* to_value,
                                                 gpointer self);
static void dino_file_item_finalize (GObject * obj);
static GType dino_file_item_get_type_once (void);
static void dino_call_item_finalize (GObject * obj);
static GType dino_call_item_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_content_item_store_get_instance_private (DinoContentItemStore* self)
{
	return G_STRUCT_MEMBER_P (self, DinoContentItemStore_private_offset);
}

static guint
_dino_entities_conversation_hash_func_gee_hash_data_func (gconstpointer v,
                                                          gpointer self)
{
	guint result;
	result = dino_entities_conversation_hash_func ((DinoEntitiesConversation*) v);
	return result;
}

static gboolean
_dino_entities_conversation_equals_func_gee_equal_data_func (gconstpointer a,
                                                             gconstpointer b,
                                                             gpointer self)
{
	gboolean result;
	result = dino_entities_conversation_equals_func ((DinoEntitiesConversation*) a, (DinoEntitiesConversation*) b);
	return result;
}

void
dino_content_item_store_start (DinoStreamInteractor* stream_interactor,
                               DinoDatabase* db)
{
	DinoContentItemStore* m = NULL;
	DinoContentItemStore* _tmp0_;
	g_return_if_fail (stream_interactor != NULL);
	g_return_if_fail (db != NULL);
	_tmp0_ = dino_content_item_store_new (stream_interactor, db);
	m = _tmp0_;
	dino_stream_interactor_add_module (stream_interactor, (DinoStreamInteractionModule*) m);
	_g_object_unref0 (m);
}

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

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

static void
_dino_content_item_store_insert_file_transfer_dino_file_manager_received_file (DinoFileManager* _sender,
                                                                               DinoEntitiesFileTransfer* file_transfer,
                                                                               DinoEntitiesConversation* conversation,
                                                                               gpointer self)
{
	dino_content_item_store_insert_file_transfer ((DinoContentItemStore*) self, file_transfer, conversation);
}

static void
_dino_content_item_store_announce_message_dino_message_processor_message_received (DinoMessageProcessor* _sender,
                                                                                   DinoEntitiesMessage* message,
                                                                                   DinoEntitiesConversation* conversation,
                                                                                   gpointer self)
{
	dino_content_item_store_announce_message ((DinoContentItemStore*) self, message, conversation);
}

static void
_dino_content_item_store_announce_message_dino_message_processor_message_sent (DinoMessageProcessor* _sender,
                                                                               DinoEntitiesMessage* message,
                                                                               DinoEntitiesConversation* conversation,
                                                                               gpointer self)
{
	dino_content_item_store_announce_message ((DinoContentItemStore*) self, message, conversation);
}

static void
_dino_content_item_store_insert_call_dino_calls_call_incoming (DinoCalls* _sender,
                                                               DinoEntitiesCall* call,
                                                               DinoCallState* state,
                                                               DinoEntitiesConversation* conversation,
                                                               gboolean video,
                                                               gboolean multiparty,
                                                               gpointer self)
{
	dino_content_item_store_insert_call ((DinoContentItemStore*) self, call, state, conversation);
}

static void
_dino_content_item_store_insert_call_dino_calls_call_outgoing (DinoCalls* _sender,
                                                               DinoEntitiesCall* call,
                                                               DinoCallState* state,
                                                               DinoEntitiesConversation* conversation,
                                                               gpointer self)
{
	dino_content_item_store_insert_call ((DinoContentItemStore*) self, call, state, conversation);
}

DinoContentItemStore*
dino_content_item_store_construct (GType object_type,
                                   DinoStreamInteractor* stream_interactor,
                                   DinoDatabase* db)
{
	DinoContentItemStore * self = NULL;
	DinoStreamInteractor* _tmp0_;
	DinoDatabase* _tmp1_;
	DinoModuleIdentity* _tmp2_;
	gpointer _tmp3_;
	DinoFileManager* _tmp4_;
	DinoModuleIdentity* _tmp5_;
	gpointer _tmp6_;
	DinoMessageProcessor* _tmp7_;
	DinoModuleIdentity* _tmp8_;
	gpointer _tmp9_;
	DinoMessageProcessor* _tmp10_;
	DinoModuleIdentity* _tmp11_;
	gpointer _tmp12_;
	DinoCalls* _tmp13_;
	DinoModuleIdentity* _tmp14_;
	gpointer _tmp15_;
	DinoCalls* _tmp16_;
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoContentItemStore*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (stream_interactor);
	_g_object_unref0 (self->priv->stream_interactor);
	self->priv->stream_interactor = _tmp0_;
	_tmp1_ = _qlite_database_ref0 (db);
	_qlite_database_unref0 (self->priv->db);
	self->priv->db = _tmp1_;
	_tmp2_ = dino_file_manager_IDENTITY;
	_tmp3_ = dino_stream_interactor_get_module (stream_interactor, DINO_TYPE_FILE_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp2_);
	_tmp4_ = (DinoFileManager*) _tmp3_;
	g_signal_connect_object (_tmp4_, "received-file", (GCallback) _dino_content_item_store_insert_file_transfer_dino_file_manager_received_file, self, 0);
	_g_object_unref0 (_tmp4_);
	_tmp5_ = dino_message_processor_IDENTITY;
	_tmp6_ = dino_stream_interactor_get_module (stream_interactor, DINO_TYPE_MESSAGE_PROCESSOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp5_);
	_tmp7_ = (DinoMessageProcessor*) _tmp6_;
	g_signal_connect_object (_tmp7_, "message-received", (GCallback) _dino_content_item_store_announce_message_dino_message_processor_message_received, self, 0);
	_g_object_unref0 (_tmp7_);
	_tmp8_ = dino_message_processor_IDENTITY;
	_tmp9_ = dino_stream_interactor_get_module (stream_interactor, DINO_TYPE_MESSAGE_PROCESSOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp8_);
	_tmp10_ = (DinoMessageProcessor*) _tmp9_;
	g_signal_connect_object (_tmp10_, "message-sent", (GCallback) _dino_content_item_store_announce_message_dino_message_processor_message_sent, self, 0);
	_g_object_unref0 (_tmp10_);
	_tmp11_ = dino_calls_IDENTITY;
	_tmp12_ = dino_stream_interactor_get_module (stream_interactor, DINO_TYPE_CALLS, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp11_);
	_tmp13_ = (DinoCalls*) _tmp12_;
	g_signal_connect_object (_tmp13_, "call-incoming", (GCallback) _dino_content_item_store_insert_call_dino_calls_call_incoming, self, 0);
	_g_object_unref0 (_tmp13_);
	_tmp14_ = dino_calls_IDENTITY;
	_tmp15_ = dino_stream_interactor_get_module (stream_interactor, DINO_TYPE_CALLS, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp14_);
	_tmp16_ = (DinoCalls*) _tmp15_;
	g_signal_connect_object (_tmp16_, "call-outgoing", (GCallback) _dino_content_item_store_insert_call_dino_calls_call_outgoing, self, 0);
	_g_object_unref0 (_tmp16_);
	return self;
}

DinoContentItemStore*
dino_content_item_store_new (DinoStreamInteractor* stream_interactor,
                             DinoDatabase* db)
{
	return dino_content_item_store_construct (DINO_TYPE_CONTENT_ITEM_STORE, stream_interactor, db);
}

void
dino_content_item_store_init (DinoContentItemStore* self,
                              DinoEntitiesConversation* conversation,
                              DinoContentItemCollection* item_collection)
{
	GeeHashMap* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (conversation != NULL);
	g_return_if_fail (item_collection != NULL);
	_tmp0_ = self->priv->collection_conversations;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp0_, conversation, item_collection);
}

void
dino_content_item_store_uninit (DinoContentItemStore* self,
                                DinoEntitiesConversation* conversation,
                                DinoContentItemCollection* item_collection)
{
	GeeHashMap* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (conversation != NULL);
	g_return_if_fail (item_collection != NULL);
	_tmp0_ = self->priv->collection_conversations;
	gee_abstract_map_unset ((GeeAbstractMap*) _tmp0_, conversation, NULL);
}

static gint
_dino_content_item_compare_func_gcompare_data_func (gconstpointer a,
                                                    gconstpointer b,
                                                    gpointer self)
{
	gint result;
	result = dino_content_item_compare_func ((DinoContentItem*) a, (DinoContentItem*) b);
	return result;
}

static GeeList*
dino_content_item_store_get_items_from_query (DinoContentItemStore* self,
                                              QliteQueryBuilder* select,
                                              DinoEntitiesConversation* conversation)
{
	GeeTreeSet* items = NULL;
	GeeTreeSet* _tmp0_;
	GeeList* ret = NULL;
	GeeArrayList* _tmp9_;
	GError* _inner_error0_ = NULL;
	GeeList* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (select != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	_tmp0_ = gee_tree_set_new (DINO_TYPE_CONTENT_ITEM, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _dino_content_item_compare_func_gcompare_data_func, NULL, NULL);
	items = _tmp0_;
	{
		QliteRowIterator* _row_it = NULL;
		QliteRowIterator* _tmp1_;
		_tmp1_ = qlite_query_builder_iterator (select);
		_row_it = _tmp1_;
		while (TRUE) {
			QliteRowIterator* _tmp2_;
			QliteRow* row = NULL;
			QliteRowIterator* _tmp3_;
			QliteRow* _tmp4_;
			DinoContentItem* content_item = NULL;
			QliteRow* _tmp5_;
			DinoContentItem* _tmp6_;
			GeeTreeSet* _tmp7_;
			DinoContentItem* _tmp8_;
			_tmp2_ = _row_it;
			if (!qlite_row_iterator_next (_tmp2_)) {
				break;
			}
			_tmp3_ = _row_it;
			_tmp4_ = qlite_row_iterator_get (_tmp3_);
			row = _tmp4_;
			_tmp5_ = row;
			_tmp6_ = dino_content_item_store_get_item_from_row (self, _tmp5_, conversation, &_inner_error0_);
			content_item = _tmp6_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_qlite_row_unref0 (row);
				_qlite_row_iterator_unref0 (_row_it);
				_g_object_unref0 (items);
				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;
			}
			_tmp7_ = items;
			_tmp8_ = content_item;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp7_, _tmp8_);
			_g_object_unref0 (content_item);
			_qlite_row_unref0 (row);
		}
		_qlite_row_iterator_unref0 (_row_it);
	}
	_tmp9_ = gee_array_list_new (DINO_TYPE_CONTENT_ITEM, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	ret = (GeeList*) _tmp9_;
	{
		GeeIterator* _item_it = NULL;
		GeeTreeSet* _tmp10_;
		GeeIterator* _tmp11_;
		_tmp10_ = items;
		_tmp11_ = gee_abstract_collection_iterator ((GeeAbstractCollection*) _tmp10_);
		_item_it = _tmp11_;
		while (TRUE) {
			GeeIterator* _tmp12_;
			DinoContentItem* item = NULL;
			GeeIterator* _tmp13_;
			gpointer _tmp14_;
			GeeList* _tmp15_;
			DinoContentItem* _tmp16_;
			_tmp12_ = _item_it;
			if (!gee_iterator_next (_tmp12_)) {
				break;
			}
			_tmp13_ = _item_it;
			_tmp14_ = gee_iterator_get (_tmp13_);
			item = (DinoContentItem*) _tmp14_;
			_tmp15_ = ret;
			_tmp16_ = item;
			gee_collection_add ((GeeCollection*) _tmp15_, _tmp16_);
			_g_object_unref0 (item);
		}
		_g_object_unref0 (_item_it);
	}
	result = ret;
	_g_object_unref0 (items);
	return result;
}

static DinoContentItem*
dino_content_item_store_get_item_from_row (DinoContentItemStore* self,
                                           QliteRow* row,
                                           DinoEntitiesConversation* conversation,
                                           GError** error)
{
	gint id = 0;
	DinoDatabase* _tmp0_;
	DinoDatabaseContentItemTable* _tmp1_;
	DinoDatabaseContentItemTable* _tmp2_;
	QliteColumn* _tmp3_;
	gpointer _tmp4_;
	gint content_type = 0;
	DinoDatabase* _tmp5_;
	DinoDatabaseContentItemTable* _tmp6_;
	DinoDatabaseContentItemTable* _tmp7_;
	QliteColumn* _tmp8_;
	gpointer _tmp9_;
	gint foreign_id = 0;
	DinoDatabase* _tmp10_;
	DinoDatabaseContentItemTable* _tmp11_;
	DinoDatabaseContentItemTable* _tmp12_;
	QliteColumn* _tmp13_;
	gpointer _tmp14_;
	GDateTime* time = NULL;
	DinoDatabase* _tmp15_;
	DinoDatabaseContentItemTable* _tmp16_;
	DinoDatabaseContentItemTable* _tmp17_;
	QliteColumn* _tmp18_;
	gpointer _tmp19_;
	GDateTime* _tmp20_;
	DinoContentItem* _tmp21_ = NULL;
	DinoContentItem* _tmp22_;
	DinoContentItem* _tmp23_;
	GError* _inner_error0_ = NULL;
	DinoContentItem* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (row != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_database_get_content_item (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_->id;
	_tmp4_ = qlite_row_get (row, G_TYPE_INT, NULL, NULL, _tmp3_);
	id = (gint) ((gintptr) _tmp4_);
	_tmp5_ = self->priv->db;
	_tmp6_ = dino_database_get_content_item (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = _tmp7_->content_type;
	_tmp9_ = qlite_row_get (row, G_TYPE_INT, NULL, NULL, _tmp8_);
	content_type = (gint) ((gintptr) _tmp9_);
	_tmp10_ = self->priv->db;
	_tmp11_ = dino_database_get_content_item (_tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = _tmp12_->foreign_id;
	_tmp14_ = qlite_row_get (row, G_TYPE_INT, NULL, NULL, _tmp13_);
	foreign_id = (gint) ((gintptr) _tmp14_);
	_tmp15_ = self->priv->db;
	_tmp16_ = dino_database_get_content_item (_tmp15_);
	_tmp17_ = _tmp16_;
	_tmp18_ = _tmp17_->time;
	_tmp19_ = qlite_row_get (row, G_TYPE_LONG, NULL, NULL, _tmp18_);
	_tmp20_ = g_date_time_new_from_unix_utc ((gint64) ((glong) ((gintptr) _tmp19_)));
	time = _tmp20_;
	_tmp22_ = dino_content_item_store_get_item (self, conversation, id, content_type, foreign_id, time, &_inner_error0_);
	_tmp21_ = _tmp22_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_date_time_unref0 (time);
		return NULL;
	}
	_tmp23_ = _tmp21_;
	_tmp21_ = NULL;
	result = _tmp23_;
	_g_object_unref0 (_tmp21_);
	_g_date_time_unref0 (time);
	return result;
}

static DinoContentItem*
dino_content_item_store_get_item (DinoContentItemStore* self,
                                  DinoEntitiesConversation* conversation,
                                  gint id,
                                  gint content_type,
                                  gint foreign_id,
                                  GDateTime* time,
                                  GError** error)
{
	GError* _tmp44_;
	GError* _inner_error0_ = NULL;
	DinoContentItem* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	g_return_val_if_fail (time != NULL, NULL);
	switch (content_type) {
		case 1:
		{
			DinoEntitiesMessage* message = NULL;
			DinoStreamInteractor* _tmp0_;
			DinoModuleIdentity* _tmp1_;
			gpointer _tmp2_;
			DinoMessageStorage* _tmp3_;
			DinoEntitiesMessage* _tmp4_;
			DinoEntitiesMessage* _tmp5_;
			DinoEntitiesMessage* _tmp6_;
			_tmp0_ = self->priv->stream_interactor;
			_tmp1_ = dino_message_storage_IDENTITY;
			_tmp2_ = dino_stream_interactor_get_module (_tmp0_, DINO_TYPE_MESSAGE_STORAGE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp1_);
			_tmp3_ = (DinoMessageStorage*) _tmp2_;
			_tmp4_ = dino_message_storage_get_message_by_id (_tmp3_, foreign_id, conversation);
			_tmp5_ = _tmp4_;
			_g_object_unref0 (_tmp3_);
			message = _tmp5_;
			_tmp6_ = message;
			if (_tmp6_ != NULL) {
				DinoMessageItem* message_item = NULL;
				DinoEntitiesMessage* _tmp7_;
				DinoMessageItem* _tmp8_;
				DinoMessageItem* _tmp9_;
				_tmp7_ = message;
				_tmp8_ = dino_message_item_new (_tmp7_, conversation, id);
				message_item = _tmp8_;
				_tmp9_ = message_item;
				dino_content_item_set_time ((DinoContentItem*) _tmp9_, time);
				result = (DinoContentItem*) message_item;
				_g_object_unref0 (message);
				return result;
			}
			_g_object_unref0 (message);
			break;
		}
		case 2:
		{
			DinoEntitiesFileTransfer* file_transfer = NULL;
			DinoStreamInteractor* _tmp10_;
			DinoModuleIdentity* _tmp11_;
			gpointer _tmp12_;
			DinoFileTransferStorage* _tmp13_;
			DinoEntitiesFileTransfer* _tmp14_;
			DinoEntitiesFileTransfer* _tmp15_;
			DinoEntitiesFileTransfer* _tmp16_;
			_tmp10_ = self->priv->stream_interactor;
			_tmp11_ = dino_file_transfer_storage_IDENTITY;
			_tmp12_ = dino_stream_interactor_get_module (_tmp10_, DINO_TYPE_FILE_TRANSFER_STORAGE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp11_);
			_tmp13_ = (DinoFileTransferStorage*) _tmp12_;
			_tmp14_ = dino_file_transfer_storage_get_file_by_id (_tmp13_, foreign_id, conversation);
			_tmp15_ = _tmp14_;
			_g_object_unref0 (_tmp13_);
			file_transfer = _tmp15_;
			_tmp16_ = file_transfer;
			if (_tmp16_ != NULL) {
				DinoEntitiesMessage* message = NULL;
				gboolean _tmp17_ = FALSE;
				DinoEntitiesFileTransfer* _tmp18_;
				gint _tmp19_;
				gint _tmp20_;
				DinoFileItem* file_item = NULL;
				DinoEntitiesFileTransfer* _tmp32_;
				DinoEntitiesMessage* _tmp33_;
				DinoFileItem* _tmp34_;
				message = NULL;
				_tmp18_ = file_transfer;
				_tmp19_ = dino_entities_file_transfer_get_provider (_tmp18_);
				_tmp20_ = _tmp19_;
				if (_tmp20_ == 0) {
					DinoEntitiesFileTransfer* _tmp21_;
					const gchar* _tmp22_;
					const gchar* _tmp23_;
					_tmp21_ = file_transfer;
					_tmp22_ = dino_entities_file_transfer_get_info (_tmp21_);
					_tmp23_ = _tmp22_;
					_tmp17_ = _tmp23_ != NULL;
				} else {
					_tmp17_ = FALSE;
				}
				if (_tmp17_) {
					DinoStreamInteractor* _tmp24_;
					DinoModuleIdentity* _tmp25_;
					gpointer _tmp26_;
					DinoMessageStorage* _tmp27_;
					DinoEntitiesFileTransfer* _tmp28_;
					const gchar* _tmp29_;
					const gchar* _tmp30_;
					DinoEntitiesMessage* _tmp31_;
					_tmp24_ = self->priv->stream_interactor;
					_tmp25_ = dino_message_storage_IDENTITY;
					_tmp26_ = dino_stream_interactor_get_module (_tmp24_, DINO_TYPE_MESSAGE_STORAGE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp25_);
					_tmp27_ = (DinoMessageStorage*) _tmp26_;
					_tmp28_ = file_transfer;
					_tmp29_ = dino_entities_file_transfer_get_info (_tmp28_);
					_tmp30_ = _tmp29_;
					_tmp31_ = dino_message_storage_get_message_by_id (_tmp27_, atoi (_tmp30_), conversation);
					_g_object_unref0 (message);
					message = _tmp31_;
					_g_object_unref0 (_tmp27_);
				}
				_tmp32_ = file_transfer;
				_tmp33_ = message;
				_tmp34_ = dino_file_item_new (_tmp32_, conversation, id, _tmp33_);
				file_item = _tmp34_;
				result = (DinoContentItem*) file_item;
				_g_object_unref0 (message);
				_g_object_unref0 (file_transfer);
				return result;
			}
			_g_object_unref0 (file_transfer);
			break;
		}
		case 3:
		{
			DinoEntitiesCall* call = NULL;
			DinoStreamInteractor* _tmp35_;
			DinoModuleIdentity* _tmp36_;
			gpointer _tmp37_;
			DinoCallStore* _tmp38_;
			DinoEntitiesCall* _tmp39_;
			DinoEntitiesCall* _tmp40_;
			DinoEntitiesCall* _tmp41_;
			_tmp35_ = self->priv->stream_interactor;
			_tmp36_ = dino_call_store_IDENTITY;
			_tmp37_ = dino_stream_interactor_get_module (_tmp35_, DINO_TYPE_CALL_STORE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp36_);
			_tmp38_ = (DinoCallStore*) _tmp37_;
			_tmp39_ = dino_call_store_get_call_by_id (_tmp38_, foreign_id, conversation);
			_tmp40_ = _tmp39_;
			_g_object_unref0 (_tmp38_);
			call = _tmp40_;
			_tmp41_ = call;
			if (_tmp41_ != NULL) {
				DinoCallItem* call_item = NULL;
				DinoEntitiesCall* _tmp42_;
				DinoCallItem* _tmp43_;
				_tmp42_ = call;
				_tmp43_ = dino_call_item_new (_tmp42_, conversation, id);
				call_item = _tmp43_;
				result = (DinoContentItem*) call_item;
				_g_object_unref0 (call);
				return result;
			}
			_g_object_unref0 (call);
			break;
		}
		default:
		{
			g_warning ("content_item_store.vala:95: Unknown content item type: %i", content_type);
			break;
		}
	}
	_tmp44_ = g_error_new ((GQuark) -1, 0, "Bad content type %i or non existing content item %i", content_type, foreign_id);
	_inner_error0_ = _tmp44_;
	g_propagate_error (error, _inner_error0_);
	return NULL;
}

DinoContentItem*
dino_content_item_store_get_item_by_foreign (DinoContentItemStore* self,
                                             DinoEntitiesConversation* conversation,
                                             gint type,
                                             gint foreign_id)
{
	QliteQueryBuilder* select = NULL;
	DinoDatabase* _tmp0_;
	DinoDatabaseContentItemTable* _tmp1_;
	DinoDatabaseContentItemTable* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	QliteQueryBuilder* _tmp4_;
	DinoDatabase* _tmp5_;
	DinoDatabaseContentItemTable* _tmp6_;
	DinoDatabaseContentItemTable* _tmp7_;
	QliteColumn* _tmp8_;
	QliteQueryBuilder* _tmp9_;
	QliteQueryBuilder* _tmp10_;
	DinoDatabase* _tmp11_;
	DinoDatabaseContentItemTable* _tmp12_;
	DinoDatabaseContentItemTable* _tmp13_;
	QliteColumn* _tmp14_;
	QliteQueryBuilder* _tmp15_;
	QliteQueryBuilder* _tmp16_;
	GeeList* item = NULL;
	QliteQueryBuilder* _tmp17_;
	GeeList* _tmp18_;
	DinoContentItem* _tmp19_ = NULL;
	GeeList* _tmp20_;
	gint _tmp21_;
	gint _tmp22_;
	DinoContentItem* _tmp25_;
	DinoContentItem* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_database_get_content_item (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = qlite_table_select ((QliteTable*) _tmp2_, NULL, (gint) 0);
	_tmp4_ = _tmp3_;
	_tmp5_ = self->priv->db;
	_tmp6_ = dino_database_get_content_item (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = _tmp7_->content_type;
	_tmp9_ = qlite_query_builder_with (_tmp4_, G_TYPE_INT, NULL, NULL, _tmp8_, "=", (gpointer) ((gintptr) type));
	_tmp10_ = _tmp9_;
	_tmp11_ = self->priv->db;
	_tmp12_ = dino_database_get_content_item (_tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = _tmp13_->foreign_id;
	_tmp15_ = qlite_query_builder_with (_tmp10_, G_TYPE_INT, NULL, NULL, _tmp14_, "=", (gpointer) ((gintptr) foreign_id));
	_tmp16_ = _tmp15_;
	_qlite_statement_builder_unref0 (_tmp10_);
	_qlite_statement_builder_unref0 (_tmp4_);
	select = _tmp16_;
	_tmp17_ = select;
	_tmp18_ = dino_content_item_store_get_items_from_query (self, _tmp17_, conversation);
	item = _tmp18_;
	_tmp20_ = item;
	_tmp21_ = gee_collection_get_size ((GeeCollection*) _tmp20_);
	_tmp22_ = _tmp21_;
	if (_tmp22_ > 0) {
		GeeList* _tmp23_;
		gpointer _tmp24_;
		_tmp23_ = item;
		_tmp24_ = gee_list_get (_tmp23_, 0);
		_g_object_unref0 (_tmp19_);
		_tmp19_ = (DinoContentItem*) _tmp24_;
	} else {
		_g_object_unref0 (_tmp19_);
		_tmp19_ = NULL;
	}
	_tmp25_ = _tmp19_;
	_tmp19_ = NULL;
	result = _tmp25_;
	_g_object_unref0 (_tmp19_);
	_g_object_unref0 (item);
	_qlite_statement_builder_unref0 (select);
	return result;
}

DinoContentItem*
dino_content_item_store_get_item_by_id (DinoContentItemStore* self,
                                        DinoEntitiesConversation* conversation,
                                        gint id)
{
	QliteQueryBuilder* select = NULL;
	DinoDatabase* _tmp0_;
	DinoDatabaseContentItemTable* _tmp1_;
	DinoDatabaseContentItemTable* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	QliteQueryBuilder* _tmp4_;
	DinoDatabase* _tmp5_;
	DinoDatabaseContentItemTable* _tmp6_;
	DinoDatabaseContentItemTable* _tmp7_;
	QliteColumn* _tmp8_;
	QliteQueryBuilder* _tmp9_;
	QliteQueryBuilder* _tmp10_;
	GeeList* item = NULL;
	QliteQueryBuilder* _tmp11_;
	GeeList* _tmp12_;
	DinoContentItem* _tmp13_ = NULL;
	GeeList* _tmp14_;
	gint _tmp15_;
	gint _tmp16_;
	DinoContentItem* _tmp19_;
	DinoContentItem* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_database_get_content_item (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = qlite_table_select ((QliteTable*) _tmp2_, NULL, (gint) 0);
	_tmp4_ = _tmp3_;
	_tmp5_ = self->priv->db;
	_tmp6_ = dino_database_get_content_item (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = _tmp7_->id;
	_tmp9_ = qlite_query_builder_with (_tmp4_, G_TYPE_INT, NULL, NULL, _tmp8_, "=", (gpointer) ((gintptr) id));
	_tmp10_ = _tmp9_;
	_qlite_statement_builder_unref0 (_tmp4_);
	select = _tmp10_;
	_tmp11_ = select;
	_tmp12_ = dino_content_item_store_get_items_from_query (self, _tmp11_, conversation);
	item = _tmp12_;
	_tmp14_ = item;
	_tmp15_ = gee_collection_get_size ((GeeCollection*) _tmp14_);
	_tmp16_ = _tmp15_;
	if (_tmp16_ > 0) {
		GeeList* _tmp17_;
		gpointer _tmp18_;
		_tmp17_ = item;
		_tmp18_ = gee_list_get (_tmp17_, 0);
		_g_object_unref0 (_tmp13_);
		_tmp13_ = (DinoContentItem*) _tmp18_;
	} else {
		_g_object_unref0 (_tmp13_);
		_tmp13_ = NULL;
	}
	_tmp19_ = _tmp13_;
	_tmp13_ = NULL;
	result = _tmp19_;
	_g_object_unref0 (_tmp13_);
	_g_object_unref0 (item);
	_qlite_statement_builder_unref0 (select);
	return result;
}

gchar*
dino_content_item_store_get_message_id_for_content_item (DinoContentItemStore* self,
                                                         DinoEntitiesConversation* conversation,
                                                         DinoContentItem* content_item)
{
	DinoEntitiesMessage* message = NULL;
	DinoEntitiesMessage* _tmp0_;
	DinoEntitiesMessage* _tmp1_;
	DinoEntitiesMessage* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	g_return_val_if_fail (content_item != NULL, NULL);
	_tmp0_ = dino_content_item_store_get_message_for_content_item (self, conversation, content_item);
	message = _tmp0_;
	_tmp1_ = message;
	if (_tmp1_ == NULL) {
		result = NULL;
		_g_object_unref0 (message);
		return result;
	}
	_tmp2_ = message;
	_tmp3_ = dino_message_storage_get_reference_id (_tmp2_);
	result = _tmp3_;
	_g_object_unref0 (message);
	return result;
}

static gpointer
_xmpp_jid_ref0 (gpointer self)
{
	return self ? xmpp_jid_ref (self) : NULL;
}

XmppJid*
dino_content_item_store_get_message_sender_for_content_item (DinoContentItemStore* self,
                                                             DinoEntitiesConversation* conversation,
                                                             DinoContentItem* content_item)
{
	DinoEntitiesMessage* message = NULL;
	DinoEntitiesMessage* _tmp0_;
	DinoEntitiesMessage* _tmp1_;
	DinoEntitiesMessage* _tmp2_;
	XmppJid* _tmp3_;
	XmppJid* _tmp4_;
	XmppJid* _tmp5_;
	XmppJid* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	g_return_val_if_fail (content_item != NULL, NULL);
	_tmp0_ = dino_content_item_store_get_message_for_content_item (self, conversation, content_item);
	message = _tmp0_;
	_tmp1_ = message;
	if (_tmp1_ == NULL) {
		result = NULL;
		_g_object_unref0 (message);
		return result;
	}
	_tmp2_ = message;
	_tmp3_ = dino_entities_message_get_from (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _xmpp_jid_ref0 (_tmp4_);
	result = _tmp5_;
	_g_object_unref0 (message);
	return result;
}

DinoEntitiesMessage*
dino_content_item_store_get_message_for_content_item (DinoContentItemStore* self,
                                                      DinoEntitiesConversation* conversation,
                                                      DinoContentItem* content_item)
{
	DinoFileItem* file_item = NULL;
	DinoFileItem* _tmp0_;
	DinoFileItem* _tmp1_;
	DinoMessageItem* message_item = NULL;
	DinoMessageItem* _tmp21_;
	DinoMessageItem* _tmp22_;
	DinoEntitiesMessage* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	g_return_val_if_fail (content_item != NULL, NULL);
	_tmp0_ = _g_object_ref0 (DINO_IS_FILE_ITEM (content_item) ? ((DinoFileItem*) content_item) : NULL);
	file_item = _tmp0_;
	_tmp1_ = file_item;
	if (_tmp1_ != NULL) {
		gboolean _tmp2_ = FALSE;
		DinoFileItem* _tmp3_;
		DinoEntitiesFileTransfer* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		gint message_db_id = 0;
		DinoFileItem* _tmp11_;
		DinoEntitiesFileTransfer* _tmp12_;
		const gchar* _tmp13_;
		const gchar* _tmp14_;
		DinoStreamInteractor* _tmp15_;
		DinoModuleIdentity* _tmp16_;
		gpointer _tmp17_;
		DinoMessageStorage* _tmp18_;
		DinoEntitiesMessage* _tmp19_;
		DinoEntitiesMessage* _tmp20_;
		_tmp3_ = file_item;
		_tmp4_ = _tmp3_->file_transfer;
		_tmp5_ = dino_entities_file_transfer_get_provider (_tmp4_);
		_tmp6_ = _tmp5_;
		if (_tmp6_ != 0) {
			_tmp2_ = TRUE;
		} else {
			DinoFileItem* _tmp7_;
			DinoEntitiesFileTransfer* _tmp8_;
			const gchar* _tmp9_;
			const gchar* _tmp10_;
			_tmp7_ = file_item;
			_tmp8_ = _tmp7_->file_transfer;
			_tmp9_ = dino_entities_file_transfer_get_info (_tmp8_);
			_tmp10_ = _tmp9_;
			_tmp2_ = _tmp10_ == NULL;
		}
		if (_tmp2_) {
			result = NULL;
			_g_object_unref0 (file_item);
			return result;
		}
		_tmp11_ = file_item;
		_tmp12_ = _tmp11_->file_transfer;
		_tmp13_ = dino_entities_file_transfer_get_info (_tmp12_);
		_tmp14_ = _tmp13_;
		message_db_id = atoi (_tmp14_);
		_tmp15_ = self->priv->stream_interactor;
		_tmp16_ = dino_message_storage_IDENTITY;
		_tmp17_ = dino_stream_interactor_get_module (_tmp15_, DINO_TYPE_MESSAGE_STORAGE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp16_);
		_tmp18_ = (DinoMessageStorage*) _tmp17_;
		_tmp19_ = dino_message_storage_get_message_by_id (_tmp18_, message_db_id, conversation);
		_tmp20_ = _tmp19_;
		_g_object_unref0 (_tmp18_);
		result = _tmp20_;
		_g_object_unref0 (file_item);
		return result;
	}
	_tmp21_ = _g_object_ref0 (DINO_IS_MESSAGE_ITEM (content_item) ? ((DinoMessageItem*) content_item) : NULL);
	message_item = _tmp21_;
	_tmp22_ = message_item;
	if (_tmp22_ != NULL) {
		DinoMessageItem* _tmp23_;
		DinoEntitiesMessage* _tmp24_;
		DinoEntitiesMessage* _tmp25_;
		_tmp23_ = message_item;
		_tmp24_ = _tmp23_->message;
		_tmp25_ = _g_object_ref0 (_tmp24_);
		result = _tmp25_;
		_g_object_unref0 (message_item);
		_g_object_unref0 (file_item);
		return result;
	}
	result = NULL;
	_g_object_unref0 (message_item);
	_g_object_unref0 (file_item);
	return result;
}

DinoContentItem*
dino_content_item_store_get_content_item_for_message_id (DinoContentItemStore* self,
                                                         DinoEntitiesConversation* conversation,
                                                         const gchar* message_id)
{
	QliteRow* row = NULL;
	QliteRow* _tmp0_;
	QliteRow* _tmp1_;
	GError* _inner_error0_ = NULL;
	DinoContentItem* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	g_return_val_if_fail (message_id != NULL, NULL);
	_tmp0_ = dino_content_item_store_get_content_item_row_for_message_id (self, conversation, message_id);
	row = _tmp0_;
	_tmp1_ = row;
	if (_tmp1_ != NULL) {
		DinoContentItem* _tmp2_ = NULL;
		QliteRow* _tmp3_;
		DinoContentItem* _tmp4_;
		DinoContentItem* _tmp5_;
		_tmp3_ = row;
		_tmp4_ = dino_content_item_store_get_item_from_row (self, _tmp3_, conversation, &_inner_error0_);
		_tmp2_ = _tmp4_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_qlite_row_unref0 (row);
			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;
		}
		_tmp5_ = _tmp2_;
		_tmp2_ = NULL;
		result = _tmp5_;
		_g_object_unref0 (_tmp2_);
		_qlite_row_unref0 (row);
		return result;
	}
	result = NULL;
	_qlite_row_unref0 (row);
	return result;
}

gint
dino_content_item_store_get_content_item_id_for_message_id (DinoContentItemStore* self,
                                                            DinoEntitiesConversation* conversation,
                                                            const gchar* message_id)
{
	QliteRow* row = NULL;
	QliteRow* _tmp0_;
	QliteRow* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (conversation != NULL, -1);
	g_return_val_if_fail (message_id != NULL, -1);
	_tmp0_ = dino_content_item_store_get_content_item_row_for_message_id (self, conversation, message_id);
	row = _tmp0_;
	_tmp1_ = row;
	if (_tmp1_ != NULL) {
		QliteRow* _tmp2_;
		DinoDatabase* _tmp3_;
		DinoDatabaseContentItemTable* _tmp4_;
		DinoDatabaseContentItemTable* _tmp5_;
		QliteColumn* _tmp6_;
		gpointer _tmp7_;
		_tmp2_ = row;
		_tmp3_ = self->priv->db;
		_tmp4_ = dino_database_get_content_item (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp6_ = _tmp5_->id;
		_tmp7_ = qlite_row_get (_tmp2_, G_TYPE_INT, NULL, NULL, _tmp6_);
		result = (gint) ((gintptr) _tmp7_);
		_qlite_row_unref0 (row);
		return result;
	}
	result = -1;
	_qlite_row_unref0 (row);
	return result;
}

static gpointer
_qlite_row_ref0 (gpointer self)
{
	return self ? qlite_row_ref (self) : NULL;
}

static QliteRow*
dino_content_item_store_get_content_item_row_for_message_id (DinoContentItemStore* self,
                                                             DinoEntitiesConversation* conversation,
                                                             const gchar* message_id)
{
	QliteQueryBuilder* content_item_row = NULL;
	DinoDatabase* _tmp0_;
	DinoDatabaseContentItemTable* _tmp1_;
	DinoDatabaseContentItemTable* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	DinoEntitiesMessage* message = NULL;
	DinoEntitiesConversationType _tmp4_;
	DinoEntitiesConversationType _tmp5_;
	DinoEntitiesMessage* _tmp16_;
	QliteRowOption* file_transfer_row = NULL;
	DinoDatabase* _tmp17_;
	DinoDatabaseFileTransferTable* _tmp18_;
	DinoDatabaseFileTransferTable* _tmp19_;
	QliteQueryBuilder* _tmp20_;
	QliteQueryBuilder* _tmp21_;
	DinoDatabase* _tmp22_;
	DinoDatabaseFileTransferTable* _tmp23_;
	DinoDatabaseFileTransferTable* _tmp24_;
	QliteColumn* _tmp25_;
	DinoEntitiesAccount* _tmp26_;
	DinoEntitiesAccount* _tmp27_;
	gint _tmp28_;
	gint _tmp29_;
	QliteQueryBuilder* _tmp30_;
	QliteQueryBuilder* _tmp31_;
	DinoDatabase* _tmp32_;
	DinoDatabaseFileTransferTable* _tmp33_;
	DinoDatabaseFileTransferTable* _tmp34_;
	QliteColumn* _tmp35_;
	DinoDatabase* _tmp36_;
	XmppJid* _tmp37_;
	XmppJid* _tmp38_;
	QliteQueryBuilder* _tmp39_;
	QliteQueryBuilder* _tmp40_;
	DinoDatabase* _tmp41_;
	DinoDatabaseFileTransferTable* _tmp42_;
	DinoDatabaseFileTransferTable* _tmp43_;
	QliteColumn* _tmp44_;
	DinoEntitiesMessage* _tmp45_;
	gint _tmp46_;
	gint _tmp47_;
	gchar* _tmp48_;
	gchar* _tmp49_;
	QliteQueryBuilder* _tmp50_;
	QliteQueryBuilder* _tmp51_;
	DinoDatabase* _tmp52_;
	DinoDatabaseFileTransferTable* _tmp53_;
	DinoDatabaseFileTransferTable* _tmp54_;
	QliteColumn* _tmp55_;
	QliteQueryBuilder* _tmp56_;
	QliteQueryBuilder* _tmp57_;
	QliteQueryBuilder* _tmp58_;
	QliteQueryBuilder* _tmp59_;
	QliteRowOption* _tmp60_;
	QliteRowOption* _tmp61_;
	QliteRowOption* _tmp62_;
	QliteRowOption* content_item_row_option = NULL;
	QliteQueryBuilder* _tmp98_;
	QliteQueryBuilder* _tmp99_;
	QliteQueryBuilder* _tmp100_;
	QliteRowOption* _tmp101_;
	QliteRowOption* _tmp102_;
	QliteRowOption* _tmp103_;
	QliteRow* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	g_return_val_if_fail (message_id != NULL, NULL);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_database_get_content_item (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = qlite_table_select ((QliteTable*) _tmp2_, NULL, (gint) 0);
	content_item_row = _tmp3_;
	message = NULL;
	_tmp4_ = dino_entities_conversation_get_type_ (conversation);
	_tmp5_ = _tmp4_;
	if (_tmp5_ == DINO_ENTITIES_CONVERSATION_TYPE_CHAT) {
		DinoStreamInteractor* _tmp6_;
		DinoModuleIdentity* _tmp7_;
		gpointer _tmp8_;
		DinoMessageStorage* _tmp9_;
		DinoEntitiesMessage* _tmp10_;
		_tmp6_ = self->priv->stream_interactor;
		_tmp7_ = dino_message_storage_IDENTITY;
		_tmp8_ = dino_stream_interactor_get_module (_tmp6_, DINO_TYPE_MESSAGE_STORAGE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp7_);
		_tmp9_ = (DinoMessageStorage*) _tmp8_;
		_tmp10_ = dino_message_storage_get_message_by_stanza_id (_tmp9_, message_id, conversation);
		_g_object_unref0 (message);
		message = _tmp10_;
		_g_object_unref0 (_tmp9_);
	} else {
		DinoStreamInteractor* _tmp11_;
		DinoModuleIdentity* _tmp12_;
		gpointer _tmp13_;
		DinoMessageStorage* _tmp14_;
		DinoEntitiesMessage* _tmp15_;
		_tmp11_ = self->priv->stream_interactor;
		_tmp12_ = dino_message_storage_IDENTITY;
		_tmp13_ = dino_stream_interactor_get_module (_tmp11_, DINO_TYPE_MESSAGE_STORAGE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp12_);
		_tmp14_ = (DinoMessageStorage*) _tmp13_;
		_tmp15_ = dino_message_storage_get_message_by_server_id (_tmp14_, message_id, conversation);
		_g_object_unref0 (message);
		message = _tmp15_;
		_g_object_unref0 (_tmp14_);
	}
	_tmp16_ = message;
	if (_tmp16_ == NULL) {
		result = NULL;
		_g_object_unref0 (message);
		_qlite_statement_builder_unref0 (content_item_row);
		return result;
	}
	_tmp17_ = self->priv->db;
	_tmp18_ = dino_database_get_file_transfer (_tmp17_);
	_tmp19_ = _tmp18_;
	_tmp20_ = qlite_table_select ((QliteTable*) _tmp19_, NULL, (gint) 0);
	_tmp21_ = _tmp20_;
	_tmp22_ = self->priv->db;
	_tmp23_ = dino_database_get_file_transfer (_tmp22_);
	_tmp24_ = _tmp23_;
	_tmp25_ = _tmp24_->account_id;
	_tmp26_ = dino_entities_conversation_get_account (conversation);
	_tmp27_ = _tmp26_;
	_tmp28_ = dino_entities_account_get_id (_tmp27_);
	_tmp29_ = _tmp28_;
	_tmp30_ = qlite_query_builder_with (_tmp21_, G_TYPE_INT, NULL, NULL, _tmp25_, "=", (gpointer) ((gintptr) _tmp29_));
	_tmp31_ = _tmp30_;
	_tmp32_ = self->priv->db;
	_tmp33_ = dino_database_get_file_transfer (_tmp32_);
	_tmp34_ = _tmp33_;
	_tmp35_ = _tmp34_->counterpart_id;
	_tmp36_ = self->priv->db;
	_tmp37_ = dino_entities_conversation_get_counterpart (conversation);
	_tmp38_ = _tmp37_;
	_tmp39_ = qlite_query_builder_with (_tmp31_, G_TYPE_INT, NULL, NULL, _tmp35_, "=", (gpointer) ((gintptr) dino_database_get_jid_id (_tmp36_, _tmp38_)));
	_tmp40_ = _tmp39_;
	_tmp41_ = self->priv->db;
	_tmp42_ = dino_database_get_file_transfer (_tmp41_);
	_tmp43_ = _tmp42_;
	_tmp44_ = _tmp43_->info;
	_tmp45_ = message;
	_tmp46_ = dino_entities_message_get_id (_tmp45_);
	_tmp47_ = _tmp46_;
	_tmp48_ = g_strdup_printf ("%i", _tmp47_);
	_tmp49_ = _tmp48_;
	_tmp50_ = qlite_query_builder_with (_tmp40_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp44_, "=", _tmp49_);
	_tmp51_ = _tmp50_;
	_tmp52_ = self->priv->db;
	_tmp53_ = dino_database_get_file_transfer (_tmp52_);
	_tmp54_ = _tmp53_;
	_tmp55_ = _tmp54_->time;
	_tmp56_ = qlite_query_builder_order_by (_tmp51_, _tmp55_, "DESC");
	_tmp57_ = _tmp56_;
	_tmp58_ = qlite_query_builder_single (_tmp57_);
	_tmp59_ = _tmp58_;
	_tmp60_ = qlite_query_builder_row (_tmp59_);
	_tmp61_ = _tmp60_;
	_qlite_statement_builder_unref0 (_tmp59_);
	_qlite_statement_builder_unref0 (_tmp57_);
	_qlite_statement_builder_unref0 (_tmp51_);
	_g_free0 (_tmp49_);
	_qlite_statement_builder_unref0 (_tmp40_);
	_qlite_statement_builder_unref0 (_tmp31_);
	_qlite_statement_builder_unref0 (_tmp21_);
	file_transfer_row = _tmp61_;
	_tmp62_ = file_transfer_row;
	if (qlite_row_option_is_present (_tmp62_)) {
		QliteQueryBuilder* _tmp63_;
		DinoDatabase* _tmp64_;
		DinoDatabaseContentItemTable* _tmp65_;
		DinoDatabaseContentItemTable* _tmp66_;
		QliteColumn* _tmp67_;
		QliteRowOption* _tmp68_;
		DinoDatabase* _tmp69_;
		DinoDatabaseFileTransferTable* _tmp70_;
		DinoDatabaseFileTransferTable* _tmp71_;
		QliteColumn* _tmp72_;
		gpointer _tmp73_;
		QliteQueryBuilder* _tmp74_;
		QliteQueryBuilder* _tmp75_;
		DinoDatabase* _tmp76_;
		DinoDatabaseContentItemTable* _tmp77_;
		DinoDatabaseContentItemTable* _tmp78_;
		QliteColumn* _tmp79_;
		QliteQueryBuilder* _tmp80_;
		QliteQueryBuilder* _tmp81_;
		_tmp63_ = content_item_row;
		_tmp64_ = self->priv->db;
		_tmp65_ = dino_database_get_content_item (_tmp64_);
		_tmp66_ = _tmp65_;
		_tmp67_ = _tmp66_->foreign_id;
		_tmp68_ = file_transfer_row;
		_tmp69_ = self->priv->db;
		_tmp70_ = dino_database_get_file_transfer (_tmp69_);
		_tmp71_ = _tmp70_;
		_tmp72_ = _tmp71_->id;
		_tmp73_ = qlite_row_option_get (_tmp68_, G_TYPE_INT, NULL, NULL, _tmp72_, NULL);
		_tmp74_ = qlite_query_builder_with (_tmp63_, G_TYPE_INT, NULL, NULL, _tmp67_, "=", (gpointer) ((gintptr) _tmp73_));
		_tmp75_ = _tmp74_;
		_tmp76_ = self->priv->db;
		_tmp77_ = dino_database_get_content_item (_tmp76_);
		_tmp78_ = _tmp77_;
		_tmp79_ = _tmp78_->content_type;
		_tmp80_ = qlite_query_builder_with (_tmp75_, G_TYPE_INT, NULL, NULL, _tmp79_, "=", (gpointer) ((gintptr) 2));
		_tmp81_ = _tmp80_;
		_qlite_statement_builder_unref0 (_tmp81_);
		_qlite_statement_builder_unref0 (_tmp75_);
	} else {
		QliteQueryBuilder* _tmp82_;
		DinoDatabase* _tmp83_;
		DinoDatabaseContentItemTable* _tmp84_;
		DinoDatabaseContentItemTable* _tmp85_;
		QliteColumn* _tmp86_;
		DinoEntitiesMessage* _tmp87_;
		gint _tmp88_;
		gint _tmp89_;
		QliteQueryBuilder* _tmp90_;
		QliteQueryBuilder* _tmp91_;
		DinoDatabase* _tmp92_;
		DinoDatabaseContentItemTable* _tmp93_;
		DinoDatabaseContentItemTable* _tmp94_;
		QliteColumn* _tmp95_;
		QliteQueryBuilder* _tmp96_;
		QliteQueryBuilder* _tmp97_;
		_tmp82_ = content_item_row;
		_tmp83_ = self->priv->db;
		_tmp84_ = dino_database_get_content_item (_tmp83_);
		_tmp85_ = _tmp84_;
		_tmp86_ = _tmp85_->foreign_id;
		_tmp87_ = message;
		_tmp88_ = dino_entities_message_get_id (_tmp87_);
		_tmp89_ = _tmp88_;
		_tmp90_ = qlite_query_builder_with (_tmp82_, G_TYPE_INT, NULL, NULL, _tmp86_, "=", (gpointer) ((gintptr) _tmp89_));
		_tmp91_ = _tmp90_;
		_tmp92_ = self->priv->db;
		_tmp93_ = dino_database_get_content_item (_tmp92_);
		_tmp94_ = _tmp93_;
		_tmp95_ = _tmp94_->content_type;
		_tmp96_ = qlite_query_builder_with (_tmp91_, G_TYPE_INT, NULL, NULL, _tmp95_, "=", (gpointer) ((gintptr) 1));
		_tmp97_ = _tmp96_;
		_qlite_statement_builder_unref0 (_tmp97_);
		_qlite_statement_builder_unref0 (_tmp91_);
	}
	_tmp98_ = content_item_row;
	_tmp99_ = qlite_query_builder_single (_tmp98_);
	_tmp100_ = _tmp99_;
	_tmp101_ = qlite_query_builder_row (_tmp100_);
	_tmp102_ = _tmp101_;
	_qlite_statement_builder_unref0 (_tmp100_);
	content_item_row_option = _tmp102_;
	_tmp103_ = content_item_row_option;
	if (qlite_row_option_is_present (_tmp103_)) {
		QliteRowOption* _tmp104_;
		QliteRow* _tmp105_;
		QliteRow* _tmp106_;
		QliteRow* _tmp107_;
		_tmp104_ = content_item_row_option;
		_tmp105_ = qlite_row_option_get_inner (_tmp104_);
		_tmp106_ = _tmp105_;
		_tmp107_ = _qlite_row_ref0 (_tmp106_);
		result = _tmp107_;
		_qlite_row_option_unref0 (content_item_row_option);
		_qlite_row_option_unref0 (file_transfer_row);
		_g_object_unref0 (message);
		_qlite_statement_builder_unref0 (content_item_row);
		return result;
	}
	result = NULL;
	_qlite_row_option_unref0 (content_item_row_option);
	_qlite_row_option_unref0 (file_transfer_row);
	_g_object_unref0 (message);
	_qlite_statement_builder_unref0 (content_item_row);
	return result;
}

DinoContentItem*
dino_content_item_store_get_latest (DinoContentItemStore* self,
                                    DinoEntitiesConversation* conversation)
{
	GeeList* items = NULL;
	GeeList* _tmp0_;
	GeeList* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	DinoContentItem* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	_tmp0_ = dino_content_item_store_get_n_latest (self, conversation, 1);
	items = _tmp0_;
	_tmp1_ = items;
	_tmp2_ = gee_collection_get_size ((GeeCollection*) _tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_ > 0) {
		GeeList* _tmp4_;
		gpointer _tmp5_;
		_tmp4_ = items;
		_tmp5_ = gee_list_get (_tmp4_, 0);
		result = (DinoContentItem*) _tmp5_;
		_g_object_unref0 (items);
		return result;
	}
	result = NULL;
	_g_object_unref0 (items);
	return result;
}

GeeList*
dino_content_item_store_get_n_latest (DinoContentItemStore* self,
                                      DinoEntitiesConversation* conversation,
                                      gint count)
{
	QliteQueryBuilder* select = NULL;
	DinoDatabase* _tmp0_;
	DinoDatabaseContentItemTable* _tmp1_;
	DinoDatabaseContentItemTable* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	QliteQueryBuilder* _tmp4_;
	DinoDatabase* _tmp5_;
	DinoDatabaseContentItemTable* _tmp6_;
	DinoDatabaseContentItemTable* _tmp7_;
	QliteColumn* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	QliteQueryBuilder* _tmp11_;
	QliteQueryBuilder* _tmp12_;
	DinoDatabase* _tmp13_;
	DinoDatabaseContentItemTable* _tmp14_;
	DinoDatabaseContentItemTable* _tmp15_;
	QliteColumn* _tmp16_;
	QliteQueryBuilder* _tmp17_;
	QliteQueryBuilder* _tmp18_;
	DinoDatabase* _tmp19_;
	DinoDatabaseContentItemTable* _tmp20_;
	DinoDatabaseContentItemTable* _tmp21_;
	QliteColumn* _tmp22_;
	QliteQueryBuilder* _tmp23_;
	QliteQueryBuilder* _tmp24_;
	DinoDatabase* _tmp25_;
	DinoDatabaseContentItemTable* _tmp26_;
	DinoDatabaseContentItemTable* _tmp27_;
	QliteColumn* _tmp28_;
	QliteQueryBuilder* _tmp29_;
	QliteQueryBuilder* _tmp30_;
	QliteQueryBuilder* _tmp31_;
	QliteQueryBuilder* _tmp32_;
	GeeList* _tmp33_;
	GeeList* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_database_get_content_item (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = qlite_table_select ((QliteTable*) _tmp2_, NULL, (gint) 0);
	_tmp4_ = _tmp3_;
	_tmp5_ = self->priv->db;
	_tmp6_ = dino_database_get_content_item (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = _tmp7_->conversation_id;
	_tmp9_ = dino_entities_conversation_get_id (conversation);
	_tmp10_ = _tmp9_;
	_tmp11_ = qlite_query_builder_with (_tmp4_, G_TYPE_INT, NULL, NULL, _tmp8_, "=", (gpointer) ((gintptr) _tmp10_));
	_tmp12_ = _tmp11_;
	_tmp13_ = self->priv->db;
	_tmp14_ = dino_database_get_content_item (_tmp13_);
	_tmp15_ = _tmp14_;
	_tmp16_ = _tmp15_->hide;
	_tmp17_ = qlite_query_builder_with (_tmp12_, G_TYPE_BOOLEAN, NULL, NULL, _tmp16_, "=", (gpointer) ((gintptr) FALSE));
	_tmp18_ = _tmp17_;
	_tmp19_ = self->priv->db;
	_tmp20_ = dino_database_get_content_item (_tmp19_);
	_tmp21_ = _tmp20_;
	_tmp22_ = _tmp21_->time;
	_tmp23_ = qlite_query_builder_order_by (_tmp18_, _tmp22_, "DESC");
	_tmp24_ = _tmp23_;
	_tmp25_ = self->priv->db;
	_tmp26_ = dino_database_get_content_item (_tmp25_);
	_tmp27_ = _tmp26_;
	_tmp28_ = _tmp27_->id;
	_tmp29_ = qlite_query_builder_order_by (_tmp24_, _tmp28_, "DESC");
	_tmp30_ = _tmp29_;
	_tmp31_ = qlite_query_builder_limit (_tmp30_, count);
	_tmp32_ = _tmp31_;
	_qlite_statement_builder_unref0 (_tmp30_);
	_qlite_statement_builder_unref0 (_tmp24_);
	_qlite_statement_builder_unref0 (_tmp18_);
	_qlite_statement_builder_unref0 (_tmp12_);
	_qlite_statement_builder_unref0 (_tmp4_);
	select = _tmp32_;
	_tmp33_ = dino_content_item_store_get_items_from_query (self, select, conversation);
	result = _tmp33_;
	_qlite_statement_builder_unref0 (select);
	return result;
}

GeeList*
dino_content_item_store_get_before (DinoContentItemStore* self,
                                    DinoEntitiesConversation* conversation,
                                    DinoContentItem* item,
                                    gint count)
{
	glong time = 0L;
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	QliteQueryBuilder* select = NULL;
	DinoDatabase* _tmp2_;
	DinoDatabaseContentItemTable* _tmp3_;
	DinoDatabaseContentItemTable* _tmp4_;
	QliteQueryBuilder* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	gchar* _tmp11_;
	gchar** _tmp12_;
	gchar** _tmp13_;
	gint _tmp13__length1;
	QliteQueryBuilder* _tmp14_;
	QliteQueryBuilder* _tmp15_;
	DinoDatabase* _tmp16_;
	DinoDatabaseContentItemTable* _tmp17_;
	DinoDatabaseContentItemTable* _tmp18_;
	QliteColumn* _tmp19_;
	gint _tmp20_;
	gint _tmp21_;
	QliteQueryBuilder* _tmp22_;
	QliteQueryBuilder* _tmp23_;
	DinoDatabase* _tmp24_;
	DinoDatabaseContentItemTable* _tmp25_;
	DinoDatabaseContentItemTable* _tmp26_;
	QliteColumn* _tmp27_;
	QliteQueryBuilder* _tmp28_;
	QliteQueryBuilder* _tmp29_;
	DinoDatabase* _tmp30_;
	DinoDatabaseContentItemTable* _tmp31_;
	DinoDatabaseContentItemTable* _tmp32_;
	QliteColumn* _tmp33_;
	QliteQueryBuilder* _tmp34_;
	QliteQueryBuilder* _tmp35_;
	DinoDatabase* _tmp36_;
	DinoDatabaseContentItemTable* _tmp37_;
	DinoDatabaseContentItemTable* _tmp38_;
	QliteColumn* _tmp39_;
	QliteQueryBuilder* _tmp40_;
	QliteQueryBuilder* _tmp41_;
	QliteQueryBuilder* _tmp42_;
	QliteQueryBuilder* _tmp43_;
	GeeList* _tmp44_;
	GeeList* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	g_return_val_if_fail (item != NULL, NULL);
	_tmp0_ = dino_content_item_get_time (item);
	_tmp1_ = _tmp0_;
	time = (glong) g_date_time_to_unix (_tmp1_);
	_tmp2_ = self->priv->db;
	_tmp3_ = dino_database_get_content_item (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = qlite_table_select ((QliteTable*) _tmp4_, NULL, (gint) 0);
	_tmp6_ = _tmp5_;
	_tmp7_ = g_strdup_printf ("%li", time);
	_tmp8_ = g_strdup_printf ("%li", time);
	_tmp9_ = dino_content_item_get_id (item);
	_tmp10_ = _tmp9_;
	_tmp11_ = g_strdup_printf ("%i", _tmp10_);
	_tmp12_ = g_new0 (gchar*, 3 + 1);
	_tmp12_[0] = _tmp7_;
	_tmp12_[1] = _tmp8_;
	_tmp12_[2] = _tmp11_;
	_tmp13_ = _tmp12_;
	_tmp13__length1 = 3;
	_tmp14_ = qlite_query_builder_where (_tmp6_, "time < ? OR (time = ? AND id < ?)", _tmp13_, (gint) 3);
	_tmp15_ = _tmp14_;
	_tmp16_ = self->priv->db;
	_tmp17_ = dino_database_get_content_item (_tmp16_);
	_tmp18_ = _tmp17_;
	_tmp19_ = _tmp18_->conversation_id;
	_tmp20_ = dino_entities_conversation_get_id (conversation);
	_tmp21_ = _tmp20_;
	_tmp22_ = qlite_query_builder_with (_tmp15_, G_TYPE_INT, NULL, NULL, _tmp19_, "=", (gpointer) ((gintptr) _tmp21_));
	_tmp23_ = _tmp22_;
	_tmp24_ = self->priv->db;
	_tmp25_ = dino_database_get_content_item (_tmp24_);
	_tmp26_ = _tmp25_;
	_tmp27_ = _tmp26_->hide;
	_tmp28_ = qlite_query_builder_with (_tmp23_, G_TYPE_BOOLEAN, NULL, NULL, _tmp27_, "=", (gpointer) ((gintptr) FALSE));
	_tmp29_ = _tmp28_;
	_tmp30_ = self->priv->db;
	_tmp31_ = dino_database_get_content_item (_tmp30_);
	_tmp32_ = _tmp31_;
	_tmp33_ = _tmp32_->time;
	_tmp34_ = qlite_query_builder_order_by (_tmp29_, _tmp33_, "DESC");
	_tmp35_ = _tmp34_;
	_tmp36_ = self->priv->db;
	_tmp37_ = dino_database_get_content_item (_tmp36_);
	_tmp38_ = _tmp37_;
	_tmp39_ = _tmp38_->id;
	_tmp40_ = qlite_query_builder_order_by (_tmp35_, _tmp39_, "DESC");
	_tmp41_ = _tmp40_;
	_tmp42_ = qlite_query_builder_limit (_tmp41_, count);
	_tmp43_ = _tmp42_;
	_qlite_statement_builder_unref0 (_tmp41_);
	_qlite_statement_builder_unref0 (_tmp35_);
	_qlite_statement_builder_unref0 (_tmp29_);
	_qlite_statement_builder_unref0 (_tmp23_);
	_qlite_statement_builder_unref0 (_tmp15_);
	_tmp13_ = (_vala_array_free (_tmp13_, _tmp13__length1, (GDestroyNotify) g_free), NULL);
	_qlite_statement_builder_unref0 (_tmp6_);
	select = _tmp43_;
	_tmp44_ = dino_content_item_store_get_items_from_query (self, select, conversation);
	result = _tmp44_;
	_qlite_statement_builder_unref0 (select);
	return result;
}

GeeList*
dino_content_item_store_get_after (DinoContentItemStore* self,
                                   DinoEntitiesConversation* conversation,
                                   DinoContentItem* item,
                                   gint count)
{
	glong time = 0L;
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	QliteQueryBuilder* select = NULL;
	DinoDatabase* _tmp2_;
	DinoDatabaseContentItemTable* _tmp3_;
	DinoDatabaseContentItemTable* _tmp4_;
	QliteQueryBuilder* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	gchar* _tmp11_;
	gchar** _tmp12_;
	gchar** _tmp13_;
	gint _tmp13__length1;
	QliteQueryBuilder* _tmp14_;
	QliteQueryBuilder* _tmp15_;
	DinoDatabase* _tmp16_;
	DinoDatabaseContentItemTable* _tmp17_;
	DinoDatabaseContentItemTable* _tmp18_;
	QliteColumn* _tmp19_;
	gint _tmp20_;
	gint _tmp21_;
	QliteQueryBuilder* _tmp22_;
	QliteQueryBuilder* _tmp23_;
	DinoDatabase* _tmp24_;
	DinoDatabaseContentItemTable* _tmp25_;
	DinoDatabaseContentItemTable* _tmp26_;
	QliteColumn* _tmp27_;
	QliteQueryBuilder* _tmp28_;
	QliteQueryBuilder* _tmp29_;
	DinoDatabase* _tmp30_;
	DinoDatabaseContentItemTable* _tmp31_;
	DinoDatabaseContentItemTable* _tmp32_;
	QliteColumn* _tmp33_;
	QliteQueryBuilder* _tmp34_;
	QliteQueryBuilder* _tmp35_;
	DinoDatabase* _tmp36_;
	DinoDatabaseContentItemTable* _tmp37_;
	DinoDatabaseContentItemTable* _tmp38_;
	QliteColumn* _tmp39_;
	QliteQueryBuilder* _tmp40_;
	QliteQueryBuilder* _tmp41_;
	QliteQueryBuilder* _tmp42_;
	QliteQueryBuilder* _tmp43_;
	GeeList* _tmp44_;
	GeeList* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	g_return_val_if_fail (item != NULL, NULL);
	_tmp0_ = dino_content_item_get_time (item);
	_tmp1_ = _tmp0_;
	time = (glong) g_date_time_to_unix (_tmp1_);
	_tmp2_ = self->priv->db;
	_tmp3_ = dino_database_get_content_item (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = qlite_table_select ((QliteTable*) _tmp4_, NULL, (gint) 0);
	_tmp6_ = _tmp5_;
	_tmp7_ = g_strdup_printf ("%li", time);
	_tmp8_ = g_strdup_printf ("%li", time);
	_tmp9_ = dino_content_item_get_id (item);
	_tmp10_ = _tmp9_;
	_tmp11_ = g_strdup_printf ("%i", _tmp10_);
	_tmp12_ = g_new0 (gchar*, 3 + 1);
	_tmp12_[0] = _tmp7_;
	_tmp12_[1] = _tmp8_;
	_tmp12_[2] = _tmp11_;
	_tmp13_ = _tmp12_;
	_tmp13__length1 = 3;
	_tmp14_ = qlite_query_builder_where (_tmp6_, "time > ? OR (time = ? AND id > ?)", _tmp13_, (gint) 3);
	_tmp15_ = _tmp14_;
	_tmp16_ = self->priv->db;
	_tmp17_ = dino_database_get_content_item (_tmp16_);
	_tmp18_ = _tmp17_;
	_tmp19_ = _tmp18_->conversation_id;
	_tmp20_ = dino_entities_conversation_get_id (conversation);
	_tmp21_ = _tmp20_;
	_tmp22_ = qlite_query_builder_with (_tmp15_, G_TYPE_INT, NULL, NULL, _tmp19_, "=", (gpointer) ((gintptr) _tmp21_));
	_tmp23_ = _tmp22_;
	_tmp24_ = self->priv->db;
	_tmp25_ = dino_database_get_content_item (_tmp24_);
	_tmp26_ = _tmp25_;
	_tmp27_ = _tmp26_->hide;
	_tmp28_ = qlite_query_builder_with (_tmp23_, G_TYPE_BOOLEAN, NULL, NULL, _tmp27_, "=", (gpointer) ((gintptr) FALSE));
	_tmp29_ = _tmp28_;
	_tmp30_ = self->priv->db;
	_tmp31_ = dino_database_get_content_item (_tmp30_);
	_tmp32_ = _tmp31_;
	_tmp33_ = _tmp32_->time;
	_tmp34_ = qlite_query_builder_order_by (_tmp29_, _tmp33_, "ASC");
	_tmp35_ = _tmp34_;
	_tmp36_ = self->priv->db;
	_tmp37_ = dino_database_get_content_item (_tmp36_);
	_tmp38_ = _tmp37_;
	_tmp39_ = _tmp38_->id;
	_tmp40_ = qlite_query_builder_order_by (_tmp35_, _tmp39_, "ASC");
	_tmp41_ = _tmp40_;
	_tmp42_ = qlite_query_builder_limit (_tmp41_, count);
	_tmp43_ = _tmp42_;
	_qlite_statement_builder_unref0 (_tmp41_);
	_qlite_statement_builder_unref0 (_tmp35_);
	_qlite_statement_builder_unref0 (_tmp29_);
	_qlite_statement_builder_unref0 (_tmp23_);
	_qlite_statement_builder_unref0 (_tmp15_);
	_tmp13_ = (_vala_array_free (_tmp13_, _tmp13__length1, (GDestroyNotify) g_free), NULL);
	_qlite_statement_builder_unref0 (_tmp6_);
	select = _tmp43_;
	_tmp44_ = dino_content_item_store_get_items_from_query (self, select, conversation);
	result = _tmp44_;
	_qlite_statement_builder_unref0 (select);
	return result;
}

void
dino_content_item_store_insert_message (DinoContentItemStore* self,
                                        DinoEntitiesMessage* message,
                                        DinoEntitiesConversation* conversation,
                                        gboolean hide)
{
	DinoMessageItem* item = NULL;
	DinoMessageItem* _tmp0_;
	DinoDatabase* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	GDateTime* _tmp4_;
	GDateTime* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (message != NULL);
	g_return_if_fail (conversation != NULL);
	_tmp0_ = dino_message_item_new (message, conversation, -1);
	item = _tmp0_;
	_tmp1_ = self->priv->db;
	_tmp2_ = dino_entities_message_get_time (message);
	_tmp3_ = _tmp2_;
	_tmp4_ = dino_entities_message_get_local_time (message);
	_tmp5_ = _tmp4_;
	_tmp6_ = dino_entities_message_get_id (message);
	_tmp7_ = _tmp6_;
	dino_content_item_set_id ((DinoContentItem*) item, dino_database_add_content_item (_tmp1_, conversation, _tmp3_, _tmp5_, 1, _tmp7_, hide));
	_g_object_unref0 (item);
}

static void
dino_content_item_store_announce_message (DinoContentItemStore* self,
                                          DinoEntitiesMessage* message,
                                          DinoEntitiesConversation* conversation)
{
	QliteQueryBuilder* select = NULL;
	DinoDatabase* _tmp0_;
	DinoDatabaseContentItemTable* _tmp1_;
	DinoDatabaseContentItemTable* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	DinoDatabase* _tmp4_;
	DinoDatabaseContentItemTable* _tmp5_;
	DinoDatabaseContentItemTable* _tmp6_;
	QliteColumn* _tmp7_;
	gint _tmp8_;
	gint _tmp9_;
	QliteQueryBuilder* _tmp10_;
	QliteQueryBuilder* _tmp11_;
	DinoDatabase* _tmp12_;
	DinoDatabaseContentItemTable* _tmp13_;
	DinoDatabaseContentItemTable* _tmp14_;
	QliteColumn* _tmp15_;
	QliteQueryBuilder* _tmp16_;
	QliteQueryBuilder* _tmp17_;
	DinoDatabase* _tmp18_;
	DinoDatabaseContentItemTable* _tmp19_;
	DinoDatabaseContentItemTable* _tmp20_;
	QliteColumn* _tmp21_;
	QliteQueryBuilder* _tmp22_;
	QliteQueryBuilder* _tmp23_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (message != NULL);
	g_return_if_fail (conversation != NULL);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_database_get_content_item (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = qlite_table_select ((QliteTable*) _tmp2_, NULL, (gint) 0);
	select = _tmp3_;
	_tmp4_ = self->priv->db;
	_tmp5_ = dino_database_get_content_item (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = _tmp6_->foreign_id;
	_tmp8_ = dino_entities_message_get_id (message);
	_tmp9_ = _tmp8_;
	_tmp10_ = qlite_query_builder_with (select, G_TYPE_INT, NULL, NULL, _tmp7_, "=", (gpointer) ((gintptr) _tmp9_));
	_tmp11_ = _tmp10_;
	_qlite_statement_builder_unref0 (_tmp11_);
	_tmp12_ = self->priv->db;
	_tmp13_ = dino_database_get_content_item (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = _tmp14_->content_type;
	_tmp16_ = qlite_query_builder_with (select, G_TYPE_INT, NULL, NULL, _tmp15_, "=", (gpointer) ((gintptr) 1));
	_tmp17_ = _tmp16_;
	_qlite_statement_builder_unref0 (_tmp17_);
	_tmp18_ = self->priv->db;
	_tmp19_ = dino_database_get_content_item (_tmp18_);
	_tmp20_ = _tmp19_;
	_tmp21_ = _tmp20_->hide;
	_tmp22_ = qlite_query_builder_with (select, G_TYPE_BOOLEAN, NULL, NULL, _tmp21_, "=", (gpointer) ((gintptr) FALSE));
	_tmp23_ = _tmp22_;
	_qlite_statement_builder_unref0 (_tmp23_);
	{
		QliteRowIterator* _row_it = NULL;
		QliteRowIterator* _tmp24_;
		_tmp24_ = qlite_query_builder_iterator (select);
		_row_it = _tmp24_;
		while (TRUE) {
			QliteRow* row = NULL;
			QliteRow* _tmp25_;
			DinoMessageItem* item = NULL;
			QliteRow* _tmp26_;
			DinoDatabase* _tmp27_;
			DinoDatabaseContentItemTable* _tmp28_;
			DinoDatabaseContentItemTable* _tmp29_;
			QliteColumn* _tmp30_;
			gpointer _tmp31_;
			DinoMessageItem* _tmp32_;
			GeeHashMap* _tmp33_;
			DinoMessageItem* _tmp38_;
			if (!qlite_row_iterator_next (_row_it)) {
				break;
			}
			_tmp25_ = qlite_row_iterator_get (_row_it);
			row = _tmp25_;
			_tmp26_ = row;
			_tmp27_ = self->priv->db;
			_tmp28_ = dino_database_get_content_item (_tmp27_);
			_tmp29_ = _tmp28_;
			_tmp30_ = _tmp29_->id;
			_tmp31_ = qlite_row_get (_tmp26_, G_TYPE_INT, NULL, NULL, _tmp30_);
			_tmp32_ = dino_message_item_new (message, conversation, (gint) ((gintptr) _tmp31_));
			item = _tmp32_;
			_tmp33_ = self->priv->collection_conversations;
			if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp33_, conversation)) {
				GeeHashMap* _tmp34_;
				gpointer _tmp35_;
				DinoContentItemCollection* _tmp36_;
				DinoMessageItem* _tmp37_;
				_tmp34_ = self->priv->collection_conversations;
				_tmp35_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp34_, conversation);
				_tmp36_ = (DinoContentItemCollection*) _tmp35_;
				_tmp37_ = item;
				dino_content_item_collection_insert_item (_tmp36_, (DinoContentItem*) _tmp37_);
				_g_object_unref0 (_tmp36_);
			}
			_tmp38_ = item;
			g_signal_emit (self, dino_content_item_store_signals[DINO_CONTENT_ITEM_STORE_NEW_ITEM_SIGNAL], 0, (DinoContentItem*) _tmp38_, conversation);
			_g_object_unref0 (item);
			_qlite_row_unref0 (row);
			break;
		}
		_qlite_row_iterator_unref0 (_row_it);
	}
	_qlite_statement_builder_unref0 (select);
}

static void
dino_content_item_store_insert_file_transfer (DinoContentItemStore* self,
                                              DinoEntitiesFileTransfer* file_transfer,
                                              DinoEntitiesConversation* conversation)
{
	DinoFileItem* item = NULL;
	DinoFileItem* _tmp0_;
	DinoFileItem* _tmp1_;
	DinoDatabase* _tmp2_;
	GDateTime* _tmp3_;
	GDateTime* _tmp4_;
	GDateTime* _tmp5_;
	GDateTime* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	GeeHashMap* _tmp9_;
	DinoFileItem* _tmp14_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (file_transfer != NULL);
	g_return_if_fail (conversation != NULL);
	_tmp0_ = dino_file_item_new (file_transfer, conversation, -1, NULL);
	item = _tmp0_;
	_tmp1_ = item;
	_tmp2_ = self->priv->db;
	_tmp3_ = dino_entities_file_transfer_get_time (file_transfer);
	_tmp4_ = _tmp3_;
	_tmp5_ = dino_entities_file_transfer_get_local_time (file_transfer);
	_tmp6_ = _tmp5_;
	_tmp7_ = dino_entities_file_transfer_get_id (file_transfer);
	_tmp8_ = _tmp7_;
	dino_content_item_set_id ((DinoContentItem*) _tmp1_, dino_database_add_content_item (_tmp2_, conversation, _tmp4_, _tmp6_, 2, _tmp8_, FALSE));
	_tmp9_ = self->priv->collection_conversations;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp9_, conversation)) {
		GeeHashMap* _tmp10_;
		gpointer _tmp11_;
		DinoContentItemCollection* _tmp12_;
		DinoFileItem* _tmp13_;
		_tmp10_ = self->priv->collection_conversations;
		_tmp11_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp10_, conversation);
		_tmp12_ = (DinoContentItemCollection*) _tmp11_;
		_tmp13_ = item;
		dino_content_item_collection_insert_item (_tmp12_, (DinoContentItem*) _tmp13_);
		_g_object_unref0 (_tmp12_);
	}
	_tmp14_ = item;
	g_signal_emit (self, dino_content_item_store_signals[DINO_CONTENT_ITEM_STORE_NEW_ITEM_SIGNAL], 0, (DinoContentItem*) _tmp14_, conversation);
	_g_object_unref0 (item);
}

static void
dino_content_item_store_insert_call (DinoContentItemStore* self,
                                     DinoEntitiesCall* call,
                                     DinoCallState* call_state,
                                     DinoEntitiesConversation* conversation)
{
	DinoCallItem* item = NULL;
	DinoCallItem* _tmp0_;
	DinoCallItem* _tmp1_;
	DinoDatabase* _tmp2_;
	GDateTime* _tmp3_;
	GDateTime* _tmp4_;
	GDateTime* _tmp5_;
	GDateTime* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	GeeHashMap* _tmp9_;
	DinoCallItem* _tmp14_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (call != NULL);
	g_return_if_fail (call_state != NULL);
	g_return_if_fail (conversation != NULL);
	_tmp0_ = dino_call_item_new (call, conversation, -1);
	item = _tmp0_;
	_tmp1_ = item;
	_tmp2_ = self->priv->db;
	_tmp3_ = dino_entities_call_get_time (call);
	_tmp4_ = _tmp3_;
	_tmp5_ = dino_entities_call_get_local_time (call);
	_tmp6_ = _tmp5_;
	_tmp7_ = dino_entities_call_get_id (call);
	_tmp8_ = _tmp7_;
	dino_content_item_set_id ((DinoContentItem*) _tmp1_, dino_database_add_content_item (_tmp2_, conversation, _tmp4_, _tmp6_, 3, _tmp8_, FALSE));
	_tmp9_ = self->priv->collection_conversations;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp9_, conversation)) {
		GeeHashMap* _tmp10_;
		gpointer _tmp11_;
		DinoContentItemCollection* _tmp12_;
		DinoCallItem* _tmp13_;
		_tmp10_ = self->priv->collection_conversations;
		_tmp11_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp10_, conversation);
		_tmp12_ = (DinoContentItemCollection*) _tmp11_;
		_tmp13_ = item;
		dino_content_item_collection_insert_item (_tmp12_, (DinoContentItem*) _tmp13_);
		_g_object_unref0 (_tmp12_);
	}
	_tmp14_ = item;
	g_signal_emit (self, dino_content_item_store_signals[DINO_CONTENT_ITEM_STORE_NEW_ITEM_SIGNAL], 0, (DinoContentItem*) _tmp14_, conversation);
	_g_object_unref0 (item);
}

gboolean
dino_content_item_store_get_item_hide (DinoContentItemStore* self,
                                       DinoContentItem* content_item)
{
	DinoDatabase* _tmp0_;
	DinoDatabaseContentItemTable* _tmp1_;
	DinoDatabaseContentItemTable* _tmp2_;
	DinoDatabase* _tmp3_;
	DinoDatabaseContentItemTable* _tmp4_;
	DinoDatabaseContentItemTable* _tmp5_;
	QliteColumn* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	QliteRowOption* _tmp9_;
	QliteRowOption* _tmp10_;
	DinoDatabase* _tmp11_;
	DinoDatabaseContentItemTable* _tmp12_;
	DinoDatabaseContentItemTable* _tmp13_;
	QliteColumn* _tmp14_;
	gpointer _tmp15_;
	gboolean _tmp16_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (content_item != NULL, FALSE);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_database_get_content_item (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->priv->db;
	_tmp4_ = dino_database_get_content_item (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = _tmp5_->id;
	_tmp7_ = dino_content_item_get_id (content_item);
	_tmp8_ = _tmp7_;
	_tmp9_ = qlite_table_row_with ((QliteTable*) _tmp2_, G_TYPE_INT, NULL, NULL, _tmp6_, (gpointer) ((gintptr) _tmp8_));
	_tmp10_ = _tmp9_;
	_tmp11_ = self->priv->db;
	_tmp12_ = dino_database_get_content_item (_tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = _tmp13_->hide;
	_tmp15_ = qlite_row_option_get (_tmp10_, G_TYPE_BOOLEAN, NULL, NULL, _tmp14_, (gpointer) ((gintptr) FALSE));
	_tmp16_ = (gboolean) ((gintptr) _tmp15_);
	_qlite_row_option_unref0 (_tmp10_);
	result = _tmp16_;
	return result;
}

void
dino_content_item_store_set_item_hide (DinoContentItemStore* self,
                                       DinoContentItem* content_item,
                                       gboolean hide)
{
	DinoDatabase* _tmp0_;
	DinoDatabaseContentItemTable* _tmp1_;
	DinoDatabaseContentItemTable* _tmp2_;
	QliteUpdateBuilder* _tmp3_;
	QliteUpdateBuilder* _tmp4_;
	DinoDatabase* _tmp5_;
	DinoDatabaseContentItemTable* _tmp6_;
	DinoDatabaseContentItemTable* _tmp7_;
	QliteColumn* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	QliteUpdateBuilder* _tmp11_;
	QliteUpdateBuilder* _tmp12_;
	DinoDatabase* _tmp13_;
	DinoDatabaseContentItemTable* _tmp14_;
	DinoDatabaseContentItemTable* _tmp15_;
	QliteColumn* _tmp16_;
	QliteUpdateBuilder* _tmp17_;
	QliteUpdateBuilder* _tmp18_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (content_item != NULL);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_database_get_content_item (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = qlite_table_update ((QliteTable*) _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = self->priv->db;
	_tmp6_ = dino_database_get_content_item (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = _tmp7_->id;
	_tmp9_ = dino_content_item_get_id (content_item);
	_tmp10_ = _tmp9_;
	_tmp11_ = qlite_update_builder_with (_tmp4_, G_TYPE_INT, NULL, NULL, _tmp8_, "=", (gpointer) ((gintptr) _tmp10_));
	_tmp12_ = _tmp11_;
	_tmp13_ = self->priv->db;
	_tmp14_ = dino_database_get_content_item (_tmp13_);
	_tmp15_ = _tmp14_;
	_tmp16_ = _tmp15_->hide;
	_tmp17_ = qlite_update_builder_set (_tmp12_, G_TYPE_BOOLEAN, NULL, NULL, _tmp16_, (gpointer) ((gintptr) hide));
	_tmp18_ = _tmp17_;
	qlite_update_builder_perform (_tmp18_);
	_qlite_statement_builder_unref0 (_tmp18_);
	_qlite_statement_builder_unref0 (_tmp12_);
	_qlite_statement_builder_unref0 (_tmp4_);
}

static const gchar*
dino_content_item_store_real_get_id (DinoStreamInteractionModule* base)
{
	const gchar* result;
	DinoContentItemStore* self;
	DinoModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	self = (DinoContentItemStore*) base;
	_tmp0_ = dino_content_item_store_IDENTITY;
	_tmp1_ = dino_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

static void
g_cclosure_user_marshal_VOID__OBJECT_OBJECT (GClosure * closure,
                                             GValue * return_value,
                                             guint n_param_values,
                                             const GValue * param_values,
                                             gpointer invocation_hint,
                                             gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__OBJECT_OBJECT) (gpointer data1, gpointer arg_1, gpointer arg_2, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_OBJECT 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_OBJECT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), g_value_get_object (param_values + 2), data2);
}

static void
dino_content_item_store_class_init (DinoContentItemStoreClass * klass,
                                    gpointer klass_data)
{
	DinoModuleIdentity* _tmp0_;
	dino_content_item_store_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoContentItemStore_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_content_item_store_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_content_item_store_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_CONTENT_ITEM_STORE_ID_PROPERTY, dino_content_item_store_properties[DINO_CONTENT_ITEM_STORE_ID_PROPERTY] = g_param_spec_string ("id", "id", "id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	dino_content_item_store_signals[DINO_CONTENT_ITEM_STORE_NEW_ITEM_SIGNAL] = g_signal_new ("new-item", DINO_TYPE_CONTENT_ITEM_STORE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2, DINO_TYPE_CONTENT_ITEM, DINO_ENTITIES_TYPE_CONVERSATION);
	_tmp0_ = dino_module_identity_new (DINO_TYPE_CONTENT_ITEM_STORE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, "content_item_store");
	dino_content_item_store_IDENTITY = _tmp0_;
}

static void
dino_content_item_store_dino_stream_interaction_module_interface_init (DinoStreamInteractionModuleIface * iface,
                                                                       gpointer iface_data)
{
	dino_content_item_store_dino_stream_interaction_module_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_id = dino_content_item_store_real_get_id;
}

static void
dino_content_item_store_instance_init (DinoContentItemStore * self,
                                       gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = dino_content_item_store_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (DINO_ENTITIES_TYPE_CONVERSATION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, DINO_TYPE_CONTENT_ITEM_COLLECTION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _dino_entities_conversation_hash_func_gee_hash_data_func, NULL, NULL, _dino_entities_conversation_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->priv->collection_conversations = _tmp0_;
}

static void
dino_content_item_store_finalize (GObject * obj)
{
	DinoContentItemStore * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_CONTENT_ITEM_STORE, DinoContentItemStore);
	_g_object_unref0 (self->priv->stream_interactor);
	_qlite_database_unref0 (self->priv->db);
	_g_object_unref0 (self->priv->collection_conversations);
	G_OBJECT_CLASS (dino_content_item_store_parent_class)->finalize (obj);
}

static GType
dino_content_item_store_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoContentItemStoreClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_content_item_store_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoContentItemStore), 0, (GInstanceInitFunc) dino_content_item_store_instance_init, NULL };
	static const GInterfaceInfo dino_stream_interaction_module_info = { (GInterfaceInitFunc) dino_content_item_store_dino_stream_interaction_module_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_content_item_store_type_id;
	dino_content_item_store_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoContentItemStore", &g_define_type_info, 0);
	g_type_add_interface_static (dino_content_item_store_type_id, DINO_TYPE_STREAM_INTERACTION_MODULE, &dino_stream_interaction_module_info);
	DinoContentItemStore_private_offset = g_type_add_instance_private (dino_content_item_store_type_id, sizeof (DinoContentItemStorePrivate));
	return dino_content_item_store_type_id;
}

GType
dino_content_item_store_get_type (void)
{
	static volatile gsize dino_content_item_store_type_id__once = 0;
	if (g_once_init_enter (&dino_content_item_store_type_id__once)) {
		GType dino_content_item_store_type_id;
		dino_content_item_store_type_id = dino_content_item_store_get_type_once ();
		g_once_init_leave (&dino_content_item_store_type_id__once, dino_content_item_store_type_id);
	}
	return dino_content_item_store_type_id__once;
}

static void
_vala_dino_content_item_store_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec)
{
	DinoContentItemStore * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_TYPE_CONTENT_ITEM_STORE, DinoContentItemStore);
	switch (property_id) {
		case DINO_CONTENT_ITEM_STORE_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;
	}
}

void
dino_content_item_collection_insert_item (DinoContentItemCollection* self,
                                          DinoContentItem* item)
{
	DinoContentItemCollectionIface* _iface_;
	g_return_if_fail (self != NULL);
	_iface_ = DINO_CONTENT_ITEM_COLLECTION_GET_INTERFACE (self);
	if (_iface_->insert_item) {
		_iface_->insert_item (self, item);
	}
}

void
dino_content_item_collection_remove_item (DinoContentItemCollection* self,
                                          DinoContentItem* item)
{
	DinoContentItemCollectionIface* _iface_;
	g_return_if_fail (self != NULL);
	_iface_ = DINO_CONTENT_ITEM_COLLECTION_GET_INTERFACE (self);
	if (_iface_->remove_item) {
		_iface_->remove_item (self, item);
	}
}

static void
dino_content_item_collection_default_init (DinoContentItemCollectionIface * iface,
                                           gpointer iface_data)
{
}

static GType
dino_content_item_collection_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoContentItemCollectionIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_content_item_collection_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType dino_content_item_collection_type_id;
	dino_content_item_collection_type_id = g_type_register_static (G_TYPE_INTERFACE, "DinoContentItemCollection", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (dino_content_item_collection_type_id, G_TYPE_OBJECT);
	return dino_content_item_collection_type_id;
}

GType
dino_content_item_collection_get_type (void)
{
	static volatile gsize dino_content_item_collection_type_id__once = 0;
	if (g_once_init_enter (&dino_content_item_collection_type_id__once)) {
		GType dino_content_item_collection_type_id;
		dino_content_item_collection_type_id = dino_content_item_collection_get_type_once ();
		g_once_init_leave (&dino_content_item_collection_type_id__once, dino_content_item_collection_type_id);
	}
	return dino_content_item_collection_type_id__once;
}

static inline gpointer
dino_content_item_get_instance_private (DinoContentItem* self)
{
	return G_STRUCT_MEMBER_P (self, DinoContentItem_private_offset);
}

static DinoContentItem*
dino_content_item_construct (GType object_type,
                             gint id,
                             const gchar* ty,
                             XmppJid* jid,
                             GDateTime* time,
                             DinoEntitiesEncryption encryption,
                             DinoEntitiesMessageMarked mark)
{
	DinoContentItem * self = NULL;
	g_return_val_if_fail (ty != NULL, NULL);
	g_return_val_if_fail (jid != NULL, NULL);
	g_return_val_if_fail (time != NULL, NULL);
	self = (DinoContentItem*) g_object_new (object_type, NULL);
	dino_content_item_set_id (self, id);
	dino_content_item_set_type_ (self, ty);
	dino_content_item_set_jid (self, jid);
	dino_content_item_set_time (self, time);
	dino_content_item_set_encryption (self, encryption);
	dino_content_item_set_mark (self, mark);
	return self;
}

gint
dino_content_item_compare (DinoContentItem* self,
                           DinoContentItem* c)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (c != NULL, -1);
	result = dino_content_item_compare_func (self, c);
	return result;
}

gint
dino_content_item_compare_func (DinoContentItem* a,
                                DinoContentItem* b)
{
	gint res = 0;
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	gint result;
	g_return_val_if_fail (a != NULL, -1);
	g_return_val_if_fail (b != NULL, -1);
	_tmp0_ = a->priv->_time;
	_tmp1_ = b->priv->_time;
	res = g_date_time_compare (_tmp0_, _tmp1_);
	if (res == 0) {
		gint _tmp2_ = 0;
		gint _tmp3_;
		gint _tmp4_;
		_tmp3_ = a->priv->_id;
		_tmp4_ = b->priv->_id;
		if ((_tmp3_ - _tmp4_) > 0) {
			_tmp2_ = 1;
		} else {
			_tmp2_ = -1;
		}
		res = _tmp2_;
	}
	result = res;
	return result;
}

gint
dino_content_item_get_id (DinoContentItem* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = self->priv->_id;
	return result;
}

void
dino_content_item_set_id (DinoContentItem* self,
                          gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = dino_content_item_get_id (self);
	if (old_value != value) {
		self->priv->_id = value;
		g_object_notify_by_pspec ((GObject *) self, dino_content_item_properties[DINO_CONTENT_ITEM_ID_PROPERTY]);
	}
}

const gchar*
dino_content_item_get_type_ (DinoContentItem* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_type_;
	result = _tmp0_;
	return result;
}

void
dino_content_item_set_type_ (DinoContentItem* self,
                             const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = dino_content_item_get_type_ (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_type_);
		self->priv->_type_ = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, dino_content_item_properties[DINO_CONTENT_ITEM_TYPE__PROPERTY]);
	}
}

XmppJid*
dino_content_item_get_jid (DinoContentItem* self)
{
	XmppJid* result;
	XmppJid* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_jid;
	result = _tmp0_;
	return result;
}

void
dino_content_item_set_jid (DinoContentItem* self,
                           XmppJid* value)
{
	XmppJid* old_value;
	g_return_if_fail (self != NULL);
	old_value = dino_content_item_get_jid (self);
	if (old_value != value) {
		XmppJid* _tmp0_;
		_tmp0_ = _xmpp_jid_ref0 (value);
		_xmpp_jid_unref0 (self->priv->_jid);
		self->priv->_jid = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, dino_content_item_properties[DINO_CONTENT_ITEM_JID_PROPERTY]);
	}
}

GDateTime*
dino_content_item_get_time (DinoContentItem* self)
{
	GDateTime* result;
	GDateTime* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_time;
	result = _tmp0_;
	return result;
}

static gpointer
_g_date_time_ref0 (gpointer self)
{
	return self ? g_date_time_ref (self) : NULL;
}

void
dino_content_item_set_time (DinoContentItem* self,
                            GDateTime* value)
{
	GDateTime* old_value;
	g_return_if_fail (self != NULL);
	old_value = dino_content_item_get_time (self);
	if (old_value != value) {
		GDateTime* _tmp0_;
		_tmp0_ = _g_date_time_ref0 (value);
		_g_date_time_unref0 (self->priv->_time);
		self->priv->_time = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, dino_content_item_properties[DINO_CONTENT_ITEM_TIME_PROPERTY]);
	}
}

DinoEntitiesEncryption
dino_content_item_get_encryption (DinoContentItem* self)
{
	DinoEntitiesEncryption result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_encryption;
	return result;
}

void
dino_content_item_set_encryption (DinoContentItem* self,
                                  DinoEntitiesEncryption value)
{
	DinoEntitiesEncryption old_value;
	g_return_if_fail (self != NULL);
	old_value = dino_content_item_get_encryption (self);
	if (old_value != value) {
		self->priv->_encryption = value;
		g_object_notify_by_pspec ((GObject *) self, dino_content_item_properties[DINO_CONTENT_ITEM_ENCRYPTION_PROPERTY]);
	}
}

DinoEntitiesMessageMarked
dino_content_item_get_mark (DinoContentItem* self)
{
	DinoEntitiesMessageMarked result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_mark;
	return result;
}

void
dino_content_item_set_mark (DinoContentItem* self,
                            DinoEntitiesMessageMarked value)
{
	DinoEntitiesMessageMarked old_value;
	g_return_if_fail (self != NULL);
	old_value = dino_content_item_get_mark (self);
	if (old_value != value) {
		self->priv->_mark = value;
		g_object_notify_by_pspec ((GObject *) self, dino_content_item_properties[DINO_CONTENT_ITEM_MARK_PROPERTY]);
	}
}

static void
dino_content_item_class_init (DinoContentItemClass * klass,
                              gpointer klass_data)
{
	dino_content_item_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoContentItem_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_content_item_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_dino_content_item_set_property;
	G_OBJECT_CLASS (klass)->finalize = dino_content_item_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_CONTENT_ITEM_ID_PROPERTY, dino_content_item_properties[DINO_CONTENT_ITEM_ID_PROPERTY] = g_param_spec_int ("id", "id", "id", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_CONTENT_ITEM_TYPE__PROPERTY, dino_content_item_properties[DINO_CONTENT_ITEM_TYPE__PROPERTY] = g_param_spec_string ("type-", "type-", "type-", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_CONTENT_ITEM_JID_PROPERTY, dino_content_item_properties[DINO_CONTENT_ITEM_JID_PROPERTY] = xmpp_param_spec_jid ("jid", "jid", "jid", XMPP_TYPE_JID, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_CONTENT_ITEM_TIME_PROPERTY, dino_content_item_properties[DINO_CONTENT_ITEM_TIME_PROPERTY] = g_param_spec_boxed ("time", "time", "time", G_TYPE_DATE_TIME, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_CONTENT_ITEM_ENCRYPTION_PROPERTY, dino_content_item_properties[DINO_CONTENT_ITEM_ENCRYPTION_PROPERTY] = g_param_spec_enum ("encryption", "encryption", "encryption", DINO_ENTITIES_TYPE_ENCRYPTION, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_CONTENT_ITEM_MARK_PROPERTY, dino_content_item_properties[DINO_CONTENT_ITEM_MARK_PROPERTY] = g_param_spec_enum ("mark", "mark", "mark", DINO_ENTITIES_MESSAGE_TYPE_MARKED, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
dino_content_item_instance_init (DinoContentItem * self,
                                 gpointer klass)
{
	self->priv = dino_content_item_get_instance_private (self);
}

static void
dino_content_item_finalize (GObject * obj)
{
	DinoContentItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_CONTENT_ITEM, DinoContentItem);
	_g_free0 (self->priv->_type_);
	_xmpp_jid_unref0 (self->priv->_jid);
	_g_date_time_unref0 (self->priv->_time);
	G_OBJECT_CLASS (dino_content_item_parent_class)->finalize (obj);
}

static GType
dino_content_item_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoContentItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_content_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoContentItem), 0, (GInstanceInitFunc) dino_content_item_instance_init, NULL };
	GType dino_content_item_type_id;
	dino_content_item_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoContentItem", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	DinoContentItem_private_offset = g_type_add_instance_private (dino_content_item_type_id, sizeof (DinoContentItemPrivate));
	return dino_content_item_type_id;
}

GType
dino_content_item_get_type (void)
{
	static volatile gsize dino_content_item_type_id__once = 0;
	if (g_once_init_enter (&dino_content_item_type_id__once)) {
		GType dino_content_item_type_id;
		dino_content_item_type_id = dino_content_item_get_type_once ();
		g_once_init_leave (&dino_content_item_type_id__once, dino_content_item_type_id);
	}
	return dino_content_item_type_id__once;
}

static void
_vala_dino_content_item_get_property (GObject * object,
                                      guint property_id,
                                      GValue * value,
                                      GParamSpec * pspec)
{
	DinoContentItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_TYPE_CONTENT_ITEM, DinoContentItem);
	switch (property_id) {
		case DINO_CONTENT_ITEM_ID_PROPERTY:
		g_value_set_int (value, dino_content_item_get_id (self));
		break;
		case DINO_CONTENT_ITEM_TYPE__PROPERTY:
		g_value_set_string (value, dino_content_item_get_type_ (self));
		break;
		case DINO_CONTENT_ITEM_JID_PROPERTY:
		xmpp_value_set_jid (value, dino_content_item_get_jid (self));
		break;
		case DINO_CONTENT_ITEM_TIME_PROPERTY:
		g_value_set_boxed (value, dino_content_item_get_time (self));
		break;
		case DINO_CONTENT_ITEM_ENCRYPTION_PROPERTY:
		g_value_set_enum (value, dino_content_item_get_encryption (self));
		break;
		case DINO_CONTENT_ITEM_MARK_PROPERTY:
		g_value_set_enum (value, dino_content_item_get_mark (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_dino_content_item_set_property (GObject * object,
                                      guint property_id,
                                      const GValue * value,
                                      GParamSpec * pspec)
{
	DinoContentItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_TYPE_CONTENT_ITEM, DinoContentItem);
	switch (property_id) {
		case DINO_CONTENT_ITEM_ID_PROPERTY:
		dino_content_item_set_id (self, g_value_get_int (value));
		break;
		case DINO_CONTENT_ITEM_TYPE__PROPERTY:
		dino_content_item_set_type_ (self, g_value_get_string (value));
		break;
		case DINO_CONTENT_ITEM_JID_PROPERTY:
		dino_content_item_set_jid (self, xmpp_value_get_jid (value));
		break;
		case DINO_CONTENT_ITEM_TIME_PROPERTY:
		dino_content_item_set_time (self, g_value_get_boxed (value));
		break;
		case DINO_CONTENT_ITEM_ENCRYPTION_PROPERTY:
		dino_content_item_set_encryption (self, g_value_get_enum (value));
		break;
		case DINO_CONTENT_ITEM_MARK_PROPERTY:
		dino_content_item_set_mark (self, g_value_get_enum (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

DinoMessageItem*
dino_message_item_construct (GType object_type,
                             DinoEntitiesMessage* message,
                             DinoEntitiesConversation* conversation,
                             gint id)
{
	DinoMessageItem * self = NULL;
	XmppJid* _tmp0_;
	XmppJid* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	DinoEntitiesEncryption _tmp4_;
	DinoEntitiesEncryption _tmp5_;
	DinoEntitiesMessageMarked _tmp6_;
	DinoEntitiesMessageMarked _tmp7_;
	DinoEntitiesMessage* _tmp8_;
	DinoEntitiesConversation* _tmp9_;
	g_return_val_if_fail (message != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	_tmp0_ = dino_entities_message_get_from (message);
	_tmp1_ = _tmp0_;
	_tmp2_ = dino_entities_message_get_time (message);
	_tmp3_ = _tmp2_;
	_tmp4_ = dino_entities_message_get_encryption (message);
	_tmp5_ = _tmp4_;
	_tmp6_ = dino_entities_message_get_marked (message);
	_tmp7_ = _tmp6_;
	self = (DinoMessageItem*) dino_content_item_construct (object_type, id, DINO_MESSAGE_ITEM_TYPE, _tmp1_, _tmp3_, _tmp5_, _tmp7_);
	_tmp8_ = _g_object_ref0 (message);
	_g_object_unref0 (self->message);
	self->message = _tmp8_;
	_tmp9_ = _g_object_ref0 (conversation);
	_g_object_unref0 (self->conversation);
	self->conversation = _tmp9_;
	g_object_bind_property_with_closures ((GObject*) message, "marked", (GObject*) self, "mark", G_BINDING_DEFAULT, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	return self;
}

DinoMessageItem*
dino_message_item_new (DinoEntitiesMessage* message,
                       DinoEntitiesConversation* conversation,
                       gint id)
{
	return dino_message_item_construct (DINO_TYPE_MESSAGE_ITEM, message, conversation, id);
}

static void
dino_message_item_class_init (DinoMessageItemClass * klass,
                              gpointer klass_data)
{
	dino_message_item_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = dino_message_item_finalize;
}

static void
dino_message_item_instance_init (DinoMessageItem * self,
                                 gpointer klass)
{
}

static void
dino_message_item_finalize (GObject * obj)
{
	DinoMessageItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_MESSAGE_ITEM, DinoMessageItem);
	_g_object_unref0 (self->message);
	_g_object_unref0 (self->conversation);
	G_OBJECT_CLASS (dino_message_item_parent_class)->finalize (obj);
}

static GType
dino_message_item_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoMessageItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_message_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoMessageItem), 0, (GInstanceInitFunc) dino_message_item_instance_init, NULL };
	GType dino_message_item_type_id;
	dino_message_item_type_id = g_type_register_static (DINO_TYPE_CONTENT_ITEM, "DinoMessageItem", &g_define_type_info, 0);
	return dino_message_item_type_id;
}

GType
dino_message_item_get_type (void)
{
	static volatile gsize dino_message_item_type_id__once = 0;
	if (g_once_init_enter (&dino_message_item_type_id__once)) {
		GType dino_message_item_type_id;
		dino_message_item_type_id = dino_message_item_get_type_once ();
		g_once_init_leave (&dino_message_item_type_id__once, dino_message_item_type_id);
	}
	return dino_message_item_type_id__once;
}

static gboolean
____lambda47_ (DinoFileItem* self,
               GBinding* _,
               GValue* from_value,
               GValue* to_value)
{
	GValue _tmp0_ = {0};
	gboolean result;
	g_return_val_if_fail (_ != NULL, FALSE);
	g_return_val_if_fail (from_value != NULL, FALSE);
	g_return_val_if_fail (to_value != NULL, FALSE);
	g_value_init (&_tmp0_, DINO_ENTITIES_MESSAGE_TYPE_MARKED);
	g_value_set_enum (&_tmp0_, dino_file_item_file_to_message_state ((DinoEntitiesFileTransferState) g_value_get_enum (from_value)));
	G_IS_VALUE (to_value) ? (g_value_unset (to_value), NULL) : NULL;
	*to_value = _tmp0_;
	result = TRUE;
	return result;
}

static gboolean
_____lambda47__gbinding_transform_func (GBinding* binding,
                                        GValue* from_value,
                                        GValue* to_value,
                                        gpointer self)
{
	gboolean result;
	result = ____lambda47_ ((DinoFileItem*) self, binding, from_value, to_value);
	return result;
}

DinoFileItem*
dino_file_item_construct (GType object_type,
                          DinoEntitiesFileTransfer* file_transfer,
                          DinoEntitiesConversation* conversation,
                          gint id,
                          DinoEntitiesMessage* message)
{
	DinoFileItem * self = NULL;
	DinoEntitiesMessageMarked mark = 0;
	XmppJid* _tmp6_;
	XmppJid* _tmp7_;
	GDateTime* _tmp8_;
	GDateTime* _tmp9_;
	DinoEntitiesEncryption _tmp10_;
	DinoEntitiesEncryption _tmp11_;
	DinoEntitiesFileTransfer* _tmp12_;
	DinoEntitiesConversation* _tmp13_;
	g_return_val_if_fail (file_transfer != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	mark = DINO_ENTITIES_MESSAGE_MARKED_NONE;
	if (message != NULL) {
		DinoEntitiesMessageMarked _tmp0_;
		DinoEntitiesMessageMarked _tmp1_;
		_tmp0_ = dino_entities_message_get_marked (message);
		_tmp1_ = _tmp0_;
		mark = _tmp1_;
	} else {
		gboolean _tmp2_;
		gboolean _tmp3_;
		_tmp2_ = dino_entities_file_transfer_get_direction (file_transfer);
		_tmp3_ = _tmp2_;
		if (_tmp3_ == DINO_ENTITIES_FILE_TRANSFER_DIRECTION_SENT) {
			DinoEntitiesFileTransferState _tmp4_;
			DinoEntitiesFileTransferState _tmp5_;
			_tmp4_ = dino_entities_file_transfer_get_state (file_transfer);
			_tmp5_ = _tmp4_;
			mark = dino_file_item_file_to_message_state (_tmp5_);
		}
	}
	_tmp6_ = dino_entities_file_transfer_get_from (file_transfer);
	_tmp7_ = _tmp6_;
	_tmp8_ = dino_entities_file_transfer_get_time (file_transfer);
	_tmp9_ = _tmp8_;
	_tmp10_ = dino_entities_file_transfer_get_encryption (file_transfer);
	_tmp11_ = _tmp10_;
	self = (DinoFileItem*) dino_content_item_construct (object_type, id, DINO_FILE_ITEM_TYPE, _tmp7_, _tmp9_, _tmp11_, mark);
	_tmp12_ = _g_object_ref0 (file_transfer);
	_g_object_unref0 (self->file_transfer);
	self->file_transfer = _tmp12_;
	_tmp13_ = _g_object_ref0 (conversation);
	_g_object_unref0 (self->conversation);
	self->conversation = _tmp13_;
	if (message != NULL) {
		g_object_bind_property_with_closures ((GObject*) message, "marked", (GObject*) self, "mark", G_BINDING_DEFAULT, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	} else {
		gboolean _tmp14_;
		gboolean _tmp15_;
		_tmp14_ = dino_entities_file_transfer_get_direction (file_transfer);
		_tmp15_ = _tmp14_;
		if (_tmp15_ == DINO_ENTITIES_FILE_TRANSFER_DIRECTION_SENT) {
			g_object_bind_property_with_closures ((GObject*) file_transfer, "state", (GObject*) self, "mark", G_BINDING_DEFAULT, (GClosure*) ((_____lambda47__gbinding_transform_func == NULL) ? NULL : g_cclosure_new ((GCallback) _____lambda47__gbinding_transform_func, g_object_ref (self), (GClosureNotify) g_object_unref)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
		}
	}
	return self;
}

DinoFileItem*
dino_file_item_new (DinoEntitiesFileTransfer* file_transfer,
                    DinoEntitiesConversation* conversation,
                    gint id,
                    DinoEntitiesMessage* message)
{
	return dino_file_item_construct (DINO_TYPE_FILE_ITEM, file_transfer, conversation, id, message);
}

static DinoEntitiesMessageMarked
dino_file_item_file_to_message_state (DinoEntitiesFileTransferState state)
{
	DinoEntitiesMessageMarked result;
	switch (state) {
		case DINO_ENTITIES_FILE_TRANSFER_STATE_IN_PROGRESS:
		{
			result = DINO_ENTITIES_MESSAGE_MARKED_UNSENT;
			return result;
		}
		case DINO_ENTITIES_FILE_TRANSFER_STATE_COMPLETE:
		{
			result = DINO_ENTITIES_MESSAGE_MARKED_NONE;
			return result;
		}
		case DINO_ENTITIES_FILE_TRANSFER_STATE_NOT_STARTED:
		{
			result = DINO_ENTITIES_MESSAGE_MARKED_UNSENT;
			return result;
		}
		case DINO_ENTITIES_FILE_TRANSFER_STATE_FAILED:
		{
			result = DINO_ENTITIES_MESSAGE_MARKED_WONTSEND;
			return result;
		}
		default:
		break;
	}
	g_assert_not_reached ();
}

static void
dino_file_item_class_init (DinoFileItemClass * klass,
                           gpointer klass_data)
{
	dino_file_item_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = dino_file_item_finalize;
}

static void
dino_file_item_instance_init (DinoFileItem * self,
                              gpointer klass)
{
}

static void
dino_file_item_finalize (GObject * obj)
{
	DinoFileItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_FILE_ITEM, DinoFileItem);
	_g_object_unref0 (self->file_transfer);
	_g_object_unref0 (self->conversation);
	G_OBJECT_CLASS (dino_file_item_parent_class)->finalize (obj);
}

static GType
dino_file_item_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoFileItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_file_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoFileItem), 0, (GInstanceInitFunc) dino_file_item_instance_init, NULL };
	GType dino_file_item_type_id;
	dino_file_item_type_id = g_type_register_static (DINO_TYPE_CONTENT_ITEM, "DinoFileItem", &g_define_type_info, 0);
	return dino_file_item_type_id;
}

GType
dino_file_item_get_type (void)
{
	static volatile gsize dino_file_item_type_id__once = 0;
	if (g_once_init_enter (&dino_file_item_type_id__once)) {
		GType dino_file_item_type_id;
		dino_file_item_type_id = dino_file_item_get_type_once ();
		g_once_init_leave (&dino_file_item_type_id__once, dino_file_item_type_id);
	}
	return dino_file_item_type_id__once;
}

DinoCallItem*
dino_call_item_construct (GType object_type,
                          DinoEntitiesCall* call,
                          DinoEntitiesConversation* conversation,
                          gint id)
{
	DinoCallItem * self = NULL;
	XmppJid* _tmp0_;
	XmppJid* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	DinoEntitiesEncryption _tmp4_;
	DinoEntitiesEncryption _tmp5_;
	DinoEntitiesCall* _tmp6_;
	DinoEntitiesConversation* _tmp7_;
	g_return_val_if_fail (call != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	_tmp0_ = dino_entities_call_get_proposer (call);
	_tmp1_ = _tmp0_;
	_tmp2_ = dino_entities_call_get_time (call);
	_tmp3_ = _tmp2_;
	_tmp4_ = dino_entities_call_get_encryption (call);
	_tmp5_ = _tmp4_;
	self = (DinoCallItem*) dino_content_item_construct (object_type, id, DINO_CALL_ITEM_TYPE, _tmp1_, _tmp3_, _tmp5_, DINO_ENTITIES_MESSAGE_MARKED_NONE);
	_tmp6_ = _g_object_ref0 (call);
	_g_object_unref0 (self->call);
	self->call = _tmp6_;
	_tmp7_ = _g_object_ref0 (conversation);
	_g_object_unref0 (self->conversation);
	self->conversation = _tmp7_;
	g_object_bind_property_with_closures ((GObject*) call, "encryption", (GObject*) self, "encryption", G_BINDING_DEFAULT, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	return self;
}

DinoCallItem*
dino_call_item_new (DinoEntitiesCall* call,
                    DinoEntitiesConversation* conversation,
                    gint id)
{
	return dino_call_item_construct (DINO_TYPE_CALL_ITEM, call, conversation, id);
}

static void
dino_call_item_class_init (DinoCallItemClass * klass,
                           gpointer klass_data)
{
	dino_call_item_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = dino_call_item_finalize;
}

static void
dino_call_item_instance_init (DinoCallItem * self,
                              gpointer klass)
{
}

static void
dino_call_item_finalize (GObject * obj)
{
	DinoCallItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_CALL_ITEM, DinoCallItem);
	_g_object_unref0 (self->call);
	_g_object_unref0 (self->conversation);
	G_OBJECT_CLASS (dino_call_item_parent_class)->finalize (obj);
}

static GType
dino_call_item_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoCallItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_call_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoCallItem), 0, (GInstanceInitFunc) dino_call_item_instance_init, NULL };
	GType dino_call_item_type_id;
	dino_call_item_type_id = g_type_register_static (DINO_TYPE_CONTENT_ITEM, "DinoCallItem", &g_define_type_info, 0);
	return dino_call_item_type_id;
}

GType
dino_call_item_get_type (void)
{
	static volatile gsize dino_call_item_type_id__once = 0;
	if (g_once_init_enter (&dino_call_item_type_id__once)) {
		GType dino_call_item_type_id;
		dino_call_item_type_id = dino_call_item_get_type_once ();
		g_once_init_leave (&dino_call_item_type_id__once, dino_call_item_type_id);
	}
	return dino_call_item_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

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;
}

