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

#include "libdino.h"
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include "qlite.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_FILE_TRANSFER_STORAGE_0_PROPERTY,
	DINO_FILE_TRANSFER_STORAGE_ID_PROPERTY,
	DINO_FILE_TRANSFER_STORAGE_NUM_PROPERTIES
};
static GParamSpec* dino_file_transfer_storage_properties[DINO_FILE_TRANSFER_STORAGE_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_statement_builder_unref0(var) ((var == NULL) ? NULL : (var = (qlite_statement_builder_unref (var), NULL)))
#define _qlite_row_option_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_option_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _DinoFileTransferStoragePrivate {
	DinoStreamInteractor* stream_interactor;
	DinoDatabase* db;
	WeakMap* files_by_db_id;
	WeakMap* files_by_message_id;
	WeakMap* files_by_message_and_file_id;
};

static gint DinoFileTransferStorage_private_offset;
static gpointer dino_file_transfer_storage_parent_class = NULL;
DinoModuleIdentity* dino_file_transfer_storage_IDENTITY = NULL;
static DinoStreamInteractionModuleIface * dino_file_transfer_storage_dino_stream_interaction_module_parent_iface = NULL;

static DinoFileTransferStorage* dino_file_transfer_storage_new (DinoStreamInteractor* stream_interactor,
                                                         DinoDatabase* db);
static DinoFileTransferStorage* dino_file_transfer_storage_construct (GType object_type,
                                                               DinoStreamInteractor* stream_interactor,
                                                               DinoDatabase* db);
static void dino_file_transfer_storage_cache_file (DinoFileTransferStorage* self,
                                            DinoEntitiesFileTransfer* file_transfer);
static DinoEntitiesFileTransfer* dino_file_transfer_storage_create_file_from_row_opt (DinoFileTransferStorage* self,
                                                                               QliteRowOption* row_opt,
                                                                               DinoEntitiesConversation* conversation);
static void dino_file_transfer_storage_finalize (GObject * obj);
static GType dino_file_transfer_storage_get_type_once (void);
static void _vala_dino_file_transfer_storage_get_property (GObject * object,
                                                    guint property_id,
                                                    GValue * value,
                                                    GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_file_transfer_storage_get_instance_private (DinoFileTransferStorage* self)
{
	return G_STRUCT_MEMBER_P (self, DinoFileTransferStorage_private_offset);
}

void
dino_file_transfer_storage_start (DinoStreamInteractor* stream_interactor,
                                  DinoDatabase* db)
{
	DinoFileTransferStorage* m = NULL;
	DinoFileTransferStorage* _tmp0_;
	g_return_if_fail (stream_interactor != NULL);
	g_return_if_fail (db != NULL);
	_tmp0_ = dino_file_transfer_storage_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 DinoFileTransferStorage*
dino_file_transfer_storage_construct (GType object_type,
                                      DinoStreamInteractor* stream_interactor,
                                      DinoDatabase* db)
{
	DinoFileTransferStorage * self = NULL;
	DinoStreamInteractor* _tmp0_;
	DinoDatabase* _tmp1_;
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoFileTransferStorage*) 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_;
	return self;
}

static DinoFileTransferStorage*
dino_file_transfer_storage_new (DinoStreamInteractor* stream_interactor,
                                DinoDatabase* db)
{
	return dino_file_transfer_storage_construct (DINO_TYPE_FILE_TRANSFER_STORAGE, stream_interactor, db);
}

void
dino_file_transfer_storage_add_file (DinoFileTransferStorage* self,
                                     DinoEntitiesFileTransfer* file_transfer)
{
	DinoDatabase* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (file_transfer != NULL);
	_tmp0_ = self->priv->db;
	dino_entities_file_transfer_persist (file_transfer, _tmp0_);
	dino_file_transfer_storage_cache_file (self, file_transfer);
}

DinoEntitiesFileTransfer*
dino_file_transfer_storage_get_file_by_id (DinoFileTransferStorage* self,
                                           gint id,
                                           DinoEntitiesConversation* conversation)
{
	DinoEntitiesFileTransfer* file_transfer = NULL;
	WeakMap* _tmp0_;
	gpointer _tmp1_;
	DinoEntitiesFileTransfer* _tmp2_;
	QliteRowOption* row_option = NULL;
	DinoDatabase* _tmp3_;
	DinoDatabaseFileTransferTable* _tmp4_;
	DinoDatabaseFileTransferTable* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	QliteQueryBuilder* _tmp7_;
	DinoDatabase* _tmp8_;
	DinoDatabaseFileTransferTable* _tmp9_;
	DinoDatabaseFileTransferTable* _tmp10_;
	QliteColumn* _tmp11_;
	QliteQueryBuilder* _tmp12_;
	QliteQueryBuilder* _tmp13_;
	QliteRowOption* _tmp14_;
	QliteRowOption* _tmp15_;
	QliteRowOption* _tmp16_;
	DinoEntitiesFileTransfer* _tmp17_;
	DinoEntitiesFileTransfer* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	_tmp0_ = self->priv->files_by_db_id;
	_tmp1_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp0_, (gpointer) ((gintptr) id));
	file_transfer = (DinoEntitiesFileTransfer*) _tmp1_;
	_tmp2_ = file_transfer;
	if (_tmp2_ != NULL) {
		result = file_transfer;
		return result;
	}
	_tmp3_ = self->priv->db;
	_tmp4_ = dino_database_get_file_transfer (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = qlite_table_select ((QliteTable*) _tmp5_, NULL, (gint) 0);
	_tmp7_ = _tmp6_;
	_tmp8_ = self->priv->db;
	_tmp9_ = dino_database_get_file_transfer (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = _tmp10_->id;
	_tmp12_ = qlite_query_builder_with (_tmp7_, G_TYPE_INT, NULL, NULL, _tmp11_, "=", (gpointer) ((gintptr) id));
	_tmp13_ = _tmp12_;
	_tmp14_ = qlite_query_builder_row (_tmp13_);
	_tmp15_ = _tmp14_;
	_qlite_statement_builder_unref0 (_tmp13_);
	_qlite_statement_builder_unref0 (_tmp7_);
	row_option = _tmp15_;
	_tmp16_ = row_option;
	_tmp17_ = dino_file_transfer_storage_create_file_from_row_opt (self, _tmp16_, conversation);
	result = _tmp17_;
	_qlite_row_option_unref0 (row_option);
	_g_object_unref0 (file_transfer);
	return result;
}

DinoEntitiesFileTransfer*
dino_file_transfer_storage_get_file_by_message_id (DinoFileTransferStorage* self,
                                                   gint id,
                                                   DinoEntitiesConversation* conversation)
{
	DinoEntitiesFileTransfer* file_transfer = NULL;
	WeakMap* _tmp0_;
	gpointer _tmp1_;
	DinoEntitiesFileTransfer* _tmp2_;
	QliteRowOption* row_option = NULL;
	DinoDatabase* _tmp3_;
	DinoDatabaseFileTransferTable* _tmp4_;
	DinoDatabaseFileTransferTable* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	QliteQueryBuilder* _tmp7_;
	DinoDatabase* _tmp8_;
	DinoDatabaseFileTransferTable* _tmp9_;
	DinoDatabaseFileTransferTable* _tmp10_;
	QliteColumn* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	QliteQueryBuilder* _tmp14_;
	QliteQueryBuilder* _tmp15_;
	QliteQueryBuilder* _tmp16_;
	QliteQueryBuilder* _tmp17_;
	QliteRowOption* _tmp18_;
	QliteRowOption* _tmp19_;
	QliteRowOption* _tmp20_;
	DinoEntitiesFileTransfer* _tmp21_;
	DinoEntitiesFileTransfer* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	_tmp0_ = self->priv->files_by_message_id;
	_tmp1_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp0_, (gpointer) ((gintptr) id));
	file_transfer = (DinoEntitiesFileTransfer*) _tmp1_;
	_tmp2_ = file_transfer;
	if (_tmp2_ != NULL) {
		result = file_transfer;
		return result;
	}
	_tmp3_ = self->priv->db;
	_tmp4_ = dino_database_get_file_transfer (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = qlite_table_select ((QliteTable*) _tmp5_, NULL, (gint) 0);
	_tmp7_ = _tmp6_;
	_tmp8_ = self->priv->db;
	_tmp9_ = dino_database_get_file_transfer (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = _tmp10_->info;
	_tmp12_ = g_strdup_printf ("%i", id);
	_tmp13_ = _tmp12_;
	_tmp14_ = qlite_query_builder_with (_tmp7_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp11_, "=", _tmp13_);
	_tmp15_ = _tmp14_;
	_tmp16_ = qlite_query_builder_single (_tmp15_);
	_tmp17_ = _tmp16_;
	_tmp18_ = qlite_query_builder_row (_tmp17_);
	_tmp19_ = _tmp18_;
	_qlite_statement_builder_unref0 (_tmp17_);
	_qlite_statement_builder_unref0 (_tmp15_);
	_g_free0 (_tmp13_);
	_qlite_statement_builder_unref0 (_tmp7_);
	row_option = _tmp19_;
	_tmp20_ = row_option;
	_tmp21_ = dino_file_transfer_storage_create_file_from_row_opt (self, _tmp20_, conversation);
	result = _tmp21_;
	_qlite_row_option_unref0 (row_option);
	_g_object_unref0 (file_transfer);
	return result;
}

DinoEntitiesFileTransfer*
dino_file_transfer_storage_get_files_by_message_and_file_id (DinoFileTransferStorage* self,
                                                             gint message_id,
                                                             const gchar* file_sharing_id,
                                                             DinoEntitiesConversation* conversation)
{
	gchar* combined_identifier = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	DinoEntitiesFileTransfer* file_transfer = NULL;
	WeakMap* _tmp4_;
	const gchar* _tmp5_;
	gpointer _tmp6_;
	DinoEntitiesFileTransfer* _tmp7_;
	gboolean _tmp33_ = FALSE;
	gboolean _tmp34_ = FALSE;
	DinoEntitiesFileTransfer* _tmp35_;
	DinoEntitiesFileTransfer* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (file_sharing_id != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	_tmp0_ = g_strdup_printf ("%i", message_id);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strconcat (_tmp1_, file_sharing_id, NULL);
	_tmp3_ = _tmp2_;
	_g_free0 (_tmp1_);
	combined_identifier = _tmp3_;
	_tmp4_ = self->priv->files_by_message_and_file_id;
	_tmp5_ = combined_identifier;
	_tmp6_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp4_, _tmp5_);
	file_transfer = (DinoEntitiesFileTransfer*) _tmp6_;
	_tmp7_ = file_transfer;
	if (_tmp7_ == NULL) {
		QliteRowOption* row_option = NULL;
		DinoDatabase* _tmp8_;
		DinoDatabaseFileTransferTable* _tmp9_;
		DinoDatabaseFileTransferTable* _tmp10_;
		QliteQueryBuilder* _tmp11_;
		QliteQueryBuilder* _tmp12_;
		DinoDatabase* _tmp13_;
		DinoDatabaseFileTransferTable* _tmp14_;
		DinoDatabaseFileTransferTable* _tmp15_;
		QliteColumn* _tmp16_;
		gchar* _tmp17_;
		gchar* _tmp18_;
		QliteQueryBuilder* _tmp19_;
		QliteQueryBuilder* _tmp20_;
		DinoDatabase* _tmp21_;
		DinoDatabaseFileTransferTable* _tmp22_;
		DinoDatabaseFileTransferTable* _tmp23_;
		QliteColumn* _tmp24_;
		QliteQueryBuilder* _tmp25_;
		QliteQueryBuilder* _tmp26_;
		QliteQueryBuilder* _tmp27_;
		QliteQueryBuilder* _tmp28_;
		QliteRowOption* _tmp29_;
		QliteRowOption* _tmp30_;
		QliteRowOption* _tmp31_;
		DinoEntitiesFileTransfer* _tmp32_;
		_tmp8_ = self->priv->db;
		_tmp9_ = dino_database_get_file_transfer (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = qlite_table_select ((QliteTable*) _tmp10_, NULL, (gint) 0);
		_tmp12_ = _tmp11_;
		_tmp13_ = self->priv->db;
		_tmp14_ = dino_database_get_file_transfer (_tmp13_);
		_tmp15_ = _tmp14_;
		_tmp16_ = _tmp15_->info;
		_tmp17_ = g_strdup_printf ("%i", message_id);
		_tmp18_ = _tmp17_;
		_tmp19_ = qlite_query_builder_with (_tmp12_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp16_, "=", _tmp18_);
		_tmp20_ = _tmp19_;
		_tmp21_ = self->priv->db;
		_tmp22_ = dino_database_get_file_transfer (_tmp21_);
		_tmp23_ = _tmp22_;
		_tmp24_ = _tmp23_->file_sharing_id;
		_tmp25_ = qlite_query_builder_with (_tmp20_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp24_, "=", file_sharing_id);
		_tmp26_ = _tmp25_;
		_tmp27_ = qlite_query_builder_single (_tmp26_);
		_tmp28_ = _tmp27_;
		_tmp29_ = qlite_query_builder_row (_tmp28_);
		_tmp30_ = _tmp29_;
		_qlite_statement_builder_unref0 (_tmp28_);
		_qlite_statement_builder_unref0 (_tmp26_);
		_qlite_statement_builder_unref0 (_tmp20_);
		_g_free0 (_tmp18_);
		_qlite_statement_builder_unref0 (_tmp12_);
		row_option = _tmp30_;
		_tmp31_ = row_option;
		_tmp32_ = dino_file_transfer_storage_create_file_from_row_opt (self, _tmp31_, conversation);
		_g_object_unref0 (file_transfer);
		file_transfer = _tmp32_;
		_qlite_row_option_unref0 (row_option);
	}
	_tmp35_ = file_transfer;
	if (_tmp35_ != NULL) {
		DinoEntitiesFileTransfer* _tmp36_;
		const gchar* _tmp37_;
		const gchar* _tmp38_;
		gchar* _tmp39_;
		gchar* _tmp40_;
		_tmp36_ = file_transfer;
		_tmp37_ = dino_entities_file_transfer_get_info (_tmp36_);
		_tmp38_ = _tmp37_;
		_tmp39_ = g_strdup_printf ("%i", message_id);
		_tmp40_ = _tmp39_;
		_tmp34_ = g_strcmp0 (_tmp38_, _tmp40_) == 0;
		_g_free0 (_tmp40_);
	} else {
		_tmp34_ = FALSE;
	}
	if (_tmp34_) {
		DinoEntitiesFileTransfer* _tmp41_;
		const gchar* _tmp42_;
		const gchar* _tmp43_;
		_tmp41_ = file_transfer;
		_tmp42_ = dino_entities_file_transfer_get_file_sharing_id (_tmp41_);
		_tmp43_ = _tmp42_;
		_tmp33_ = g_strcmp0 (_tmp43_, file_sharing_id) == 0;
	} else {
		_tmp33_ = FALSE;
	}
	if (_tmp33_) {
		result = file_transfer;
		_g_free0 (combined_identifier);
		return result;
	}
	result = NULL;
	_g_object_unref0 (file_transfer);
	_g_free0 (combined_identifier);
	return result;
}

static DinoEntitiesFileTransfer*
dino_file_transfer_storage_create_file_from_row_opt (DinoFileTransferStorage* self,
                                                     QliteRowOption* row_opt,
                                                     DinoEntitiesConversation* conversation)
{
	GError* _inner_error0_ = NULL;
	DinoEntitiesFileTransfer* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (row_opt != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	if (!qlite_row_option_is_present (row_opt)) {
		result = NULL;
		return result;
	}
	{
		DinoEntitiesFileTransfer* file_transfer = NULL;
		DinoDatabase* _tmp0_;
		QliteRow* _tmp1_;
		QliteRow* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		DinoEntitiesFileTransfer* _tmp5_;
		DinoEntitiesFileTransfer* _tmp6_;
		DinoEntitiesConversationType _tmp7_;
		DinoEntitiesConversationType _tmp8_;
		DinoEntitiesFileTransfer* _tmp18_;
		_tmp0_ = self->priv->db;
		_tmp1_ = qlite_row_option_get_inner (row_opt);
		_tmp2_ = _tmp1_;
		_tmp3_ = dino_file_manager_get_storage_dir ();
		_tmp4_ = _tmp3_;
		_tmp5_ = dino_entities_file_transfer_new_from_row (_tmp0_, _tmp2_, _tmp4_, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		file_transfer = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == XMPP_INVALID_JID_ERROR) {
				goto __catch0_xmpp_invalid_jid_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp7_ = dino_entities_conversation_get_type_ (conversation);
		_tmp8_ = _tmp7_;
		if (dino_entities_conversation_type_is_muc_semantic (_tmp8_)) {
			XmppJid* _tmp9_ = NULL;
			XmppJid* _tmp10_;
			XmppJid* _tmp11_;
			DinoEntitiesFileTransfer* _tmp12_;
			XmppJid* _tmp13_;
			XmppJid* _tmp14_;
			const gchar* _tmp15_;
			XmppJid* _tmp16_;
			DinoEntitiesFileTransfer* _tmp17_;
			_tmp10_ = dino_entities_conversation_get_counterpart (conversation);
			_tmp11_ = _tmp10_;
			_tmp12_ = file_transfer;
			_tmp13_ = dino_entities_file_transfer_get_ourpart (_tmp12_);
			_tmp14_ = _tmp13_;
			_tmp15_ = _tmp14_->resourcepart;
			_tmp16_ = xmpp_jid_with_resource (_tmp11_, _tmp15_, &_inner_error0_);
			_tmp9_ = _tmp16_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (file_transfer);
				if (_inner_error0_->domain == XMPP_INVALID_JID_ERROR) {
					goto __catch0_xmpp_invalid_jid_error;
				}
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return NULL;
			}
			_tmp17_ = file_transfer;
			dino_entities_file_transfer_set_ourpart (_tmp17_, _tmp9_);
			_xmpp_jid_unref0 (_tmp9_);
		}
		_tmp18_ = file_transfer;
		dino_file_transfer_storage_cache_file (self, _tmp18_);
		result = file_transfer;
		return result;
	}
	goto __finally0;
	__catch0_xmpp_invalid_jid_error:
	{
		GError* e = NULL;
		GError* _tmp19_;
		const gchar* _tmp20_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp19_ = e;
		_tmp20_ = _tmp19_->message;
		g_warning ("file_transfer_storage.vala:95: Got file transfer with invalid Jid: %s", _tmp20_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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;
	}
	result = NULL;
	return result;
}

static void
dino_file_transfer_storage_cache_file (DinoFileTransferStorage* self,
                                       DinoEntitiesFileTransfer* file_transfer)
{
	WeakMap* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gboolean _tmp3_ = FALSE;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (file_transfer != NULL);
	_tmp0_ = self->priv->files_by_db_id;
	_tmp1_ = dino_entities_file_transfer_get_id (file_transfer);
	_tmp2_ = _tmp1_;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp0_, (gpointer) ((gintptr) _tmp2_), file_transfer);
	_tmp4_ = dino_entities_file_transfer_get_info (file_transfer);
	_tmp5_ = _tmp4_;
	if (_tmp5_ != NULL) {
		const gchar* _tmp6_;
		const gchar* _tmp7_;
		_tmp6_ = dino_entities_file_transfer_get_info (file_transfer);
		_tmp7_ = _tmp6_;
		_tmp3_ = g_strcmp0 (_tmp7_, "") != 0;
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		WeakMap* _tmp8_;
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		gboolean _tmp11_ = FALSE;
		const gchar* _tmp12_;
		const gchar* _tmp13_;
		_tmp8_ = self->priv->files_by_message_id;
		_tmp9_ = dino_entities_file_transfer_get_info (file_transfer);
		_tmp10_ = _tmp9_;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp8_, (gpointer) ((gintptr) atoi (_tmp10_)), file_transfer);
		_tmp12_ = dino_entities_file_transfer_get_file_sharing_id (file_transfer);
		_tmp13_ = _tmp12_;
		if (_tmp13_ != NULL) {
			const gchar* _tmp14_;
			const gchar* _tmp15_;
			_tmp14_ = dino_entities_file_transfer_get_info (file_transfer);
			_tmp15_ = _tmp14_;
			_tmp11_ = _tmp15_ != NULL;
		} else {
			_tmp11_ = FALSE;
		}
		if (_tmp11_) {
			gchar* combined_identifier = NULL;
			const gchar* _tmp16_;
			const gchar* _tmp17_;
			const gchar* _tmp18_;
			const gchar* _tmp19_;
			gchar* _tmp20_;
			WeakMap* _tmp21_;
			const gchar* _tmp22_;
			_tmp16_ = dino_entities_file_transfer_get_info (file_transfer);
			_tmp17_ = _tmp16_;
			_tmp18_ = dino_entities_file_transfer_get_file_sharing_id (file_transfer);
			_tmp19_ = _tmp18_;
			_tmp20_ = g_strconcat (_tmp17_, _tmp19_, NULL);
			combined_identifier = _tmp20_;
			_tmp21_ = self->priv->files_by_message_and_file_id;
			_tmp22_ = combined_identifier;
			gee_abstract_map_set ((GeeAbstractMap*) _tmp21_, _tmp22_, file_transfer);
			_g_free0 (combined_identifier);
		}
	}
}

static const gchar*
dino_file_transfer_storage_real_get_id (DinoStreamInteractionModule* base)
{
	const gchar* result;
	DinoFileTransferStorage* self;
	DinoModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	self = (DinoFileTransferStorage*) base;
	_tmp0_ = dino_file_transfer_storage_IDENTITY;
	_tmp1_ = dino_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

static void
dino_file_transfer_storage_class_init (DinoFileTransferStorageClass * klass,
                                       gpointer klass_data)
{
	DinoModuleIdentity* _tmp0_;
	dino_file_transfer_storage_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoFileTransferStorage_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_file_transfer_storage_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_file_transfer_storage_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_FILE_TRANSFER_STORAGE_ID_PROPERTY, dino_file_transfer_storage_properties[DINO_FILE_TRANSFER_STORAGE_ID_PROPERTY] = g_param_spec_string ("id", "id", "id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	_tmp0_ = dino_module_identity_new (DINO_TYPE_FILE_TRANSFER_STORAGE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, "file_store");
	dino_file_transfer_storage_IDENTITY = _tmp0_;
}

static void
dino_file_transfer_storage_dino_stream_interaction_module_interface_init (DinoStreamInteractionModuleIface * iface,
                                                                          gpointer iface_data)
{
	dino_file_transfer_storage_dino_stream_interaction_module_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_id = dino_file_transfer_storage_real_get_id;
}

static void
dino_file_transfer_storage_instance_init (DinoFileTransferStorage * self,
                                          gpointer klass)
{
	WeakMap* _tmp0_;
	WeakMap* _tmp1_;
	WeakMap* _tmp2_;
	self->priv = dino_file_transfer_storage_get_instance_private (self);
	_tmp0_ = weak_map_new (G_TYPE_INT, NULL, NULL, DINO_ENTITIES_TYPE_FILE_TRANSFER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->files_by_db_id = _tmp0_;
	_tmp1_ = weak_map_new (G_TYPE_INT, NULL, NULL, DINO_ENTITIES_TYPE_FILE_TRANSFER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->files_by_message_id = _tmp1_;
	_tmp2_ = weak_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, DINO_ENTITIES_TYPE_FILE_TRANSFER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->files_by_message_and_file_id = _tmp2_;
}

static void
dino_file_transfer_storage_finalize (GObject * obj)
{
	DinoFileTransferStorage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_FILE_TRANSFER_STORAGE, DinoFileTransferStorage);
	_g_object_unref0 (self->priv->stream_interactor);
	_qlite_database_unref0 (self->priv->db);
	_g_object_unref0 (self->priv->files_by_db_id);
	_g_object_unref0 (self->priv->files_by_message_id);
	_g_object_unref0 (self->priv->files_by_message_and_file_id);
	G_OBJECT_CLASS (dino_file_transfer_storage_parent_class)->finalize (obj);
}

static GType
dino_file_transfer_storage_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoFileTransferStorageClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_file_transfer_storage_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoFileTransferStorage), 0, (GInstanceInitFunc) dino_file_transfer_storage_instance_init, NULL };
	static const GInterfaceInfo dino_stream_interaction_module_info = { (GInterfaceInitFunc) dino_file_transfer_storage_dino_stream_interaction_module_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_file_transfer_storage_type_id;
	dino_file_transfer_storage_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoFileTransferStorage", &g_define_type_info, 0);
	g_type_add_interface_static (dino_file_transfer_storage_type_id, DINO_TYPE_STREAM_INTERACTION_MODULE, &dino_stream_interaction_module_info);
	DinoFileTransferStorage_private_offset = g_type_add_instance_private (dino_file_transfer_storage_type_id, sizeof (DinoFileTransferStoragePrivate));
	return dino_file_transfer_storage_type_id;
}

GType
dino_file_transfer_storage_get_type (void)
{
	static volatile gsize dino_file_transfer_storage_type_id__once = 0;
	if (g_once_init_enter (&dino_file_transfer_storage_type_id__once)) {
		GType dino_file_transfer_storage_type_id;
		dino_file_transfer_storage_type_id = dino_file_transfer_storage_get_type_once ();
		g_once_init_leave (&dino_file_transfer_storage_type_id__once, dino_file_transfer_storage_type_id);
	}
	return dino_file_transfer_storage_type_id__once;
}

static void
_vala_dino_file_transfer_storage_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec)
{
	DinoFileTransferStorage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_TYPE_FILE_TRANSFER_STORAGE, DinoFileTransferStorage);
	switch (property_id) {
		case DINO_FILE_TRANSFER_STORAGE_ID_PROPERTY:
		g_value_set_string (value, dino_stream_interaction_module_get_id ((DinoStreamInteractionModule*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_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;
}

