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

#include "libdino.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gee.h>
#include <glib-object.h>
#include "xmpp-vala.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gio/gio.h>
#include <glib/gstdio.h>
#include <float.h>
#include <math.h>
#include "qlite.h"

#define DINO_AVATAR_MANAGER_MAX_PIXEL 192
#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_AVATAR_MANAGER_0_PROPERTY,
	DINO_AVATAR_MANAGER_ID_PROPERTY,
	DINO_AVATAR_MANAGER_NUM_PROPERTIES
};
static GParamSpec* dino_avatar_manager_properties[DINO_AVATAR_MANAGER_NUM_PROPERTIES];
typedef enum  {
	DINO_AVATAR_MANAGER_SOURCE_USER_AVATARS,
	DINO_AVATAR_MANAGER_SOURCE_VCARD
} DinoAvatarManagerSource;

#define DINO_AVATAR_MANAGER_TYPE_SOURCE (dino_avatar_manager_source_get_type ())
#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 _g_free0(var) (var = (g_free (var), NULL))
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
typedef struct _DinoAvatarManagerGetAvatarData DinoAvatarManagerGetAvatarData;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _Block1Data Block1Data;
#define _qlite_statement_builder_unref0(var) ((var == NULL) ? NULL : (var = (qlite_statement_builder_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)))
typedef struct _DinoAvatarManagerFetchAndStoreForJidData DinoAvatarManagerFetchAndStoreForJidData;
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))
typedef struct _DinoAvatarManagerFetchAndStoreData DinoAvatarManagerFetchAndStoreData;
typedef struct _DinoAvatarManagerStoreImageData DinoAvatarManagerStoreImageData;
#define _g_checksum_free0(var) ((var == NULL) ? NULL : (var = (g_checksum_free (var), NULL)))
typedef struct _DinoAvatarManagerGetImageData DinoAvatarManagerGetImageData;
enum  {
	DINO_AVATAR_MANAGER_RECEIVED_AVATAR_SIGNAL,
	DINO_AVATAR_MANAGER_FETCHED_AVATAR_SIGNAL,
	DINO_AVATAR_MANAGER_NUM_SIGNALS
};
static guint dino_avatar_manager_signals[DINO_AVATAR_MANAGER_NUM_SIGNALS] = {0};

struct _DinoAvatarManagerPrivate {
	DinoStreamInteractor* stream_interactor;
	DinoDatabase* db;
	gchar* folder;
	GeeHashMap* user_avatars;
	GeeHashMap* vcard_avatars;
	GeeHashMap* cached_pixbuf;
	GeeHashMap* pending_pixbuf;
	GeeHashSet* pending_fetch;
};

struct _DinoAvatarManagerGetAvatarData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoAvatarManager* self;
	DinoEntitiesAccount* account;
	XmppJid* jid_;
	GdkPixbuf* result;
	XmppJid* jid;
	XmppJid* _tmp0_;
	DinoStreamInteractor* _tmp1_;
	DinoModuleIdentity* _tmp2_;
	gpointer _tmp3_;
	DinoMucManager* _tmp4_;
	gboolean _tmp5_;
	XmppJid* _tmp6_;
	XmppJid* _tmp7_;
	gint source;
	gchar* hash;
	GeeHashMap* _tmp8_;
	XmppJid* _tmp9_;
	GeeHashMap* _tmp10_;
	XmppJid* _tmp11_;
	gpointer _tmp12_;
	GeeHashMap* _tmp13_;
	XmppJid* _tmp14_;
	GeeHashMap* _tmp15_;
	XmppJid* _tmp16_;
	gpointer _tmp17_;
	const gchar* _tmp18_;
	GeeHashMap* _tmp19_;
	const gchar* _tmp20_;
	GeeHashMap* _tmp21_;
	const gchar* _tmp22_;
	gpointer _tmp23_;
	XmppXmppStream* stream;
	DinoStreamInteractor* _tmp24_;
	XmppXmppStream* _tmp25_;
	gboolean _tmp26_;
	XmppXmppStream* _tmp27_;
	XmppXmppStream* _tmp28_;
	gboolean _tmp29_;
	gboolean _tmp30_;
	GeeHashMap* _tmp31_;
	const gchar* _tmp32_;
	GeeHashMap* _tmp33_;
	const gchar* _tmp34_;
	gpointer _tmp35_;
	GeeList* _tmp36_;
	XmppSourceFuncWrapper* _tmp37_;
	XmppSourceFuncWrapper* _tmp38_;
	GeeHashMap* _tmp39_;
	const gchar* _tmp40_;
	gpointer _tmp41_;
	GeeHashMap* _tmp42_;
	const gchar* _tmp43_;
	GeeArrayList* _tmp44_;
	GeeArrayList* _tmp45_;
	GdkPixbuf* image;
	const gchar* _tmp46_;
	GdkPixbuf* _tmp47_;
	GdkPixbuf* _tmp48_;
	GeeHashMap* _tmp49_;
	const gchar* _tmp50_;
	GdkPixbuf* _tmp51_;
	XmppXmppStream* _tmp52_;
	XmppJid* _tmp53_;
	const gchar* _tmp54_;
	const gchar* _tmp55_;
	GdkPixbuf* _tmp56_;
	GeeHashMap* _tmp57_;
	const gchar* _tmp58_;
	GdkPixbuf* _tmp59_;
	GeeList* _sfw_list;
	GeeHashMap* _tmp60_;
	const gchar* _tmp61_;
	gpointer _tmp62_;
	gint _sfw_size;
	GeeList* _tmp63_;
	gint _tmp64_;
	gint _tmp65_;
	gint _sfw_index;
	gint _tmp66_;
	gint _tmp67_;
	XmppSourceFuncWrapper* sfw;
	GeeList* _tmp68_;
	gpointer _tmp69_;
	XmppSourceFuncWrapper* _tmp70_;
	GSourceFunc _tmp71_;
	gpointer _tmp71__target;
};

struct _Block1Data {
	int _ref_count_;
	DinoAvatarManager* self;
	DinoEntitiesAccount* account;
};

struct _DinoAvatarManagerFetchAndStoreForJidData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoAvatarManager* self;
	DinoEntitiesAccount* account;
	XmppJid* jid;
	gboolean result;
	gint source;
	gchar* hash;
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	gpointer _tmp2_;
	GeeHashMap* _tmp3_;
	GeeHashMap* _tmp4_;
	gpointer _tmp5_;
	XmppXmppStream* stream;
	DinoStreamInteractor* _tmp6_;
	XmppXmppStream* _tmp7_;
	gboolean _tmp8_;
	XmppXmppStream* _tmp9_;
	XmppXmppStream* _tmp10_;
	gboolean _tmp11_;
	gboolean _tmp12_;
	XmppXmppStream* _tmp13_;
	const gchar* _tmp14_;
};

struct _DinoAvatarManagerFetchAndStoreData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoAvatarManager* self;
	XmppXmppStream* stream;
	DinoEntitiesAccount* account;
	XmppJid* jid;
	gint source;
	gchar* hash;
	gboolean result;
	gboolean _tmp0_;
	GeeHashSet* _tmp1_;
	GeeHashSet* _tmp2_;
	GBytes* bytes;
	GBytes* _tmp3_;
	GBytes* _tmp4_;
	gboolean _tmp5_;
	GBytes* _tmp6_;
	DinoDatabase* _tmp7_;
	DinoDatabaseAvatarTable* _tmp8_;
	DinoDatabaseAvatarTable* _tmp9_;
	QliteDeleteBuilder* _tmp10_;
	QliteDeleteBuilder* _tmp11_;
	DinoDatabase* _tmp12_;
	DinoDatabaseAvatarTable* _tmp13_;
	DinoDatabaseAvatarTable* _tmp14_;
	QliteColumn* _tmp15_;
	DinoDatabase* _tmp16_;
	QliteDeleteBuilder* _tmp17_;
	QliteDeleteBuilder* _tmp18_;
	GBytes* _tmp19_;
	GBytes* _tmp20_;
	GeeHashSet* _tmp21_;
	GBytes* _tmp22_;
};

struct _DinoAvatarManagerStoreImageData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoAvatarManager* self;
	gchar* id;
	GBytes* data;
	GFile* file;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GFile* _tmp3_;
	GFile* _tmp4_;
	GFile* _tmp5_;
	GFile* _tmp6_;
	GFileOutputStream* _tmp7_;
	GFile* _tmp8_;
	GFileOutputStream* _tmp9_;
	GDataOutputStream* fos;
	GDataOutputStream* _tmp10_;
	GDataOutputStream* _tmp11_;
	GError* _inner_error0_;
};

struct _DinoAvatarManagerGetImageData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoAvatarManager* self;
	gchar* id;
	GdkPixbuf* result;
	GFile* file;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GFile* _tmp3_;
	GFile* _tmp4_;
	GFileInputStream* stream;
	GFile* _tmp5_;
	GFileInputStream* _tmp6_;
	guint8 fbuf[1024];
	gsize size;
	GChecksum* checksum;
	GChecksum* _tmp7_;
	gssize _tmp8_;
	GFileInputStream* _tmp9_;
	GChecksum* _tmp10_;
	GChecksum* _tmp11_;
	const gchar* _tmp12_;
	GFile* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	GFileInputStream* _tmp16_;
	GdkPixbuf* _tmp17_;
	GFileInputStream* _tmp18_;
	GdkPixbuf* _tmp19_;
	GdkPixbuf* _tmp20_;
	GError* _inner_error0_;
};

static gint DinoAvatarManager_private_offset;
static gpointer dino_avatar_manager_parent_class = NULL;
DinoModuleIdentity* dino_avatar_manager_IDENTITY = NULL;
static DinoStreamInteractionModuleIface * dino_avatar_manager_dino_stream_interaction_module_parent_iface = NULL;

static GType dino_avatar_manager_source_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static guint _xmpp_jid_hash_func_gee_hash_data_func (gconstpointer v,
                                              gpointer self);
static gboolean _xmpp_jid_equals_func_gee_equal_data_func (gconstpointer a,
                                                    gconstpointer b,
                                                    gpointer self);
static DinoAvatarManager* dino_avatar_manager_new (DinoStreamInteractor* stream_interactor,
                                            DinoDatabase* db);
static DinoAvatarManager* dino_avatar_manager_construct (GType object_type,
                                                  DinoStreamInteractor* stream_interactor,
                                                  DinoDatabase* db);
static void dino_avatar_manager_on_account_added (DinoAvatarManager* self,
                                           DinoEntitiesAccount* account);
static void _dino_avatar_manager_on_account_added_dino_stream_interactor_account_added (DinoStreamInteractor* _sender,
                                                                                 DinoEntitiesAccount* account,
                                                                                 gpointer self);
static void __lambda113_ (DinoAvatarManager* self,
                   DinoEntitiesAccount* _,
                   GeeArrayList* modules);
static void ___lambda113__dino_module_manager_initialize_account_modules (DinoModuleManager* _sender,
                                                                   DinoEntitiesAccount* account,
                                                                   GeeArrayList* modules,
                                                                   gpointer self);
static gchar* dino_avatar_manager_get_avatar_hash (DinoAvatarManager* self,
                                            DinoEntitiesAccount* account,
                                            XmppJid* jid_);
static void dino_avatar_manager_get_avatar_data_free (gpointer _data);
static gboolean dino_avatar_manager_get_avatar_co (DinoAvatarManagerGetAvatarData* _data_);
static gboolean _dino_avatar_manager_get_avatar_co_gsource_func (gpointer self);
static void dino_avatar_manager_get_avatar_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_);
static void dino_avatar_manager_fetch_and_store (DinoAvatarManager* self,
                                          XmppXmppStream* stream,
                                          DinoEntitiesAccount* account,
                                          XmppJid* jid,
                                          gint source,
                                          const gchar* hash,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_);
static gboolean dino_avatar_manager_fetch_and_store_finish (DinoAvatarManager* self,
                                                     GAsyncResult* _res_);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void __lambda110_ (Block1Data* _data1_,
                   XmppXmppStream* stream,
                   XmppJid* jid,
                   const gchar* id);
static void dino_avatar_manager_on_user_avatar_received (DinoAvatarManager* self,
                                                  DinoEntitiesAccount* account,
                                                  XmppJid* jid_,
                                                  const gchar* id);
static void ___lambda110__xmpp_xep_user_avatars_module_received_avatar_hash (XmppXepUserAvatarsModule* _sender,
                                                                      XmppXmppStream* stream,
                                                                      XmppJid* jid,
                                                                      const gchar* id,
                                                                      gpointer self);
static void __lambda111_ (Block1Data* _data1_,
                   XmppXmppStream* stream,
                   XmppJid* jid);
static void dino_avatar_manager_on_user_avatar_removed (DinoAvatarManager* self,
                                                 DinoEntitiesAccount* account,
                                                 XmppJid* jid_);
static void ___lambda111__xmpp_xep_user_avatars_module_avatar_removed (XmppXepUserAvatarsModule* _sender,
                                                                XmppXmppStream* stream,
                                                                XmppJid* jid,
                                                                gpointer self);
static void __lambda112_ (Block1Data* _data1_,
                   XmppXmppStream* stream,
                   XmppJid* jid,
                   const gchar* id);
static void dino_avatar_manager_on_vcard_avatar_received (DinoAvatarManager* self,
                                                   DinoEntitiesAccount* account,
                                                   XmppJid* jid_,
                                                   const gchar* id);
static void ___lambda112__xmpp_xep_vcard_module_received_avatar_hash (XmppXepVCardModule* _sender,
                                                               XmppXmppStream* stream,
                                                               XmppJid* jid,
                                                               const gchar* hash,
                                                               gpointer self);
static void dino_avatar_manager_fetch_and_store_for_jid_data_free (gpointer _data);
static gboolean dino_avatar_manager_fetch_and_store_for_jid_co (DinoAvatarManagerFetchAndStoreForJidData* _data_);
static void dino_avatar_manager_fetch_and_store_for_jid_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_);
static void dino_avatar_manager_fetch_and_store_data_free (gpointer _data);
static gboolean dino_avatar_manager_fetch_and_store_co (DinoAvatarManagerFetchAndStoreData* _data_);
static void dino_avatar_manager_fetch_and_store_ready (GObject* source_object,
                                                GAsyncResult* _res_,
                                                gpointer _user_data_);
static void dino_avatar_manager_store_image (DinoAvatarManager* self,
                                      const gchar* id,
                                      GBytes* data,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_);
static void dino_avatar_manager_store_image_finish (DinoAvatarManager* self,
                                             GAsyncResult* _res_);
static void dino_avatar_manager_store_image_data_free (gpointer _data);
static gboolean dino_avatar_manager_store_image_co (DinoAvatarManagerStoreImageData* _data_);
static void dino_avatar_manager_store_image_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_);
static void dino_avatar_manager_get_image_data_free (gpointer _data);
static gboolean dino_avatar_manager_get_image_co (DinoAvatarManagerGetImageData* _data_);
static void dino_avatar_manager_get_image_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_);
static void g_cclosure_user_marshal_VOID__XMPP_JID_OBJECT (GClosure * closure,
                                                    GValue * return_value,
                                                    guint n_param_values,
                                                    const GValue * param_values,
                                                    gpointer invocation_hint,
                                                    gpointer marshal_data);
static void dino_avatar_manager_finalize (GObject * obj);
static GType dino_avatar_manager_get_type_once (void);
static void _vala_dino_avatar_manager_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec);
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
dino_avatar_manager_get_instance_private (DinoAvatarManager* self)
{
	return G_STRUCT_MEMBER_P (self, DinoAvatarManager_private_offset);
}

static GType
dino_avatar_manager_source_get_type_once (void)
{
	static const GEnumValue values[] = {{DINO_AVATAR_MANAGER_SOURCE_USER_AVATARS, "DINO_AVATAR_MANAGER_SOURCE_USER_AVATARS", "user-avatars"}, {DINO_AVATAR_MANAGER_SOURCE_VCARD, "DINO_AVATAR_MANAGER_SOURCE_VCARD", "vcard"}, {0, NULL, NULL}};
	GType dino_avatar_manager_source_type_id;
	dino_avatar_manager_source_type_id = g_enum_register_static ("DinoAvatarManagerSource", values);
	return dino_avatar_manager_source_type_id;
}

static GType
dino_avatar_manager_source_get_type (void)
{
	static volatile gsize dino_avatar_manager_source_type_id__once = 0;
	if (g_once_init_enter (&dino_avatar_manager_source_type_id__once)) {
		GType dino_avatar_manager_source_type_id;
		dino_avatar_manager_source_type_id = dino_avatar_manager_source_get_type_once ();
		g_once_init_leave (&dino_avatar_manager_source_type_id__once, dino_avatar_manager_source_type_id);
	}
	return dino_avatar_manager_source_type_id__once;
}

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

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

void
dino_avatar_manager_start (DinoStreamInteractor* stream_interactor,
                           DinoDatabase* db)
{
	DinoAvatarManager* m = NULL;
	DinoAvatarManager* _tmp0_;
	g_return_if_fail (stream_interactor != NULL);
	g_return_if_fail (db != NULL);
	_tmp0_ = dino_avatar_manager_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_avatar_manager_on_account_added_dino_stream_interactor_account_added (DinoStreamInteractor* _sender,
                                                                            DinoEntitiesAccount* account,
                                                                            gpointer self)
{
	dino_avatar_manager_on_account_added ((DinoAvatarManager*) self, account);
}

static void
__lambda113_ (DinoAvatarManager* self,
              DinoEntitiesAccount* _,
              GeeArrayList* modules)
{
	XmppXepUserAvatarsModule* _tmp0_;
	XmppXepUserAvatarsModule* _tmp1_;
	XmppXepVCardModule* _tmp2_;
	XmppXepVCardModule* _tmp3_;
	g_return_if_fail (_ != NULL);
	g_return_if_fail (modules != NULL);
	_tmp0_ = xmpp_xep_user_avatars_module_new ();
	_tmp1_ = _tmp0_;
	gee_abstract_collection_add ((GeeAbstractCollection*) modules, (XmppXmppStreamModule*) _tmp1_);
	_g_object_unref0 (_tmp1_);
	_tmp2_ = xmpp_xep_vcard_module_new ();
	_tmp3_ = _tmp2_;
	gee_abstract_collection_add ((GeeAbstractCollection*) modules, (XmppXmppStreamModule*) _tmp3_);
	_g_object_unref0 (_tmp3_);
}

static void
___lambda113__dino_module_manager_initialize_account_modules (DinoModuleManager* _sender,
                                                              DinoEntitiesAccount* account,
                                                              GeeArrayList* modules,
                                                              gpointer self)
{
	__lambda113_ ((DinoAvatarManager*) self, account, modules);
}

static DinoAvatarManager*
dino_avatar_manager_construct (GType object_type,
                               DinoStreamInteractor* stream_interactor,
                               DinoDatabase* db)
{
	DinoAvatarManager * self = NULL;
	DinoStreamInteractor* _tmp0_;
	DinoDatabase* _tmp1_;
	GFile* old_avatars = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GFile* _tmp4_;
	GFile* _tmp5_;
	GFile* new_avatars = NULL;
	gchar* _tmp6_;
	gchar* _tmp7_;
	GFile* _tmp8_;
	GFile* _tmp9_;
	GFile* _tmp10_;
	gchar* _tmp11_;
	GFile* _tmp12_;
	DinoModuleManager* _tmp45_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoAvatarManager*) 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_get_storage_dir ();
	_tmp3_ = _tmp2_;
	_tmp4_ = g_file_new_build_filename (_tmp3_, "avatars", NULL);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	old_avatars = _tmp5_;
	_tmp6_ = dino_get_cache_dir ();
	_tmp7_ = _tmp6_;
	_tmp8_ = g_file_new_build_filename (_tmp7_, "avatars", NULL);
	_tmp9_ = _tmp8_;
	_g_free0 (_tmp7_);
	new_avatars = _tmp9_;
	_tmp10_ = new_avatars;
	_tmp11_ = g_file_get_path (_tmp10_);
	_g_free0 (self->priv->folder);
	self->priv->folder = _tmp11_;
	_tmp12_ = old_avatars;
	if (g_file_query_exists (_tmp12_, NULL)) {
		GFile* _tmp13_;
		_tmp13_ = new_avatars;
		if (!g_file_query_exists (_tmp13_, NULL)) {
			{
				GFile* _tmp14_;
				GFile* _tmp15_;
				GFile* _tmp16_;
				_tmp14_ = new_avatars;
				_tmp15_ = g_file_get_parent (_tmp14_);
				_tmp16_ = _tmp15_;
				g_file_make_directory_with_parents (_tmp16_, NULL, &_inner_error0_);
				_g_object_unref0 (_tmp16_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					goto __catch0_g_error;
				}
			}
			goto __finally0;
			__catch0_g_error:
			{
				g_clear_error (&_inner_error0_);
			}
			__finally0:
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (new_avatars);
				_g_object_unref0 (old_avatars);
				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;
			}
			{
				GFile* _tmp17_;
				GFile* _tmp18_;
				GFile* _tmp19_;
				gchar* _tmp20_;
				gchar* _tmp21_;
				GFile* _tmp22_;
				gchar* _tmp23_;
				gchar* _tmp24_;
				_tmp17_ = old_avatars;
				_tmp18_ = new_avatars;
				g_file_move (_tmp17_, _tmp18_, G_FILE_COPY_NONE, NULL, NULL, NULL, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					goto __catch1_g_error;
				}
				_tmp19_ = old_avatars;
				_tmp20_ = g_file_get_path (_tmp19_);
				_tmp21_ = _tmp20_;
				_tmp22_ = new_avatars;
				_tmp23_ = g_file_get_path (_tmp22_);
				_tmp24_ = _tmp23_;
				g_debug ("avatar_manager.vala:54: Avatars directory %s moved to %s", _tmp21_, _tmp24_);
				_g_free0 (_tmp24_);
				_g_free0 (_tmp21_);
			}
			goto __finally1;
			__catch1_g_error:
			{
				g_clear_error (&_inner_error0_);
			}
			__finally1:
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (new_avatars);
				_g_object_unref0 (old_avatars);
				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;
			}
		} else {
			{
				GFileEnumerator* enumerator = NULL;
				GFile* _tmp25_;
				GFileEnumerator* _tmp26_;
				GFileInfo* info = NULL;
				GFile* _tmp41_;
				gchar* _tmp42_;
				gchar* _tmp43_;
				_tmp25_ = old_avatars;
				_tmp26_ = g_file_enumerate_children (_tmp25_, "standard::*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &_inner_error0_);
				enumerator = _tmp26_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					goto __catch2_g_error;
				}
				info = NULL;
				while (TRUE) {
					GFileInfo* _tmp27_ = NULL;
					GFileEnumerator* _tmp28_;
					GFileInfo* _tmp29_;
					GFileInfo* _tmp30_;
					GFileInfo* _tmp31_;
					GFile* _tmp32_;
					gchar* _tmp33_;
					gchar* _tmp34_;
					gchar* _tmp35_;
					gchar* _tmp36_;
					GFileInfo* _tmp37_;
					const gchar* _tmp38_;
					gchar* _tmp39_;
					gchar* _tmp40_;
					_tmp28_ = enumerator;
					_tmp29_ = g_file_enumerator_next_file (_tmp28_, NULL, &_inner_error0_);
					_tmp27_ = _tmp29_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_g_object_unref0 (info);
						_g_object_unref0 (enumerator);
						goto __catch2_g_error;
					}
					_tmp30_ = _tmp27_;
					_tmp27_ = NULL;
					_g_object_unref0 (info);
					info = _tmp30_;
					_tmp31_ = info;
					if (!(_tmp31_ != NULL)) {
						_g_object_unref0 (_tmp27_);
						break;
					}
					_tmp32_ = old_avatars;
					_tmp33_ = g_file_get_path (_tmp32_);
					_tmp34_ = _tmp33_;
					_tmp35_ = g_strconcat (_tmp34_, "/", NULL);
					_tmp36_ = _tmp35_;
					_tmp37_ = info;
					_tmp38_ = g_file_info_get_name (_tmp37_);
					_tmp39_ = g_strconcat (_tmp36_, _tmp38_, NULL);
					_tmp40_ = _tmp39_;
					g_remove (_tmp40_);
					_g_free0 (_tmp40_);
					_g_free0 (_tmp36_);
					_g_free0 (_tmp34_);
					_g_object_unref0 (_tmp27_);
				}
				_tmp41_ = old_avatars;
				_tmp42_ = g_file_get_path (_tmp41_);
				_tmp43_ = _tmp42_;
				g_rmdir (_tmp43_);
				_g_free0 (_tmp43_);
				_g_object_unref0 (info);
				_g_object_unref0 (enumerator);
			}
			goto __finally2;
			__catch2_g_error:
			{
				g_clear_error (&_inner_error0_);
			}
			__finally2:
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (new_avatars);
				_g_object_unref0 (old_avatars);
				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;
			}
		}
	}
	{
		GFile* _tmp44_;
		_tmp44_ = new_avatars;
		g_file_make_directory_with_parents (_tmp44_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch3_g_error;
		}
	}
	goto __finally3;
	__catch3_g_error:
	{
		g_clear_error (&_inner_error0_);
	}
	__finally3:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (new_avatars);
		_g_object_unref0 (old_avatars);
		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;
	}
	g_signal_connect_object (stream_interactor, "account-added", (GCallback) _dino_avatar_manager_on_account_added_dino_stream_interactor_account_added, self, 0);
	_tmp45_ = stream_interactor->module_manager;
	g_signal_connect_object (_tmp45_, "initialize-account-modules", (GCallback) ___lambda113__dino_module_manager_initialize_account_modules, self, 0);
	_g_object_unref0 (new_avatars);
	_g_object_unref0 (old_avatars);
	return self;
}

static DinoAvatarManager*
dino_avatar_manager_new (DinoStreamInteractor* stream_interactor,
                         DinoDatabase* db)
{
	return dino_avatar_manager_construct (DINO_TYPE_AVATAR_MANAGER, stream_interactor, db);
}

GFile*
dino_avatar_manager_get_avatar_file (DinoAvatarManager* self,
                                     DinoEntitiesAccount* account,
                                     XmppJid* jid_)
{
	gchar* hash = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	GFile* file = NULL;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GFile* _tmp6_;
	GFile* _tmp7_;
	GFile* _tmp8_;
	GFile* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (account != NULL, NULL);
	g_return_val_if_fail (jid_ != NULL, NULL);
	_tmp0_ = dino_avatar_manager_get_avatar_hash (self, account, jid_);
	hash = _tmp0_;
	_tmp1_ = hash;
	if (_tmp1_ == NULL) {
		result = NULL;
		_g_free0 (hash);
		return result;
	}
	_tmp2_ = self->priv->folder;
	_tmp3_ = hash;
	_tmp4_ = g_build_filename (_tmp2_, _tmp3_, NULL);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_file_new_for_path (_tmp5_);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	file = _tmp7_;
	_tmp8_ = file;
	if (!g_file_query_exists (_tmp8_, NULL)) {
		dino_avatar_manager_fetch_and_store_for_jid (self, account, jid_, NULL, NULL);
		result = NULL;
		_g_object_unref0 (file);
		_g_free0 (hash);
		return result;
	} else {
		result = file;
		_g_free0 (hash);
		return result;
	}
}

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

static gchar*
dino_avatar_manager_get_avatar_hash (DinoAvatarManager* self,
                                     DinoEntitiesAccount* account,
                                     XmppJid* jid_)
{
	XmppJid* jid = NULL;
	XmppJid* _tmp0_;
	DinoStreamInteractor* _tmp1_;
	DinoModuleIdentity* _tmp2_;
	gpointer _tmp3_;
	DinoMucManager* _tmp4_;
	gboolean _tmp5_;
	GeeHashMap* _tmp8_;
	XmppJid* _tmp9_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (account != NULL, NULL);
	g_return_val_if_fail (jid_ != NULL, NULL);
	_tmp0_ = _xmpp_jid_ref0 (jid_);
	jid = _tmp0_;
	_tmp1_ = self->priv->stream_interactor;
	_tmp2_ = dino_muc_manager_IDENTITY;
	_tmp3_ = dino_stream_interactor_get_module (_tmp1_, DINO_TYPE_MUC_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp2_);
	_tmp4_ = (DinoMucManager*) _tmp3_;
	_tmp5_ = !dino_muc_manager_is_groupchat_occupant (_tmp4_, jid_, account);
	_g_object_unref0 (_tmp4_);
	if (_tmp5_) {
		XmppJid* _tmp6_;
		XmppJid* _tmp7_;
		_tmp6_ = xmpp_jid_get_bare_jid (jid_);
		_tmp7_ = _tmp6_;
		_xmpp_jid_unref0 (jid);
		jid = _tmp7_;
	}
	_tmp8_ = self->priv->user_avatars;
	_tmp9_ = jid;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp8_, _tmp9_)) {
		GeeHashMap* _tmp10_;
		XmppJid* _tmp11_;
		gpointer _tmp12_;
		_tmp10_ = self->priv->user_avatars;
		_tmp11_ = jid;
		_tmp12_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp10_, _tmp11_);
		result = (gchar*) _tmp12_;
		_xmpp_jid_unref0 (jid);
		return result;
	} else {
		GeeHashMap* _tmp13_;
		XmppJid* _tmp14_;
		_tmp13_ = self->priv->vcard_avatars;
		_tmp14_ = jid;
		if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp13_, _tmp14_)) {
			GeeHashMap* _tmp15_;
			XmppJid* _tmp16_;
			gpointer _tmp17_;
			_tmp15_ = self->priv->vcard_avatars;
			_tmp16_ = jid;
			_tmp17_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp15_, _tmp16_);
			result = (gchar*) _tmp17_;
			_xmpp_jid_unref0 (jid);
			return result;
		} else {
			result = NULL;
			_xmpp_jid_unref0 (jid);
			return result;
		}
	}
}

gboolean
dino_avatar_manager_has_avatar_cached (DinoAvatarManager* self,
                                       DinoEntitiesAccount* account,
                                       XmppJid* jid)
{
	gchar* hash = NULL;
	gchar* _tmp0_;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (account != NULL, FALSE);
	g_return_val_if_fail (jid != NULL, FALSE);
	_tmp0_ = dino_avatar_manager_get_avatar_hash (self, account, jid);
	hash = _tmp0_;
	_tmp2_ = hash;
	if (_tmp2_ != NULL) {
		GeeHashMap* _tmp3_;
		const gchar* _tmp4_;
		_tmp3_ = self->priv->cached_pixbuf;
		_tmp4_ = hash;
		_tmp1_ = gee_abstract_map_has_key ((GeeAbstractMap*) _tmp3_, _tmp4_);
	} else {
		_tmp1_ = FALSE;
	}
	result = _tmp1_;
	_g_free0 (hash);
	return result;
}

gboolean
dino_avatar_manager_has_avatar (DinoAvatarManager* self,
                                DinoEntitiesAccount* account,
                                XmppJid* jid)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (account != NULL, FALSE);
	g_return_val_if_fail (jid != NULL, FALSE);
	_tmp0_ = dino_avatar_manager_get_avatar_hash (self, account, jid);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_ != NULL;
	_g_free0 (_tmp1_);
	result = _tmp2_;
	return result;
}

GdkPixbuf*
dino_avatar_manager_get_cached_avatar (DinoAvatarManager* self,
                                       DinoEntitiesAccount* account,
                                       XmppJid* jid_)
{
	gchar* hash = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	GeeHashMap* _tmp2_;
	const gchar* _tmp3_;
	GdkPixbuf* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (account != NULL, NULL);
	g_return_val_if_fail (jid_ != NULL, NULL);
	_tmp0_ = dino_avatar_manager_get_avatar_hash (self, account, jid_);
	hash = _tmp0_;
	_tmp1_ = hash;
	if (_tmp1_ == NULL) {
		result = NULL;
		_g_free0 (hash);
		return result;
	}
	_tmp2_ = self->priv->cached_pixbuf;
	_tmp3_ = hash;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp2_, _tmp3_)) {
		GeeHashMap* _tmp4_;
		const gchar* _tmp5_;
		gpointer _tmp6_;
		_tmp4_ = self->priv->cached_pixbuf;
		_tmp5_ = hash;
		_tmp6_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp4_, _tmp5_);
		result = (GdkPixbuf*) _tmp6_;
		_g_free0 (hash);
		return result;
	}
	result = NULL;
	_g_free0 (hash);
	return result;
}

static void
dino_avatar_manager_get_avatar_data_free (gpointer _data)
{
	DinoAvatarManagerGetAvatarData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->account);
	_xmpp_jid_unref0 (_data_->jid_);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (DinoAvatarManagerGetAvatarData, _data_);
}

void
dino_avatar_manager_get_avatar (DinoAvatarManager* self,
                                DinoEntitiesAccount* account,
                                XmppJid* jid_,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_)
{
	DinoAvatarManagerGetAvatarData* _data_;
	DinoAvatarManager* _tmp0_;
	DinoEntitiesAccount* _tmp1_;
	XmppJid* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid_ != NULL);
	_data_ = g_slice_new0 (DinoAvatarManagerGetAvatarData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_avatar_manager_get_avatar_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (account);
	_g_object_unref0 (_data_->account);
	_data_->account = _tmp1_;
	_tmp2_ = _xmpp_jid_ref0 (jid_);
	_xmpp_jid_unref0 (_data_->jid_);
	_data_->jid_ = _tmp2_;
	dino_avatar_manager_get_avatar_co (_data_);
}

GdkPixbuf*
dino_avatar_manager_get_avatar_finish (DinoAvatarManager* self,
                                       GAsyncResult* _res_)
{
	GdkPixbuf* result;
	DinoAvatarManagerGetAvatarData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static gboolean
_dino_avatar_manager_get_avatar_co_gsource_func (gpointer self)
{
	gboolean result;
	result = dino_avatar_manager_get_avatar_co (self);
	return result;
}

static void
dino_avatar_manager_get_avatar_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_)
{
	DinoAvatarManagerGetAvatarData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_avatar_manager_get_avatar_co (_data_);
}

static gboolean
dino_avatar_manager_get_avatar_co (DinoAvatarManagerGetAvatarData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _xmpp_jid_ref0 (_data_->jid_);
	_data_->jid = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->self->priv->stream_interactor;
	_data_->_tmp2_ = dino_muc_manager_IDENTITY;
	_data_->_tmp3_ = dino_stream_interactor_get_module (_data_->_tmp1_, DINO_TYPE_MUC_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp2_);
	_data_->_tmp4_ = (DinoMucManager*) _data_->_tmp3_;
	_data_->_tmp5_ = !dino_muc_manager_is_groupchat_occupant (_data_->_tmp4_, _data_->jid_, _data_->account);
	_g_object_unref0 (_data_->_tmp4_);
	if (_data_->_tmp5_) {
		_data_->_tmp6_ = xmpp_jid_get_bare_jid (_data_->jid_);
		_data_->_tmp7_ = _data_->_tmp6_;
		_xmpp_jid_unref0 (_data_->jid);
		_data_->jid = _data_->_tmp7_;
	}
	_data_->source = -1;
	_data_->hash = NULL;
	_data_->_tmp8_ = _data_->self->priv->user_avatars;
	_data_->_tmp9_ = _data_->jid;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp8_, _data_->_tmp9_)) {
		_data_->_tmp10_ = _data_->self->priv->user_avatars;
		_data_->_tmp11_ = _data_->jid;
		_data_->_tmp12_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp10_, _data_->_tmp11_);
		_g_free0 (_data_->hash);
		_data_->hash = (gchar*) _data_->_tmp12_;
		_data_->source = 1;
	} else {
		_data_->_tmp13_ = _data_->self->priv->vcard_avatars;
		_data_->_tmp14_ = _data_->jid;
		if (gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp13_, _data_->_tmp14_)) {
			_data_->_tmp15_ = _data_->self->priv->vcard_avatars;
			_data_->_tmp16_ = _data_->jid;
			_data_->_tmp17_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp15_, _data_->_tmp16_);
			_g_free0 (_data_->hash);
			_data_->hash = (gchar*) _data_->_tmp17_;
			_data_->source = 2;
		}
	}
	_data_->_tmp18_ = _data_->hash;
	if (_data_->_tmp18_ == NULL) {
		_data_->result = NULL;
		_g_free0 (_data_->hash);
		_xmpp_jid_unref0 (_data_->jid);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp19_ = _data_->self->priv->cached_pixbuf;
	_data_->_tmp20_ = _data_->hash;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp19_, _data_->_tmp20_)) {
		_data_->_tmp21_ = _data_->self->priv->cached_pixbuf;
		_data_->_tmp22_ = _data_->hash;
		_data_->_tmp23_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp21_, _data_->_tmp22_);
		_data_->result = (GdkPixbuf*) _data_->_tmp23_;
		_g_free0 (_data_->hash);
		_xmpp_jid_unref0 (_data_->jid);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp24_ = _data_->self->priv->stream_interactor;
	_data_->_tmp25_ = dino_stream_interactor_get_stream (_data_->_tmp24_, _data_->account);
	_data_->stream = _data_->_tmp25_;
	_data_->_tmp27_ = _data_->stream;
	if (_data_->_tmp27_ == NULL) {
		_data_->_tmp26_ = TRUE;
	} else {
		_data_->_tmp28_ = _data_->stream;
		_data_->_tmp29_ = xmpp_xmpp_stream_get_negotiation_complete (_data_->_tmp28_);
		_data_->_tmp30_ = _data_->_tmp29_;
		_data_->_tmp26_ = !_data_->_tmp30_;
	}
	if (_data_->_tmp26_) {
		_data_->result = NULL;
		_g_object_unref0 (_data_->stream);
		_g_free0 (_data_->hash);
		_xmpp_jid_unref0 (_data_->jid);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp31_ = _data_->self->priv->pending_pixbuf;
	_data_->_tmp32_ = _data_->hash;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp31_, _data_->_tmp32_)) {
		_data_->_tmp33_ = _data_->self->priv->pending_pixbuf;
		_data_->_tmp34_ = _data_->hash;
		_data_->_tmp35_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp33_, _data_->_tmp34_);
		_data_->_tmp36_ = (GeeList*) _data_->_tmp35_;
		_data_->_tmp37_ = xmpp_source_func_wrapper_new (_dino_avatar_manager_get_avatar_co_gsource_func, _data_, NULL);
		_data_->_tmp38_ = _data_->_tmp37_;
		gee_collection_add ((GeeCollection*) _data_->_tmp36_, _data_->_tmp38_);
		_g_object_unref0 (_data_->_tmp38_);
		_g_object_unref0 (_data_->_tmp36_);
		_data_->_state_ = 1;
		return FALSE;
		_state_1:
		;
		_data_->_tmp39_ = _data_->self->priv->cached_pixbuf;
		_data_->_tmp40_ = _data_->hash;
		_data_->_tmp41_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp39_, _data_->_tmp40_);
		_data_->result = (GdkPixbuf*) _data_->_tmp41_;
		_g_object_unref0 (_data_->stream);
		_g_free0 (_data_->hash);
		_xmpp_jid_unref0 (_data_->jid);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp42_ = _data_->self->priv->pending_pixbuf;
	_data_->_tmp43_ = _data_->hash;
	_data_->_tmp44_ = gee_array_list_new (XMPP_TYPE_SOURCE_FUNC_WRAPPER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->_tmp45_ = _data_->_tmp44_;
	gee_abstract_map_set ((GeeAbstractMap*) _data_->_tmp42_, _data_->_tmp43_, (GeeList*) _data_->_tmp45_);
	_g_object_unref0 (_data_->_tmp45_);
	_data_->_tmp46_ = _data_->hash;
	_data_->_state_ = 2;
	dino_avatar_manager_get_image (_data_->self, _data_->_tmp46_, dino_avatar_manager_get_avatar_ready, _data_);
	return FALSE;
	_state_2:
	_data_->_tmp47_ = dino_avatar_manager_get_image_finish (_data_->self, _data_->_res_);
	_data_->image = _data_->_tmp47_;
	_data_->_tmp48_ = _data_->image;
	if (_data_->_tmp48_ != NULL) {
		_data_->_tmp49_ = _data_->self->priv->cached_pixbuf;
		_data_->_tmp50_ = _data_->hash;
		_data_->_tmp51_ = _data_->image;
		gee_abstract_map_set ((GeeAbstractMap*) _data_->_tmp49_, _data_->_tmp50_, _data_->_tmp51_);
	} else {
		_data_->_tmp52_ = _data_->stream;
		_data_->_tmp53_ = _data_->jid;
		_data_->_tmp54_ = _data_->hash;
		_data_->_state_ = 3;
		dino_avatar_manager_fetch_and_store (_data_->self, _data_->_tmp52_, _data_->account, _data_->_tmp53_, _data_->source, _data_->_tmp54_, dino_avatar_manager_get_avatar_ready, _data_);
		return FALSE;
		_state_3:
		if (dino_avatar_manager_fetch_and_store_finish (_data_->self, _data_->_res_)) {
			_data_->_tmp55_ = _data_->hash;
			_data_->_state_ = 4;
			dino_avatar_manager_get_image (_data_->self, _data_->_tmp55_, dino_avatar_manager_get_avatar_ready, _data_);
			return FALSE;
			_state_4:
			_data_->_tmp56_ = dino_avatar_manager_get_image_finish (_data_->self, _data_->_res_);
			_g_object_unref0 (_data_->image);
			_data_->image = _data_->_tmp56_;
		}
		_data_->_tmp57_ = _data_->self->priv->cached_pixbuf;
		_data_->_tmp58_ = _data_->hash;
		_data_->_tmp59_ = _data_->image;
		gee_abstract_map_set ((GeeAbstractMap*) _data_->_tmp57_, _data_->_tmp58_, _data_->_tmp59_);
	}
	{
		_data_->_tmp60_ = _data_->self->priv->pending_pixbuf;
		_data_->_tmp61_ = _data_->hash;
		_data_->_tmp62_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp60_, _data_->_tmp61_);
		_data_->_sfw_list = (GeeList*) _data_->_tmp62_;
		_data_->_tmp63_ = _data_->_sfw_list;
		_data_->_tmp64_ = gee_collection_get_size ((GeeCollection*) _data_->_tmp63_);
		_data_->_tmp65_ = _data_->_tmp64_;
		_data_->_sfw_size = _data_->_tmp65_;
		_data_->_sfw_index = -1;
		while (TRUE) {
			_data_->_sfw_index = _data_->_sfw_index + 1;
			_data_->_tmp66_ = _data_->_sfw_index;
			_data_->_tmp67_ = _data_->_sfw_size;
			if (!(_data_->_tmp66_ < _data_->_tmp67_)) {
				break;
			}
			_data_->_tmp68_ = _data_->_sfw_list;
			_data_->_tmp69_ = gee_list_get (_data_->_tmp68_, _data_->_sfw_index);
			_data_->sfw = (XmppSourceFuncWrapper*) _data_->_tmp69_;
			_data_->_tmp70_ = _data_->sfw;
			_data_->_tmp71_ = _data_->_tmp70_->sfun;
			_data_->_tmp71__target = _data_->_tmp70_->sfun_target;
			_data_->_tmp71_ (_data_->_tmp71__target);
			_g_object_unref0 (_data_->sfw);
		}
		_g_object_unref0 (_data_->_sfw_list);
	}
	_data_->result = _data_->image;
	_g_object_unref0 (_data_->stream);
	_g_free0 (_data_->hash);
	_xmpp_jid_unref0 (_data_->jid);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

void
dino_avatar_manager_publish (DinoAvatarManager* self,
                             DinoEntitiesAccount* account,
                             const gchar* file)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (file != NULL);
	{
		GdkPixbuf* pixbuf = NULL;
		GdkPixbuf* _tmp0_;
		gboolean _tmp1_ = FALSE;
		GdkPixbuf* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		GdkPixbuf* _tmp5_;
		gint _tmp6_;
		gint _tmp7_;
		guint8* buffer = NULL;
		gint buffer_length1 = 0;
		gint _buffer_size_ = 0;
		GdkPixbuf* _tmp37_;
		guint8* _tmp38_ = NULL;
		gsize _tmp39_ = 0;
		XmppXmppStream* stream = NULL;
		DinoStreamInteractor* _tmp40_;
		XmppXmppStream* _tmp41_;
		XmppXmppStream* _tmp42_;
		_tmp0_ = gdk_pixbuf_new_from_file (file, &_inner_error0_);
		pixbuf = _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp2_ = pixbuf;
		_tmp3_ = gdk_pixbuf_get_width (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = pixbuf;
		_tmp6_ = gdk_pixbuf_get_height (_tmp5_);
		_tmp7_ = _tmp6_;
		if (_tmp4_ >= _tmp7_) {
			GdkPixbuf* _tmp8_;
			gint _tmp9_;
			gint _tmp10_;
			_tmp8_ = pixbuf;
			_tmp9_ = gdk_pixbuf_get_width (_tmp8_);
			_tmp10_ = _tmp9_;
			_tmp1_ = _tmp10_ > DINO_AVATAR_MANAGER_MAX_PIXEL;
		} else {
			_tmp1_ = FALSE;
		}
		if (_tmp1_) {
			gint dest_height = 0;
			GdkPixbuf* _tmp11_;
			gint _tmp12_;
			gint _tmp13_;
			GdkPixbuf* _tmp14_;
			gint _tmp15_;
			gint _tmp16_;
			GdkPixbuf* _tmp17_;
			GdkPixbuf* _tmp18_;
			_tmp11_ = pixbuf;
			_tmp12_ = gdk_pixbuf_get_width (_tmp11_);
			_tmp13_ = _tmp12_;
			_tmp14_ = pixbuf;
			_tmp15_ = gdk_pixbuf_get_height (_tmp14_);
			_tmp16_ = _tmp15_;
			dest_height = (gint) ((((gfloat) DINO_AVATAR_MANAGER_MAX_PIXEL) / _tmp13_) * _tmp16_);
			_tmp17_ = pixbuf;
			_tmp18_ = gdk_pixbuf_scale_simple (_tmp17_, DINO_AVATAR_MANAGER_MAX_PIXEL, dest_height, GDK_INTERP_BILINEAR);
			_g_object_unref0 (pixbuf);
			pixbuf = _tmp18_;
		} else {
			gboolean _tmp19_ = FALSE;
			GdkPixbuf* _tmp20_;
			gint _tmp21_;
			gint _tmp22_;
			GdkPixbuf* _tmp23_;
			gint _tmp24_;
			gint _tmp25_;
			_tmp20_ = pixbuf;
			_tmp21_ = gdk_pixbuf_get_height (_tmp20_);
			_tmp22_ = _tmp21_;
			_tmp23_ = pixbuf;
			_tmp24_ = gdk_pixbuf_get_width (_tmp23_);
			_tmp25_ = _tmp24_;
			if (_tmp22_ > _tmp25_) {
				GdkPixbuf* _tmp26_;
				gint _tmp27_;
				gint _tmp28_;
				_tmp26_ = pixbuf;
				_tmp27_ = gdk_pixbuf_get_width (_tmp26_);
				_tmp28_ = _tmp27_;
				_tmp19_ = _tmp28_ > DINO_AVATAR_MANAGER_MAX_PIXEL;
			} else {
				_tmp19_ = FALSE;
			}
			if (_tmp19_) {
				gint dest_width = 0;
				GdkPixbuf* _tmp29_;
				gint _tmp30_;
				gint _tmp31_;
				GdkPixbuf* _tmp32_;
				gint _tmp33_;
				gint _tmp34_;
				GdkPixbuf* _tmp35_;
				GdkPixbuf* _tmp36_;
				_tmp29_ = pixbuf;
				_tmp30_ = gdk_pixbuf_get_height (_tmp29_);
				_tmp31_ = _tmp30_;
				_tmp32_ = pixbuf;
				_tmp33_ = gdk_pixbuf_get_width (_tmp32_);
				_tmp34_ = _tmp33_;
				dest_width = (gint) ((((gfloat) DINO_AVATAR_MANAGER_MAX_PIXEL) / _tmp31_) * _tmp34_);
				_tmp35_ = pixbuf;
				_tmp36_ = gdk_pixbuf_scale_simple (_tmp35_, dest_width, DINO_AVATAR_MANAGER_MAX_PIXEL, GDK_INTERP_BILINEAR);
				_g_object_unref0 (pixbuf);
				pixbuf = _tmp36_;
			}
		}
		_tmp37_ = pixbuf;
		gdk_pixbuf_save_to_buffer (_tmp37_, &_tmp38_, &_tmp39_, "png", &_inner_error0_, NULL);
		buffer = (g_free (buffer), NULL);
		buffer = _tmp38_;
		buffer_length1 = _tmp39_;
		_buffer_size_ = buffer_length1;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			buffer = (g_free (buffer), NULL);
			_g_object_unref0 (pixbuf);
			goto __catch0_g_error;
		}
		_tmp40_ = self->priv->stream_interactor;
		_tmp41_ = dino_stream_interactor_get_stream (_tmp40_, account);
		stream = _tmp41_;
		_tmp42_ = stream;
		if (_tmp42_ != NULL) {
			XmppXmppStream* _tmp43_;
			guint8* _tmp44_;
			gint _tmp44__length1;
			GdkPixbuf* _tmp45_;
			gint _tmp46_;
			gint _tmp47_;
			GdkPixbuf* _tmp48_;
			gint _tmp49_;
			gint _tmp50_;
			_tmp43_ = stream;
			_tmp44_ = buffer;
			_tmp44__length1 = buffer_length1;
			_tmp45_ = pixbuf;
			_tmp46_ = gdk_pixbuf_get_width (_tmp45_);
			_tmp47_ = _tmp46_;
			_tmp48_ = pixbuf;
			_tmp49_ = gdk_pixbuf_get_height (_tmp48_);
			_tmp50_ = _tmp49_;
			xmpp_xep_user_avatars_publish_png (_tmp43_, _tmp44_, (gint) _tmp44__length1, _tmp47_, _tmp50_);
		}
		_g_object_unref0 (stream);
		buffer = (g_free (buffer), NULL);
		_g_object_unref0 (pixbuf);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp51_;
		const gchar* _tmp52_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp51_ = e;
		_tmp52_ = _tmp51_->message;
		g_warning ("avatar_manager.vala:190: %s", _tmp52_);
		_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;
	}
}

void
dino_avatar_manager_unset_avatar (DinoAvatarManager* self,
                                  DinoEntitiesAccount* account)
{
	XmppXmppStream* stream = NULL;
	DinoStreamInteractor* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppXmppStream* _tmp2_;
	XmppXmppStream* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	_tmp0_ = self->priv->stream_interactor;
	_tmp1_ = dino_stream_interactor_get_stream (_tmp0_, account);
	stream = _tmp1_;
	_tmp2_ = stream;
	if (_tmp2_ == NULL) {
		_g_object_unref0 (stream);
		return;
	}
	_tmp3_ = stream;
	xmpp_xep_user_avatars_unset_avatar (_tmp3_);
	_g_object_unref0 (stream);
}

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		DinoAvatarManager* self;
		self = _data1_->self;
		_g_object_unref0 (_data1_->account);
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

static void
__lambda110_ (Block1Data* _data1_,
              XmppXmppStream* stream,
              XmppJid* jid,
              const gchar* id)
{
	DinoAvatarManager* self;
	self = _data1_->self;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (jid != NULL);
	g_return_if_fail (id != NULL);
	dino_avatar_manager_on_user_avatar_received (self, _data1_->account, jid, id);
}

static void
___lambda110__xmpp_xep_user_avatars_module_received_avatar_hash (XmppXepUserAvatarsModule* _sender,
                                                                 XmppXmppStream* stream,
                                                                 XmppJid* jid,
                                                                 const gchar* id,
                                                                 gpointer self)
{
	__lambda110_ (self, stream, jid, id);
}

static void
__lambda111_ (Block1Data* _data1_,
              XmppXmppStream* stream,
              XmppJid* jid)
{
	DinoAvatarManager* self;
	self = _data1_->self;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (jid != NULL);
	dino_avatar_manager_on_user_avatar_removed (self, _data1_->account, jid);
}

static void
___lambda111__xmpp_xep_user_avatars_module_avatar_removed (XmppXepUserAvatarsModule* _sender,
                                                           XmppXmppStream* stream,
                                                           XmppJid* jid,
                                                           gpointer self)
{
	__lambda111_ (self, stream, jid);
}

static void
__lambda112_ (Block1Data* _data1_,
              XmppXmppStream* stream,
              XmppJid* jid,
              const gchar* id)
{
	DinoAvatarManager* self;
	self = _data1_->self;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (jid != NULL);
	g_return_if_fail (id != NULL);
	dino_avatar_manager_on_vcard_avatar_received (self, _data1_->account, jid, id);
}

static void
___lambda112__xmpp_xep_vcard_module_received_avatar_hash (XmppXepVCardModule* _sender,
                                                          XmppXmppStream* stream,
                                                          XmppJid* jid,
                                                          const gchar* hash,
                                                          gpointer self)
{
	__lambda112_ (self, stream, jid, hash);
}

static void
dino_avatar_manager_on_account_added (DinoAvatarManager* self,
                                      DinoEntitiesAccount* account)
{
	Block1Data* _data1_;
	DinoEntitiesAccount* _tmp0_;
	DinoStreamInteractor* _tmp1_;
	DinoModuleManager* _tmp2_;
	XmppModuleIdentity* _tmp3_;
	gpointer _tmp4_;
	XmppXepUserAvatarsModule* _tmp5_;
	DinoStreamInteractor* _tmp6_;
	DinoModuleManager* _tmp7_;
	XmppModuleIdentity* _tmp8_;
	gpointer _tmp9_;
	XmppXepUserAvatarsModule* _tmp10_;
	DinoStreamInteractor* _tmp11_;
	DinoModuleManager* _tmp12_;
	XmppModuleIdentity* _tmp13_;
	gpointer _tmp14_;
	XmppXepVCardModule* _tmp15_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (account);
	_g_object_unref0 (_data1_->account);
	_data1_->account = _tmp0_;
	_tmp1_ = self->priv->stream_interactor;
	_tmp2_ = _tmp1_->module_manager;
	_tmp3_ = xmpp_xep_user_avatars_module_IDENTITY;
	_tmp4_ = dino_module_manager_get_module (_tmp2_, XMPP_XEP_USER_AVATARS_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data1_->account, _tmp3_);
	_tmp5_ = (XmppXepUserAvatarsModule*) _tmp4_;
	g_signal_connect_data (_tmp5_, "received-avatar-hash", (GCallback) ___lambda110__xmpp_xep_user_avatars_module_received_avatar_hash, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	_g_object_unref0 (_tmp5_);
	_tmp6_ = self->priv->stream_interactor;
	_tmp7_ = _tmp6_->module_manager;
	_tmp8_ = xmpp_xep_user_avatars_module_IDENTITY;
	_tmp9_ = dino_module_manager_get_module (_tmp7_, XMPP_XEP_USER_AVATARS_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data1_->account, _tmp8_);
	_tmp10_ = (XmppXepUserAvatarsModule*) _tmp9_;
	g_signal_connect_data (_tmp10_, "avatar-removed", (GCallback) ___lambda111__xmpp_xep_user_avatars_module_avatar_removed, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	_g_object_unref0 (_tmp10_);
	_tmp11_ = self->priv->stream_interactor;
	_tmp12_ = _tmp11_->module_manager;
	_tmp13_ = xmpp_xep_vcard_module_IDENTITY;
	_tmp14_ = dino_module_manager_get_module (_tmp12_, XMPP_XEP_VCARD_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data1_->account, _tmp13_);
	_tmp15_ = (XmppXepVCardModule*) _tmp14_;
	g_signal_connect_data (_tmp15_, "received-avatar-hash", (GCallback) ___lambda112__xmpp_xep_vcard_module_received_avatar_hash, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	_g_object_unref0 (_tmp15_);
	{
		GeeIterator* _entry_it = NULL;
		GeeHashMap* _tmp16_;
		GeeHashMap* _tmp17_;
		GeeSet* _tmp18_;
		GeeSet* _tmp19_;
		GeeSet* _tmp20_;
		GeeIterator* _tmp21_;
		GeeIterator* _tmp22_;
		_tmp16_ = dino_avatar_manager_get_avatar_hashes (self, _data1_->account, (gint) DINO_AVATAR_MANAGER_SOURCE_USER_AVATARS);
		_tmp17_ = _tmp16_;
		_tmp18_ = gee_abstract_map_get_entries ((GeeAbstractMap*) _tmp17_);
		_tmp19_ = _tmp18_;
		_tmp20_ = _tmp19_;
		_tmp21_ = gee_iterable_iterator ((GeeIterable*) _tmp20_);
		_tmp22_ = _tmp21_;
		_g_object_unref0 (_tmp20_);
		_g_object_unref0 (_tmp17_);
		_entry_it = _tmp22_;
		while (TRUE) {
			GeeIterator* _tmp23_;
			GeeMapEntry* entry = NULL;
			GeeIterator* _tmp24_;
			gpointer _tmp25_;
			GeeMapEntry* _tmp26_;
			gconstpointer _tmp27_;
			gconstpointer _tmp28_;
			GeeMapEntry* _tmp29_;
			gconstpointer _tmp30_;
			gconstpointer _tmp31_;
			_tmp23_ = _entry_it;
			if (!gee_iterator_next (_tmp23_)) {
				break;
			}
			_tmp24_ = _entry_it;
			_tmp25_ = gee_iterator_get (_tmp24_);
			entry = (GeeMapEntry*) _tmp25_;
			_tmp26_ = entry;
			_tmp27_ = gee_map_entry_get_key (_tmp26_);
			_tmp28_ = _tmp27_;
			_tmp29_ = entry;
			_tmp30_ = gee_map_entry_get_value (_tmp29_);
			_tmp31_ = _tmp30_;
			dino_avatar_manager_on_user_avatar_received (self, _data1_->account, (XmppJid*) _tmp28_, (const gchar*) _tmp31_);
			_g_object_unref0 (entry);
		}
		_g_object_unref0 (_entry_it);
	}
	{
		GeeIterator* _entry_it = NULL;
		GeeHashMap* _tmp32_;
		GeeHashMap* _tmp33_;
		GeeSet* _tmp34_;
		GeeSet* _tmp35_;
		GeeSet* _tmp36_;
		GeeIterator* _tmp37_;
		GeeIterator* _tmp38_;
		_tmp32_ = dino_avatar_manager_get_avatar_hashes (self, _data1_->account, (gint) DINO_AVATAR_MANAGER_SOURCE_VCARD);
		_tmp33_ = _tmp32_;
		_tmp34_ = gee_abstract_map_get_entries ((GeeAbstractMap*) _tmp33_);
		_tmp35_ = _tmp34_;
		_tmp36_ = _tmp35_;
		_tmp37_ = gee_iterable_iterator ((GeeIterable*) _tmp36_);
		_tmp38_ = _tmp37_;
		_g_object_unref0 (_tmp36_);
		_g_object_unref0 (_tmp33_);
		_entry_it = _tmp38_;
		while (TRUE) {
			GeeIterator* _tmp39_;
			GeeMapEntry* entry = NULL;
			GeeIterator* _tmp40_;
			gpointer _tmp41_;
			GeeMapEntry* _tmp42_;
			gconstpointer _tmp43_;
			gconstpointer _tmp44_;
			GeeMapEntry* _tmp45_;
			gconstpointer _tmp46_;
			gconstpointer _tmp47_;
			_tmp39_ = _entry_it;
			if (!gee_iterator_next (_tmp39_)) {
				break;
			}
			_tmp40_ = _entry_it;
			_tmp41_ = gee_iterator_get (_tmp40_);
			entry = (GeeMapEntry*) _tmp41_;
			_tmp42_ = entry;
			_tmp43_ = gee_map_entry_get_key (_tmp42_);
			_tmp44_ = _tmp43_;
			_tmp45_ = entry;
			_tmp46_ = gee_map_entry_get_value (_tmp45_);
			_tmp47_ = _tmp46_;
			dino_avatar_manager_on_vcard_avatar_received (self, _data1_->account, (XmppJid*) _tmp44_, (const gchar*) _tmp47_);
			_g_object_unref0 (entry);
		}
		_g_object_unref0 (_entry_it);
	}
	block1_data_unref (_data1_);
	_data1_ = NULL;
}

static void
dino_avatar_manager_on_user_avatar_received (DinoAvatarManager* self,
                                             DinoEntitiesAccount* account,
                                             XmppJid* jid_,
                                             const gchar* id)
{
	XmppJid* jid = NULL;
	XmppJid* _tmp0_;
	XmppJid* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GeeHashMap* _tmp3_;
	XmppJid* _tmp4_;
	XmppJid* _tmp12_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid_ != NULL);
	g_return_if_fail (id != NULL);
	_tmp0_ = xmpp_jid_get_bare_jid (jid_);
	_tmp1_ = _tmp0_;
	jid = _tmp1_;
	_tmp3_ = self->priv->user_avatars;
	_tmp4_ = jid;
	if (!gee_abstract_map_has_key ((GeeAbstractMap*) _tmp3_, _tmp4_)) {
		_tmp2_ = TRUE;
	} else {
		GeeHashMap* _tmp5_;
		XmppJid* _tmp6_;
		gpointer _tmp7_;
		gchar* _tmp8_;
		_tmp5_ = self->priv->user_avatars;
		_tmp6_ = jid;
		_tmp7_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp5_, _tmp6_);
		_tmp8_ = (gchar*) _tmp7_;
		_tmp2_ = g_strcmp0 (_tmp8_, id) != 0;
		_g_free0 (_tmp8_);
	}
	if (_tmp2_) {
		GeeHashMap* _tmp9_;
		XmppJid* _tmp10_;
		XmppJid* _tmp11_;
		_tmp9_ = self->priv->user_avatars;
		_tmp10_ = jid;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp9_, _tmp10_, id);
		_tmp11_ = jid;
		dino_avatar_manager_set_avatar_hash (self, account, _tmp11_, id, (gint) DINO_AVATAR_MANAGER_SOURCE_USER_AVATARS);
	}
	_tmp12_ = jid;
	g_signal_emit (self, dino_avatar_manager_signals[DINO_AVATAR_MANAGER_RECEIVED_AVATAR_SIGNAL], 0, _tmp12_, account);
	_xmpp_jid_unref0 (jid);
}

static void
dino_avatar_manager_on_user_avatar_removed (DinoAvatarManager* self,
                                            DinoEntitiesAccount* account,
                                            XmppJid* jid_)
{
	XmppJid* jid = NULL;
	XmppJid* _tmp0_;
	XmppJid* _tmp1_;
	GeeHashMap* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid_ != NULL);
	_tmp0_ = xmpp_jid_get_bare_jid (jid_);
	_tmp1_ = _tmp0_;
	jid = _tmp1_;
	_tmp2_ = self->priv->user_avatars;
	gee_abstract_map_unset ((GeeAbstractMap*) _tmp2_, jid, NULL);
	dino_avatar_manager_remove_avatar_hash (self, account, jid, (gint) DINO_AVATAR_MANAGER_SOURCE_USER_AVATARS);
	g_signal_emit (self, dino_avatar_manager_signals[DINO_AVATAR_MANAGER_RECEIVED_AVATAR_SIGNAL], 0, jid, account);
	_xmpp_jid_unref0 (jid);
}

static void
dino_avatar_manager_on_vcard_avatar_received (DinoAvatarManager* self,
                                              DinoEntitiesAccount* account,
                                              XmppJid* jid_,
                                              const gchar* id)
{
	gboolean is_gc = FALSE;
	DinoStreamInteractor* _tmp0_;
	DinoModuleIdentity* _tmp1_;
	gpointer _tmp2_;
	DinoMucManager* _tmp3_;
	XmppJid* _tmp4_;
	XmppJid* _tmp5_;
	XmppJid* _tmp6_;
	gboolean _tmp7_;
	XmppJid* _tmp8_ = NULL;
	XmppJid* jid = NULL;
	XmppJid* _tmp12_;
	gboolean _tmp13_ = FALSE;
	GeeHashMap* _tmp14_;
	XmppJid* _tmp15_;
	XmppJid* _tmp24_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid_ != NULL);
	g_return_if_fail (id != NULL);
	_tmp0_ = self->priv->stream_interactor;
	_tmp1_ = dino_muc_manager_IDENTITY;
	_tmp2_ = dino_stream_interactor_get_module (_tmp0_, DINO_TYPE_MUC_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp1_);
	_tmp3_ = (DinoMucManager*) _tmp2_;
	_tmp4_ = xmpp_jid_get_bare_jid (jid_);
	_tmp5_ = _tmp4_;
	_tmp6_ = _tmp5_;
	_tmp7_ = dino_muc_manager_might_be_groupchat (_tmp3_, _tmp6_, account);
	_xmpp_jid_unref0 (_tmp6_);
	_g_object_unref0 (_tmp3_);
	is_gc = _tmp7_;
	if (is_gc) {
		XmppJid* _tmp9_;
		_tmp9_ = _xmpp_jid_ref0 (jid_);
		_xmpp_jid_unref0 (_tmp8_);
		_tmp8_ = _tmp9_;
	} else {
		XmppJid* _tmp10_;
		XmppJid* _tmp11_;
		_tmp10_ = xmpp_jid_get_bare_jid (jid_);
		_tmp11_ = _tmp10_;
		_xmpp_jid_unref0 (_tmp8_);
		_tmp8_ = _tmp11_;
	}
	_tmp12_ = _tmp8_;
	_tmp8_ = NULL;
	jid = _tmp12_;
	_tmp14_ = self->priv->vcard_avatars;
	_tmp15_ = jid;
	if (!gee_abstract_map_has_key ((GeeAbstractMap*) _tmp14_, _tmp15_)) {
		_tmp13_ = TRUE;
	} else {
		GeeHashMap* _tmp16_;
		XmppJid* _tmp17_;
		gpointer _tmp18_;
		gchar* _tmp19_;
		_tmp16_ = self->priv->vcard_avatars;
		_tmp17_ = jid;
		_tmp18_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp16_, _tmp17_);
		_tmp19_ = (gchar*) _tmp18_;
		_tmp13_ = g_strcmp0 (_tmp19_, id) != 0;
		_g_free0 (_tmp19_);
	}
	if (_tmp13_) {
		GeeHashMap* _tmp20_;
		XmppJid* _tmp21_;
		XmppJid* _tmp22_;
		_tmp20_ = self->priv->vcard_avatars;
		_tmp21_ = jid;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp20_, _tmp21_, id);
		_tmp22_ = jid;
		if (xmpp_jid_is_bare (_tmp22_)) {
			XmppJid* _tmp23_;
			_tmp23_ = jid;
			dino_avatar_manager_set_avatar_hash (self, account, _tmp23_, id, (gint) DINO_AVATAR_MANAGER_SOURCE_VCARD);
		}
	}
	_tmp24_ = jid;
	g_signal_emit (self, dino_avatar_manager_signals[DINO_AVATAR_MANAGER_RECEIVED_AVATAR_SIGNAL], 0, _tmp24_, account);
	_xmpp_jid_unref0 (jid);
	_xmpp_jid_unref0 (_tmp8_);
}

void
dino_avatar_manager_set_avatar_hash (DinoAvatarManager* self,
                                     DinoEntitiesAccount* account,
                                     XmppJid* jid,
                                     const gchar* hash,
                                     gint type)
{
	DinoDatabase* _tmp0_;
	DinoDatabaseAvatarTable* _tmp1_;
	DinoDatabaseAvatarTable* _tmp2_;
	QliteInsertBuilder* _tmp3_;
	QliteInsertBuilder* _tmp4_;
	DinoDatabase* _tmp5_;
	DinoDatabaseAvatarTable* _tmp6_;
	DinoDatabaseAvatarTable* _tmp7_;
	QliteColumn* _tmp8_;
	DinoDatabase* _tmp9_;
	QliteInsertBuilder* _tmp10_;
	QliteInsertBuilder* _tmp11_;
	DinoDatabase* _tmp12_;
	DinoDatabaseAvatarTable* _tmp13_;
	DinoDatabaseAvatarTable* _tmp14_;
	QliteColumn* _tmp15_;
	gint _tmp16_;
	gint _tmp17_;
	QliteInsertBuilder* _tmp18_;
	QliteInsertBuilder* _tmp19_;
	DinoDatabase* _tmp20_;
	DinoDatabaseAvatarTable* _tmp21_;
	DinoDatabaseAvatarTable* _tmp22_;
	QliteColumn* _tmp23_;
	QliteInsertBuilder* _tmp24_;
	QliteInsertBuilder* _tmp25_;
	DinoDatabase* _tmp26_;
	DinoDatabaseAvatarTable* _tmp27_;
	DinoDatabaseAvatarTable* _tmp28_;
	QliteColumn* _tmp29_;
	QliteInsertBuilder* _tmp30_;
	QliteInsertBuilder* _tmp31_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	g_return_if_fail (hash != NULL);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_database_get_avatar (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = qlite_table_insert ((QliteTable*) _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = self->priv->db;
	_tmp6_ = dino_database_get_avatar (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = _tmp7_->jid_id;
	_tmp9_ = self->priv->db;
	_tmp10_ = qlite_insert_builder_value (_tmp4_, G_TYPE_INT, NULL, NULL, _tmp8_, (gpointer) ((gintptr) dino_database_get_jid_id (_tmp9_, jid)));
	_tmp11_ = _tmp10_;
	_tmp12_ = self->priv->db;
	_tmp13_ = dino_database_get_avatar (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = _tmp14_->account_id;
	_tmp16_ = dino_entities_account_get_id (account);
	_tmp17_ = _tmp16_;
	_tmp18_ = qlite_insert_builder_value (_tmp11_, G_TYPE_INT, NULL, NULL, _tmp15_, (gpointer) ((gintptr) _tmp17_));
	_tmp19_ = _tmp18_;
	_tmp20_ = self->priv->db;
	_tmp21_ = dino_database_get_avatar (_tmp20_);
	_tmp22_ = _tmp21_;
	_tmp23_ = _tmp22_->hash;
	_tmp24_ = qlite_insert_builder_value (_tmp19_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp23_, hash);
	_tmp25_ = _tmp24_;
	_tmp26_ = self->priv->db;
	_tmp27_ = dino_database_get_avatar (_tmp26_);
	_tmp28_ = _tmp27_;
	_tmp29_ = _tmp28_->type_;
	_tmp30_ = qlite_insert_builder_value (_tmp25_, G_TYPE_INT, NULL, NULL, _tmp29_, (gpointer) ((gintptr) type));
	_tmp31_ = _tmp30_;
	qlite_insert_builder_perform (_tmp31_);
	_qlite_statement_builder_unref0 (_tmp31_);
	_qlite_statement_builder_unref0 (_tmp25_);
	_qlite_statement_builder_unref0 (_tmp19_);
	_qlite_statement_builder_unref0 (_tmp11_);
	_qlite_statement_builder_unref0 (_tmp4_);
}

void
dino_avatar_manager_remove_avatar_hash (DinoAvatarManager* self,
                                        DinoEntitiesAccount* account,
                                        XmppJid* jid,
                                        gint type)
{
	DinoDatabase* _tmp0_;
	DinoDatabaseAvatarTable* _tmp1_;
	DinoDatabaseAvatarTable* _tmp2_;
	QliteDeleteBuilder* _tmp3_;
	QliteDeleteBuilder* _tmp4_;
	DinoDatabase* _tmp5_;
	DinoDatabaseAvatarTable* _tmp6_;
	DinoDatabaseAvatarTable* _tmp7_;
	QliteColumn* _tmp8_;
	DinoDatabase* _tmp9_;
	QliteDeleteBuilder* _tmp10_;
	QliteDeleteBuilder* _tmp11_;
	DinoDatabase* _tmp12_;
	DinoDatabaseAvatarTable* _tmp13_;
	DinoDatabaseAvatarTable* _tmp14_;
	QliteColumn* _tmp15_;
	gint _tmp16_;
	gint _tmp17_;
	QliteDeleteBuilder* _tmp18_;
	QliteDeleteBuilder* _tmp19_;
	DinoDatabase* _tmp20_;
	DinoDatabaseAvatarTable* _tmp21_;
	DinoDatabaseAvatarTable* _tmp22_;
	QliteColumn* _tmp23_;
	QliteDeleteBuilder* _tmp24_;
	QliteDeleteBuilder* _tmp25_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_database_get_avatar (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = qlite_table_delete ((QliteTable*) _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = self->priv->db;
	_tmp6_ = dino_database_get_avatar (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = _tmp7_->jid_id;
	_tmp9_ = self->priv->db;
	_tmp10_ = qlite_delete_builder_with (_tmp4_, G_TYPE_INT, NULL, NULL, _tmp8_, "=", (gpointer) ((gintptr) dino_database_get_jid_id (_tmp9_, jid)));
	_tmp11_ = _tmp10_;
	_tmp12_ = self->priv->db;
	_tmp13_ = dino_database_get_avatar (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = _tmp14_->account_id;
	_tmp16_ = dino_entities_account_get_id (account);
	_tmp17_ = _tmp16_;
	_tmp18_ = qlite_delete_builder_with (_tmp11_, G_TYPE_INT, NULL, NULL, _tmp15_, "=", (gpointer) ((gintptr) _tmp17_));
	_tmp19_ = _tmp18_;
	_tmp20_ = self->priv->db;
	_tmp21_ = dino_database_get_avatar (_tmp20_);
	_tmp22_ = _tmp21_;
	_tmp23_ = _tmp22_->type_;
	_tmp24_ = qlite_delete_builder_with (_tmp19_, G_TYPE_INT, NULL, NULL, _tmp23_, "=", (gpointer) ((gintptr) type));
	_tmp25_ = _tmp24_;
	qlite_delete_builder_perform (_tmp25_);
	_qlite_statement_builder_unref0 (_tmp25_);
	_qlite_statement_builder_unref0 (_tmp19_);
	_qlite_statement_builder_unref0 (_tmp11_);
	_qlite_statement_builder_unref0 (_tmp4_);
}

static gpointer
_qlite_column_ref0 (gpointer self)
{
	return self ? qlite_column_ref (self) : NULL;
}

GeeHashMap*
dino_avatar_manager_get_avatar_hashes (DinoAvatarManager* self,
                                       DinoEntitiesAccount* account,
                                       gint type)
{
	GeeHashMap* ret = NULL;
	GeeHashMap* _tmp0_;
	GError* _inner_error0_ = NULL;
	GeeHashMap* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (account != NULL, NULL);
	_tmp0_ = gee_hash_map_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _xmpp_jid_hash_func_gee_hash_data_func, NULL, NULL, _xmpp_jid_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	ret = _tmp0_;
	{
		QliteRowIterator* _row_it = NULL;
		DinoDatabase* _tmp1_;
		DinoDatabaseAvatarTable* _tmp2_;
		DinoDatabaseAvatarTable* _tmp3_;
		DinoDatabase* _tmp4_;
		DinoDatabaseAvatarTable* _tmp5_;
		DinoDatabaseAvatarTable* _tmp6_;
		QliteColumn* _tmp7_;
		QliteColumn* _tmp8_;
		DinoDatabase* _tmp9_;
		DinoDatabaseAvatarTable* _tmp10_;
		DinoDatabaseAvatarTable* _tmp11_;
		QliteColumn* _tmp12_;
		QliteColumn* _tmp13_;
		QliteColumn** _tmp14_;
		QliteColumn** _tmp15_;
		gint _tmp15__length1;
		QliteQueryBuilder* _tmp16_;
		QliteQueryBuilder* _tmp17_;
		DinoDatabase* _tmp18_;
		DinoDatabaseAvatarTable* _tmp19_;
		DinoDatabaseAvatarTable* _tmp20_;
		QliteColumn* _tmp21_;
		QliteQueryBuilder* _tmp22_;
		QliteQueryBuilder* _tmp23_;
		DinoDatabase* _tmp24_;
		DinoDatabaseAvatarTable* _tmp25_;
		DinoDatabaseAvatarTable* _tmp26_;
		QliteColumn* _tmp27_;
		gint _tmp28_;
		gint _tmp29_;
		QliteQueryBuilder* _tmp30_;
		QliteQueryBuilder* _tmp31_;
		QliteRowIterator* _tmp32_;
		QliteRowIterator* _tmp33_;
		_tmp1_ = self->priv->db;
		_tmp2_ = dino_database_get_avatar (_tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = self->priv->db;
		_tmp5_ = dino_database_get_avatar (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = _tmp6_->jid_id;
		_tmp8_ = _qlite_column_ref0 (_tmp7_);
		_tmp9_ = self->priv->db;
		_tmp10_ = dino_database_get_avatar (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = _tmp11_->hash;
		_tmp13_ = _qlite_column_ref0 (_tmp12_);
		_tmp14_ = g_new0 (QliteColumn*, 2 + 1);
		_tmp14_[0] = _tmp8_;
		_tmp14_[1] = _tmp13_;
		_tmp15_ = _tmp14_;
		_tmp15__length1 = 2;
		_tmp16_ = qlite_table_select ((QliteTable*) _tmp3_, _tmp15_, (gint) 2);
		_tmp17_ = _tmp16_;
		_tmp18_ = self->priv->db;
		_tmp19_ = dino_database_get_avatar (_tmp18_);
		_tmp20_ = _tmp19_;
		_tmp21_ = _tmp20_->type_;
		_tmp22_ = qlite_query_builder_with (_tmp17_, G_TYPE_INT, NULL, NULL, _tmp21_, "=", (gpointer) ((gintptr) type));
		_tmp23_ = _tmp22_;
		_tmp24_ = self->priv->db;
		_tmp25_ = dino_database_get_avatar (_tmp24_);
		_tmp26_ = _tmp25_;
		_tmp27_ = _tmp26_->account_id;
		_tmp28_ = dino_entities_account_get_id (account);
		_tmp29_ = _tmp28_;
		_tmp30_ = qlite_query_builder_with (_tmp23_, G_TYPE_INT, NULL, NULL, _tmp27_, "=", (gpointer) ((gintptr) _tmp29_));
		_tmp31_ = _tmp30_;
		_tmp32_ = qlite_query_builder_iterator (_tmp31_);
		_tmp33_ = _tmp32_;
		_qlite_statement_builder_unref0 (_tmp31_);
		_qlite_statement_builder_unref0 (_tmp23_);
		_qlite_statement_builder_unref0 (_tmp17_);
		_tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) qlite_column_unref), NULL);
		_row_it = _tmp33_;
		while (TRUE) {
			QliteRowIterator* _tmp34_;
			QliteRow* row = NULL;
			QliteRowIterator* _tmp35_;
			QliteRow* _tmp36_;
			XmppJid* _tmp37_ = NULL;
			DinoDatabase* _tmp38_;
			QliteRow* _tmp39_;
			DinoDatabase* _tmp40_;
			DinoDatabaseAvatarTable* _tmp41_;
			DinoDatabaseAvatarTable* _tmp42_;
			QliteColumn* _tmp43_;
			gpointer _tmp44_;
			XmppJid* _tmp45_;
			GeeHashMap* _tmp46_;
			QliteRow* _tmp47_;
			DinoDatabase* _tmp48_;
			DinoDatabaseAvatarTable* _tmp49_;
			DinoDatabaseAvatarTable* _tmp50_;
			QliteColumn* _tmp51_;
			gpointer _tmp52_;
			gchar* _tmp53_;
			_tmp34_ = _row_it;
			if (!qlite_row_iterator_next (_tmp34_)) {
				break;
			}
			_tmp35_ = _row_it;
			_tmp36_ = qlite_row_iterator_get (_tmp35_);
			row = _tmp36_;
			_tmp38_ = self->priv->db;
			_tmp39_ = row;
			_tmp40_ = self->priv->db;
			_tmp41_ = dino_database_get_avatar (_tmp40_);
			_tmp42_ = _tmp41_;
			_tmp43_ = _tmp42_->jid_id;
			_tmp44_ = qlite_row_get (_tmp39_, G_TYPE_INT, NULL, NULL, _tmp43_);
			_tmp45_ = dino_database_get_jid_by_id (_tmp38_, (gint) ((gintptr) _tmp44_), &_inner_error0_);
			_tmp37_ = _tmp45_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_qlite_row_unref0 (row);
				_qlite_row_iterator_unref0 (_row_it);
				_g_object_unref0 (ret);
				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;
			}
			_tmp46_ = ret;
			_tmp47_ = row;
			_tmp48_ = self->priv->db;
			_tmp49_ = dino_database_get_avatar (_tmp48_);
			_tmp50_ = _tmp49_;
			_tmp51_ = _tmp50_->hash;
			_tmp52_ = qlite_row_get (_tmp47_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp51_);
			_tmp53_ = (gchar*) _tmp52_;
			gee_abstract_map_set ((GeeAbstractMap*) _tmp46_, _tmp37_, _tmp53_);
			_g_free0 (_tmp53_);
			_xmpp_jid_unref0 (_tmp37_);
			_qlite_row_unref0 (row);
		}
		_qlite_row_iterator_unref0 (_row_it);
	}
	result = ret;
	return result;
}

static void
dino_avatar_manager_fetch_and_store_for_jid_data_free (gpointer _data)
{
	DinoAvatarManagerFetchAndStoreForJidData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->account);
	_xmpp_jid_unref0 (_data_->jid);
	_g_object_unref0 (_data_->self);
	g_slice_free (DinoAvatarManagerFetchAndStoreForJidData, _data_);
}

void
dino_avatar_manager_fetch_and_store_for_jid (DinoAvatarManager* self,
                                             DinoEntitiesAccount* account,
                                             XmppJid* jid,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_)
{
	DinoAvatarManagerFetchAndStoreForJidData* _data_;
	DinoAvatarManager* _tmp0_;
	DinoEntitiesAccount* _tmp1_;
	XmppJid* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	_data_ = g_slice_new0 (DinoAvatarManagerFetchAndStoreForJidData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_avatar_manager_fetch_and_store_for_jid_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (account);
	_g_object_unref0 (_data_->account);
	_data_->account = _tmp1_;
	_tmp2_ = _xmpp_jid_ref0 (jid);
	_xmpp_jid_unref0 (_data_->jid);
	_data_->jid = _tmp2_;
	dino_avatar_manager_fetch_and_store_for_jid_co (_data_);
}

gboolean
dino_avatar_manager_fetch_and_store_for_jid_finish (DinoAvatarManager* self,
                                                    GAsyncResult* _res_)
{
	gboolean result;
	DinoAvatarManagerFetchAndStoreForJidData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static void
dino_avatar_manager_fetch_and_store_for_jid_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_)
{
	DinoAvatarManagerFetchAndStoreForJidData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_avatar_manager_fetch_and_store_for_jid_co (_data_);
}

static gboolean
dino_avatar_manager_fetch_and_store_for_jid_co (DinoAvatarManagerFetchAndStoreForJidData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->source = -1;
	_data_->hash = NULL;
	_data_->_tmp0_ = _data_->self->priv->user_avatars;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp0_, _data_->jid)) {
		_data_->_tmp1_ = _data_->self->priv->user_avatars;
		_data_->_tmp2_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp1_, _data_->jid);
		_g_free0 (_data_->hash);
		_data_->hash = (gchar*) _data_->_tmp2_;
		_data_->source = 1;
	} else {
		_data_->_tmp3_ = _data_->self->priv->vcard_avatars;
		if (gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp3_, _data_->jid)) {
			_data_->_tmp4_ = _data_->self->priv->vcard_avatars;
			_data_->_tmp5_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp4_, _data_->jid);
			_g_free0 (_data_->hash);
			_data_->hash = (gchar*) _data_->_tmp5_;
			_data_->source = 2;
		} else {
			_data_->result = FALSE;
			_g_free0 (_data_->hash);
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp6_ = _data_->self->priv->stream_interactor;
	_data_->_tmp7_ = dino_stream_interactor_get_stream (_data_->_tmp6_, _data_->account);
	_data_->stream = _data_->_tmp7_;
	_data_->_tmp9_ = _data_->stream;
	if (_data_->_tmp9_ == NULL) {
		_data_->_tmp8_ = TRUE;
	} else {
		_data_->_tmp10_ = _data_->stream;
		_data_->_tmp11_ = xmpp_xmpp_stream_get_negotiation_complete (_data_->_tmp10_);
		_data_->_tmp12_ = _data_->_tmp11_;
		_data_->_tmp8_ = !_data_->_tmp12_;
	}
	if (_data_->_tmp8_) {
		_data_->result = FALSE;
		_g_object_unref0 (_data_->stream);
		_g_free0 (_data_->hash);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp13_ = _data_->stream;
	_data_->_tmp14_ = _data_->hash;
	_data_->_state_ = 1;
	dino_avatar_manager_fetch_and_store (_data_->self, _data_->_tmp13_, _data_->account, _data_->jid, _data_->source, _data_->_tmp14_, dino_avatar_manager_fetch_and_store_for_jid_ready, _data_);
	return FALSE;
	_state_1:
	_data_->result = dino_avatar_manager_fetch_and_store_finish (_data_->self, _data_->_res_);
	_g_object_unref0 (_data_->stream);
	_g_free0 (_data_->hash);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
dino_avatar_manager_fetch_and_store_data_free (gpointer _data)
{
	DinoAvatarManagerFetchAndStoreData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->stream);
	_g_object_unref0 (_data_->account);
	_xmpp_jid_unref0 (_data_->jid);
	_g_free0 (_data_->hash);
	_g_object_unref0 (_data_->self);
	g_slice_free (DinoAvatarManagerFetchAndStoreData, _data_);
}

static void
dino_avatar_manager_fetch_and_store (DinoAvatarManager* self,
                                     XmppXmppStream* stream,
                                     DinoEntitiesAccount* account,
                                     XmppJid* jid,
                                     gint source,
                                     const gchar* hash,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_)
{
	DinoAvatarManagerFetchAndStoreData* _data_;
	DinoAvatarManager* _tmp0_;
	XmppXmppStream* _tmp1_;
	DinoEntitiesAccount* _tmp2_;
	XmppJid* _tmp3_;
	gchar* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	_data_ = g_slice_new0 (DinoAvatarManagerFetchAndStoreData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_avatar_manager_fetch_and_store_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (stream);
	_g_object_unref0 (_data_->stream);
	_data_->stream = _tmp1_;
	_tmp2_ = _g_object_ref0 (account);
	_g_object_unref0 (_data_->account);
	_data_->account = _tmp2_;
	_tmp3_ = _xmpp_jid_ref0 (jid);
	_xmpp_jid_unref0 (_data_->jid);
	_data_->jid = _tmp3_;
	_data_->source = source;
	_tmp4_ = g_strdup (hash);
	_g_free0 (_data_->hash);
	_data_->hash = _tmp4_;
	dino_avatar_manager_fetch_and_store_co (_data_);
}

static gboolean
dino_avatar_manager_fetch_and_store_finish (DinoAvatarManager* self,
                                            GAsyncResult* _res_)
{
	gboolean result;
	DinoAvatarManagerFetchAndStoreData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static void
dino_avatar_manager_fetch_and_store_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_)
{
	DinoAvatarManagerFetchAndStoreData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_avatar_manager_fetch_and_store_co (_data_);
}

static gboolean
dino_avatar_manager_fetch_and_store_co (DinoAvatarManagerFetchAndStoreData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->hash == NULL) {
		_data_->_tmp0_ = TRUE;
	} else {
		_data_->_tmp1_ = _data_->self->priv->pending_fetch;
		_data_->_tmp0_ = gee_abstract_collection_contains ((GeeAbstractCollection*) _data_->_tmp1_, _data_->hash);
	}
	if (_data_->_tmp0_) {
		_data_->result = FALSE;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _data_->self->priv->pending_fetch;
	gee_abstract_collection_add ((GeeAbstractCollection*) _data_->_tmp2_, _data_->hash);
	_data_->bytes = NULL;
	if (_data_->source == 1) {
		_data_->_state_ = 1;
		xmpp_xep_user_avatars_fetch_image (_data_->stream, _data_->jid, _data_->hash, dino_avatar_manager_fetch_and_store_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp3_ = xmpp_xep_user_avatars_fetch_image_finish (_data_->_res_);
		_g_bytes_unref0 (_data_->bytes);
		_data_->bytes = _data_->_tmp3_;
	} else {
		if (_data_->source == 2) {
			_data_->_state_ = 2;
			xmpp_xep_vcard_fetch_image (_data_->stream, _data_->jid, _data_->hash, dino_avatar_manager_fetch_and_store_ready, _data_);
			return FALSE;
			_state_2:
			_data_->_tmp4_ = xmpp_xep_vcard_fetch_image_finish (_data_->_res_);
			_g_bytes_unref0 (_data_->bytes);
			_data_->bytes = _data_->_tmp4_;
			_data_->_tmp6_ = _data_->bytes;
			if (_data_->_tmp6_ == NULL) {
				_data_->_tmp5_ = xmpp_jid_is_bare (_data_->jid);
			} else {
				_data_->_tmp5_ = FALSE;
			}
			if (_data_->_tmp5_) {
				_data_->_tmp7_ = _data_->self->priv->db;
				_data_->_tmp8_ = dino_database_get_avatar (_data_->_tmp7_);
				_data_->_tmp9_ = _data_->_tmp8_;
				_data_->_tmp10_ = qlite_table_delete ((QliteTable*) _data_->_tmp9_);
				_data_->_tmp11_ = _data_->_tmp10_;
				_data_->_tmp12_ = _data_->self->priv->db;
				_data_->_tmp13_ = dino_database_get_avatar (_data_->_tmp12_);
				_data_->_tmp14_ = _data_->_tmp13_;
				_data_->_tmp15_ = _data_->_tmp14_->jid_id;
				_data_->_tmp16_ = _data_->self->priv->db;
				_data_->_tmp17_ = qlite_delete_builder_with (_data_->_tmp11_, G_TYPE_INT, NULL, NULL, _data_->_tmp15_, "=", (gpointer) ((gintptr) dino_database_get_jid_id (_data_->_tmp16_, _data_->jid)));
				_data_->_tmp18_ = _data_->_tmp17_;
				qlite_delete_builder_perform (_data_->_tmp18_);
				_qlite_statement_builder_unref0 (_data_->_tmp18_);
				_qlite_statement_builder_unref0 (_data_->_tmp11_);
			}
		}
	}
	_data_->_tmp19_ = _data_->bytes;
	if (_data_->_tmp19_ != NULL) {
		_data_->_tmp20_ = _data_->bytes;
		_data_->_state_ = 3;
		dino_avatar_manager_store_image (_data_->self, _data_->hash, _data_->_tmp20_, dino_avatar_manager_fetch_and_store_ready, _data_);
		return FALSE;
		_state_3:
		dino_avatar_manager_store_image_finish (_data_->self, _data_->_res_);
		g_signal_emit (_data_->self, dino_avatar_manager_signals[DINO_AVATAR_MANAGER_FETCHED_AVATAR_SIGNAL], 0, _data_->jid, _data_->account);
	}
	_data_->_tmp21_ = _data_->self->priv->pending_fetch;
	gee_abstract_collection_remove ((GeeAbstractCollection*) _data_->_tmp21_, _data_->hash);
	_data_->_tmp22_ = _data_->bytes;
	_data_->result = _data_->_tmp22_ != NULL;
	_g_bytes_unref0 (_data_->bytes);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
dino_avatar_manager_store_image_data_free (gpointer _data)
{
	DinoAvatarManagerStoreImageData* _data_;
	_data_ = _data;
	_g_free0 (_data_->id);
	_g_bytes_unref0 (_data_->data);
	_g_object_unref0 (_data_->self);
	g_slice_free (DinoAvatarManagerStoreImageData, _data_);
}

static gpointer
_g_bytes_ref0 (gpointer self)
{
	return self ? g_bytes_ref (self) : NULL;
}

static void
dino_avatar_manager_store_image (DinoAvatarManager* self,
                                 const gchar* id,
                                 GBytes* data,
                                 GAsyncReadyCallback _callback_,
                                 gpointer _user_data_)
{
	DinoAvatarManagerStoreImageData* _data_;
	DinoAvatarManager* _tmp0_;
	gchar* _tmp1_;
	GBytes* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (id != NULL);
	g_return_if_fail (data != NULL);
	_data_ = g_slice_new0 (DinoAvatarManagerStoreImageData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_avatar_manager_store_image_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (id);
	_g_free0 (_data_->id);
	_data_->id = _tmp1_;
	_tmp2_ = _g_bytes_ref0 (data);
	_g_bytes_unref0 (_data_->data);
	_data_->data = _tmp2_;
	dino_avatar_manager_store_image_co (_data_);
}

static void
dino_avatar_manager_store_image_finish (DinoAvatarManager* self,
                                        GAsyncResult* _res_)
{
	DinoAvatarManagerStoreImageData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dino_avatar_manager_store_image_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_)
{
	DinoAvatarManagerStoreImageData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_avatar_manager_store_image_co (_data_);
}

static gboolean
dino_avatar_manager_store_image_co (DinoAvatarManagerStoreImageData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->folder;
	_data_->_tmp1_ = g_build_filename (_data_->_tmp0_, _data_->id, NULL);
	_data_->_tmp2_ = _data_->_tmp1_;
	_data_->_tmp3_ = g_file_new_for_path (_data_->_tmp2_);
	_data_->_tmp4_ = _data_->_tmp3_;
	_g_free0 (_data_->_tmp2_);
	_data_->file = _data_->_tmp4_;
	{
		_data_->_tmp5_ = _data_->file;
		if (g_file_query_exists (_data_->_tmp5_, NULL)) {
			_data_->_tmp6_ = _data_->file;
			g_file_delete (_data_->_tmp6_, NULL, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		_data_->_tmp8_ = _data_->file;
		_data_->_tmp9_ = g_file_create (_data_->_tmp8_, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &_data_->_inner_error0_);
		_data_->_tmp7_ = _data_->_tmp9_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp10_ = g_data_output_stream_new ((GOutputStream*) _data_->_tmp7_);
		_data_->fos = _data_->_tmp10_;
		_data_->_tmp11_ = _data_->fos;
		_data_->_state_ = 1;
		g_output_stream_write_bytes_async ((GOutputStream*) _data_->_tmp11_, _data_->data, G_PRIORITY_DEFAULT, NULL, dino_avatar_manager_store_image_ready, _data_);
		return FALSE;
		_state_1:
		g_output_stream_write_bytes_finish ((GOutputStream*) _data_->_tmp11_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->fos);
			_g_object_unref0 (_data_->_tmp7_);
			goto __catch0_g_error;
		}
		_g_object_unref0 (_data_->fos);
		_g_object_unref0 (_data_->_tmp7_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_data_->_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->file);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->file);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

gboolean
dino_avatar_manager_has_image (DinoAvatarManager* self,
                               const gchar* id)
{
	GFile* file = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GFile* _tmp3_;
	GFile* _tmp4_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (id != NULL, FALSE);
	_tmp0_ = self->priv->folder;
	_tmp1_ = g_build_filename (_tmp0_, id, NULL);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_file_new_for_path (_tmp2_);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	file = _tmp4_;
	result = g_file_query_exists (file, NULL);
	_g_object_unref0 (file);
	return result;
}

static void
dino_avatar_manager_get_image_data_free (gpointer _data)
{
	DinoAvatarManagerGetImageData* _data_;
	_data_ = _data;
	_g_free0 (_data_->id);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (DinoAvatarManagerGetImageData, _data_);
}

void
dino_avatar_manager_get_image (DinoAvatarManager* self,
                               const gchar* id,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_)
{
	DinoAvatarManagerGetImageData* _data_;
	DinoAvatarManager* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (id != NULL);
	_data_ = g_slice_new0 (DinoAvatarManagerGetImageData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_avatar_manager_get_image_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (id);
	_g_free0 (_data_->id);
	_data_->id = _tmp1_;
	dino_avatar_manager_get_image_co (_data_);
}

GdkPixbuf*
dino_avatar_manager_get_image_finish (DinoAvatarManager* self,
                                      GAsyncResult* _res_)
{
	GdkPixbuf* result;
	DinoAvatarManagerGetImageData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
dino_avatar_manager_get_image_ready (GObject* source_object,
                                     GAsyncResult* _res_,
                                     gpointer _user_data_)
{
	DinoAvatarManagerGetImageData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_avatar_manager_get_image_co (_data_);
}

static gboolean
dino_avatar_manager_get_image_co (DinoAvatarManagerGetImageData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->_tmp0_ = _data_->self->priv->folder;
		_data_->_tmp1_ = g_build_filename (_data_->_tmp0_, _data_->id, NULL);
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_tmp3_ = g_file_new_for_path (_data_->_tmp2_);
		_data_->_tmp4_ = _data_->_tmp3_;
		_g_free0 (_data_->_tmp2_);
		_data_->file = _data_->_tmp4_;
		_data_->_tmp5_ = _data_->file;
		_data_->_state_ = 1;
		g_file_read_async (_data_->_tmp5_, G_PRIORITY_LOW, NULL, dino_avatar_manager_get_image_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp6_ = g_file_read_finish (_data_->_tmp5_, _data_->_res_, &_data_->_inner_error0_);
		_data_->stream = _data_->_tmp6_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->file);
			goto __catch0_g_error;
		}
		_data_->_tmp7_ = g_checksum_new (G_CHECKSUM_SHA1);
		_data_->checksum = _data_->_tmp7_;
		while (TRUE) {
			_data_->_tmp9_ = _data_->stream;
			_data_->_state_ = 2;
			g_input_stream_read_async ((GInputStream*) _data_->_tmp9_, _data_->fbuf, (gsize) 1024, G_PRIORITY_LOW, NULL, dino_avatar_manager_get_image_ready, _data_);
			return FALSE;
			_state_2:
			_data_->_tmp8_ = g_input_stream_read_finish ((GInputStream*) _data_->_tmp9_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_checksum_free0 (_data_->checksum);
				_g_object_unref0 (_data_->stream);
				_g_object_unref0 (_data_->file);
				goto __catch0_g_error;
			}
			_data_->size = (gsize) _data_->_tmp8_;
			if (!(_data_->size > ((gsize) 0))) {
				break;
			}
			_data_->_tmp10_ = _data_->checksum;
			g_checksum_update (_data_->_tmp10_, _data_->fbuf, _data_->size);
		}
		_data_->_tmp11_ = _data_->checksum;
		_data_->_tmp12_ = g_checksum_get_string (_data_->_tmp11_);
		if (g_strcmp0 (_data_->_tmp12_, _data_->id) != 0) {
			_data_->_tmp13_ = _data_->file;
			_data_->_tmp14_ = g_file_get_path (_data_->_tmp13_);
			_data_->_tmp15_ = _data_->_tmp14_;
			g_remove (_data_->_tmp15_);
			_g_free0 (_data_->_tmp15_);
		}
		_data_->_tmp16_ = _data_->stream;
		G_TYPE_INSTANCE_GET_CLASS (_data_->_tmp16_, g_file_input_stream_get_type (), GFileInputStreamClass)->seek (_data_->_tmp16_, (gint64) 0, G_SEEK_SET, NULL, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_checksum_free0 (_data_->checksum);
			_g_object_unref0 (_data_->stream);
			_g_object_unref0 (_data_->file);
			goto __catch0_g_error;
		}
		_data_->_tmp18_ = _data_->stream;
		_data_->_state_ = 3;
		gdk_pixbuf_new_from_stream_async ((GInputStream*) _data_->_tmp18_, NULL, dino_avatar_manager_get_image_ready, _data_);
		return FALSE;
		_state_3:
		_data_->_tmp19_ = (GdkPixbuf*) gdk_pixbuf_new_from_stream_finish (_data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp17_ = _data_->_tmp19_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_checksum_free0 (_data_->checksum);
			_g_object_unref0 (_data_->stream);
			_g_object_unref0 (_data_->file);
			goto __catch0_g_error;
		}
		_data_->_tmp20_ = _data_->_tmp17_;
		_data_->_tmp17_ = NULL;
		_data_->result = _data_->_tmp20_;
		_g_object_unref0 (_data_->_tmp17_);
		_g_checksum_free0 (_data_->checksum);
		_g_object_unref0 (_data_->stream);
		_g_object_unref0 (_data_->file);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_data_->_inner_error0_);
		_data_->result = NULL;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
	g_clear_error (&_data_->_inner_error0_);
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static const gchar*
dino_avatar_manager_real_get_id (DinoStreamInteractionModule* base)
{
	const gchar* result;
	DinoAvatarManager* self;
	DinoModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	self = (DinoAvatarManager*) base;
	_tmp0_ = dino_avatar_manager_IDENTITY;
	_tmp1_ = dino_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

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

static void
dino_avatar_manager_class_init (DinoAvatarManagerClass * klass,
                                gpointer klass_data)
{
	DinoModuleIdentity* _tmp0_;
	dino_avatar_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoAvatarManager_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_avatar_manager_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_avatar_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_AVATAR_MANAGER_ID_PROPERTY, dino_avatar_manager_properties[DINO_AVATAR_MANAGER_ID_PROPERTY] = g_param_spec_string ("id", "id", "id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	dino_avatar_manager_signals[DINO_AVATAR_MANAGER_RECEIVED_AVATAR_SIGNAL] = g_signal_new ("received-avatar", DINO_TYPE_AVATAR_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__XMPP_JID_OBJECT, G_TYPE_NONE, 2, XMPP_TYPE_JID, DINO_ENTITIES_TYPE_ACCOUNT);
	dino_avatar_manager_signals[DINO_AVATAR_MANAGER_FETCHED_AVATAR_SIGNAL] = g_signal_new ("fetched-avatar", DINO_TYPE_AVATAR_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__XMPP_JID_OBJECT, G_TYPE_NONE, 2, XMPP_TYPE_JID, DINO_ENTITIES_TYPE_ACCOUNT);
	_tmp0_ = dino_module_identity_new (DINO_TYPE_AVATAR_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, "avatar_manager");
	dino_avatar_manager_IDENTITY = _tmp0_;
}

static void
dino_avatar_manager_dino_stream_interaction_module_interface_init (DinoStreamInteractionModuleIface * iface,
                                                                   gpointer iface_data)
{
	dino_avatar_manager_dino_stream_interaction_module_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_id = dino_avatar_manager_real_get_id;
}

static void
dino_avatar_manager_instance_init (DinoAvatarManager * self,
                                   gpointer klass)
{
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	GeeHashMap* _tmp2_;
	GeeHashMap* _tmp3_;
	GeeHashSet* _tmp4_;
	self->priv = dino_avatar_manager_get_instance_private (self);
	self->priv->folder = NULL;
	_tmp0_ = gee_hash_map_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _xmpp_jid_hash_func_gee_hash_data_func, NULL, NULL, _xmpp_jid_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->priv->user_avatars = _tmp0_;
	_tmp1_ = gee_hash_map_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _xmpp_jid_hash_func_gee_hash_data_func, NULL, NULL, _xmpp_jid_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->priv->vcard_avatars = _tmp1_;
	_tmp2_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, gdk_pixbuf_get_type (), (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->cached_pixbuf = _tmp2_;
	_tmp3_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, GEE_TYPE_LIST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->pending_pixbuf = _tmp3_;
	_tmp4_ = gee_hash_set_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->pending_fetch = _tmp4_;
}

static void
dino_avatar_manager_finalize (GObject * obj)
{
	DinoAvatarManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_AVATAR_MANAGER, DinoAvatarManager);
	_g_object_unref0 (self->priv->stream_interactor);
	_qlite_database_unref0 (self->priv->db);
	_g_free0 (self->priv->folder);
	_g_object_unref0 (self->priv->user_avatars);
	_g_object_unref0 (self->priv->vcard_avatars);
	_g_object_unref0 (self->priv->cached_pixbuf);
	_g_object_unref0 (self->priv->pending_pixbuf);
	_g_object_unref0 (self->priv->pending_fetch);
	G_OBJECT_CLASS (dino_avatar_manager_parent_class)->finalize (obj);
}

static GType
dino_avatar_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoAvatarManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_avatar_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoAvatarManager), 0, (GInstanceInitFunc) dino_avatar_manager_instance_init, NULL };
	static const GInterfaceInfo dino_stream_interaction_module_info = { (GInterfaceInitFunc) dino_avatar_manager_dino_stream_interaction_module_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_avatar_manager_type_id;
	dino_avatar_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoAvatarManager", &g_define_type_info, 0);
	g_type_add_interface_static (dino_avatar_manager_type_id, DINO_TYPE_STREAM_INTERACTION_MODULE, &dino_stream_interaction_module_info);
	DinoAvatarManager_private_offset = g_type_add_instance_private (dino_avatar_manager_type_id, sizeof (DinoAvatarManagerPrivate));
	return dino_avatar_manager_type_id;
}

GType
dino_avatar_manager_get_type (void)
{
	static volatile gsize dino_avatar_manager_type_id__once = 0;
	if (g_once_init_enter (&dino_avatar_manager_type_id__once)) {
		GType dino_avatar_manager_type_id;
		dino_avatar_manager_type_id = dino_avatar_manager_get_type_once ();
		g_once_init_leave (&dino_avatar_manager_type_id__once, dino_avatar_manager_type_id);
	}
	return dino_avatar_manager_type_id__once;
}

static void
_vala_dino_avatar_manager_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec)
{
	DinoAvatarManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_TYPE_AVATAR_MANAGER, DinoAvatarManager);
	switch (property_id) {
		case DINO_AVATAR_MANAGER_ID_PROPERTY:
		g_value_set_string (value, dino_stream_interaction_module_get_id ((DinoStreamInteractionModule*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

