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

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

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

enum  {
	DINO_CONVERSATION_MANAGER_0_PROPERTY,
	DINO_CONVERSATION_MANAGER_ID_PROPERTY,
	DINO_CONVERSATION_MANAGER_NUM_PROPERTIES
};
static GParamSpec* dino_conversation_manager_properties[DINO_CONVERSATION_MANAGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _qlite_database_unref0(var) ((var == NULL) ? NULL : (var = (qlite_database_unref (var), NULL)))

#define DINO_CONVERSATION_MANAGER_TYPE_MESSAGE_LISTENER (dino_conversation_manager_message_listener_get_type ())
#define DINO_CONVERSATION_MANAGER_MESSAGE_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_CONVERSATION_MANAGER_TYPE_MESSAGE_LISTENER, DinoConversationManagerMessageListener))
#define DINO_CONVERSATION_MANAGER_MESSAGE_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_CONVERSATION_MANAGER_TYPE_MESSAGE_LISTENER, DinoConversationManagerMessageListenerClass))
#define DINO_CONVERSATION_MANAGER_IS_MESSAGE_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_CONVERSATION_MANAGER_TYPE_MESSAGE_LISTENER))
#define DINO_CONVERSATION_MANAGER_IS_MESSAGE_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_CONVERSATION_MANAGER_TYPE_MESSAGE_LISTENER))
#define DINO_CONVERSATION_MANAGER_MESSAGE_LISTENER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_CONVERSATION_MANAGER_TYPE_MESSAGE_LISTENER, DinoConversationManagerMessageListenerClass))

typedef struct _DinoConversationManagerMessageListener DinoConversationManagerMessageListener;
typedef struct _DinoConversationManagerMessageListenerClass DinoConversationManagerMessageListenerClass;
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
typedef struct _DinoConversationManagerMessageListenerPrivate DinoConversationManagerMessageListenerPrivate;
enum  {
	DINO_CONVERSATION_MANAGER_MESSAGE_LISTENER_0_PROPERTY,
	DINO_CONVERSATION_MANAGER_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY,
	DINO_CONVERSATION_MANAGER_MESSAGE_LISTENER_AFTER_ACTIONS_PROPERTY,
	DINO_CONVERSATION_MANAGER_MESSAGE_LISTENER_NUM_PROPERTIES
};
static GParamSpec* dino_conversation_manager_message_listener_properties[DINO_CONVERSATION_MANAGER_MESSAGE_LISTENER_NUM_PROPERTIES];
typedef struct _DinoConversationManagerMessageListenerRunData DinoConversationManagerMessageListenerRunData;
enum  {
	DINO_CONVERSATION_MANAGER_CONVERSATION_ACTIVATED_SIGNAL,
	DINO_CONVERSATION_MANAGER_CONVERSATION_DEACTIVATED_SIGNAL,
	DINO_CONVERSATION_MANAGER_NUM_SIGNALS
};
static guint dino_conversation_manager_signals[DINO_CONVERSATION_MANAGER_NUM_SIGNALS] = {0};
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _DinoConversationManagerPrivate {
	DinoStreamInteractor* stream_interactor;
	DinoDatabase* db;
	GeeHashMap* conversations;
};

struct _DinoConversationManagerMessageListener {
	DinoMessageListener parent_instance;
	DinoConversationManagerMessageListenerPrivate * priv;
	gchar** after_actions_const;
	gint after_actions_const_length1;
	gint _after_actions_const_size_;
};

struct _DinoConversationManagerMessageListenerClass {
	DinoMessageListenerClass parent_class;
};

struct _DinoConversationManagerMessageListenerPrivate {
	DinoStreamInteractor* stream_interactor;
};

struct _DinoConversationManagerMessageListenerRunData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoConversationManagerMessageListener* self;
	DinoEntitiesMessage* message;
	XmppMessageStanza* stanza;
	DinoEntitiesConversation* conversation;
	gboolean result;
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	gboolean is_mam_message;
	XmppMessageArchiveManagementMessageFlag* _tmp2_;
	XmppMessageArchiveManagementMessageFlag* _tmp3_;
	gboolean _tmp4_;
	gboolean is_recent;
	GDateTime* _tmp5_;
	GDateTime* _tmp6_;
	GDateTime* _tmp7_;
	GDateTime* _tmp8_;
	GDateTime* _tmp9_;
	GDateTime* _tmp10_;
	gboolean _tmp11_;
	gboolean _tmp12_;
	DinoStreamInteractor* _tmp13_;
	DinoModuleIdentity* _tmp14_;
	gpointer _tmp15_;
	DinoConversationManager* _tmp16_;
};

static gint DinoConversationManager_private_offset;
static gpointer dino_conversation_manager_parent_class = NULL;
DinoModuleIdentity* dino_conversation_manager_IDENTITY = NULL;
static gint DinoConversationManagerMessageListener_private_offset;
static gpointer dino_conversation_manager_message_listener_parent_class = NULL;
static DinoStreamInteractionModuleIface * dino_conversation_manager_dino_stream_interaction_module_parent_iface = NULL;

static guint _dino_entities_account_hash_func_gee_hash_data_func (gconstpointer v,
                                                           gpointer self);
static gboolean _dino_entities_account_equals_func_gee_equal_data_func (gconstpointer a,
                                                                 gconstpointer b,
                                                                 gpointer self);
static DinoConversationManager* dino_conversation_manager_new (DinoStreamInteractor* stream_interactor,
                                                        DinoDatabase* db);
static DinoConversationManager* dino_conversation_manager_construct (GType object_type,
                                                              DinoStreamInteractor* stream_interactor,
                                                              DinoDatabase* db);
static void dino_conversation_manager_on_account_added (DinoConversationManager* self,
                                                 DinoEntitiesAccount* account);
static void _dino_conversation_manager_on_account_added_dino_stream_interactor_account_added (DinoStreamInteractor* _sender,
                                                                                       DinoEntitiesAccount* account,
                                                                                       gpointer self);
static void dino_conversation_manager_on_account_removed (DinoConversationManager* self,
                                                   DinoEntitiesAccount* account);
static void _dino_conversation_manager_on_account_removed_dino_stream_interactor_account_removed (DinoStreamInteractor* _sender,
                                                                                           DinoEntitiesAccount* account,
                                                                                           gpointer self);
static DinoConversationManagerMessageListener* dino_conversation_manager_message_listener_new (DinoStreamInteractor* stream_interactor);
static DinoConversationManagerMessageListener* dino_conversation_manager_message_listener_construct (GType object_type,
                                                                                              DinoStreamInteractor* stream_interactor);
static GType dino_conversation_manager_message_listener_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static void dino_conversation_manager_handle_sent_message (DinoConversationManager* self,
                                                    DinoEntitiesMessage* message,
                                                    DinoEntitiesConversation* conversation);
static void _dino_conversation_manager_handle_sent_message_dino_message_processor_message_sent (DinoMessageProcessor* _sender,
                                                                                         DinoEntitiesMessage* message,
                                                                                         DinoEntitiesConversation* conversation,
                                                                                         gpointer self);
static void dino_conversation_manager_handle_new_call (DinoConversationManager* self,
                                                DinoEntitiesCall* call,
                                                DinoCallState* state,
                                                DinoEntitiesConversation* conversation);
static void _dino_conversation_manager_handle_new_call_dino_calls_call_incoming (DinoCalls* _sender,
                                                                          DinoEntitiesCall* call,
                                                                          DinoCallState* state,
                                                                          DinoEntitiesConversation* conversation,
                                                                          gboolean video,
                                                                          gboolean multiparty,
                                                                          gpointer self);
static void _dino_conversation_manager_handle_new_call_dino_calls_call_outgoing (DinoCalls* _sender,
                                                                          DinoEntitiesCall* call,
                                                                          DinoCallState* state,
                                                                          DinoEntitiesConversation* conversation,
                                                                          gpointer self);
static gboolean _dino_entities_conversation_type_equal (const DinoEntitiesConversationType * s1,
                                                 const DinoEntitiesConversationType * s2);
static void dino_conversation_manager_add_conversation (DinoConversationManager* self,
                                                 DinoEntitiesConversation* conversation);
static gboolean _dino_entities_conversation_equals_func_gee_equal_data_func (gconstpointer a,
                                                                      gconstpointer b,
                                                                      gpointer self);
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 void dino_conversation_manager_message_listener_real_run_data_free (gpointer _data);
static void dino_conversation_manager_message_listener_real_run (DinoMessageListener* base,
                                                          DinoEntitiesMessage* message,
                                                          XmppMessageStanza* stanza,
                                                          DinoEntitiesConversation* conversation,
                                                          GAsyncReadyCallback _callback_,
                                                          gpointer _user_data_);
static gboolean dino_conversation_manager_message_listener_real_run_co (DinoConversationManagerMessageListenerRunData* _data_);
static void dino_conversation_manager_message_listener_finalize (GObject * obj);
static GType dino_conversation_manager_message_listener_get_type_once (void);
static void _vala_dino_conversation_manager_message_listener_get_property (GObject * object,
                                                                    guint property_id,
                                                                    GValue * value,
                                                                    GParamSpec * pspec);
static void dino_conversation_manager_finalize (GObject * obj);
static GType dino_conversation_manager_get_type_once (void);
static void _vala_dino_conversation_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 _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_conversation_manager_get_instance_private (DinoConversationManager* self)
{
	return G_STRUCT_MEMBER_P (self, DinoConversationManager_private_offset);
}

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

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

void
dino_conversation_manager_start (DinoStreamInteractor* stream_interactor,
                                 DinoDatabase* db)
{
	DinoConversationManager* m = NULL;
	DinoConversationManager* _tmp0_;
	g_return_if_fail (stream_interactor != NULL);
	g_return_if_fail (db != NULL);
	_tmp0_ = dino_conversation_manager_new (stream_interactor, db);
	m = _tmp0_;
	dino_stream_interactor_add_module (stream_interactor, (DinoStreamInteractionModule*) m);
	_g_object_unref0 (m);
}

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

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

static void
_dino_conversation_manager_on_account_added_dino_stream_interactor_account_added (DinoStreamInteractor* _sender,
                                                                                  DinoEntitiesAccount* account,
                                                                                  gpointer self)
{
	dino_conversation_manager_on_account_added ((DinoConversationManager*) self, account);
}

static void
_dino_conversation_manager_on_account_removed_dino_stream_interactor_account_removed (DinoStreamInteractor* _sender,
                                                                                      DinoEntitiesAccount* account,
                                                                                      gpointer self)
{
	dino_conversation_manager_on_account_removed ((DinoConversationManager*) self, account);
}

static void
_dino_conversation_manager_handle_sent_message_dino_message_processor_message_sent (DinoMessageProcessor* _sender,
                                                                                    DinoEntitiesMessage* message,
                                                                                    DinoEntitiesConversation* conversation,
                                                                                    gpointer self)
{
	dino_conversation_manager_handle_sent_message ((DinoConversationManager*) self, message, conversation);
}

static void
_dino_conversation_manager_handle_new_call_dino_calls_call_incoming (DinoCalls* _sender,
                                                                     DinoEntitiesCall* call,
                                                                     DinoCallState* state,
                                                                     DinoEntitiesConversation* conversation,
                                                                     gboolean video,
                                                                     gboolean multiparty,
                                                                     gpointer self)
{
	dino_conversation_manager_handle_new_call ((DinoConversationManager*) self, call, state, conversation);
}

static void
_dino_conversation_manager_handle_new_call_dino_calls_call_outgoing (DinoCalls* _sender,
                                                                     DinoEntitiesCall* call,
                                                                     DinoCallState* state,
                                                                     DinoEntitiesConversation* conversation,
                                                                     gpointer self)
{
	dino_conversation_manager_handle_new_call ((DinoConversationManager*) self, call, state, conversation);
}

static DinoConversationManager*
dino_conversation_manager_construct (GType object_type,
                                     DinoStreamInteractor* stream_interactor,
                                     DinoDatabase* db)
{
	DinoConversationManager * self = NULL;
	DinoDatabase* _tmp0_;
	DinoStreamInteractor* _tmp1_;
	DinoModuleIdentity* _tmp2_;
	gpointer _tmp3_;
	DinoMessageProcessor* _tmp4_;
	DinoMessageListenerHolder* _tmp5_;
	DinoConversationManagerMessageListener* _tmp6_;
	DinoConversationManagerMessageListener* _tmp7_;
	DinoModuleIdentity* _tmp8_;
	gpointer _tmp9_;
	DinoMessageProcessor* _tmp10_;
	DinoModuleIdentity* _tmp11_;
	gpointer _tmp12_;
	DinoCalls* _tmp13_;
	DinoModuleIdentity* _tmp14_;
	gpointer _tmp15_;
	DinoCalls* _tmp16_;
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoConversationManager*) g_object_new (object_type, NULL);
	_tmp0_ = _qlite_database_ref0 (db);
	_qlite_database_unref0 (self->priv->db);
	self->priv->db = _tmp0_;
	_tmp1_ = _g_object_ref0 (stream_interactor);
	_g_object_unref0 (self->priv->stream_interactor);
	self->priv->stream_interactor = _tmp1_;
	dino_stream_interactor_add_module (stream_interactor, (DinoStreamInteractionModule*) self);
	g_signal_connect_object (stream_interactor, "account-added", (GCallback) _dino_conversation_manager_on_account_added_dino_stream_interactor_account_added, self, 0);
	g_signal_connect_object (stream_interactor, "account-removed", (GCallback) _dino_conversation_manager_on_account_removed_dino_stream_interactor_account_removed, self, 0);
	_tmp2_ = dino_message_processor_IDENTITY;
	_tmp3_ = dino_stream_interactor_get_module (stream_interactor, DINO_TYPE_MESSAGE_PROCESSOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp2_);
	_tmp4_ = (DinoMessageProcessor*) _tmp3_;
	_tmp5_ = _tmp4_->received_pipeline;
	_tmp6_ = dino_conversation_manager_message_listener_new (stream_interactor);
	_tmp7_ = _tmp6_;
	xmpp_listener_holder_connect ((XmppListenerHolder*) _tmp5_, (XmppOrderedListener*) _tmp7_);
	_g_object_unref0 (_tmp7_);
	_g_object_unref0 (_tmp4_);
	_tmp8_ = dino_message_processor_IDENTITY;
	_tmp9_ = dino_stream_interactor_get_module (stream_interactor, DINO_TYPE_MESSAGE_PROCESSOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp8_);
	_tmp10_ = (DinoMessageProcessor*) _tmp9_;
	g_signal_connect_object (_tmp10_, "message-sent", (GCallback) _dino_conversation_manager_handle_sent_message_dino_message_processor_message_sent, self, 0);
	_g_object_unref0 (_tmp10_);
	_tmp11_ = dino_calls_IDENTITY;
	_tmp12_ = dino_stream_interactor_get_module (stream_interactor, DINO_TYPE_CALLS, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp11_);
	_tmp13_ = (DinoCalls*) _tmp12_;
	g_signal_connect_object (_tmp13_, "call-incoming", (GCallback) _dino_conversation_manager_handle_new_call_dino_calls_call_incoming, self, 0);
	_g_object_unref0 (_tmp13_);
	_tmp14_ = dino_calls_IDENTITY;
	_tmp15_ = dino_stream_interactor_get_module (stream_interactor, DINO_TYPE_CALLS, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp14_);
	_tmp16_ = (DinoCalls*) _tmp15_;
	g_signal_connect_object (_tmp16_, "call-outgoing", (GCallback) _dino_conversation_manager_handle_new_call_dino_calls_call_outgoing, self, 0);
	_g_object_unref0 (_tmp16_);
	return self;
}

static DinoConversationManager*
dino_conversation_manager_new (DinoStreamInteractor* stream_interactor,
                               DinoDatabase* db)
{
	return dino_conversation_manager_construct (DINO_TYPE_CONVERSATION_MANAGER, stream_interactor, db);
}

static gboolean
_dino_entities_conversation_type_equal (const DinoEntitiesConversationType * s1,
                                        const DinoEntitiesConversationType * s2)
{
	if (s1 == s2) {
		return TRUE;
	}
	if (s1 == NULL) {
		return FALSE;
	}
	if (s2 == NULL) {
		return FALSE;
	}
	return (*s1) == (*s2);
}

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

DinoEntitiesConversation*
dino_conversation_manager_create_conversation (DinoConversationManager* self,
                                               XmppJid* jid,
                                               DinoEntitiesAccount* account,
                                               DinoEntitiesConversationType* type)
{
	GeeHashMap* _tmp0_;
	XmppJid* _tmp1_ = NULL;
	DinoEntitiesConversationType _tmp2_;
	XmppJid* store_jid = NULL;
	XmppJid* _tmp6_;
	GeeHashMap* _tmp7_;
	gpointer _tmp8_;
	GeeHashMap* _tmp9_;
	XmppJid* _tmp10_;
	gboolean _tmp11_;
	DinoEntitiesConversation* conversation = NULL;
	DinoEntitiesConversation* _tmp28_;
	gboolean _tmp29_ = FALSE;
	DinoEntitiesConversationType _tmp30_;
	DinoEntitiesConversation* _tmp42_;
	DinoEntitiesConversation* _tmp43_;
	DinoDatabase* _tmp44_;
	DinoEntitiesConversation* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (jid != NULL, NULL);
	g_return_val_if_fail (account != NULL, NULL);
	_tmp0_ = self->priv->conversations;
	_vala_assert (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp0_, account), "conversations.has_key(account)");
	_tmp2_ = DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT;
	if (_dino_entities_conversation_type_equal (type, &_tmp2_) == TRUE) {
		XmppJid* _tmp3_;
		XmppJid* _tmp4_;
		_tmp3_ = xmpp_jid_get_bare_jid (jid);
		_tmp4_ = _tmp3_;
		_xmpp_jid_unref0 (_tmp1_);
		_tmp1_ = _tmp4_;
	} else {
		XmppJid* _tmp5_;
		_tmp5_ = _xmpp_jid_ref0 (jid);
		_xmpp_jid_unref0 (_tmp1_);
		_tmp1_ = _tmp5_;
	}
	_tmp6_ = _tmp1_;
	_tmp1_ = NULL;
	store_jid = _tmp6_;
	_tmp7_ = self->priv->conversations;
	_tmp8_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp7_, account);
	_tmp9_ = (GeeHashMap*) _tmp8_;
	_tmp10_ = store_jid;
	_tmp11_ = gee_abstract_map_has_key ((GeeAbstractMap*) _tmp9_, _tmp10_);
	_g_object_unref0 (_tmp9_);
	if (_tmp11_) {
		{
			GeeList* _conversation_list = NULL;
			GeeHashMap* _tmp12_;
			gpointer _tmp13_;
			GeeHashMap* _tmp14_;
			XmppJid* _tmp15_;
			gpointer _tmp16_;
			GeeList* _tmp17_;
			gint _conversation_size = 0;
			GeeList* _tmp18_;
			gint _tmp19_;
			gint _tmp20_;
			gint _conversation_index = 0;
			_tmp12_ = self->priv->conversations;
			_tmp13_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp12_, account);
			_tmp14_ = (GeeHashMap*) _tmp13_;
			_tmp15_ = store_jid;
			_tmp16_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp14_, _tmp15_);
			_tmp17_ = (GeeList*) _tmp16_;
			_g_object_unref0 (_tmp14_);
			_conversation_list = _tmp17_;
			_tmp18_ = _conversation_list;
			_tmp19_ = gee_collection_get_size ((GeeCollection*) _tmp18_);
			_tmp20_ = _tmp19_;
			_conversation_size = _tmp20_;
			_conversation_index = -1;
			while (TRUE) {
				gint _tmp21_;
				gint _tmp22_;
				DinoEntitiesConversation* conversation = NULL;
				GeeList* _tmp23_;
				gpointer _tmp24_;
				DinoEntitiesConversation* _tmp25_;
				DinoEntitiesConversationType _tmp26_;
				DinoEntitiesConversationType _tmp27_;
				_conversation_index = _conversation_index + 1;
				_tmp21_ = _conversation_index;
				_tmp22_ = _conversation_size;
				if (!(_tmp21_ < _tmp22_)) {
					break;
				}
				_tmp23_ = _conversation_list;
				_tmp24_ = gee_list_get (_tmp23_, _conversation_index);
				conversation = (DinoEntitiesConversation*) _tmp24_;
				_tmp25_ = conversation;
				_tmp26_ = dino_entities_conversation_get_type_ (_tmp25_);
				_tmp27_ = _tmp26_;
				if (_dino_entities_conversation_type_equal (&_tmp27_, type) == TRUE) {
					result = conversation;
					_g_object_unref0 (_conversation_list);
					_xmpp_jid_unref0 (store_jid);
					_xmpp_jid_unref0 (_tmp1_);
					return result;
				}
				_g_object_unref0 (conversation);
			}
			_g_object_unref0 (_conversation_list);
		}
	}
	_tmp28_ = dino_entities_conversation_new (jid, account, *type);
	conversation = _tmp28_;
	_tmp30_ = DINO_ENTITIES_CONVERSATION_TYPE_CHAT;
	if (_dino_entities_conversation_type_equal (type, &_tmp30_) == TRUE) {
		_tmp29_ = TRUE;
	} else {
		gboolean _tmp31_ = FALSE;
		DinoEntitiesConversationType _tmp32_;
		_tmp32_ = DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT;
		if (_dino_entities_conversation_type_equal (type, &_tmp32_) == TRUE) {
			DinoStreamInteractor* _tmp33_;
			DinoModuleIdentity* _tmp34_;
			gpointer _tmp35_;
			DinoMucManager* _tmp36_;
			_tmp33_ = self->priv->stream_interactor;
			_tmp34_ = dino_muc_manager_IDENTITY;
			_tmp35_ = dino_stream_interactor_get_module (_tmp33_, DINO_TYPE_MUC_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp34_);
			_tmp36_ = (DinoMucManager*) _tmp35_;
			_tmp31_ = dino_muc_manager_is_private_room (_tmp36_, account, jid);
			_g_object_unref0 (_tmp36_);
		} else {
			_tmp31_ = FALSE;
		}
		_tmp29_ = _tmp31_;
	}
	if (_tmp29_) {
		DinoEntitiesConversation* _tmp37_;
		DinoApplication* _tmp38_;
		DinoEntitiesSettings* _tmp39_;
		DinoEntitiesSettings* _tmp40_;
		_tmp37_ = conversation;
		_tmp38_ = dino_application_get_default ();
		_tmp39_ = dino_application_get_settings (_tmp38_);
		_tmp40_ = _tmp39_;
		dino_entities_conversation_set_encryption (_tmp37_, dino_entities_settings_get_default_encryption (_tmp40_, account));
	} else {
		DinoEntitiesConversation* _tmp41_;
		_tmp41_ = conversation;
		dino_entities_conversation_set_encryption (_tmp41_, DINO_ENTITIES_ENCRYPTION_NONE);
	}
	_tmp42_ = conversation;
	dino_conversation_manager_add_conversation (self, _tmp42_);
	_tmp43_ = conversation;
	_tmp44_ = self->priv->db;
	dino_entities_conversation_persist (_tmp43_, _tmp44_);
	result = conversation;
	_xmpp_jid_unref0 (store_jid);
	_xmpp_jid_unref0 (_tmp1_);
	return result;
}

DinoEntitiesConversation*
dino_conversation_manager_get_conversation_for_message (DinoConversationManager* self,
                                                        DinoEntitiesMessage* message)
{
	GeeHashMap* _tmp0_;
	DinoEntitiesAccount* _tmp1_;
	DinoEntitiesAccount* _tmp2_;
	DinoEntitiesConversation* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (message != NULL, NULL);
	_tmp0_ = self->priv->conversations;
	_tmp1_ = dino_entities_message_get_account (message);
	_tmp2_ = _tmp1_;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp0_, _tmp2_)) {
		DinoEntitiesMessageType _tmp3_;
		DinoEntitiesMessageType _tmp4_;
		_tmp3_ = dino_entities_message_get_type_ (message);
		_tmp4_ = _tmp3_;
		if (_tmp4_ == DINO_ENTITIES_MESSAGE_TYPE_CHAT) {
			XmppJid* _tmp5_;
			XmppJid* _tmp6_;
			XmppJid* _tmp7_;
			XmppJid* _tmp8_;
			XmppJid* _tmp9_;
			DinoEntitiesAccount* _tmp10_;
			DinoEntitiesAccount* _tmp11_;
			DinoEntitiesConversationType _tmp12_;
			DinoEntitiesConversation* _tmp13_;
			DinoEntitiesConversation* _tmp14_;
			_tmp5_ = dino_entities_message_get_counterpart (message);
			_tmp6_ = _tmp5_;
			_tmp7_ = xmpp_jid_get_bare_jid (_tmp6_);
			_tmp8_ = _tmp7_;
			_tmp9_ = _tmp8_;
			_tmp10_ = dino_entities_message_get_account (message);
			_tmp11_ = _tmp10_;
			_tmp12_ = DINO_ENTITIES_CONVERSATION_TYPE_CHAT;
			_tmp13_ = dino_conversation_manager_create_conversation (self, _tmp9_, _tmp11_, &_tmp12_);
			_tmp14_ = _tmp13_;
			_xmpp_jid_unref0 (_tmp9_);
			result = _tmp14_;
			return result;
		} else {
			DinoEntitiesMessageType _tmp15_;
			DinoEntitiesMessageType _tmp16_;
			_tmp15_ = dino_entities_message_get_type_ (message);
			_tmp16_ = _tmp15_;
			if (_tmp16_ == DINO_ENTITIES_MESSAGE_TYPE_GROUPCHAT) {
				XmppJid* _tmp17_;
				XmppJid* _tmp18_;
				XmppJid* _tmp19_;
				XmppJid* _tmp20_;
				XmppJid* _tmp21_;
				DinoEntitiesAccount* _tmp22_;
				DinoEntitiesAccount* _tmp23_;
				DinoEntitiesConversationType _tmp24_;
				DinoEntitiesConversation* _tmp25_;
				DinoEntitiesConversation* _tmp26_;
				_tmp17_ = dino_entities_message_get_counterpart (message);
				_tmp18_ = _tmp17_;
				_tmp19_ = xmpp_jid_get_bare_jid (_tmp18_);
				_tmp20_ = _tmp19_;
				_tmp21_ = _tmp20_;
				_tmp22_ = dino_entities_message_get_account (message);
				_tmp23_ = _tmp22_;
				_tmp24_ = DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT;
				_tmp25_ = dino_conversation_manager_create_conversation (self, _tmp21_, _tmp23_, &_tmp24_);
				_tmp26_ = _tmp25_;
				_xmpp_jid_unref0 (_tmp21_);
				result = _tmp26_;
				return result;
			} else {
				DinoEntitiesMessageType _tmp27_;
				DinoEntitiesMessageType _tmp28_;
				_tmp27_ = dino_entities_message_get_type_ (message);
				_tmp28_ = _tmp27_;
				if (_tmp28_ == DINO_ENTITIES_MESSAGE_TYPE_GROUPCHAT_PM) {
					XmppJid* _tmp29_;
					XmppJid* _tmp30_;
					DinoEntitiesAccount* _tmp31_;
					DinoEntitiesAccount* _tmp32_;
					DinoEntitiesConversationType _tmp33_;
					DinoEntitiesConversation* _tmp34_;
					_tmp29_ = dino_entities_message_get_counterpart (message);
					_tmp30_ = _tmp29_;
					_tmp31_ = dino_entities_message_get_account (message);
					_tmp32_ = _tmp31_;
					_tmp33_ = DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT_PM;
					_tmp34_ = dino_conversation_manager_create_conversation (self, _tmp30_, _tmp32_, &_tmp33_);
					result = _tmp34_;
					return result;
				}
			}
		}
	}
	result = NULL;
	return result;
}

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

GeeList*
dino_conversation_manager_get_conversations (DinoConversationManager* self,
                                             XmppJid* jid,
                                             DinoEntitiesAccount* account)
{
	GeeList* ret = NULL;
	GeeArrayList* _tmp0_;
	DinoEntitiesConversation* bare_conversation = NULL;
	DinoEntitiesConversation* _tmp1_;
	DinoEntitiesConversation* _tmp2_;
	DinoEntitiesConversation* full_conversation = NULL;
	XmppJid* _tmp5_;
	XmppJid* _tmp6_;
	XmppJid* _tmp7_;
	DinoEntitiesConversation* _tmp8_;
	DinoEntitiesConversation* _tmp9_;
	DinoEntitiesConversation* _tmp10_;
	GeeList* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (jid != NULL, NULL);
	g_return_val_if_fail (account != NULL, NULL);
	_tmp0_ = gee_array_list_new (DINO_ENTITIES_TYPE_CONVERSATION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _dino_entities_conversation_equals_func_gee_equal_data_func, NULL, NULL);
	ret = (GeeList*) _tmp0_;
	_tmp1_ = dino_conversation_manager_get_conversation (self, jid, account, NULL);
	bare_conversation = _tmp1_;
	_tmp2_ = bare_conversation;
	if (_tmp2_ != NULL) {
		GeeList* _tmp3_;
		DinoEntitiesConversation* _tmp4_;
		_tmp3_ = ret;
		_tmp4_ = bare_conversation;
		gee_collection_add ((GeeCollection*) _tmp3_, _tmp4_);
	}
	_tmp5_ = xmpp_jid_get_bare_jid (jid);
	_tmp6_ = _tmp5_;
	_tmp7_ = _tmp6_;
	_tmp8_ = dino_conversation_manager_get_conversation (self, _tmp7_, account, NULL);
	_tmp9_ = _tmp8_;
	_xmpp_jid_unref0 (_tmp7_);
	full_conversation = _tmp9_;
	_tmp10_ = full_conversation;
	if (_tmp10_ != NULL) {
		GeeList* _tmp11_;
		DinoEntitiesConversation* _tmp12_;
		_tmp11_ = ret;
		_tmp12_ = full_conversation;
		gee_collection_add ((GeeCollection*) _tmp11_, _tmp12_);
	}
	result = ret;
	_g_object_unref0 (full_conversation);
	_g_object_unref0 (bare_conversation);
	return result;
}

DinoEntitiesConversation*
dino_conversation_manager_get_conversation (DinoConversationManager* self,
                                            XmppJid* jid,
                                            DinoEntitiesAccount* account,
                                            DinoEntitiesConversationType* type)
{
	GeeHashMap* _tmp0_;
	DinoEntitiesConversation* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (jid != NULL, NULL);
	g_return_val_if_fail (account != NULL, NULL);
	_tmp0_ = self->priv->conversations;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp0_, account)) {
		GeeHashMap* _tmp1_;
		gpointer _tmp2_;
		GeeHashMap* _tmp3_;
		gboolean _tmp4_;
		_tmp1_ = self->priv->conversations;
		_tmp2_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp1_, account);
		_tmp3_ = (GeeHashMap*) _tmp2_;
		_tmp4_ = gee_abstract_map_has_key ((GeeAbstractMap*) _tmp3_, jid);
		_g_object_unref0 (_tmp3_);
		if (_tmp4_) {
			{
				GeeList* _conversation_list = NULL;
				GeeHashMap* _tmp5_;
				gpointer _tmp6_;
				GeeHashMap* _tmp7_;
				gpointer _tmp8_;
				GeeList* _tmp9_;
				gint _conversation_size = 0;
				GeeList* _tmp10_;
				gint _tmp11_;
				gint _tmp12_;
				gint _conversation_index = 0;
				_tmp5_ = self->priv->conversations;
				_tmp6_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp5_, account);
				_tmp7_ = (GeeHashMap*) _tmp6_;
				_tmp8_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp7_, jid);
				_tmp9_ = (GeeList*) _tmp8_;
				_g_object_unref0 (_tmp7_);
				_conversation_list = _tmp9_;
				_tmp10_ = _conversation_list;
				_tmp11_ = gee_collection_get_size ((GeeCollection*) _tmp10_);
				_tmp12_ = _tmp11_;
				_conversation_size = _tmp12_;
				_conversation_index = -1;
				while (TRUE) {
					gint _tmp13_;
					gint _tmp14_;
					DinoEntitiesConversation* conversation = NULL;
					GeeList* _tmp15_;
					gpointer _tmp16_;
					gboolean _tmp17_ = FALSE;
					_conversation_index = _conversation_index + 1;
					_tmp13_ = _conversation_index;
					_tmp14_ = _conversation_size;
					if (!(_tmp13_ < _tmp14_)) {
						break;
					}
					_tmp15_ = _conversation_list;
					_tmp16_ = gee_list_get (_tmp15_, _conversation_index);
					conversation = (DinoEntitiesConversation*) _tmp16_;
					if (type == NULL) {
						_tmp17_ = TRUE;
					} else {
						DinoEntitiesConversation* _tmp18_;
						DinoEntitiesConversationType _tmp19_;
						DinoEntitiesConversationType _tmp20_;
						_tmp18_ = conversation;
						_tmp19_ = dino_entities_conversation_get_type_ (_tmp18_);
						_tmp20_ = _tmp19_;
						_tmp17_ = _dino_entities_conversation_type_equal (&_tmp20_, type) == TRUE;
					}
					if (_tmp17_) {
						result = conversation;
						_g_object_unref0 (_conversation_list);
						return result;
					}
					_g_object_unref0 (conversation);
				}
				_g_object_unref0 (_conversation_list);
			}
		}
	}
	result = NULL;
	return result;
}

DinoEntitiesConversation*
dino_conversation_manager_approx_conversation_for_stanza (DinoConversationManager* self,
                                                          XmppJid* from,
                                                          XmppJid* to,
                                                          DinoEntitiesAccount* account,
                                                          const gchar* msg_ty)
{
	XmppJid* _tmp6_ = NULL;
	XmppJid* _tmp7_;
	XmppJid* _tmp8_;
	XmppJid* _tmp9_;
	gboolean _tmp10_;
	XmppJid* counterpart = NULL;
	XmppJid* _tmp11_;
	gboolean _tmp12_ = FALSE;
	gboolean _tmp13_ = FALSE;
	XmppJid* _tmp26_;
	XmppJid* _tmp27_;
	XmppJid* _tmp28_;
	XmppJid* _tmp29_;
	DinoEntitiesConversationType _tmp30_;
	DinoEntitiesConversation* _tmp31_;
	DinoEntitiesConversation* _tmp32_;
	DinoEntitiesConversation* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (from != NULL, NULL);
	g_return_val_if_fail (to != NULL, NULL);
	g_return_val_if_fail (account != NULL, NULL);
	g_return_val_if_fail (msg_ty != NULL, NULL);
	if (g_strcmp0 (msg_ty, XMPP_MESSAGE_STANZA_TYPE_GROUPCHAT) == 0) {
		XmppJid* _tmp0_;
		XmppJid* _tmp1_;
		XmppJid* _tmp2_;
		DinoEntitiesConversationType _tmp3_;
		DinoEntitiesConversation* _tmp4_;
		DinoEntitiesConversation* _tmp5_;
		_tmp0_ = xmpp_jid_get_bare_jid (from);
		_tmp1_ = _tmp0_;
		_tmp2_ = _tmp1_;
		_tmp3_ = DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT;
		_tmp4_ = dino_conversation_manager_get_conversation (self, _tmp2_, account, &_tmp3_);
		_tmp5_ = _tmp4_;
		_xmpp_jid_unref0 (_tmp2_);
		result = _tmp5_;
		return result;
	}
	_tmp7_ = dino_entities_account_get_bare_jid (account);
	_tmp8_ = _tmp7_;
	_tmp9_ = _tmp8_;
	_tmp10_ = xmpp_jid_equals_bare (from, _tmp9_);
	_xmpp_jid_unref0 (_tmp9_);
	if (_tmp10_) {
		_tmp6_ = to;
	} else {
		_tmp6_ = from;
	}
	_tmp11_ = _xmpp_jid_ref0 (_tmp6_);
	counterpart = _tmp11_;
	if (g_strcmp0 (msg_ty, XMPP_MESSAGE_STANZA_TYPE_CHAT) == 0) {
		XmppJid* _tmp14_;
		_tmp14_ = counterpart;
		_tmp13_ = xmpp_jid_is_full (_tmp14_);
	} else {
		_tmp13_ = FALSE;
	}
	if (_tmp13_) {
		XmppJid* _tmp15_;
		XmppJid* _tmp16_;
		XmppJid* _tmp17_;
		XmppJid* _tmp18_;
		DinoEntitiesConversationType _tmp19_;
		DinoEntitiesConversation* _tmp20_;
		DinoEntitiesConversation* _tmp21_;
		_tmp15_ = counterpart;
		_tmp16_ = xmpp_jid_get_bare_jid (_tmp15_);
		_tmp17_ = _tmp16_;
		_tmp18_ = _tmp17_;
		_tmp19_ = DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT;
		_tmp20_ = dino_conversation_manager_get_conversation (self, _tmp18_, account, &_tmp19_);
		_tmp21_ = _tmp20_;
		_tmp12_ = _tmp21_ != NULL;
		_g_object_unref0 (_tmp21_);
		_xmpp_jid_unref0 (_tmp18_);
	} else {
		_tmp12_ = FALSE;
	}
	if (_tmp12_) {
		DinoEntitiesConversation* pm = NULL;
		XmppJid* _tmp22_;
		DinoEntitiesConversationType _tmp23_;
		DinoEntitiesConversation* _tmp24_;
		DinoEntitiesConversation* _tmp25_;
		_tmp22_ = counterpart;
		_tmp23_ = DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT_PM;
		_tmp24_ = dino_conversation_manager_get_conversation (self, _tmp22_, account, &_tmp23_);
		pm = _tmp24_;
		_tmp25_ = pm;
		if (_tmp25_ != NULL) {
			result = pm;
			_xmpp_jid_unref0 (counterpart);
			return result;
		}
		_g_object_unref0 (pm);
	}
	_tmp26_ = counterpart;
	_tmp27_ = xmpp_jid_get_bare_jid (_tmp26_);
	_tmp28_ = _tmp27_;
	_tmp29_ = _tmp28_;
	_tmp30_ = DINO_ENTITIES_CONVERSATION_TYPE_CHAT;
	_tmp31_ = dino_conversation_manager_get_conversation (self, _tmp29_, account, &_tmp30_);
	_tmp32_ = _tmp31_;
	_xmpp_jid_unref0 (_tmp29_);
	result = _tmp32_;
	_xmpp_jid_unref0 (counterpart);
	return result;
}

DinoEntitiesConversation*
dino_conversation_manager_get_conversation_by_id (DinoConversationManager* self,
                                                  gint id)
{
	DinoEntitiesConversation* result;
	g_return_val_if_fail (self != NULL, NULL);
	{
		GeeIterator* _hm_it = NULL;
		GeeHashMap* _tmp0_;
		GeeCollection* _tmp1_;
		GeeCollection* _tmp2_;
		GeeCollection* _tmp3_;
		GeeIterator* _tmp4_;
		GeeIterator* _tmp5_;
		_tmp0_ = self->priv->conversations;
		_tmp1_ = gee_abstract_map_get_values ((GeeAbstractMap*) _tmp0_);
		_tmp2_ = _tmp1_;
		_tmp3_ = _tmp2_;
		_tmp4_ = gee_iterable_iterator ((GeeIterable*) _tmp3_);
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp3_);
		_hm_it = _tmp5_;
		while (TRUE) {
			GeeIterator* _tmp6_;
			GeeHashMap* hm = NULL;
			GeeIterator* _tmp7_;
			gpointer _tmp8_;
			_tmp6_ = _hm_it;
			if (!gee_iterator_next (_tmp6_)) {
				break;
			}
			_tmp7_ = _hm_it;
			_tmp8_ = gee_iterator_get (_tmp7_);
			hm = (GeeHashMap*) _tmp8_;
			{
				GeeIterator* _hm2_it = NULL;
				GeeHashMap* _tmp9_;
				GeeCollection* _tmp10_;
				GeeCollection* _tmp11_;
				GeeCollection* _tmp12_;
				GeeIterator* _tmp13_;
				GeeIterator* _tmp14_;
				_tmp9_ = hm;
				_tmp10_ = gee_abstract_map_get_values ((GeeAbstractMap*) _tmp9_);
				_tmp11_ = _tmp10_;
				_tmp12_ = _tmp11_;
				_tmp13_ = gee_iterable_iterator ((GeeIterable*) _tmp12_);
				_tmp14_ = _tmp13_;
				_g_object_unref0 (_tmp12_);
				_hm2_it = _tmp14_;
				while (TRUE) {
					GeeIterator* _tmp15_;
					GeeList* hm2 = NULL;
					GeeIterator* _tmp16_;
					gpointer _tmp17_;
					_tmp15_ = _hm2_it;
					if (!gee_iterator_next (_tmp15_)) {
						break;
					}
					_tmp16_ = _hm2_it;
					_tmp17_ = gee_iterator_get (_tmp16_);
					hm2 = (GeeList*) _tmp17_;
					{
						GeeList* _conversation_list = NULL;
						GeeList* _tmp18_;
						gint _conversation_size = 0;
						GeeList* _tmp19_;
						gint _tmp20_;
						gint _tmp21_;
						gint _conversation_index = 0;
						_tmp18_ = hm2;
						_conversation_list = _tmp18_;
						_tmp19_ = _conversation_list;
						_tmp20_ = gee_collection_get_size ((GeeCollection*) _tmp19_);
						_tmp21_ = _tmp20_;
						_conversation_size = _tmp21_;
						_conversation_index = -1;
						while (TRUE) {
							gint _tmp22_;
							gint _tmp23_;
							DinoEntitiesConversation* conversation = NULL;
							GeeList* _tmp24_;
							gpointer _tmp25_;
							DinoEntitiesConversation* _tmp26_;
							gint _tmp27_;
							gint _tmp28_;
							_conversation_index = _conversation_index + 1;
							_tmp22_ = _conversation_index;
							_tmp23_ = _conversation_size;
							if (!(_tmp22_ < _tmp23_)) {
								break;
							}
							_tmp24_ = _conversation_list;
							_tmp25_ = gee_list_get (_tmp24_, _conversation_index);
							conversation = (DinoEntitiesConversation*) _tmp25_;
							_tmp26_ = conversation;
							_tmp27_ = dino_entities_conversation_get_id (_tmp26_);
							_tmp28_ = _tmp27_;
							if (_tmp28_ == id) {
								result = conversation;
								_g_object_unref0 (hm2);
								_g_object_unref0 (_hm2_it);
								_g_object_unref0 (hm);
								_g_object_unref0 (_hm_it);
								return result;
							}
							_g_object_unref0 (conversation);
						}
					}
					_g_object_unref0 (hm2);
				}
				_g_object_unref0 (_hm2_it);
			}
			_g_object_unref0 (hm);
		}
		_g_object_unref0 (_hm_it);
	}
	result = NULL;
	return result;
}

GeeList*
dino_conversation_manager_get_active_conversations (DinoConversationManager* self,
                                                    DinoEntitiesAccount* account)
{
	GeeList* ret = NULL;
	GeeArrayList* _tmp0_;
	GeeList* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = gee_array_list_new (DINO_ENTITIES_TYPE_CONVERSATION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _dino_entities_conversation_equals_func_gee_equal_data_func, NULL, NULL);
	ret = (GeeList*) _tmp0_;
	{
		GeeIterator* _account__it = NULL;
		GeeHashMap* _tmp1_;
		GeeSet* _tmp2_;
		GeeSet* _tmp3_;
		GeeSet* _tmp4_;
		GeeIterator* _tmp5_;
		GeeIterator* _tmp6_;
		_tmp1_ = self->priv->conversations;
		_tmp2_ = gee_abstract_map_get_keys ((GeeAbstractMap*) _tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = _tmp3_;
		_tmp5_ = gee_iterable_iterator ((GeeIterable*) _tmp4_);
		_tmp6_ = _tmp5_;
		_g_object_unref0 (_tmp4_);
		_account__it = _tmp6_;
		while (TRUE) {
			GeeIterator* _tmp7_;
			DinoEntitiesAccount* account_ = NULL;
			GeeIterator* _tmp8_;
			gpointer _tmp9_;
			gboolean _tmp10_ = FALSE;
			_tmp7_ = _account__it;
			if (!gee_iterator_next (_tmp7_)) {
				break;
			}
			_tmp8_ = _account__it;
			_tmp9_ = gee_iterator_get (_tmp8_);
			account_ = (DinoEntitiesAccount*) _tmp9_;
			if (account != NULL) {
				DinoEntitiesAccount* _tmp11_;
				_tmp11_ = account_;
				_tmp10_ = !dino_entities_account_equals (_tmp11_, account);
			} else {
				_tmp10_ = FALSE;
			}
			if (_tmp10_) {
				_g_object_unref0 (account_);
				continue;
			}
			{
				GeeIterator* _list_it = NULL;
				GeeHashMap* _tmp12_;
				DinoEntitiesAccount* _tmp13_;
				gpointer _tmp14_;
				GeeHashMap* _tmp15_;
				GeeCollection* _tmp16_;
				GeeCollection* _tmp17_;
				GeeCollection* _tmp18_;
				GeeIterator* _tmp19_;
				GeeIterator* _tmp20_;
				_tmp12_ = self->priv->conversations;
				_tmp13_ = account_;
				_tmp14_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp12_, _tmp13_);
				_tmp15_ = (GeeHashMap*) _tmp14_;
				_tmp16_ = gee_abstract_map_get_values ((GeeAbstractMap*) _tmp15_);
				_tmp17_ = _tmp16_;
				_tmp18_ = _tmp17_;
				_tmp19_ = gee_iterable_iterator ((GeeIterable*) _tmp18_);
				_tmp20_ = _tmp19_;
				_g_object_unref0 (_tmp18_);
				_g_object_unref0 (_tmp15_);
				_list_it = _tmp20_;
				while (TRUE) {
					GeeIterator* _tmp21_;
					GeeList* list = NULL;
					GeeIterator* _tmp22_;
					gpointer _tmp23_;
					_tmp21_ = _list_it;
					if (!gee_iterator_next (_tmp21_)) {
						break;
					}
					_tmp22_ = _list_it;
					_tmp23_ = gee_iterator_get (_tmp22_);
					list = (GeeList*) _tmp23_;
					{
						GeeList* _conversation_list = NULL;
						GeeList* _tmp24_;
						gint _conversation_size = 0;
						GeeList* _tmp25_;
						gint _tmp26_;
						gint _tmp27_;
						gint _conversation_index = 0;
						_tmp24_ = list;
						_conversation_list = _tmp24_;
						_tmp25_ = _conversation_list;
						_tmp26_ = gee_collection_get_size ((GeeCollection*) _tmp25_);
						_tmp27_ = _tmp26_;
						_conversation_size = _tmp27_;
						_conversation_index = -1;
						while (TRUE) {
							gint _tmp28_;
							gint _tmp29_;
							DinoEntitiesConversation* conversation = NULL;
							GeeList* _tmp30_;
							gpointer _tmp31_;
							DinoEntitiesConversation* _tmp32_;
							gboolean _tmp33_;
							gboolean _tmp34_;
							_conversation_index = _conversation_index + 1;
							_tmp28_ = _conversation_index;
							_tmp29_ = _conversation_size;
							if (!(_tmp28_ < _tmp29_)) {
								break;
							}
							_tmp30_ = _conversation_list;
							_tmp31_ = gee_list_get (_tmp30_, _conversation_index);
							conversation = (DinoEntitiesConversation*) _tmp31_;
							_tmp32_ = conversation;
							_tmp33_ = dino_entities_conversation_get_active (_tmp32_);
							_tmp34_ = _tmp33_;
							if (_tmp34_) {
								GeeList* _tmp35_;
								DinoEntitiesConversation* _tmp36_;
								_tmp35_ = ret;
								_tmp36_ = conversation;
								gee_collection_add ((GeeCollection*) _tmp35_, _tmp36_);
							}
							_g_object_unref0 (conversation);
						}
					}
					_g_object_unref0 (list);
				}
				_g_object_unref0 (_list_it);
			}
			_g_object_unref0 (account_);
		}
		_g_object_unref0 (_account__it);
	}
	result = ret;
	return result;
}

void
dino_conversation_manager_start_conversation (DinoConversationManager* self,
                                              DinoEntitiesConversation* conversation)
{
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (conversation != NULL);
	_tmp0_ = dino_entities_conversation_get_last_active (conversation);
	_tmp1_ = _tmp0_;
	if (_tmp1_ == NULL) {
		GDateTime* _tmp2_;
		GDateTime* _tmp3_;
		gboolean _tmp4_;
		gboolean _tmp5_;
		_tmp2_ = g_date_time_new_now_utc ();
		_tmp3_ = _tmp2_;
		dino_entities_conversation_set_last_active (conversation, _tmp3_);
		_g_date_time_unref0 (_tmp3_);
		_tmp4_ = dino_entities_conversation_get_active (conversation);
		_tmp5_ = _tmp4_;
		if (_tmp5_) {
			g_signal_emit (self, dino_conversation_manager_signals[DINO_CONVERSATION_MANAGER_CONVERSATION_ACTIVATED_SIGNAL], 0, conversation);
		}
	}
	_tmp6_ = dino_entities_conversation_get_active (conversation);
	_tmp7_ = _tmp6_;
	if (!_tmp7_) {
		dino_entities_conversation_set_active (conversation, TRUE);
		g_signal_emit (self, dino_conversation_manager_signals[DINO_CONVERSATION_MANAGER_CONVERSATION_ACTIVATED_SIGNAL], 0, conversation);
	}
}

void
dino_conversation_manager_close_conversation (DinoConversationManager* self,
                                              DinoEntitiesConversation* conversation)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (conversation != NULL);
	_tmp0_ = dino_entities_conversation_get_active (conversation);
	_tmp1_ = _tmp0_;
	if (!_tmp1_) {
		return;
	}
	dino_entities_conversation_set_active (conversation, FALSE);
	g_signal_emit (self, dino_conversation_manager_signals[DINO_CONVERSATION_MANAGER_CONVERSATION_DEACTIVATED_SIGNAL], 0, conversation);
}

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

static void
dino_conversation_manager_on_account_added (DinoConversationManager* self,
                                            DinoEntitiesAccount* account)
{
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	GeeHashMap* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	_tmp0_ = self->priv->conversations;
	_tmp1_ = gee_hash_map_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, GEE_TYPE_ARRAY_LIST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _xmpp_jid_hash_func_gee_hash_data_func, NULL, NULL, _xmpp_jid_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	_tmp2_ = _tmp1_;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp0_, account, _tmp2_);
	_g_object_unref0 (_tmp2_);
	{
		GeeArrayList* _conversation_list = NULL;
		DinoDatabase* _tmp3_;
		GeeArrayList* _tmp4_;
		gint _conversation_size = 0;
		GeeArrayList* _tmp5_;
		gint _tmp6_;
		gint _tmp7_;
		gint _conversation_index = 0;
		_tmp3_ = self->priv->db;
		_tmp4_ = dino_database_get_conversations (_tmp3_, account);
		_conversation_list = _tmp4_;
		_tmp5_ = _conversation_list;
		_tmp6_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp5_);
		_tmp7_ = _tmp6_;
		_conversation_size = _tmp7_;
		_conversation_index = -1;
		while (TRUE) {
			gint _tmp8_;
			gint _tmp9_;
			DinoEntitiesConversation* conversation = NULL;
			GeeArrayList* _tmp10_;
			gpointer _tmp11_;
			DinoEntitiesConversation* _tmp12_;
			_conversation_index = _conversation_index + 1;
			_tmp8_ = _conversation_index;
			_tmp9_ = _conversation_size;
			if (!(_tmp8_ < _tmp9_)) {
				break;
			}
			_tmp10_ = _conversation_list;
			_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) _tmp10_, _conversation_index);
			conversation = (DinoEntitiesConversation*) _tmp11_;
			_tmp12_ = conversation;
			dino_conversation_manager_add_conversation (self, _tmp12_);
			_g_object_unref0 (conversation);
		}
		_g_object_unref0 (_conversation_list);
	}
}

static void
dino_conversation_manager_on_account_removed (DinoConversationManager* self,
                                              DinoEntitiesAccount* account)
{
	GeeHashMap* _tmp23_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	{
		GeeIterator* _list_it = NULL;
		GeeHashMap* _tmp0_;
		gpointer _tmp1_;
		GeeHashMap* _tmp2_;
		GeeCollection* _tmp3_;
		GeeCollection* _tmp4_;
		GeeCollection* _tmp5_;
		GeeIterator* _tmp6_;
		GeeIterator* _tmp7_;
		_tmp0_ = self->priv->conversations;
		_tmp1_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp0_, account);
		_tmp2_ = (GeeHashMap*) _tmp1_;
		_tmp3_ = gee_abstract_map_get_values ((GeeAbstractMap*) _tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = _tmp4_;
		_tmp6_ = gee_iterable_iterator ((GeeIterable*) _tmp5_);
		_tmp7_ = _tmp6_;
		_g_object_unref0 (_tmp5_);
		_g_object_unref0 (_tmp2_);
		_list_it = _tmp7_;
		while (TRUE) {
			GeeIterator* _tmp8_;
			GeeList* list = NULL;
			GeeIterator* _tmp9_;
			gpointer _tmp10_;
			_tmp8_ = _list_it;
			if (!gee_iterator_next (_tmp8_)) {
				break;
			}
			_tmp9_ = _list_it;
			_tmp10_ = gee_iterator_get (_tmp9_);
			list = (GeeList*) _tmp10_;
			{
				GeeList* _conversation_list = NULL;
				GeeList* _tmp11_;
				gint _conversation_size = 0;
				GeeList* _tmp12_;
				gint _tmp13_;
				gint _tmp14_;
				gint _conversation_index = 0;
				_tmp11_ = list;
				_conversation_list = _tmp11_;
				_tmp12_ = _conversation_list;
				_tmp13_ = gee_collection_get_size ((GeeCollection*) _tmp12_);
				_tmp14_ = _tmp13_;
				_conversation_size = _tmp14_;
				_conversation_index = -1;
				while (TRUE) {
					gint _tmp15_;
					gint _tmp16_;
					DinoEntitiesConversation* conversation = NULL;
					GeeList* _tmp17_;
					gpointer _tmp18_;
					DinoEntitiesConversation* _tmp19_;
					gboolean _tmp20_;
					gboolean _tmp21_;
					_conversation_index = _conversation_index + 1;
					_tmp15_ = _conversation_index;
					_tmp16_ = _conversation_size;
					if (!(_tmp15_ < _tmp16_)) {
						break;
					}
					_tmp17_ = _conversation_list;
					_tmp18_ = gee_list_get (_tmp17_, _conversation_index);
					conversation = (DinoEntitiesConversation*) _tmp18_;
					_tmp19_ = conversation;
					_tmp20_ = dino_entities_conversation_get_active (_tmp19_);
					_tmp21_ = _tmp20_;
					if (_tmp21_) {
						DinoEntitiesConversation* _tmp22_;
						_tmp22_ = conversation;
						g_signal_emit (self, dino_conversation_manager_signals[DINO_CONVERSATION_MANAGER_CONVERSATION_DEACTIVATED_SIGNAL], 0, _tmp22_);
					}
					_g_object_unref0 (conversation);
				}
			}
			_g_object_unref0 (list);
		}
		_g_object_unref0 (_list_it);
	}
	_tmp23_ = self->priv->conversations;
	gee_abstract_map_unset ((GeeAbstractMap*) _tmp23_, account, NULL);
}

static void
dino_conversation_manager_handle_sent_message (DinoConversationManager* self,
                                               DinoEntitiesMessage* message,
                                               DinoEntitiesConversation* conversation)
{
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	gboolean is_recent = FALSE;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	GDateTime* _tmp4_;
	GDateTime* _tmp5_;
	GDateTime* _tmp6_;
	GDateTime* _tmp7_;
	gboolean _tmp8_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (message != NULL);
	g_return_if_fail (conversation != NULL);
	_tmp0_ = dino_entities_message_get_time (message);
	_tmp1_ = _tmp0_;
	dino_entities_conversation_set_last_active (conversation, _tmp1_);
	_tmp2_ = dino_entities_message_get_time (message);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_date_time_new_now_utc ();
	_tmp5_ = _tmp4_;
	_tmp6_ = g_date_time_add_hours (_tmp5_, -24);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_date_time_compare (_tmp3_, _tmp7_) > 0;
	_g_date_time_unref0 (_tmp7_);
	_g_date_time_unref0 (_tmp5_);
	is_recent = _tmp8_;
	if (is_recent) {
		dino_conversation_manager_start_conversation (self, conversation);
	}
}

static void
dino_conversation_manager_handle_new_call (DinoConversationManager* self,
                                           DinoEntitiesCall* call,
                                           DinoCallState* state,
                                           DinoEntitiesConversation* conversation)
{
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (call != NULL);
	g_return_if_fail (state != NULL);
	g_return_if_fail (conversation != NULL);
	_tmp0_ = dino_entities_call_get_time (call);
	_tmp1_ = _tmp0_;
	dino_entities_conversation_set_last_active (conversation, _tmp1_);
	dino_conversation_manager_start_conversation (self, conversation);
}

static void
dino_conversation_manager_add_conversation (DinoConversationManager* self,
                                            DinoEntitiesConversation* conversation)
{
	GeeHashMap* _tmp0_;
	DinoEntitiesAccount* _tmp1_;
	DinoEntitiesAccount* _tmp2_;
	gpointer _tmp3_;
	GeeHashMap* _tmp4_;
	XmppJid* _tmp5_;
	XmppJid* _tmp6_;
	gboolean _tmp7_;
	GeeHashMap* _tmp17_;
	DinoEntitiesAccount* _tmp18_;
	DinoEntitiesAccount* _tmp19_;
	gpointer _tmp20_;
	GeeHashMap* _tmp21_;
	XmppJid* _tmp22_;
	XmppJid* _tmp23_;
	gpointer _tmp24_;
	GeeList* _tmp25_;
	gboolean _tmp26_;
	gboolean _tmp27_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (conversation != NULL);
	_tmp0_ = self->priv->conversations;
	_tmp1_ = dino_entities_conversation_get_account (conversation);
	_tmp2_ = _tmp1_;
	_tmp3_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp0_, _tmp2_);
	_tmp4_ = (GeeHashMap*) _tmp3_;
	_tmp5_ = dino_entities_conversation_get_counterpart (conversation);
	_tmp6_ = _tmp5_;
	_tmp7_ = !gee_abstract_map_has_key ((GeeAbstractMap*) _tmp4_, _tmp6_);
	_g_object_unref0 (_tmp4_);
	if (_tmp7_) {
		GeeHashMap* _tmp8_;
		DinoEntitiesAccount* _tmp9_;
		DinoEntitiesAccount* _tmp10_;
		gpointer _tmp11_;
		GeeHashMap* _tmp12_;
		XmppJid* _tmp13_;
		XmppJid* _tmp14_;
		GeeArrayList* _tmp15_;
		GeeArrayList* _tmp16_;
		_tmp8_ = self->priv->conversations;
		_tmp9_ = dino_entities_conversation_get_account (conversation);
		_tmp10_ = _tmp9_;
		_tmp11_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp8_, _tmp10_);
		_tmp12_ = (GeeHashMap*) _tmp11_;
		_tmp13_ = dino_entities_conversation_get_counterpart (conversation);
		_tmp14_ = _tmp13_;
		_tmp15_ = gee_array_list_new (DINO_ENTITIES_TYPE_CONVERSATION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _dino_entities_conversation_equals_func_gee_equal_data_func, NULL, NULL);
		_tmp16_ = _tmp15_;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp12_, _tmp14_, (GeeList*) _tmp16_);
		_g_object_unref0 (_tmp16_);
		_g_object_unref0 (_tmp12_);
	}
	_tmp17_ = self->priv->conversations;
	_tmp18_ = dino_entities_conversation_get_account (conversation);
	_tmp19_ = _tmp18_;
	_tmp20_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp17_, _tmp19_);
	_tmp21_ = (GeeHashMap*) _tmp20_;
	_tmp22_ = dino_entities_conversation_get_counterpart (conversation);
	_tmp23_ = _tmp22_;
	_tmp24_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp21_, _tmp23_);
	_tmp25_ = (GeeList*) _tmp24_;
	gee_collection_add ((GeeCollection*) _tmp25_, conversation);
	_g_object_unref0 (_tmp25_);
	_g_object_unref0 (_tmp21_);
	_tmp26_ = dino_entities_conversation_get_active (conversation);
	_tmp27_ = _tmp26_;
	if (_tmp27_) {
		g_signal_emit (self, dino_conversation_manager_signals[DINO_CONVERSATION_MANAGER_CONVERSATION_ACTIVATED_SIGNAL], 0, conversation);
	}
}

static const gchar*
dino_conversation_manager_real_get_id (DinoStreamInteractionModule* base)
{
	const gchar* result;
	DinoConversationManager* self;
	DinoModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	self = (DinoConversationManager*) base;
	_tmp0_ = dino_conversation_manager_IDENTITY;
	_tmp1_ = dino_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

static inline gpointer
dino_conversation_manager_message_listener_get_instance_private (DinoConversationManagerMessageListener* self)
{
	return G_STRUCT_MEMBER_P (self, DinoConversationManagerMessageListener_private_offset);
}

static DinoConversationManagerMessageListener*
dino_conversation_manager_message_listener_construct (GType object_type,
                                                      DinoStreamInteractor* stream_interactor)
{
	DinoConversationManagerMessageListener * self = NULL;
	DinoStreamInteractor* _tmp0_;
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	self = (DinoConversationManagerMessageListener*) dino_message_listener_construct (object_type);
	_tmp0_ = _g_object_ref0 (stream_interactor);
	_g_object_unref0 (self->priv->stream_interactor);
	self->priv->stream_interactor = _tmp0_;
	return self;
}

static DinoConversationManagerMessageListener*
dino_conversation_manager_message_listener_new (DinoStreamInteractor* stream_interactor)
{
	return dino_conversation_manager_message_listener_construct (DINO_CONVERSATION_MANAGER_TYPE_MESSAGE_LISTENER, stream_interactor);
}

static void
dino_conversation_manager_message_listener_real_run_data_free (gpointer _data)
{
	DinoConversationManagerMessageListenerRunData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->message);
	_g_object_unref0 (_data_->stanza);
	_g_object_unref0 (_data_->conversation);
	_g_object_unref0 (_data_->self);
	g_slice_free (DinoConversationManagerMessageListenerRunData, _data_);
}

static void
dino_conversation_manager_message_listener_real_run (DinoMessageListener* base,
                                                     DinoEntitiesMessage* message,
                                                     XmppMessageStanza* stanza,
                                                     DinoEntitiesConversation* conversation,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_)
{
	DinoConversationManagerMessageListener * self;
	DinoConversationManagerMessageListenerRunData* _data_;
	DinoConversationManagerMessageListener* _tmp0_;
	DinoEntitiesMessage* _tmp1_;
	XmppMessageStanza* _tmp2_;
	DinoEntitiesConversation* _tmp3_;
	g_return_if_fail (message != NULL);
	g_return_if_fail (stanza != NULL);
	g_return_if_fail (conversation != NULL);
	self = (DinoConversationManagerMessageListener*) base;
	_data_ = g_slice_new0 (DinoConversationManagerMessageListenerRunData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_conversation_manager_message_listener_real_run_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (message);
	_g_object_unref0 (_data_->message);
	_data_->message = _tmp1_;
	_tmp2_ = _g_object_ref0 (stanza);
	_g_object_unref0 (_data_->stanza);
	_data_->stanza = _tmp2_;
	_tmp3_ = _g_object_ref0 (conversation);
	_g_object_unref0 (_data_->conversation);
	_data_->conversation = _tmp3_;
	dino_conversation_manager_message_listener_real_run_co (_data_);
}

static gboolean
dino_conversation_manager_message_listener_run_finish (DinoMessageListener* base,
                                                       GAsyncResult* _res_)
{
	gboolean result;
	DinoConversationManagerMessageListenerRunData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static gboolean
dino_conversation_manager_message_listener_real_run_co (DinoConversationManagerMessageListenerRunData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = dino_entities_message_get_time (_data_->message);
	_data_->_tmp1_ = _data_->_tmp0_;
	dino_entities_conversation_set_last_active (_data_->conversation, _data_->_tmp1_);
	if (_data_->stanza != NULL) {
		_data_->_tmp2_ = xmpp_message_archive_management_message_flag_get_flag (_data_->stanza);
		_data_->_tmp3_ = _data_->_tmp2_;
		_data_->_tmp4_ = _data_->_tmp3_ != NULL;
		_g_object_unref0 (_data_->_tmp3_);
		_data_->is_mam_message = _data_->_tmp4_;
		_data_->_tmp5_ = dino_entities_message_get_time (_data_->message);
		_data_->_tmp6_ = _data_->_tmp5_;
		_data_->_tmp7_ = g_date_time_new_now_utc ();
		_data_->_tmp8_ = _data_->_tmp7_;
		_data_->_tmp9_ = g_date_time_add_days (_data_->_tmp8_, -3);
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->_tmp11_ = g_date_time_compare (_data_->_tmp6_, _data_->_tmp10_) > 0;
		_g_date_time_unref0 (_data_->_tmp10_);
		_g_date_time_unref0 (_data_->_tmp8_);
		_data_->is_recent = _data_->_tmp11_;
		if (_data_->is_mam_message) {
			_data_->_tmp12_ = !_data_->is_recent;
		} else {
			_data_->_tmp12_ = FALSE;
		}
		if (_data_->_tmp12_) {
			_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_->_tmp13_ = _data_->self->priv->stream_interactor;
	_data_->_tmp14_ = dino_conversation_manager_IDENTITY;
	_data_->_tmp15_ = dino_stream_interactor_get_module (_data_->_tmp13_, DINO_TYPE_CONVERSATION_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp14_);
	_data_->_tmp16_ = (DinoConversationManager*) _data_->_tmp15_;
	dino_conversation_manager_start_conversation (_data_->_tmp16_, _data_->conversation);
	_g_object_unref0 (_data_->_tmp16_);
	_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;
}

static const gchar*
dino_conversation_manager_message_listener_real_get_action_group (XmppOrderedListener* base)
{
	const gchar* result;
	DinoConversationManagerMessageListener* self;
	self = (DinoConversationManagerMessageListener*) base;
	result = "MANAGER";
	return result;
}

static gchar**
dino_conversation_manager_message_listener_real_get_after_actions (XmppOrderedListener* base,
                                                                   gint* result_length1)
{
	gchar** result;
	DinoConversationManagerMessageListener* self;
	gchar** _tmp0_;
	gint _tmp0__length1;
	gchar** _tmp1_;
	gint _tmp1__length1;
	self = (DinoConversationManagerMessageListener*) base;
	_tmp0_ = self->after_actions_const;
	_tmp0__length1 = self->after_actions_const_length1;
	_tmp1_ = _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	if (result_length1) {
		*result_length1 = _tmp1__length1;
	}
	result = _tmp1_;
	return result;
}

static void
dino_conversation_manager_message_listener_class_init (DinoConversationManagerMessageListenerClass * klass,
                                                       gpointer klass_data)
{
	dino_conversation_manager_message_listener_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoConversationManagerMessageListener_private_offset);
	((DinoMessageListenerClass *) klass)->run = (void (*) (DinoMessageListener*, DinoEntitiesMessage*, XmppMessageStanza*, DinoEntitiesConversation*, GAsyncReadyCallback, gpointer)) dino_conversation_manager_message_listener_real_run;
	((DinoMessageListenerClass *) klass)->run_finish = (gboolean (*) (DinoMessageListener*, GAsyncResult*)) dino_conversation_manager_message_listener_run_finish;
	XMPP_ORDERED_LISTENER_CLASS (klass)->get_action_group = (const gchar* (*) (XmppOrderedListener*)) dino_conversation_manager_message_listener_real_get_action_group;
	XMPP_ORDERED_LISTENER_CLASS (klass)->get_after_actions = (gchar** (*) (XmppOrderedListener*, gint*)) dino_conversation_manager_message_listener_real_get_after_actions;
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_conversation_manager_message_listener_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_conversation_manager_message_listener_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_CONVERSATION_MANAGER_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY, dino_conversation_manager_message_listener_properties[DINO_CONVERSATION_MANAGER_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY] = g_param_spec_string ("action-group", "action-group", "action-group", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_CONVERSATION_MANAGER_MESSAGE_LISTENER_AFTER_ACTIONS_PROPERTY, dino_conversation_manager_message_listener_properties[DINO_CONVERSATION_MANAGER_MESSAGE_LISTENER_AFTER_ACTIONS_PROPERTY] = g_param_spec_boxed ("after-actions", "after-actions", "after-actions", G_TYPE_STRV, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
dino_conversation_manager_message_listener_instance_init (DinoConversationManagerMessageListener * self,
                                                          gpointer klass)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_;
	self->priv = dino_conversation_manager_message_listener_get_instance_private (self);
	_tmp0_ = g_strdup ("DEDUPLICATE");
	_tmp1_ = g_strdup ("FILTER_EMPTY");
	_tmp2_ = g_new0 (gchar*, 2 + 1);
	_tmp2_[0] = _tmp0_;
	_tmp2_[1] = _tmp1_;
	self->after_actions_const = _tmp2_;
	self->after_actions_const_length1 = 2;
	self->_after_actions_const_size_ = self->after_actions_const_length1;
}

static void
dino_conversation_manager_message_listener_finalize (GObject * obj)
{
	DinoConversationManagerMessageListener * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_CONVERSATION_MANAGER_TYPE_MESSAGE_LISTENER, DinoConversationManagerMessageListener);
	self->after_actions_const = (_vala_array_free (self->after_actions_const, self->after_actions_const_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (self->priv->stream_interactor);
	G_OBJECT_CLASS (dino_conversation_manager_message_listener_parent_class)->finalize (obj);
}

static GType
dino_conversation_manager_message_listener_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoConversationManagerMessageListenerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_conversation_manager_message_listener_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoConversationManagerMessageListener), 0, (GInstanceInitFunc) dino_conversation_manager_message_listener_instance_init, NULL };
	GType dino_conversation_manager_message_listener_type_id;
	dino_conversation_manager_message_listener_type_id = g_type_register_static (DINO_TYPE_MESSAGE_LISTENER, "DinoConversationManagerMessageListener", &g_define_type_info, 0);
	DinoConversationManagerMessageListener_private_offset = g_type_add_instance_private (dino_conversation_manager_message_listener_type_id, sizeof (DinoConversationManagerMessageListenerPrivate));
	return dino_conversation_manager_message_listener_type_id;
}

static GType
dino_conversation_manager_message_listener_get_type (void)
{
	static volatile gsize dino_conversation_manager_message_listener_type_id__once = 0;
	if (g_once_init_enter (&dino_conversation_manager_message_listener_type_id__once)) {
		GType dino_conversation_manager_message_listener_type_id;
		dino_conversation_manager_message_listener_type_id = dino_conversation_manager_message_listener_get_type_once ();
		g_once_init_leave (&dino_conversation_manager_message_listener_type_id__once, dino_conversation_manager_message_listener_type_id);
	}
	return dino_conversation_manager_message_listener_type_id__once;
}

static void
_vala_dino_conversation_manager_message_listener_get_property (GObject * object,
                                                               guint property_id,
                                                               GValue * value,
                                                               GParamSpec * pspec)
{
	DinoConversationManagerMessageListener * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_CONVERSATION_MANAGER_TYPE_MESSAGE_LISTENER, DinoConversationManagerMessageListener);
	switch (property_id) {
		case DINO_CONVERSATION_MANAGER_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY:
		g_value_set_string (value, xmpp_ordered_listener_get_action_group ((XmppOrderedListener*) self));
		break;
		case DINO_CONVERSATION_MANAGER_MESSAGE_LISTENER_AFTER_ACTIONS_PROPERTY:
		{
			int length;
			g_value_set_boxed (value, xmpp_ordered_listener_get_after_actions ((XmppOrderedListener*) self, &length));
		}
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
dino_conversation_manager_class_init (DinoConversationManagerClass * klass,
                                      gpointer klass_data)
{
	DinoModuleIdentity* _tmp0_;
	dino_conversation_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoConversationManager_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_conversation_manager_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_conversation_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_CONVERSATION_MANAGER_ID_PROPERTY, dino_conversation_manager_properties[DINO_CONVERSATION_MANAGER_ID_PROPERTY] = g_param_spec_string ("id", "id", "id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	dino_conversation_manager_signals[DINO_CONVERSATION_MANAGER_CONVERSATION_ACTIVATED_SIGNAL] = g_signal_new ("conversation-activated", DINO_TYPE_CONVERSATION_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, DINO_ENTITIES_TYPE_CONVERSATION);
	dino_conversation_manager_signals[DINO_CONVERSATION_MANAGER_CONVERSATION_DEACTIVATED_SIGNAL] = g_signal_new ("conversation-deactivated", DINO_TYPE_CONVERSATION_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, DINO_ENTITIES_TYPE_CONVERSATION);
	_tmp0_ = dino_module_identity_new (DINO_TYPE_CONVERSATION_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, "conversation_manager");
	dino_conversation_manager_IDENTITY = _tmp0_;
}

static void
dino_conversation_manager_dino_stream_interaction_module_interface_init (DinoStreamInteractionModuleIface * iface,
                                                                         gpointer iface_data)
{
	dino_conversation_manager_dino_stream_interaction_module_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_id = dino_conversation_manager_real_get_id;
}

static void
dino_conversation_manager_instance_init (DinoConversationManager * self,
                                         gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = dino_conversation_manager_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (DINO_ENTITIES_TYPE_ACCOUNT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEE_TYPE_HASH_MAP, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _dino_entities_account_hash_func_gee_hash_data_func, NULL, NULL, _dino_entities_account_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->priv->conversations = _tmp0_;
}

static void
dino_conversation_manager_finalize (GObject * obj)
{
	DinoConversationManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_CONVERSATION_MANAGER, DinoConversationManager);
	_g_object_unref0 (self->priv->stream_interactor);
	_qlite_database_unref0 (self->priv->db);
	_g_object_unref0 (self->priv->conversations);
	G_OBJECT_CLASS (dino_conversation_manager_parent_class)->finalize (obj);
}

static GType
dino_conversation_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoConversationManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_conversation_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoConversationManager), 0, (GInstanceInitFunc) dino_conversation_manager_instance_init, NULL };
	static const GInterfaceInfo dino_stream_interaction_module_info = { (GInterfaceInitFunc) dino_conversation_manager_dino_stream_interaction_module_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_conversation_manager_type_id;
	dino_conversation_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoConversationManager", &g_define_type_info, 0);
	g_type_add_interface_static (dino_conversation_manager_type_id, DINO_TYPE_STREAM_INTERACTION_MODULE, &dino_stream_interaction_module_info);
	DinoConversationManager_private_offset = g_type_add_instance_private (dino_conversation_manager_type_id, sizeof (DinoConversationManagerPrivate));
	return dino_conversation_manager_type_id;
}

GType
dino_conversation_manager_get_type (void)
{
	static volatile gsize dino_conversation_manager_type_id__once = 0;
	if (g_once_init_enter (&dino_conversation_manager_type_id__once)) {
		GType dino_conversation_manager_type_id;
		dino_conversation_manager_type_id = dino_conversation_manager_get_type_once ();
		g_once_init_leave (&dino_conversation_manager_type_id__once, dino_conversation_manager_type_id);
	}
	return dino_conversation_manager_type_id__once;
}

static void
_vala_dino_conversation_manager_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	DinoConversationManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_TYPE_CONVERSATION_MANAGER, DinoConversationManager);
	switch (property_id) {
		case DINO_CONVERSATION_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);
}

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

