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

#include "libdino.h"
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "xmpp-vala.h"
#include "qlite.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

#define DINO_REPLIES_TYPE_RECEIVED_MESSAGE_LISTENER (dino_replies_received_message_listener_get_type ())
#define DINO_REPLIES_RECEIVED_MESSAGE_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_REPLIES_TYPE_RECEIVED_MESSAGE_LISTENER, DinoRepliesReceivedMessageListener))
#define DINO_REPLIES_RECEIVED_MESSAGE_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_REPLIES_TYPE_RECEIVED_MESSAGE_LISTENER, DinoRepliesReceivedMessageListenerClass))
#define DINO_REPLIES_IS_RECEIVED_MESSAGE_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_REPLIES_TYPE_RECEIVED_MESSAGE_LISTENER))
#define DINO_REPLIES_IS_RECEIVED_MESSAGE_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_REPLIES_TYPE_RECEIVED_MESSAGE_LISTENER))
#define DINO_REPLIES_RECEIVED_MESSAGE_LISTENER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_REPLIES_TYPE_RECEIVED_MESSAGE_LISTENER, DinoRepliesReceivedMessageListenerClass))

typedef struct _DinoRepliesReceivedMessageListener DinoRepliesReceivedMessageListener;
typedef struct _DinoRepliesReceivedMessageListenerClass DinoRepliesReceivedMessageListenerClass;
enum  {
	DINO_REPLIES_0_PROPERTY,
	DINO_REPLIES_ID_PROPERTY,
	DINO_REPLIES_NUM_PROPERTIES
};
static GParamSpec* dino_replies_properties[DINO_REPLIES_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _qlite_database_unref0(var) ((var == NULL) ? NULL : (var = (qlite_database_unref (var), NULL)))
#define _qlite_statement_builder_unref0(var) ((var == NULL) ? NULL : (var = (qlite_statement_builder_unref (var), NULL)))
#define _qlite_row_option_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_option_unref (var), NULL)))
#define _qlite_row_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_unref (var), NULL)))
#define _qlite_row_iterator_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_iterator_unref (var), NULL)))
#define _xmpp_xep_replies_reply_to_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_xep_replies_reply_to_unref (var), NULL)))
typedef struct _DinoRepliesReceivedMessageListenerPrivate DinoRepliesReceivedMessageListenerPrivate;
enum  {
	DINO_REPLIES_RECEIVED_MESSAGE_LISTENER_0_PROPERTY,
	DINO_REPLIES_RECEIVED_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY,
	DINO_REPLIES_RECEIVED_MESSAGE_LISTENER_AFTER_ACTIONS_PROPERTY,
	DINO_REPLIES_RECEIVED_MESSAGE_LISTENER_NUM_PROPERTIES
};
static GParamSpec* dino_replies_received_message_listener_properties[DINO_REPLIES_RECEIVED_MESSAGE_LISTENER_NUM_PROPERTIES];
typedef struct _DinoRepliesReceivedMessageListenerRunData DinoRepliesReceivedMessageListenerRunData;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _xmpp_xep_fallback_indication_fallback_location_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_xep_fallback_indication_fallback_location_unref (var), NULL)))
#define _xmpp_xep_fallback_indication_fallback_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_xep_fallback_indication_fallback_unref (var), NULL)))

struct _DinoRepliesPrivate {
	DinoStreamInteractor* stream_interactor;
	DinoDatabase* db;
	GeeHashMap* unmapped_replies;
	DinoRepliesReceivedMessageListener* received_message_listener;
};

struct _DinoRepliesReceivedMessageListener {
	DinoMessageListener parent_instance;
	DinoRepliesReceivedMessageListenerPrivate * priv;
	gchar** after_actions_const;
	gint after_actions_const_length1;
	gint _after_actions_const_size_;
};

struct _DinoRepliesReceivedMessageListenerClass {
	DinoMessageListenerClass parent_class;
};

struct _DinoRepliesReceivedMessageListenerPrivate {
	DinoReplies* outer;
};

struct _DinoRepliesReceivedMessageListenerRunData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoRepliesReceivedMessageListener* self;
	DinoEntitiesMessage* message;
	XmppMessageStanza* stanza;
	DinoEntitiesConversation* conversation;
	gboolean result;
	DinoReplies* _tmp0_;
};

static gint DinoReplies_private_offset;
static gpointer dino_replies_parent_class = NULL;
DinoModuleIdentity* dino_replies_IDENTITY = NULL;
static gint DinoRepliesReceivedMessageListener_private_offset;
static gpointer dino_replies_received_message_listener_parent_class = NULL;
static DinoStreamInteractionModuleIface * dino_replies_dino_stream_interaction_module_parent_iface = NULL;

static GType dino_replies_received_message_listener_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static DinoReplies* dino_replies_new (DinoStreamInteractor* stream_interactor,
                               DinoDatabase* db);
static DinoReplies* dino_replies_construct (GType object_type,
                                     DinoStreamInteractor* stream_interactor,
                                     DinoDatabase* db);
static DinoRepliesReceivedMessageListener* dino_replies_received_message_listener_new (DinoStreamInteractor* stream_interactor,
                                                                                DinoReplies* outer);
static DinoRepliesReceivedMessageListener* dino_replies_received_message_listener_construct (GType object_type,
                                                                                      DinoStreamInteractor* stream_interactor,
                                                                                      DinoReplies* outer);
static void dino_replies_on_incoming_message (DinoReplies* self,
                                       DinoEntitiesMessage* message,
                                       XmppMessageStanza* stanza,
                                       DinoEntitiesConversation* conversation);
static void dino_replies_received_message_listener_real_run_data_free (gpointer _data);
static void dino_replies_received_message_listener_real_run (DinoMessageListener* base,
                                                      DinoEntitiesMessage* message,
                                                      XmppMessageStanza* stanza,
                                                      DinoEntitiesConversation* conversation,
                                                      GAsyncReadyCallback _callback_,
                                                      gpointer _user_data_);
static gboolean dino_replies_received_message_listener_real_run_co (DinoRepliesReceivedMessageListenerRunData* _data_);
static void dino_replies_received_message_listener_finalize (GObject * obj);
static GType dino_replies_received_message_listener_get_type_once (void);
static void _vala_dino_replies_received_message_listener_get_property (GObject * object,
                                                                guint property_id,
                                                                GValue * value,
                                                                GParamSpec * pspec);
static void dino_replies_finalize (GObject * obj);
static GType dino_replies_get_type_once (void);
static void _vala_dino_replies_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_replies_get_instance_private (DinoReplies* self)
{
	return G_STRUCT_MEMBER_P (self, DinoReplies_private_offset);
}

void
dino_replies_start (DinoStreamInteractor* stream_interactor,
                    DinoDatabase* db)
{
	DinoReplies* m = NULL;
	DinoReplies* _tmp0_;
	g_return_if_fail (stream_interactor != NULL);
	g_return_if_fail (db != NULL);
	_tmp0_ = dino_replies_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 DinoReplies*
dino_replies_construct (GType object_type,
                        DinoStreamInteractor* stream_interactor,
                        DinoDatabase* db)
{
	DinoReplies * self = NULL;
	DinoStreamInteractor* _tmp0_;
	DinoDatabase* _tmp1_;
	DinoRepliesReceivedMessageListener* _tmp2_;
	DinoModuleIdentity* _tmp3_;
	gpointer _tmp4_;
	DinoMessageProcessor* _tmp5_;
	DinoMessageListenerHolder* _tmp6_;
	DinoRepliesReceivedMessageListener* _tmp7_;
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoReplies*) 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_replies_received_message_listener_new (stream_interactor, self);
	_g_object_unref0 (self->priv->received_message_listener);
	self->priv->received_message_listener = _tmp2_;
	_tmp3_ = dino_message_processor_IDENTITY;
	_tmp4_ = dino_stream_interactor_get_module (stream_interactor, DINO_TYPE_MESSAGE_PROCESSOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp3_);
	_tmp5_ = (DinoMessageProcessor*) _tmp4_;
	_tmp6_ = _tmp5_->received_pipeline;
	_tmp7_ = self->priv->received_message_listener;
	xmpp_listener_holder_connect ((XmppListenerHolder*) _tmp6_, (XmppOrderedListener*) _tmp7_);
	_g_object_unref0 (_tmp5_);
	return self;
}

static DinoReplies*
dino_replies_new (DinoStreamInteractor* stream_interactor,
                  DinoDatabase* db)
{
	return dino_replies_construct (DINO_TYPE_REPLIES, stream_interactor, db);
}

DinoContentItem*
dino_replies_get_quoted_content_item (DinoReplies* self,
                                      DinoEntitiesMessage* message,
                                      DinoEntitiesConversation* conversation)
{
	gint _tmp0_;
	gint _tmp1_;
	QliteRowOption* row_option = NULL;
	DinoDatabase* _tmp2_;
	DinoDatabaseReplyTable* _tmp3_;
	DinoDatabaseReplyTable* _tmp4_;
	QliteQueryBuilder* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	DinoDatabase* _tmp7_;
	DinoDatabaseReplyTable* _tmp8_;
	DinoDatabaseReplyTable* _tmp9_;
	QliteColumn* _tmp10_;
	gint _tmp11_;
	gint _tmp12_;
	QliteQueryBuilder* _tmp13_;
	QliteQueryBuilder* _tmp14_;
	QliteRowOption* _tmp15_;
	QliteRowOption* _tmp16_;
	QliteRowOption* _tmp17_;
	DinoContentItem* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (message != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	_tmp0_ = dino_entities_message_get_quoted_item_id (message);
	_tmp1_ = _tmp0_;
	if (_tmp1_ == 0) {
		result = NULL;
		return result;
	}
	_tmp2_ = self->priv->db;
	_tmp3_ = dino_database_get_reply (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = qlite_table_select ((QliteTable*) _tmp4_, NULL, (gint) 0);
	_tmp6_ = _tmp5_;
	_tmp7_ = self->priv->db;
	_tmp8_ = dino_database_get_reply (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = _tmp9_->message_id;
	_tmp11_ = dino_entities_message_get_id (message);
	_tmp12_ = _tmp11_;
	_tmp13_ = qlite_query_builder_with (_tmp6_, G_TYPE_INT, NULL, NULL, _tmp10_, "=", (gpointer) ((gintptr) _tmp12_));
	_tmp14_ = _tmp13_;
	_tmp15_ = qlite_query_builder_row (_tmp14_);
	_tmp16_ = _tmp15_;
	_qlite_statement_builder_unref0 (_tmp14_);
	_qlite_statement_builder_unref0 (_tmp6_);
	row_option = _tmp16_;
	_tmp17_ = row_option;
	if (qlite_row_option_is_present (_tmp17_)) {
		DinoStreamInteractor* _tmp18_;
		DinoModuleIdentity* _tmp19_;
		gpointer _tmp20_;
		DinoContentItemStore* _tmp21_;
		QliteRowOption* _tmp22_;
		DinoDatabase* _tmp23_;
		DinoDatabaseReplyTable* _tmp24_;
		DinoDatabaseReplyTable* _tmp25_;
		QliteColumn* _tmp26_;
		gpointer _tmp27_;
		DinoContentItem* _tmp28_;
		DinoContentItem* _tmp29_;
		_tmp18_ = self->priv->stream_interactor;
		_tmp19_ = dino_content_item_store_IDENTITY;
		_tmp20_ = dino_stream_interactor_get_module (_tmp18_, DINO_TYPE_CONTENT_ITEM_STORE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp19_);
		_tmp21_ = (DinoContentItemStore*) _tmp20_;
		_tmp22_ = row_option;
		_tmp23_ = self->priv->db;
		_tmp24_ = dino_database_get_reply (_tmp23_);
		_tmp25_ = _tmp24_;
		_tmp26_ = _tmp25_->quoted_content_item_id;
		_tmp27_ = qlite_row_option_get (_tmp22_, G_TYPE_INT, NULL, NULL, _tmp26_, NULL);
		_tmp28_ = dino_content_item_store_get_item_by_id (_tmp21_, conversation, (gint) ((gintptr) _tmp27_));
		_tmp29_ = _tmp28_;
		_g_object_unref0 (_tmp21_);
		result = _tmp29_;
		_qlite_row_option_unref0 (row_option);
		return result;
	}
	result = NULL;
	_qlite_row_option_unref0 (row_option);
	return result;
}

static void
dino_replies_on_incoming_message (DinoReplies* self,
                                  DinoEntitiesMessage* message,
                                  XmppMessageStanza* stanza,
                                  DinoEntitiesConversation* conversation)
{
	QliteQueryBuilder* reply_qry = NULL;
	DinoDatabase* _tmp0_;
	DinoDatabaseReplyTable* _tmp1_;
	DinoDatabaseReplyTable* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	DinoEntitiesConversationType _tmp4_;
	DinoEntitiesConversationType _tmp5_;
	QliteQueryBuilder* _tmp24_;
	DinoDatabase* _tmp25_;
	DinoDatabaseMessageTable* _tmp26_;
	DinoDatabaseMessageTable* _tmp27_;
	DinoDatabase* _tmp28_;
	DinoDatabaseReplyTable* _tmp29_;
	DinoDatabaseReplyTable* _tmp30_;
	QliteColumn* _tmp31_;
	DinoDatabase* _tmp32_;
	DinoDatabaseMessageTable* _tmp33_;
	DinoDatabaseMessageTable* _tmp34_;
	QliteColumn* _tmp35_;
	QliteQueryBuilder* _tmp36_;
	QliteQueryBuilder* _tmp37_;
	DinoDatabase* _tmp38_;
	DinoDatabaseMessageTable* _tmp39_;
	DinoDatabaseMessageTable* _tmp40_;
	QliteColumn* _tmp41_;
	DinoEntitiesAccount* _tmp42_;
	DinoEntitiesAccount* _tmp43_;
	gint _tmp44_;
	gint _tmp45_;
	QliteQueryBuilder* _tmp46_;
	QliteQueryBuilder* _tmp47_;
	DinoDatabase* _tmp48_;
	DinoDatabaseMessageTable* _tmp49_;
	DinoDatabaseMessageTable* _tmp50_;
	QliteColumn* _tmp51_;
	DinoDatabase* _tmp52_;
	XmppJid* _tmp53_;
	XmppJid* _tmp54_;
	QliteQueryBuilder* _tmp55_;
	QliteQueryBuilder* _tmp56_;
	DinoDatabase* _tmp57_;
	DinoDatabaseMessageTable* _tmp58_;
	DinoDatabaseMessageTable* _tmp59_;
	QliteColumn* _tmp60_;
	GDateTime* _tmp61_;
	GDateTime* _tmp62_;
	QliteQueryBuilder* _tmp63_;
	QliteQueryBuilder* _tmp64_;
	DinoDatabase* _tmp65_;
	DinoDatabaseMessageTable* _tmp66_;
	DinoDatabaseMessageTable* _tmp67_;
	QliteColumn* _tmp68_;
	QliteQueryBuilder* _tmp69_;
	QliteQueryBuilder* _tmp70_;
	XmppXepRepliesReplyTo* reply_to = NULL;
	XmppXepRepliesReplyTo* _tmp103_;
	XmppXepRepliesReplyTo* _tmp104_;
	DinoContentItem* quoted_content_item = NULL;
	DinoStreamInteractor* _tmp105_;
	DinoModuleIdentity* _tmp106_;
	gpointer _tmp107_;
	DinoContentItemStore* _tmp108_;
	XmppXepRepliesReplyTo* _tmp109_;
	const gchar* _tmp110_;
	const gchar* _tmp111_;
	DinoContentItem* _tmp112_;
	DinoContentItem* _tmp113_;
	DinoContentItem* _tmp114_;
	DinoContentItem* _tmp115_;
	gint _tmp116_;
	gint _tmp117_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (message != NULL);
	g_return_if_fail (stanza != NULL);
	g_return_if_fail (conversation != NULL);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_database_get_reply (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = qlite_table_select ((QliteTable*) _tmp2_, NULL, (gint) 0);
	reply_qry = _tmp3_;
	_tmp4_ = dino_entities_conversation_get_type_ (conversation);
	_tmp5_ = _tmp4_;
	if (_tmp5_ == DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT) {
		QliteQueryBuilder* _tmp6_;
		DinoDatabase* _tmp7_;
		DinoDatabaseReplyTable* _tmp8_;
		DinoDatabaseReplyTable* _tmp9_;
		QliteColumn* _tmp10_;
		const gchar* _tmp11_;
		const gchar* _tmp12_;
		QliteQueryBuilder* _tmp13_;
		QliteQueryBuilder* _tmp14_;
		_tmp6_ = reply_qry;
		_tmp7_ = self->priv->db;
		_tmp8_ = dino_database_get_reply (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = _tmp9_->quoted_message_stanza_id;
		_tmp11_ = dino_entities_message_get_server_id (message);
		_tmp12_ = _tmp11_;
		_tmp13_ = qlite_query_builder_with (_tmp6_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp10_, "=", _tmp12_);
		_tmp14_ = _tmp13_;
		_qlite_statement_builder_unref0 (_tmp14_);
	} else {
		QliteQueryBuilder* _tmp15_;
		DinoDatabase* _tmp16_;
		DinoDatabaseReplyTable* _tmp17_;
		DinoDatabaseReplyTable* _tmp18_;
		QliteColumn* _tmp19_;
		const gchar* _tmp20_;
		const gchar* _tmp21_;
		QliteQueryBuilder* _tmp22_;
		QliteQueryBuilder* _tmp23_;
		_tmp15_ = reply_qry;
		_tmp16_ = self->priv->db;
		_tmp17_ = dino_database_get_reply (_tmp16_);
		_tmp18_ = _tmp17_;
		_tmp19_ = _tmp18_->quoted_message_stanza_id;
		_tmp20_ = dino_entities_message_get_stanza_id (message);
		_tmp21_ = _tmp20_;
		_tmp22_ = qlite_query_builder_with (_tmp15_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp19_, "=", _tmp21_);
		_tmp23_ = _tmp22_;
		_qlite_statement_builder_unref0 (_tmp23_);
	}
	_tmp24_ = reply_qry;
	_tmp25_ = self->priv->db;
	_tmp26_ = dino_database_get_message (_tmp25_);
	_tmp27_ = _tmp26_;
	_tmp28_ = self->priv->db;
	_tmp29_ = dino_database_get_reply (_tmp28_);
	_tmp30_ = _tmp29_;
	_tmp31_ = _tmp30_->message_id;
	_tmp32_ = self->priv->db;
	_tmp33_ = dino_database_get_message (_tmp32_);
	_tmp34_ = _tmp33_;
	_tmp35_ = _tmp34_->id;
	_tmp36_ = qlite_query_builder_join_with (_tmp24_, G_TYPE_INT, NULL, NULL, (QliteTable*) _tmp27_, _tmp31_, _tmp35_, NULL);
	_tmp37_ = _tmp36_;
	_tmp38_ = self->priv->db;
	_tmp39_ = dino_database_get_message (_tmp38_);
	_tmp40_ = _tmp39_;
	_tmp41_ = _tmp40_->account_id;
	_tmp42_ = dino_entities_conversation_get_account (conversation);
	_tmp43_ = _tmp42_;
	_tmp44_ = dino_entities_account_get_id (_tmp43_);
	_tmp45_ = _tmp44_;
	_tmp46_ = qlite_query_builder_with (_tmp37_, G_TYPE_INT, NULL, NULL, _tmp41_, "=", (gpointer) ((gintptr) _tmp45_));
	_tmp47_ = _tmp46_;
	_tmp48_ = self->priv->db;
	_tmp49_ = dino_database_get_message (_tmp48_);
	_tmp50_ = _tmp49_;
	_tmp51_ = _tmp50_->counterpart_id;
	_tmp52_ = self->priv->db;
	_tmp53_ = dino_entities_conversation_get_counterpart (conversation);
	_tmp54_ = _tmp53_;
	_tmp55_ = qlite_query_builder_with (_tmp47_, G_TYPE_INT, NULL, NULL, _tmp51_, "=", (gpointer) ((gintptr) dino_database_get_jid_id (_tmp52_, _tmp54_)));
	_tmp56_ = _tmp55_;
	_tmp57_ = self->priv->db;
	_tmp58_ = dino_database_get_message (_tmp57_);
	_tmp59_ = _tmp58_;
	_tmp60_ = _tmp59_->time;
	_tmp61_ = dino_entities_message_get_time (message);
	_tmp62_ = _tmp61_;
	_tmp63_ = qlite_query_builder_with (_tmp56_, G_TYPE_LONG, NULL, NULL, _tmp60_, ">", (gpointer) ((gintptr) g_date_time_to_unix (_tmp62_)));
	_tmp64_ = _tmp63_;
	_tmp65_ = self->priv->db;
	_tmp66_ = dino_database_get_message (_tmp65_);
	_tmp67_ = _tmp66_;
	_tmp68_ = _tmp67_->time;
	_tmp69_ = qlite_query_builder_order_by (_tmp64_, _tmp68_, "DESC");
	_tmp70_ = _tmp69_;
	_qlite_statement_builder_unref0 (_tmp70_);
	_qlite_statement_builder_unref0 (_tmp64_);
	_qlite_statement_builder_unref0 (_tmp56_);
	_qlite_statement_builder_unref0 (_tmp47_);
	_qlite_statement_builder_unref0 (_tmp37_);
	{
		QliteRowIterator* _reply_row_it = NULL;
		QliteQueryBuilder* _tmp71_;
		QliteRowIterator* _tmp72_;
		_tmp71_ = reply_qry;
		_tmp72_ = qlite_query_builder_iterator (_tmp71_);
		_reply_row_it = _tmp72_;
		while (TRUE) {
			QliteRowIterator* _tmp73_;
			QliteRow* reply_row = NULL;
			QliteRowIterator* _tmp74_;
			QliteRow* _tmp75_;
			DinoContentItem* message_item = NULL;
			DinoStreamInteractor* _tmp76_;
			DinoModuleIdentity* _tmp77_;
			gpointer _tmp78_;
			DinoContentItemStore* _tmp79_;
			gint _tmp80_;
			gint _tmp81_;
			DinoContentItem* _tmp82_;
			DinoContentItem* _tmp83_;
			DinoEntitiesMessage* reply_message = NULL;
			DinoStreamInteractor* _tmp84_;
			DinoModuleIdentity* _tmp85_;
			gpointer _tmp86_;
			DinoMessageStorage* _tmp87_;
			QliteRow* _tmp88_;
			DinoDatabase* _tmp89_;
			DinoDatabaseMessageTable* _tmp90_;
			DinoDatabaseMessageTable* _tmp91_;
			QliteColumn* _tmp92_;
			gpointer _tmp93_;
			DinoEntitiesMessage* _tmp94_;
			DinoEntitiesMessage* _tmp95_;
			gboolean _tmp96_ = FALSE;
			DinoContentItem* _tmp97_;
			_tmp73_ = _reply_row_it;
			if (!qlite_row_iterator_next (_tmp73_)) {
				break;
			}
			_tmp74_ = _reply_row_it;
			_tmp75_ = qlite_row_iterator_get (_tmp74_);
			reply_row = _tmp75_;
			_tmp76_ = self->priv->stream_interactor;
			_tmp77_ = dino_content_item_store_IDENTITY;
			_tmp78_ = dino_stream_interactor_get_module (_tmp76_, DINO_TYPE_CONTENT_ITEM_STORE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp77_);
			_tmp79_ = (DinoContentItemStore*) _tmp78_;
			_tmp80_ = dino_entities_message_get_id (message);
			_tmp81_ = _tmp80_;
			_tmp82_ = dino_content_item_store_get_item_by_foreign (_tmp79_, conversation, 1, _tmp81_);
			_tmp83_ = _tmp82_;
			_g_object_unref0 (_tmp79_);
			message_item = _tmp83_;
			_tmp84_ = self->priv->stream_interactor;
			_tmp85_ = dino_message_storage_IDENTITY;
			_tmp86_ = dino_stream_interactor_get_module (_tmp84_, DINO_TYPE_MESSAGE_STORAGE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp85_);
			_tmp87_ = (DinoMessageStorage*) _tmp86_;
			_tmp88_ = reply_row;
			_tmp89_ = self->priv->db;
			_tmp90_ = dino_database_get_message (_tmp89_);
			_tmp91_ = _tmp90_;
			_tmp92_ = _tmp91_->id;
			_tmp93_ = qlite_row_get (_tmp88_, G_TYPE_INT, NULL, NULL, _tmp92_);
			_tmp94_ = dino_message_storage_get_message_by_id (_tmp87_, (gint) ((gintptr) _tmp93_), conversation);
			_tmp95_ = _tmp94_;
			_g_object_unref0 (_tmp87_);
			reply_message = _tmp95_;
			_tmp97_ = message_item;
			if (_tmp97_ != NULL) {
				DinoEntitiesMessage* _tmp98_;
				_tmp98_ = reply_message;
				_tmp96_ = _tmp98_ != NULL;
			} else {
				_tmp96_ = FALSE;
			}
			if (_tmp96_) {
				DinoEntitiesMessage* _tmp99_;
				DinoContentItem* _tmp100_;
				gint _tmp101_;
				gint _tmp102_;
				_tmp99_ = reply_message;
				_tmp100_ = message_item;
				_tmp101_ = dino_content_item_get_id (_tmp100_);
				_tmp102_ = _tmp101_;
				dino_entities_message_set_quoted_item (_tmp99_, _tmp102_);
			}
			_g_object_unref0 (reply_message);
			_g_object_unref0 (message_item);
			_qlite_row_unref0 (reply_row);
		}
		_qlite_row_iterator_unref0 (_reply_row_it);
	}
	_tmp103_ = xmpp_xep_replies_get_reply_to (stanza);
	reply_to = _tmp103_;
	_tmp104_ = reply_to;
	if (_tmp104_ == NULL) {
		_xmpp_xep_replies_reply_to_unref0 (reply_to);
		_qlite_statement_builder_unref0 (reply_qry);
		return;
	}
	_tmp105_ = self->priv->stream_interactor;
	_tmp106_ = dino_content_item_store_IDENTITY;
	_tmp107_ = dino_stream_interactor_get_module (_tmp105_, DINO_TYPE_CONTENT_ITEM_STORE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp106_);
	_tmp108_ = (DinoContentItemStore*) _tmp107_;
	_tmp109_ = reply_to;
	_tmp110_ = xmpp_xep_replies_reply_to_get_to_message_id (_tmp109_);
	_tmp111_ = _tmp110_;
	_tmp112_ = dino_content_item_store_get_content_item_for_message_id (_tmp108_, conversation, _tmp111_);
	_tmp113_ = _tmp112_;
	_g_object_unref0 (_tmp108_);
	quoted_content_item = _tmp113_;
	_tmp114_ = quoted_content_item;
	if (_tmp114_ == NULL) {
		_g_object_unref0 (quoted_content_item);
		_xmpp_xep_replies_reply_to_unref0 (reply_to);
		_qlite_statement_builder_unref0 (reply_qry);
		return;
	}
	_tmp115_ = quoted_content_item;
	_tmp116_ = dino_content_item_get_id (_tmp115_);
	_tmp117_ = _tmp116_;
	dino_entities_message_set_quoted_item (message, _tmp117_);
	_g_object_unref0 (quoted_content_item);
	_xmpp_xep_replies_reply_to_unref0 (reply_to);
	_qlite_statement_builder_unref0 (reply_qry);
}

static const gchar*
dino_replies_real_get_id (DinoStreamInteractionModule* base)
{
	const gchar* result;
	DinoReplies* self;
	DinoModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	self = (DinoReplies*) base;
	_tmp0_ = dino_replies_IDENTITY;
	_tmp1_ = dino_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

static inline gpointer
dino_replies_received_message_listener_get_instance_private (DinoRepliesReceivedMessageListener* self)
{
	return G_STRUCT_MEMBER_P (self, DinoRepliesReceivedMessageListener_private_offset);
}

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

static DinoRepliesReceivedMessageListener*
dino_replies_received_message_listener_new (DinoStreamInteractor* stream_interactor,
                                            DinoReplies* outer)
{
	return dino_replies_received_message_listener_construct (DINO_REPLIES_TYPE_RECEIVED_MESSAGE_LISTENER, stream_interactor, outer);
}

static void
dino_replies_received_message_listener_real_run_data_free (gpointer _data)
{
	DinoRepliesReceivedMessageListenerRunData* _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 (DinoRepliesReceivedMessageListenerRunData, _data_);
}

static void
dino_replies_received_message_listener_real_run (DinoMessageListener* base,
                                                 DinoEntitiesMessage* message,
                                                 XmppMessageStanza* stanza,
                                                 DinoEntitiesConversation* conversation,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_)
{
	DinoRepliesReceivedMessageListener * self;
	DinoRepliesReceivedMessageListenerRunData* _data_;
	DinoRepliesReceivedMessageListener* _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 = (DinoRepliesReceivedMessageListener*) base;
	_data_ = g_slice_new0 (DinoRepliesReceivedMessageListenerRunData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_replies_received_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_replies_received_message_listener_real_run_co (_data_);
}

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

static gboolean
dino_replies_received_message_listener_real_run_co (DinoRepliesReceivedMessageListenerRunData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->outer;
	dino_replies_on_incoming_message (_data_->_tmp0_, _data_->message, _data_->stanza, _data_->conversation);
	_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_replies_received_message_listener_real_get_action_group (XmppOrderedListener* base)
{
	const gchar* result;
	DinoRepliesReceivedMessageListener* self;
	self = (DinoRepliesReceivedMessageListener*) base;
	result = "Quote";
	return result;
}

static gchar**
dino_replies_received_message_listener_real_get_after_actions (XmppOrderedListener* base,
                                                               gint* result_length1)
{
	gchar** result;
	DinoRepliesReceivedMessageListener* self;
	gchar** _tmp0_;
	gint _tmp0__length1;
	gchar** _tmp1_;
	gint _tmp1__length1;
	self = (DinoRepliesReceivedMessageListener*) 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_replies_received_message_listener_class_init (DinoRepliesReceivedMessageListenerClass * klass,
                                                   gpointer klass_data)
{
	dino_replies_received_message_listener_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoRepliesReceivedMessageListener_private_offset);
	((DinoMessageListenerClass *) klass)->run = (void (*) (DinoMessageListener*, DinoEntitiesMessage*, XmppMessageStanza*, DinoEntitiesConversation*, GAsyncReadyCallback, gpointer)) dino_replies_received_message_listener_real_run;
	((DinoMessageListenerClass *) klass)->run_finish = (gboolean (*) (DinoMessageListener*, GAsyncResult*)) dino_replies_received_message_listener_run_finish;
	XMPP_ORDERED_LISTENER_CLASS (klass)->get_action_group = (const gchar* (*) (XmppOrderedListener*)) dino_replies_received_message_listener_real_get_action_group;
	XMPP_ORDERED_LISTENER_CLASS (klass)->get_after_actions = (gchar** (*) (XmppOrderedListener*, gint*)) dino_replies_received_message_listener_real_get_after_actions;
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_replies_received_message_listener_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_replies_received_message_listener_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_REPLIES_RECEIVED_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY, dino_replies_received_message_listener_properties[DINO_REPLIES_RECEIVED_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_REPLIES_RECEIVED_MESSAGE_LISTENER_AFTER_ACTIONS_PROPERTY, dino_replies_received_message_listener_properties[DINO_REPLIES_RECEIVED_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_replies_received_message_listener_instance_init (DinoRepliesReceivedMessageListener * self,
                                                      gpointer klass)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_;
	self->priv = dino_replies_received_message_listener_get_instance_private (self);
	_tmp0_ = g_strdup ("STORE");
	_tmp1_ = g_strdup ("STORE_CONTENT_ITEM");
	_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_replies_received_message_listener_finalize (GObject * obj)
{
	DinoRepliesReceivedMessageListener * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_REPLIES_TYPE_RECEIVED_MESSAGE_LISTENER, DinoRepliesReceivedMessageListener);
	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->outer);
	G_OBJECT_CLASS (dino_replies_received_message_listener_parent_class)->finalize (obj);
}

static GType
dino_replies_received_message_listener_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoRepliesReceivedMessageListenerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_replies_received_message_listener_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoRepliesReceivedMessageListener), 0, (GInstanceInitFunc) dino_replies_received_message_listener_instance_init, NULL };
	GType dino_replies_received_message_listener_type_id;
	dino_replies_received_message_listener_type_id = g_type_register_static (DINO_TYPE_MESSAGE_LISTENER, "DinoRepliesReceivedMessageListener", &g_define_type_info, 0);
	DinoRepliesReceivedMessageListener_private_offset = g_type_add_instance_private (dino_replies_received_message_listener_type_id, sizeof (DinoRepliesReceivedMessageListenerPrivate));
	return dino_replies_received_message_listener_type_id;
}

static GType
dino_replies_received_message_listener_get_type (void)
{
	static volatile gsize dino_replies_received_message_listener_type_id__once = 0;
	if (g_once_init_enter (&dino_replies_received_message_listener_type_id__once)) {
		GType dino_replies_received_message_listener_type_id;
		dino_replies_received_message_listener_type_id = dino_replies_received_message_listener_get_type_once ();
		g_once_init_leave (&dino_replies_received_message_listener_type_id__once, dino_replies_received_message_listener_type_id);
	}
	return dino_replies_received_message_listener_type_id__once;
}

static void
_vala_dino_replies_received_message_listener_get_property (GObject * object,
                                                           guint property_id,
                                                           GValue * value,
                                                           GParamSpec * pspec)
{
	DinoRepliesReceivedMessageListener * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_REPLIES_TYPE_RECEIVED_MESSAGE_LISTENER, DinoRepliesReceivedMessageListener);
	switch (property_id) {
		case DINO_REPLIES_RECEIVED_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY:
		g_value_set_string (value, xmpp_ordered_listener_get_action_group ((XmppOrderedListener*) self));
		break;
		case DINO_REPLIES_RECEIVED_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_replies_class_init (DinoRepliesClass * klass,
                         gpointer klass_data)
{
	DinoModuleIdentity* _tmp0_;
	dino_replies_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoReplies_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_replies_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_replies_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_REPLIES_ID_PROPERTY, dino_replies_properties[DINO_REPLIES_ID_PROPERTY] = g_param_spec_string ("id", "id", "id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	_tmp0_ = dino_module_identity_new (DINO_TYPE_REPLIES, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, "reply");
	dino_replies_IDENTITY = _tmp0_;
}

static void
dino_replies_dino_stream_interaction_module_interface_init (DinoStreamInteractionModuleIface * iface,
                                                            gpointer iface_data)
{
	dino_replies_dino_stream_interaction_module_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_id = dino_replies_real_get_id;
}

static void
dino_replies_instance_init (DinoReplies * self,
                            gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = dino_replies_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (DINO_ENTITIES_TYPE_CONVERSATION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEE_TYPE_HASH_MAP, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->unmapped_replies = _tmp0_;
}

static void
dino_replies_finalize (GObject * obj)
{
	DinoReplies * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_REPLIES, DinoReplies);
	_g_object_unref0 (self->priv->stream_interactor);
	_qlite_database_unref0 (self->priv->db);
	_g_object_unref0 (self->priv->unmapped_replies);
	_g_object_unref0 (self->priv->received_message_listener);
	G_OBJECT_CLASS (dino_replies_parent_class)->finalize (obj);
}

static GType
dino_replies_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoRepliesClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_replies_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoReplies), 0, (GInstanceInitFunc) dino_replies_instance_init, NULL };
	static const GInterfaceInfo dino_stream_interaction_module_info = { (GInterfaceInitFunc) dino_replies_dino_stream_interaction_module_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_replies_type_id;
	dino_replies_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoReplies", &g_define_type_info, 0);
	g_type_add_interface_static (dino_replies_type_id, DINO_TYPE_STREAM_INTERACTION_MODULE, &dino_stream_interaction_module_info);
	DinoReplies_private_offset = g_type_add_instance_private (dino_replies_type_id, sizeof (DinoRepliesPrivate));
	return dino_replies_type_id;
}

GType
dino_replies_get_type (void)
{
	static volatile gsize dino_replies_type_id__once = 0;
	if (g_once_init_enter (&dino_replies_type_id__once)) {
		GType dino_replies_type_id;
		dino_replies_type_id = dino_replies_get_type_once ();
		g_once_init_leave (&dino_replies_type_id__once, dino_replies_type_id);
	}
	return dino_replies_type_id__once;
}

static void
_vala_dino_replies_get_property (GObject * object,
                                 guint property_id,
                                 GValue * value,
                                 GParamSpec * pspec)
{
	DinoReplies * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_TYPE_REPLIES, DinoReplies);
	switch (property_id) {
		case DINO_REPLIES_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 gchar*
string_slice (const gchar* self,
              glong start,
              glong end)
{
	glong string_length = 0L;
	gint _tmp0_;
	gint _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	if (start < ((glong) 0)) {
		start = string_length + start;
	}
	if (end < ((glong) 0)) {
		end = string_length + end;
	}
	if (start >= ((glong) 0)) {
		_tmp2_ = start <= string_length;
	} else {
		_tmp2_ = FALSE;
	}
	g_return_val_if_fail (_tmp2_, NULL);
	if (end >= ((glong) 0)) {
		_tmp3_ = end <= string_length;
	} else {
		_tmp3_ = FALSE;
	}
	g_return_val_if_fail (_tmp3_, NULL);
	g_return_val_if_fail (start <= end, NULL);
	_tmp4_ = g_strndup (((gchar*) self) + start, (gsize) (end - start));
	result = _tmp4_;
	return result;
}

static gint
string_index_of_nth_char (const gchar* self,
                          glong c)
{
	gchar* _tmp0_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	_tmp0_ = g_utf8_offset_to_pointer (self, c);
	result = (gint) (_tmp0_ - ((gchar*) self));
	return result;
}

gchar*
dino_message_body_without_reply_fallback (DinoEntitiesMessage* message)
{
	gchar* body = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* result;
	g_return_val_if_fail (message != NULL, NULL);
	_tmp0_ = dino_entities_message_get_body (message);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strdup (_tmp1_);
	body = _tmp2_;
	{
		GeeList* _fallback_list = NULL;
		GeeList* _tmp3_;
		gint _fallback_size = 0;
		GeeList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		gint _fallback_index = 0;
		_tmp3_ = dino_entities_message_get_fallbacks (message);
		_fallback_list = _tmp3_;
		_tmp4_ = _fallback_list;
		_tmp5_ = gee_collection_get_size ((GeeCollection*) _tmp4_);
		_tmp6_ = _tmp5_;
		_fallback_size = _tmp6_;
		_fallback_index = -1;
		while (TRUE) {
			gint _tmp7_;
			gint _tmp8_;
			XmppXepFallbackIndicationFallback* fallback = NULL;
			GeeList* _tmp9_;
			gpointer _tmp10_;
			gboolean _tmp11_ = FALSE;
			XmppXepFallbackIndicationFallback* _tmp12_;
			const gchar* _tmp13_;
			const gchar* _tmp14_;
			_fallback_index = _fallback_index + 1;
			_tmp7_ = _fallback_index;
			_tmp8_ = _fallback_size;
			if (!(_tmp7_ < _tmp8_)) {
				break;
			}
			_tmp9_ = _fallback_list;
			_tmp10_ = gee_list_get (_tmp9_, _fallback_index);
			fallback = (XmppXepFallbackIndicationFallback*) _tmp10_;
			_tmp12_ = fallback;
			_tmp13_ = xmpp_xep_fallback_indication_fallback_get_ns_uri (_tmp12_);
			_tmp14_ = _tmp13_;
			if (g_strcmp0 (_tmp14_, XMPP_XEP_REPLIES_NS_URI) == 0) {
				gint _tmp15_;
				gint _tmp16_;
				_tmp15_ = dino_entities_message_get_quoted_item_id (message);
				_tmp16_ = _tmp15_;
				_tmp11_ = _tmp16_ > 0;
			} else {
				_tmp11_ = FALSE;
			}
			if (_tmp11_) {
				const gchar* _tmp17_;
				const gchar* _tmp18_;
				XmppXepFallbackIndicationFallback* _tmp19_;
				GeeList* _tmp20_;
				gpointer _tmp21_;
				XmppXepFallbackIndicationFallbackLocation* _tmp22_;
				gint _tmp23_;
				gint _tmp24_;
				gchar* _tmp25_;
				gchar* _tmp26_;
				const gchar* _tmp27_;
				const gchar* _tmp28_;
				XmppXepFallbackIndicationFallback* _tmp29_;
				GeeList* _tmp30_;
				gpointer _tmp31_;
				XmppXepFallbackIndicationFallbackLocation* _tmp32_;
				gint _tmp33_;
				gint _tmp34_;
				const gchar* _tmp35_;
				gint _tmp36_;
				gint _tmp37_;
				gchar* _tmp38_;
				gchar* _tmp39_;
				gchar* _tmp40_;
				_tmp17_ = body;
				_tmp18_ = body;
				_tmp19_ = fallback;
				_tmp20_ = _tmp19_->locations;
				_tmp21_ = gee_list_get (_tmp20_, 0);
				_tmp22_ = (XmppXepFallbackIndicationFallbackLocation*) _tmp21_;
				_tmp23_ = xmpp_xep_fallback_indication_fallback_location_get_from_char (_tmp22_);
				_tmp24_ = _tmp23_;
				_tmp25_ = string_slice (_tmp17_, (glong) 0, (glong) string_index_of_nth_char (_tmp18_, (glong) _tmp24_));
				_tmp26_ = _tmp25_;
				_tmp27_ = body;
				_tmp28_ = body;
				_tmp29_ = fallback;
				_tmp30_ = _tmp29_->locations;
				_tmp31_ = gee_list_get (_tmp30_, 0);
				_tmp32_ = (XmppXepFallbackIndicationFallbackLocation*) _tmp31_;
				_tmp33_ = xmpp_xep_fallback_indication_fallback_location_get_to_char (_tmp32_);
				_tmp34_ = _tmp33_;
				_tmp35_ = body;
				_tmp36_ = strlen (_tmp35_);
				_tmp37_ = _tmp36_;
				_tmp38_ = string_slice (_tmp27_, (glong) string_index_of_nth_char (_tmp28_, (glong) _tmp34_), (glong) _tmp37_);
				_tmp39_ = _tmp38_;
				_tmp40_ = g_strconcat (_tmp26_, _tmp39_, NULL);
				_g_free0 (body);
				body = _tmp40_;
				_g_free0 (_tmp39_);
				_xmpp_xep_fallback_indication_fallback_location_unref0 (_tmp32_);
				_g_free0 (_tmp26_);
				_xmpp_xep_fallback_indication_fallback_location_unref0 (_tmp22_);
			}
			_xmpp_xep_fallback_indication_fallback_unref0 (fallback);
		}
		_g_object_unref0 (_fallback_list);
	}
	result = body;
	return result;
}

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

