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

#include "libdino.h"
#include <gee.h>
#include <glib-object.h>
#include "xmpp-vala.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include "qlite.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_MESSAGE_CORRECTION_0_PROPERTY,
	DINO_MESSAGE_CORRECTION_ID_PROPERTY,
	DINO_MESSAGE_CORRECTION_ACTION_GROUP_PROPERTY,
	DINO_MESSAGE_CORRECTION_AFTER_ACTIONS_PROPERTY,
	DINO_MESSAGE_CORRECTION_NUM_PROPERTIES
};
static GParamSpec* dino_message_correction_properties[DINO_MESSAGE_CORRECTION_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)))
typedef struct _Block19Data Block19Data;
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _qlite_statement_builder_unref0(var) ((var == NULL) ? NULL : (var = (qlite_statement_builder_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
typedef struct _DinoMessageCorrectionRunData DinoMessageCorrectionRunData;
#define _qlite_row_option_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_option_unref (var), NULL)))
enum  {
	DINO_MESSAGE_CORRECTION_RECEIVED_CORRECTION_SIGNAL,
	DINO_MESSAGE_CORRECTION_NUM_SIGNALS
};
static guint dino_message_correction_signals[DINO_MESSAGE_CORRECTION_NUM_SIGNALS] = {0};

struct _DinoMessageCorrectionPrivate {
	DinoStreamInteractor* stream_interactor;
	DinoDatabase* db;
	GeeHashMap* last_messages;
	GeeHashMap* outstanding_correction_nodes;
};

struct _Block19Data {
	int _ref_count_;
	DinoMessageCorrection* self;
	DinoStreamInteractor* stream_interactor;
};

struct _DinoMessageCorrectionRunData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoMessageCorrection* self;
	DinoEntitiesMessage* message;
	XmppMessageStanza* stanza;
	DinoEntitiesConversation* conversation;
	gboolean result;
	DinoEntitiesConversationType _tmp0_;
	DinoEntitiesConversationType _tmp1_;
	GDateTime* mam_delay;
	XmppJid* _tmp2_;
	XmppJid* _tmp3_;
	XmppJid* _tmp4_;
	XmppJid* _tmp5_;
	XmppJid* _tmp6_;
	GDateTime* _tmp7_;
	GDateTime* _tmp8_;
	GDateTime* _tmp9_;
	XmppMessageArchiveManagementMessageFlag* _tmp10_;
	XmppMessageArchiveManagementMessageFlag* _tmp11_;
	gboolean _tmp12_;
	gchar* replace_id;
	gchar* _tmp13_;
	const gchar* _tmp14_;
	GeeHashMap* _tmp15_;
	GeeHashMap* _tmp16_;
	GeeHashMap* _tmp17_;
	GeeHashMap* _tmp18_;
	GeeHashMap* _tmp19_;
	gpointer _tmp20_;
	GeeHashMap* _tmp21_;
	XmppJid* _tmp22_;
	XmppJid* _tmp23_;
	gboolean _tmp24_;
	GeeHashMap* _tmp25_;
	GeeHashMap* _tmp26_;
	gpointer _tmp27_;
	GeeHashMap* _tmp28_;
	XmppJid* _tmp29_;
	XmppJid* _tmp30_;
	DinoEntitiesMessage* original_message;
	GeeHashMap* _tmp31_;
	gpointer _tmp32_;
	GeeHashMap* _tmp33_;
	XmppJid* _tmp34_;
	XmppJid* _tmp35_;
	gpointer _tmp36_;
	DinoEntitiesMessage* _tmp37_;
	DinoEntitiesMessage* _tmp38_;
	const gchar* _tmp39_;
	const gchar* _tmp40_;
	const gchar* _tmp41_;
	gint message_id_to_be_updated;
	DinoEntitiesAccount* _tmp42_;
	DinoEntitiesAccount* _tmp43_;
	gint _tmp44_;
	gint _tmp45_;
	const gchar* _tmp46_;
	DinoDatabase* _tmp47_;
	XmppJid* _tmp48_;
	XmppJid* _tmp49_;
	XmppJid* _tmp50_;
	XmppJid* _tmp51_;
	const gchar* _tmp52_;
	DinoEntitiesMessage* _tmp53_;
	gint _tmp54_;
	gint _tmp55_;
	DinoDatabase* _tmp56_;
	DinoDatabaseMessageCorrectionTable* _tmp57_;
	DinoDatabaseMessageCorrectionTable* _tmp58_;
	QliteInsertBuilder* _tmp59_;
	QliteInsertBuilder* _tmp60_;
	DinoDatabase* _tmp61_;
	DinoDatabaseMessageCorrectionTable* _tmp62_;
	DinoDatabaseMessageCorrectionTable* _tmp63_;
	QliteColumn* _tmp64_;
	gint _tmp65_;
	gint _tmp66_;
	QliteInsertBuilder* _tmp67_;
	QliteInsertBuilder* _tmp68_;
	DinoDatabase* _tmp69_;
	DinoDatabaseMessageCorrectionTable* _tmp70_;
	DinoDatabaseMessageCorrectionTable* _tmp71_;
	QliteColumn* _tmp72_;
	const gchar* _tmp73_;
	QliteInsertBuilder* _tmp74_;
	QliteInsertBuilder* _tmp75_;
	gint current_correction_message_id;
	DinoEntitiesAccount* _tmp76_;
	DinoEntitiesAccount* _tmp77_;
	gint _tmp78_;
	gint _tmp79_;
	const gchar* _tmp80_;
	DinoDatabase* _tmp81_;
	XmppJid* _tmp82_;
	XmppJid* _tmp83_;
	XmppJid* _tmp84_;
	XmppJid* _tmp85_;
	const gchar* _tmp86_;
	DinoDatabase* _tmp87_;
	DinoDatabaseContentItemTable* _tmp88_;
	DinoDatabaseContentItemTable* _tmp89_;
	QliteUpdateBuilder* _tmp90_;
	QliteUpdateBuilder* _tmp91_;
	DinoDatabase* _tmp92_;
	DinoDatabaseContentItemTable* _tmp93_;
	DinoDatabaseContentItemTable* _tmp94_;
	QliteColumn* _tmp95_;
	QliteUpdateBuilder* _tmp96_;
	QliteUpdateBuilder* _tmp97_;
	DinoDatabase* _tmp98_;
	DinoDatabaseContentItemTable* _tmp99_;
	DinoDatabaseContentItemTable* _tmp100_;
	QliteColumn* _tmp101_;
	QliteUpdateBuilder* _tmp102_;
	QliteUpdateBuilder* _tmp103_;
	DinoDatabase* _tmp104_;
	DinoDatabaseContentItemTable* _tmp105_;
	DinoDatabaseContentItemTable* _tmp106_;
	QliteColumn* _tmp107_;
	QliteUpdateBuilder* _tmp108_;
	QliteUpdateBuilder* _tmp109_;
	const gchar* _tmp110_;
	gchar* _tmp111_;
};

static gint DinoMessageCorrection_private_offset;
static gpointer dino_message_correction_parent_class = NULL;
DinoModuleIdentity* dino_message_correction_IDENTITY = NULL;
static DinoStreamInteractionModuleIface * dino_message_correction_dino_stream_interaction_module_parent_iface = NULL;

static guint _dino_entities_conversation_hash_func_gee_hash_data_func (gconstpointer v,
                                                                gpointer self);
static gboolean _dino_entities_conversation_equals_func_gee_equal_data_func (gconstpointer a,
                                                                      gconstpointer b,
                                                                      gpointer self);
static Block19Data* block19_data_ref (Block19Data* _data19_);
static void block19_data_unref (void * _userdata_);
static void dino_message_correction_on_account_added (DinoMessageCorrection* self,
                                               DinoEntitiesAccount* account);
static void _dino_message_correction_on_account_added_dino_stream_interactor_account_added (DinoStreamInteractor* _sender,
                                                                                     DinoEntitiesAccount* account,
                                                                                     gpointer self);
static void dino_message_correction_check_add_correction_node (DinoMessageCorrection* self,
                                                        DinoEntitiesMessage* message,
                                                        XmppMessageStanza* message_stanza,
                                                        DinoEntitiesConversation* conversation);
static void _dino_message_correction_check_add_correction_node_dino_message_processor_build_message_stanza (DinoMessageProcessor* _sender,
                                                                                                     DinoEntitiesMessage* message,
                                                                                                     XmppMessageStanza* message_stanza,
                                                                                                     DinoEntitiesConversation* conversation,
                                                                                                     gpointer self);
static void __lambda136_ (Block19Data* _data19_,
                   XmppJid* jid,
                   DinoEntitiesAccount* account);
static void ___lambda136__dino_presence_manager_received_offline_presence (DinoPresenceManager* _sender,
                                                                    XmppJid* jid,
                                                                    DinoEntitiesAccount* account,
                                                                    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_message_correction_real_run_data_free (gpointer _data);
static void dino_message_correction_real_run (DinoMessageListener* base,
                                       DinoEntitiesMessage* message,
                                       XmppMessageStanza* stanza,
                                       DinoEntitiesConversation* conversation,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_);
static gboolean dino_message_correction_real_run_co (DinoMessageCorrectionRunData* _data_);
static gint dino_message_correction_get_latest_correction_message_id (DinoMessageCorrection* self,
                                                               gint account_id,
                                                               const gchar* stanza_id,
                                                               gint counterpart_jid_id,
                                                               const gchar* counterpart_resource);
static void dino_message_correction_finalize (GObject * obj);
static GType dino_message_correction_get_type_once (void);
static void _vala_dino_message_correction_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_message_correction_get_instance_private (DinoMessageCorrection* self)
{
	return G_STRUCT_MEMBER_P (self, DinoMessageCorrection_private_offset);
}

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

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

void
dino_message_correction_start (DinoStreamInteractor* stream_interactor,
                               DinoDatabase* db)
{
	DinoMessageCorrection* m = NULL;
	DinoMessageCorrection* _tmp0_;
	g_return_if_fail (stream_interactor != NULL);
	g_return_if_fail (db != NULL);
	_tmp0_ = dino_message_correction_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 Block19Data*
block19_data_ref (Block19Data* _data19_)
{
	g_atomic_int_inc (&_data19_->_ref_count_);
	return _data19_;
}

static void
block19_data_unref (void * _userdata_)
{
	Block19Data* _data19_;
	_data19_ = (Block19Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data19_->_ref_count_)) {
		DinoMessageCorrection* self;
		self = _data19_->self;
		_g_object_unref0 (_data19_->stream_interactor);
		_g_object_unref0 (self);
		g_slice_free (Block19Data, _data19_);
	}
}

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

static void
_dino_message_correction_on_account_added_dino_stream_interactor_account_added (DinoStreamInteractor* _sender,
                                                                                DinoEntitiesAccount* account,
                                                                                gpointer self)
{
	dino_message_correction_on_account_added ((DinoMessageCorrection*) self, account);
}

static void
_dino_message_correction_check_add_correction_node_dino_message_processor_build_message_stanza (DinoMessageProcessor* _sender,
                                                                                                DinoEntitiesMessage* message,
                                                                                                XmppMessageStanza* message_stanza,
                                                                                                DinoEntitiesConversation* conversation,
                                                                                                gpointer self)
{
	dino_message_correction_check_add_correction_node ((DinoMessageCorrection*) self, message, message_stanza, conversation);
}

static void
__lambda136_ (Block19Data* _data19_,
              XmppJid* jid,
              DinoEntitiesAccount* account)
{
	DinoMessageCorrection* self;
	DinoEntitiesConversation* conversation = NULL;
	DinoModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	DinoConversationManager* _tmp2_;
	XmppJid* _tmp3_;
	XmppJid* _tmp4_;
	XmppJid* _tmp5_;
	DinoEntitiesConversationType _tmp6_;
	DinoEntitiesConversation* _tmp7_;
	DinoEntitiesConversation* _tmp8_;
	DinoEntitiesConversation* _tmp9_;
	self = _data19_->self;
	g_return_if_fail (jid != NULL);
	g_return_if_fail (account != NULL);
	_tmp0_ = dino_conversation_manager_IDENTITY;
	_tmp1_ = dino_stream_interactor_get_module (_data19_->stream_interactor, DINO_TYPE_CONVERSATION_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_);
	_tmp2_ = (DinoConversationManager*) _tmp1_;
	_tmp3_ = xmpp_jid_get_bare_jid (jid);
	_tmp4_ = _tmp3_;
	_tmp5_ = _tmp4_;
	_tmp6_ = DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT;
	_tmp7_ = dino_conversation_manager_get_conversation (_tmp2_, _tmp5_, account, &_tmp6_);
	_tmp8_ = _tmp7_;
	_xmpp_jid_unref0 (_tmp5_);
	_g_object_unref0 (_tmp2_);
	conversation = _tmp8_;
	_tmp9_ = conversation;
	if (_tmp9_ != NULL) {
		GeeHashMap* _tmp10_;
		DinoEntitiesConversation* _tmp11_;
		_tmp10_ = self->priv->last_messages;
		_tmp11_ = conversation;
		if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp10_, _tmp11_)) {
			GeeHashMap* _tmp12_;
			DinoEntitiesConversation* _tmp13_;
			gpointer _tmp14_;
			GeeHashMap* _tmp15_;
			_tmp12_ = self->priv->last_messages;
			_tmp13_ = conversation;
			_tmp14_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp12_, _tmp13_);
			_tmp15_ = (GeeHashMap*) _tmp14_;
			gee_abstract_map_unset ((GeeAbstractMap*) _tmp15_, jid, NULL);
			_g_object_unref0 (_tmp15_);
		}
	}
	_g_object_unref0 (conversation);
}

static void
___lambda136__dino_presence_manager_received_offline_presence (DinoPresenceManager* _sender,
                                                               XmppJid* jid,
                                                               DinoEntitiesAccount* account,
                                                               gpointer self)
{
	__lambda136_ (self, jid, account);
}

DinoMessageCorrection*
dino_message_correction_construct (GType object_type,
                                   DinoStreamInteractor* stream_interactor,
                                   DinoDatabase* db)
{
	DinoMessageCorrection * self = NULL;
	Block19Data* _data19_;
	DinoStreamInteractor* _tmp0_;
	DinoStreamInteractor* _tmp1_;
	DinoDatabase* _tmp2_;
	DinoModuleIdentity* _tmp3_;
	gpointer _tmp4_;
	DinoMessageProcessor* _tmp5_;
	DinoMessageListenerHolder* _tmp6_;
	DinoModuleIdentity* _tmp7_;
	gpointer _tmp8_;
	DinoMessageProcessor* _tmp9_;
	DinoModuleIdentity* _tmp10_;
	gpointer _tmp11_;
	DinoPresenceManager* _tmp12_;
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	g_return_val_if_fail (db != NULL, NULL);
	_data19_ = g_slice_new0 (Block19Data);
	_data19_->_ref_count_ = 1;
	_tmp0_ = _g_object_ref0 (stream_interactor);
	_g_object_unref0 (_data19_->stream_interactor);
	_data19_->stream_interactor = _tmp0_;
	self = (DinoMessageCorrection*) dino_message_listener_construct (object_type);
	_data19_->self = g_object_ref (self);
	_tmp1_ = _g_object_ref0 (_data19_->stream_interactor);
	_g_object_unref0 (self->priv->stream_interactor);
	self->priv->stream_interactor = _tmp1_;
	_tmp2_ = _qlite_database_ref0 (db);
	_qlite_database_unref0 (self->priv->db);
	self->priv->db = _tmp2_;
	g_signal_connect_object (_data19_->stream_interactor, "account-added", (GCallback) _dino_message_correction_on_account_added_dino_stream_interactor_account_added, self, 0);
	_tmp3_ = dino_message_processor_IDENTITY;
	_tmp4_ = dino_stream_interactor_get_module (_data19_->stream_interactor, DINO_TYPE_MESSAGE_PROCESSOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp3_);
	_tmp5_ = (DinoMessageProcessor*) _tmp4_;
	_tmp6_ = _tmp5_->received_pipeline;
	xmpp_listener_holder_connect ((XmppListenerHolder*) _tmp6_, (XmppOrderedListener*) self);
	_g_object_unref0 (_tmp5_);
	_tmp7_ = dino_message_processor_IDENTITY;
	_tmp8_ = dino_stream_interactor_get_module (_data19_->stream_interactor, DINO_TYPE_MESSAGE_PROCESSOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp7_);
	_tmp9_ = (DinoMessageProcessor*) _tmp8_;
	g_signal_connect_object (_tmp9_, "build-message-stanza", (GCallback) _dino_message_correction_check_add_correction_node_dino_message_processor_build_message_stanza, self, 0);
	_g_object_unref0 (_tmp9_);
	_tmp10_ = dino_presence_manager_IDENTITY;
	_tmp11_ = dino_stream_interactor_get_module (_data19_->stream_interactor, DINO_TYPE_PRESENCE_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp10_);
	_tmp12_ = (DinoPresenceManager*) _tmp11_;
	g_signal_connect_data (_tmp12_, "received-offline-presence", (GCallback) ___lambda136__dino_presence_manager_received_offline_presence, block19_data_ref (_data19_), (GClosureNotify) block19_data_unref, 0);
	_g_object_unref0 (_tmp12_);
	block19_data_unref (_data19_);
	_data19_ = NULL;
	return self;
}

DinoMessageCorrection*
dino_message_correction_new (DinoStreamInteractor* stream_interactor,
                             DinoDatabase* db)
{
	return dino_message_correction_construct (DINO_TYPE_MESSAGE_CORRECTION, stream_interactor, db);
}

void
dino_message_correction_set_correction (DinoMessageCorrection* self,
                                        DinoEntitiesConversation* conversation,
                                        DinoEntitiesMessage* message,
                                        DinoEntitiesMessage* old_message)
{
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp1_;
	gchar* reference_stanza_id = NULL;
	gchar* _tmp4_;
	GeeHashMap* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	DinoDatabase* _tmp8_;
	DinoDatabaseMessageCorrectionTable* _tmp9_;
	DinoDatabaseMessageCorrectionTable* _tmp10_;
	QliteInsertBuilder* _tmp11_;
	QliteInsertBuilder* _tmp12_;
	DinoDatabase* _tmp13_;
	DinoDatabaseMessageCorrectionTable* _tmp14_;
	DinoDatabaseMessageCorrectionTable* _tmp15_;
	QliteColumn* _tmp16_;
	gint _tmp17_;
	gint _tmp18_;
	QliteInsertBuilder* _tmp19_;
	QliteInsertBuilder* _tmp20_;
	DinoDatabase* _tmp21_;
	DinoDatabaseMessageCorrectionTable* _tmp22_;
	DinoDatabaseMessageCorrectionTable* _tmp23_;
	QliteColumn* _tmp24_;
	QliteInsertBuilder* _tmp25_;
	QliteInsertBuilder* _tmp26_;
	DinoDatabase* _tmp27_;
	DinoDatabaseContentItemTable* _tmp28_;
	DinoDatabaseContentItemTable* _tmp29_;
	QliteUpdateBuilder* _tmp30_;
	QliteUpdateBuilder* _tmp31_;
	DinoDatabase* _tmp32_;
	DinoDatabaseContentItemTable* _tmp33_;
	DinoDatabaseContentItemTable* _tmp34_;
	QliteColumn* _tmp35_;
	gint _tmp36_;
	gint _tmp37_;
	QliteUpdateBuilder* _tmp38_;
	QliteUpdateBuilder* _tmp39_;
	DinoDatabase* _tmp40_;
	DinoDatabaseContentItemTable* _tmp41_;
	DinoDatabaseContentItemTable* _tmp42_;
	QliteColumn* _tmp43_;
	QliteUpdateBuilder* _tmp44_;
	QliteUpdateBuilder* _tmp45_;
	DinoDatabase* _tmp46_;
	DinoDatabaseContentItemTable* _tmp47_;
	DinoDatabaseContentItemTable* _tmp48_;
	QliteColumn* _tmp49_;
	gint _tmp50_;
	gint _tmp51_;
	QliteUpdateBuilder* _tmp52_;
	QliteUpdateBuilder* _tmp53_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (conversation != NULL);
	g_return_if_fail (message != NULL);
	g_return_if_fail (old_message != NULL);
	_tmp1_ = old_message->edit_to;
	_tmp0_ = _tmp1_;
	if (_tmp0_ == NULL) {
		const gchar* _tmp2_;
		const gchar* _tmp3_;
		_tmp2_ = dino_entities_message_get_stanza_id (old_message);
		_tmp3_ = _tmp2_;
		_tmp0_ = _tmp3_;
	}
	_tmp4_ = g_strdup (_tmp0_);
	reference_stanza_id = _tmp4_;
	_tmp5_ = self->priv->outstanding_correction_nodes;
	_tmp6_ = dino_entities_message_get_stanza_id (message);
	_tmp7_ = _tmp6_;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp5_, _tmp7_, reference_stanza_id);
	_tmp8_ = self->priv->db;
	_tmp9_ = dino_database_get_message_correction (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = qlite_table_insert ((QliteTable*) _tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = self->priv->db;
	_tmp14_ = dino_database_get_message_correction (_tmp13_);
	_tmp15_ = _tmp14_;
	_tmp16_ = _tmp15_->message_id;
	_tmp17_ = dino_entities_message_get_id (message);
	_tmp18_ = _tmp17_;
	_tmp19_ = qlite_insert_builder_value (_tmp12_, G_TYPE_INT, NULL, NULL, _tmp16_, (gpointer) ((gintptr) _tmp18_));
	_tmp20_ = _tmp19_;
	_tmp21_ = self->priv->db;
	_tmp22_ = dino_database_get_message_correction (_tmp21_);
	_tmp23_ = _tmp22_;
	_tmp24_ = _tmp23_->to_stanza_id;
	_tmp25_ = qlite_insert_builder_value (_tmp20_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp24_, reference_stanza_id);
	_tmp26_ = _tmp25_;
	qlite_insert_builder_perform (_tmp26_);
	_qlite_statement_builder_unref0 (_tmp26_);
	_qlite_statement_builder_unref0 (_tmp20_);
	_qlite_statement_builder_unref0 (_tmp12_);
	_tmp27_ = self->priv->db;
	_tmp28_ = dino_database_get_content_item (_tmp27_);
	_tmp29_ = _tmp28_;
	_tmp30_ = qlite_table_update ((QliteTable*) _tmp29_);
	_tmp31_ = _tmp30_;
	_tmp32_ = self->priv->db;
	_tmp33_ = dino_database_get_content_item (_tmp32_);
	_tmp34_ = _tmp33_;
	_tmp35_ = _tmp34_->foreign_id;
	_tmp36_ = dino_entities_message_get_id (old_message);
	_tmp37_ = _tmp36_;
	_tmp38_ = qlite_update_builder_with (_tmp31_, G_TYPE_INT, NULL, NULL, _tmp35_, "=", (gpointer) ((gintptr) _tmp37_));
	_tmp39_ = _tmp38_;
	_tmp40_ = self->priv->db;
	_tmp41_ = dino_database_get_content_item (_tmp40_);
	_tmp42_ = _tmp41_;
	_tmp43_ = _tmp42_->content_type;
	_tmp44_ = qlite_update_builder_with (_tmp39_, G_TYPE_INT, NULL, NULL, _tmp43_, "=", (gpointer) ((gintptr) 1));
	_tmp45_ = _tmp44_;
	_tmp46_ = self->priv->db;
	_tmp47_ = dino_database_get_content_item (_tmp46_);
	_tmp48_ = _tmp47_;
	_tmp49_ = _tmp48_->foreign_id;
	_tmp50_ = dino_entities_message_get_id (message);
	_tmp51_ = _tmp50_;
	_tmp52_ = qlite_update_builder_set (_tmp45_, G_TYPE_INT, NULL, NULL, _tmp49_, (gpointer) ((gintptr) _tmp51_));
	_tmp53_ = _tmp52_;
	qlite_update_builder_perform (_tmp53_);
	_qlite_statement_builder_unref0 (_tmp53_);
	_qlite_statement_builder_unref0 (_tmp45_);
	_qlite_statement_builder_unref0 (_tmp39_);
	_qlite_statement_builder_unref0 (_tmp31_);
	_g_free0 (reference_stanza_id);
}

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

gboolean
dino_message_correction_is_own_correction_allowed (DinoMessageCorrection* self,
                                                   DinoEntitiesConversation* conversation,
                                                   DinoEntitiesMessage* message)
{
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp1_;
	gchar* stanza_id = NULL;
	gchar* _tmp4_;
	XmppJid* own_jid = NULL;
	DinoEntitiesConversationType _tmp5_;
	DinoEntitiesConversationType _tmp6_;
	XmppJid* _tmp23_;
	gboolean _tmp24_ = FALSE;
	gboolean _tmp25_ = FALSE;
	GeeHashMap* _tmp26_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (conversation != NULL, FALSE);
	g_return_val_if_fail (message != NULL, FALSE);
	_tmp1_ = message->edit_to;
	_tmp0_ = _tmp1_;
	if (_tmp0_ == NULL) {
		const gchar* _tmp2_;
		const gchar* _tmp3_;
		_tmp2_ = dino_entities_message_get_stanza_id (message);
		_tmp3_ = _tmp2_;
		_tmp0_ = _tmp3_;
	}
	_tmp4_ = g_strdup (_tmp0_);
	stanza_id = _tmp4_;
	own_jid = NULL;
	_tmp5_ = dino_entities_conversation_get_type_ (conversation);
	_tmp6_ = _tmp5_;
	if (_tmp6_ == DINO_ENTITIES_CONVERSATION_TYPE_CHAT) {
		DinoEntitiesAccount* _tmp7_;
		DinoEntitiesAccount* _tmp8_;
		XmppJid* _tmp9_;
		XmppJid* _tmp10_;
		XmppJid* _tmp11_;
		_tmp7_ = dino_entities_conversation_get_account (conversation);
		_tmp8_ = _tmp7_;
		_tmp9_ = dino_entities_account_get_full_jid (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = _xmpp_jid_ref0 (_tmp10_);
		_xmpp_jid_unref0 (own_jid);
		own_jid = _tmp11_;
	} else {
		DinoEntitiesConversationType _tmp12_;
		DinoEntitiesConversationType _tmp13_;
		_tmp12_ = dino_entities_conversation_get_type_ (conversation);
		_tmp13_ = _tmp12_;
		if (_tmp13_ == DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT) {
			DinoStreamInteractor* _tmp14_;
			DinoModuleIdentity* _tmp15_;
			gpointer _tmp16_;
			DinoMucManager* _tmp17_;
			XmppJid* _tmp18_;
			XmppJid* _tmp19_;
			DinoEntitiesAccount* _tmp20_;
			DinoEntitiesAccount* _tmp21_;
			XmppJid* _tmp22_;
			_tmp14_ = self->priv->stream_interactor;
			_tmp15_ = dino_muc_manager_IDENTITY;
			_tmp16_ = dino_stream_interactor_get_module (_tmp14_, DINO_TYPE_MUC_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp15_);
			_tmp17_ = (DinoMucManager*) _tmp16_;
			_tmp18_ = dino_entities_conversation_get_counterpart (conversation);
			_tmp19_ = _tmp18_;
			_tmp20_ = dino_entities_conversation_get_account (conversation);
			_tmp21_ = _tmp20_;
			_tmp22_ = dino_muc_manager_get_own_jid (_tmp17_, _tmp19_, _tmp21_);
			_xmpp_jid_unref0 (own_jid);
			own_jid = _tmp22_;
			_g_object_unref0 (_tmp17_);
		}
	}
	_tmp23_ = own_jid;
	if (_tmp23_ == NULL) {
		result = FALSE;
		_xmpp_jid_unref0 (own_jid);
		_g_free0 (stanza_id);
		return result;
	}
	_tmp26_ = self->priv->last_messages;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp26_, conversation)) {
		GeeHashMap* _tmp27_;
		gpointer _tmp28_;
		GeeHashMap* _tmp29_;
		XmppJid* _tmp30_;
		_tmp27_ = self->priv->last_messages;
		_tmp28_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp27_, conversation);
		_tmp29_ = (GeeHashMap*) _tmp28_;
		_tmp30_ = own_jid;
		_tmp25_ = gee_abstract_map_has_key ((GeeAbstractMap*) _tmp29_, _tmp30_);
		_g_object_unref0 (_tmp29_);
	} else {
		_tmp25_ = FALSE;
	}
	if (_tmp25_) {
		GeeHashMap* _tmp31_;
		gpointer _tmp32_;
		GeeHashMap* _tmp33_;
		XmppJid* _tmp34_;
		gpointer _tmp35_;
		DinoEntitiesMessage* _tmp36_;
		const gchar* _tmp37_;
		const gchar* _tmp38_;
		const gchar* _tmp39_;
		_tmp31_ = self->priv->last_messages;
		_tmp32_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp31_, conversation);
		_tmp33_ = (GeeHashMap*) _tmp32_;
		_tmp34_ = own_jid;
		_tmp35_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp33_, _tmp34_);
		_tmp36_ = (DinoEntitiesMessage*) _tmp35_;
		_tmp37_ = dino_entities_message_get_stanza_id (_tmp36_);
		_tmp38_ = _tmp37_;
		_tmp39_ = stanza_id;
		_tmp24_ = g_strcmp0 (_tmp38_, _tmp39_) == 0;
		_g_object_unref0 (_tmp36_);
		_g_object_unref0 (_tmp33_);
	} else {
		_tmp24_ = FALSE;
	}
	result = _tmp24_;
	_xmpp_jid_unref0 (own_jid);
	_g_free0 (stanza_id);
	return result;
}

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_message_correction_check_add_correction_node (DinoMessageCorrection* self,
                                                   DinoEntitiesMessage* message,
                                                   XmppMessageStanza* message_stanza,
                                                   DinoEntitiesConversation* conversation)
{
	GeeHashMap* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (message != NULL);
	g_return_if_fail (message_stanza != NULL);
	g_return_if_fail (conversation != NULL);
	_tmp0_ = self->priv->outstanding_correction_nodes;
	_tmp1_ = dino_entities_message_get_stanza_id (message);
	_tmp2_ = _tmp1_;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp0_, _tmp2_)) {
		GeeHashMap* _tmp3_;
		const gchar* _tmp4_;
		const gchar* _tmp5_;
		gpointer _tmp6_;
		gchar* _tmp7_;
		GeeHashMap* _tmp8_;
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		_tmp3_ = self->priv->outstanding_correction_nodes;
		_tmp4_ = dino_entities_message_get_stanza_id (message);
		_tmp5_ = _tmp4_;
		_tmp6_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp3_, _tmp5_);
		_tmp7_ = (gchar*) _tmp6_;
		xmpp_xep_last_message_correction_set_replace_id (message_stanza, _tmp7_);
		_g_free0 (_tmp7_);
		_tmp8_ = self->priv->outstanding_correction_nodes;
		_tmp9_ = dino_entities_message_get_stanza_id (message);
		_tmp10_ = _tmp9_;
		gee_abstract_map_unset ((GeeAbstractMap*) _tmp8_, _tmp10_, NULL);
	} else {
		GeeHashMap* _tmp11_;
		GeeHashMap* _tmp15_;
		gpointer _tmp16_;
		GeeHashMap* _tmp17_;
		XmppJid* _tmp18_;
		XmppJid* _tmp19_;
		_tmp11_ = self->priv->last_messages;
		if (!gee_abstract_map_has_key ((GeeAbstractMap*) _tmp11_, conversation)) {
			GeeHashMap* _tmp12_;
			GeeHashMap* _tmp13_;
			GeeHashMap* _tmp14_;
			_tmp12_ = self->priv->last_messages;
			_tmp13_ = gee_hash_map_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, DINO_ENTITIES_TYPE_MESSAGE, (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);
			_tmp14_ = _tmp13_;
			gee_abstract_map_set ((GeeAbstractMap*) _tmp12_, conversation, _tmp14_);
			_g_object_unref0 (_tmp14_);
		}
		_tmp15_ = self->priv->last_messages;
		_tmp16_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp15_, conversation);
		_tmp17_ = (GeeHashMap*) _tmp16_;
		_tmp18_ = dino_entities_message_get_from (message);
		_tmp19_ = _tmp18_;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp17_, _tmp19_, message);
		_g_object_unref0 (_tmp17_);
	}
}

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

static void
dino_message_correction_real_run (DinoMessageListener* base,
                                  DinoEntitiesMessage* message,
                                  XmppMessageStanza* stanza,
                                  DinoEntitiesConversation* conversation,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_)
{
	DinoMessageCorrection * self;
	DinoMessageCorrectionRunData* _data_;
	DinoMessageCorrection* _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 = (DinoMessageCorrection*) base;
	_data_ = g_slice_new0 (DinoMessageCorrectionRunData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_message_correction_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_message_correction_real_run_co (_data_);
}

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

static gboolean
dino_message_correction_real_run_co (DinoMessageCorrectionRunData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = dino_entities_conversation_get_type_ (_data_->conversation);
	_data_->_tmp1_ = _data_->_tmp0_;
	if (_data_->_tmp1_ != DINO_ENTITIES_CONVERSATION_TYPE_CHAT) {
		_data_->_tmp2_ = dino_entities_message_get_from (_data_->message);
		_data_->_tmp3_ = _data_->_tmp2_;
		_data_->_tmp4_ = xmpp_jid_get_bare_jid (_data_->_tmp3_);
		_data_->_tmp5_ = _data_->_tmp4_;
		_data_->_tmp6_ = _data_->_tmp5_;
		_data_->_tmp7_ = xmpp_xep_delayed_delivery_get_time_for_message (_data_->stanza, _data_->_tmp6_);
		_data_->_tmp8_ = _data_->_tmp7_;
		_xmpp_jid_unref0 (_data_->_tmp6_);
		_data_->mam_delay = _data_->_tmp8_;
		_data_->_tmp9_ = _data_->mam_delay;
		if (_data_->_tmp9_ != NULL) {
			_data_->result = FALSE;
			_g_date_time_unref0 (_data_->mam_delay);
			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_->_tmp10_ = xmpp_message_archive_management_message_flag_get_flag (_data_->stanza);
		_data_->_tmp11_ = _data_->_tmp10_;
		_data_->_tmp12_ = _data_->_tmp11_ != NULL;
		_g_object_unref0 (_data_->_tmp11_);
		if (_data_->_tmp12_) {
			_data_->result = FALSE;
			_g_date_time_unref0 (_data_->mam_delay);
			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;
		}
		_g_date_time_unref0 (_data_->mam_delay);
	}
	_data_->_tmp13_ = xmpp_xep_last_message_correction_get_replace_id (_data_->stanza);
	_data_->replace_id = _data_->_tmp13_;
	_data_->_tmp14_ = _data_->replace_id;
	if (_data_->_tmp14_ == NULL) {
		_data_->_tmp15_ = _data_->self->priv->last_messages;
		if (!gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp15_, _data_->conversation)) {
			_data_->_tmp16_ = _data_->self->priv->last_messages;
			_data_->_tmp17_ = gee_hash_map_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, DINO_ENTITIES_TYPE_MESSAGE, (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);
			_data_->_tmp18_ = _data_->_tmp17_;
			gee_abstract_map_set ((GeeAbstractMap*) _data_->_tmp16_, _data_->conversation, _data_->_tmp18_);
			_g_object_unref0 (_data_->_tmp18_);
		}
		_data_->_tmp19_ = _data_->self->priv->last_messages;
		_data_->_tmp20_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp19_, _data_->conversation);
		_data_->_tmp21_ = (GeeHashMap*) _data_->_tmp20_;
		_data_->_tmp22_ = dino_entities_message_get_from (_data_->message);
		_data_->_tmp23_ = _data_->_tmp22_;
		gee_abstract_map_set ((GeeAbstractMap*) _data_->_tmp21_, _data_->_tmp23_, _data_->message);
		_g_object_unref0 (_data_->_tmp21_);
		_data_->result = FALSE;
		_g_free0 (_data_->replace_id);
		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_->_tmp25_ = _data_->self->priv->last_messages;
	if (!gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp25_, _data_->conversation)) {
		_data_->_tmp24_ = TRUE;
	} else {
		_data_->_tmp26_ = _data_->self->priv->last_messages;
		_data_->_tmp27_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp26_, _data_->conversation);
		_data_->_tmp28_ = (GeeHashMap*) _data_->_tmp27_;
		_data_->_tmp29_ = dino_entities_message_get_from (_data_->message);
		_data_->_tmp30_ = _data_->_tmp29_;
		_data_->_tmp24_ = !gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp28_, _data_->_tmp30_);
		_g_object_unref0 (_data_->_tmp28_);
	}
	if (_data_->_tmp24_) {
		_data_->result = FALSE;
		_g_free0 (_data_->replace_id);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp31_ = _data_->self->priv->last_messages;
	_data_->_tmp32_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp31_, _data_->conversation);
	_data_->_tmp33_ = (GeeHashMap*) _data_->_tmp32_;
	_data_->_tmp34_ = dino_entities_message_get_from (_data_->message);
	_data_->_tmp35_ = _data_->_tmp34_;
	_data_->_tmp36_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp33_, _data_->_tmp35_);
	_data_->_tmp37_ = (DinoEntitiesMessage*) _data_->_tmp36_;
	_g_object_unref0 (_data_->_tmp33_);
	_data_->original_message = _data_->_tmp37_;
	_data_->_tmp38_ = _data_->original_message;
	_data_->_tmp39_ = dino_entities_message_get_stanza_id (_data_->_tmp38_);
	_data_->_tmp40_ = _data_->_tmp39_;
	_data_->_tmp41_ = _data_->replace_id;
	if (g_strcmp0 (_data_->_tmp40_, _data_->_tmp41_) != 0) {
		_data_->result = FALSE;
		_g_object_unref0 (_data_->original_message);
		_g_free0 (_data_->replace_id);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp42_ = dino_entities_conversation_get_account (_data_->conversation);
	_data_->_tmp43_ = _data_->_tmp42_;
	_data_->_tmp44_ = dino_entities_account_get_id (_data_->_tmp43_);
	_data_->_tmp45_ = _data_->_tmp44_;
	_data_->_tmp46_ = _data_->replace_id;
	_data_->_tmp47_ = _data_->self->priv->db;
	_data_->_tmp48_ = dino_entities_message_get_counterpart (_data_->message);
	_data_->_tmp49_ = _data_->_tmp48_;
	_data_->_tmp50_ = dino_entities_message_get_counterpart (_data_->message);
	_data_->_tmp51_ = _data_->_tmp50_;
	_data_->_tmp52_ = _data_->_tmp51_->resourcepart;
	_data_->message_id_to_be_updated = dino_message_correction_get_latest_correction_message_id (_data_->self, _data_->_tmp45_, _data_->_tmp46_, dino_database_get_jid_id (_data_->_tmp47_, _data_->_tmp49_), _data_->_tmp52_);
	if (_data_->message_id_to_be_updated == -1) {
		_data_->_tmp53_ = _data_->original_message;
		_data_->_tmp54_ = dino_entities_message_get_id (_data_->_tmp53_);
		_data_->_tmp55_ = _data_->_tmp54_;
		_data_->message_id_to_be_updated = _data_->_tmp55_;
	}
	_data_->_tmp56_ = _data_->self->priv->db;
	_data_->_tmp57_ = dino_database_get_message_correction (_data_->_tmp56_);
	_data_->_tmp58_ = _data_->_tmp57_;
	_data_->_tmp59_ = qlite_table_insert ((QliteTable*) _data_->_tmp58_);
	_data_->_tmp60_ = _data_->_tmp59_;
	_data_->_tmp61_ = _data_->self->priv->db;
	_data_->_tmp62_ = dino_database_get_message_correction (_data_->_tmp61_);
	_data_->_tmp63_ = _data_->_tmp62_;
	_data_->_tmp64_ = _data_->_tmp63_->message_id;
	_data_->_tmp65_ = dino_entities_message_get_id (_data_->message);
	_data_->_tmp66_ = _data_->_tmp65_;
	_data_->_tmp67_ = qlite_insert_builder_value (_data_->_tmp60_, G_TYPE_INT, NULL, NULL, _data_->_tmp64_, (gpointer) ((gintptr) _data_->_tmp66_));
	_data_->_tmp68_ = _data_->_tmp67_;
	_data_->_tmp69_ = _data_->self->priv->db;
	_data_->_tmp70_ = dino_database_get_message_correction (_data_->_tmp69_);
	_data_->_tmp71_ = _data_->_tmp70_;
	_data_->_tmp72_ = _data_->_tmp71_->to_stanza_id;
	_data_->_tmp73_ = _data_->replace_id;
	_data_->_tmp74_ = qlite_insert_builder_value (_data_->_tmp68_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp72_, _data_->_tmp73_);
	_data_->_tmp75_ = _data_->_tmp74_;
	qlite_insert_builder_perform (_data_->_tmp75_);
	_qlite_statement_builder_unref0 (_data_->_tmp75_);
	_qlite_statement_builder_unref0 (_data_->_tmp68_);
	_qlite_statement_builder_unref0 (_data_->_tmp60_);
	_data_->_tmp76_ = dino_entities_conversation_get_account (_data_->conversation);
	_data_->_tmp77_ = _data_->_tmp76_;
	_data_->_tmp78_ = dino_entities_account_get_id (_data_->_tmp77_);
	_data_->_tmp79_ = _data_->_tmp78_;
	_data_->_tmp80_ = _data_->replace_id;
	_data_->_tmp81_ = _data_->self->priv->db;
	_data_->_tmp82_ = dino_entities_message_get_counterpart (_data_->message);
	_data_->_tmp83_ = _data_->_tmp82_;
	_data_->_tmp84_ = dino_entities_message_get_counterpart (_data_->message);
	_data_->_tmp85_ = _data_->_tmp84_;
	_data_->_tmp86_ = _data_->_tmp85_->resourcepart;
	_data_->current_correction_message_id = dino_message_correction_get_latest_correction_message_id (_data_->self, _data_->_tmp79_, _data_->_tmp80_, dino_database_get_jid_id (_data_->_tmp81_, _data_->_tmp83_), _data_->_tmp86_);
	if (_data_->current_correction_message_id != _data_->message_id_to_be_updated) {
		_data_->_tmp87_ = _data_->self->priv->db;
		_data_->_tmp88_ = dino_database_get_content_item (_data_->_tmp87_);
		_data_->_tmp89_ = _data_->_tmp88_;
		_data_->_tmp90_ = qlite_table_update ((QliteTable*) _data_->_tmp89_);
		_data_->_tmp91_ = _data_->_tmp90_;
		_data_->_tmp92_ = _data_->self->priv->db;
		_data_->_tmp93_ = dino_database_get_content_item (_data_->_tmp92_);
		_data_->_tmp94_ = _data_->_tmp93_;
		_data_->_tmp95_ = _data_->_tmp94_->foreign_id;
		_data_->_tmp96_ = qlite_update_builder_with (_data_->_tmp91_, G_TYPE_INT, NULL, NULL, _data_->_tmp95_, "=", (gpointer) ((gintptr) _data_->message_id_to_be_updated));
		_data_->_tmp97_ = _data_->_tmp96_;
		_data_->_tmp98_ = _data_->self->priv->db;
		_data_->_tmp99_ = dino_database_get_content_item (_data_->_tmp98_);
		_data_->_tmp100_ = _data_->_tmp99_;
		_data_->_tmp101_ = _data_->_tmp100_->content_type;
		_data_->_tmp102_ = qlite_update_builder_with (_data_->_tmp97_, G_TYPE_INT, NULL, NULL, _data_->_tmp101_, "=", (gpointer) ((gintptr) 1));
		_data_->_tmp103_ = _data_->_tmp102_;
		_data_->_tmp104_ = _data_->self->priv->db;
		_data_->_tmp105_ = dino_database_get_content_item (_data_->_tmp104_);
		_data_->_tmp106_ = _data_->_tmp105_;
		_data_->_tmp107_ = _data_->_tmp106_->foreign_id;
		_data_->_tmp108_ = qlite_update_builder_set (_data_->_tmp103_, G_TYPE_INT, NULL, NULL, _data_->_tmp107_, (gpointer) ((gintptr) _data_->current_correction_message_id));
		_data_->_tmp109_ = _data_->_tmp108_;
		qlite_update_builder_perform (_data_->_tmp109_);
		_qlite_statement_builder_unref0 (_data_->_tmp109_);
		_qlite_statement_builder_unref0 (_data_->_tmp103_);
		_qlite_statement_builder_unref0 (_data_->_tmp97_);
		_qlite_statement_builder_unref0 (_data_->_tmp91_);
		_data_->_tmp110_ = _data_->replace_id;
		_data_->_tmp111_ = g_strdup (_data_->_tmp110_);
		_g_free0 (_data_->message->edit_to);
		_data_->message->edit_to = _data_->_tmp111_;
		dino_message_correction_on_received_correction (_data_->self, _data_->conversation, _data_->current_correction_message_id);
		_data_->result = TRUE;
		_g_object_unref0 (_data_->original_message);
		_g_free0 (_data_->replace_id);
		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_->result = FALSE;
	_g_object_unref0 (_data_->original_message);
	_g_free0 (_data_->replace_id);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

void
dino_message_correction_on_received_correction (DinoMessageCorrection* self,
                                                DinoEntitiesConversation* conversation,
                                                gint message_id)
{
	DinoContentItem* content_item = NULL;
	DinoStreamInteractor* _tmp0_;
	DinoModuleIdentity* _tmp1_;
	gpointer _tmp2_;
	DinoContentItemStore* _tmp3_;
	DinoContentItem* _tmp4_;
	DinoContentItem* _tmp5_;
	DinoContentItem* _tmp6_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (conversation != NULL);
	_tmp0_ = self->priv->stream_interactor;
	_tmp1_ = dino_content_item_store_IDENTITY;
	_tmp2_ = dino_stream_interactor_get_module (_tmp0_, DINO_TYPE_CONTENT_ITEM_STORE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp1_);
	_tmp3_ = (DinoContentItemStore*) _tmp2_;
	_tmp4_ = dino_content_item_store_get_item_by_foreign (_tmp3_, conversation, 1, message_id);
	_tmp5_ = _tmp4_;
	_g_object_unref0 (_tmp3_);
	content_item = _tmp5_;
	_tmp6_ = content_item;
	if (_tmp6_ != NULL) {
		DinoContentItem* _tmp7_;
		_tmp7_ = content_item;
		g_signal_emit (self, dino_message_correction_signals[DINO_MESSAGE_CORRECTION_RECEIVED_CORRECTION_SIGNAL], 0, _tmp7_);
	}
	_g_object_unref0 (content_item);
}

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

static gint
dino_message_correction_get_latest_correction_message_id (DinoMessageCorrection* self,
                                                          gint account_id,
                                                          const gchar* stanza_id,
                                                          gint counterpart_jid_id,
                                                          const gchar* counterpart_resource)
{
	QliteQueryBuilder* qry = NULL;
	DinoDatabase* _tmp0_;
	DinoDatabaseMessageCorrectionTable* _tmp1_;
	DinoDatabaseMessageCorrectionTable* _tmp2_;
	DinoDatabase* _tmp3_;
	DinoDatabaseMessageTable* _tmp4_;
	DinoDatabaseMessageTable* _tmp5_;
	QliteColumn* _tmp6_;
	QliteColumn* _tmp7_;
	QliteColumn** _tmp8_;
	QliteColumn** _tmp9_;
	gint _tmp9__length1;
	QliteQueryBuilder* _tmp10_;
	QliteQueryBuilder* _tmp11_;
	DinoDatabase* _tmp12_;
	DinoDatabaseMessageTable* _tmp13_;
	DinoDatabaseMessageTable* _tmp14_;
	DinoDatabase* _tmp15_;
	DinoDatabaseMessageTable* _tmp16_;
	DinoDatabaseMessageTable* _tmp17_;
	QliteColumn* _tmp18_;
	DinoDatabase* _tmp19_;
	DinoDatabaseMessageCorrectionTable* _tmp20_;
	DinoDatabaseMessageCorrectionTable* _tmp21_;
	QliteColumn* _tmp22_;
	QliteQueryBuilder* _tmp23_;
	QliteQueryBuilder* _tmp24_;
	DinoDatabase* _tmp25_;
	DinoDatabaseMessageTable* _tmp26_;
	DinoDatabaseMessageTable* _tmp27_;
	QliteColumn* _tmp28_;
	QliteQueryBuilder* _tmp29_;
	QliteQueryBuilder* _tmp30_;
	DinoDatabase* _tmp31_;
	DinoDatabaseMessageTable* _tmp32_;
	DinoDatabaseMessageTable* _tmp33_;
	QliteColumn* _tmp34_;
	QliteQueryBuilder* _tmp35_;
	QliteQueryBuilder* _tmp36_;
	DinoDatabase* _tmp37_;
	DinoDatabaseMessageCorrectionTable* _tmp38_;
	DinoDatabaseMessageCorrectionTable* _tmp39_;
	QliteColumn* _tmp40_;
	QliteQueryBuilder* _tmp41_;
	QliteQueryBuilder* _tmp42_;
	DinoDatabase* _tmp43_;
	DinoDatabaseMessageTable* _tmp44_;
	DinoDatabaseMessageTable* _tmp45_;
	QliteColumn* _tmp46_;
	QliteQueryBuilder* _tmp47_;
	QliteQueryBuilder* _tmp48_;
	QliteRowOption* row = NULL;
	QliteQueryBuilder* _tmp56_;
	QliteQueryBuilder* _tmp57_;
	QliteQueryBuilder* _tmp58_;
	QliteRowOption* _tmp59_;
	QliteRowOption* _tmp60_;
	QliteRowOption* _tmp61_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (stanza_id != NULL, -1);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_database_get_message_correction (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->priv->db;
	_tmp4_ = dino_database_get_message (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = _tmp5_->id;
	_tmp7_ = _qlite_column_ref0 (_tmp6_);
	_tmp8_ = g_new0 (QliteColumn*, 1 + 1);
	_tmp8_[0] = _tmp7_;
	_tmp9_ = _tmp8_;
	_tmp9__length1 = 1;
	_tmp10_ = qlite_table_select ((QliteTable*) _tmp2_, _tmp9_, (gint) 1);
	_tmp11_ = _tmp10_;
	_tmp12_ = self->priv->db;
	_tmp13_ = dino_database_get_message (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = self->priv->db;
	_tmp16_ = dino_database_get_message (_tmp15_);
	_tmp17_ = _tmp16_;
	_tmp18_ = _tmp17_->id;
	_tmp19_ = self->priv->db;
	_tmp20_ = dino_database_get_message_correction (_tmp19_);
	_tmp21_ = _tmp20_;
	_tmp22_ = _tmp21_->message_id;
	_tmp23_ = qlite_query_builder_join_with (_tmp11_, G_TYPE_INT, NULL, NULL, (QliteTable*) _tmp14_, _tmp18_, _tmp22_, NULL);
	_tmp24_ = _tmp23_;
	_tmp25_ = self->priv->db;
	_tmp26_ = dino_database_get_message (_tmp25_);
	_tmp27_ = _tmp26_;
	_tmp28_ = _tmp27_->account_id;
	_tmp29_ = qlite_query_builder_with (_tmp24_, G_TYPE_INT, NULL, NULL, _tmp28_, "=", (gpointer) ((gintptr) account_id));
	_tmp30_ = _tmp29_;
	_tmp31_ = self->priv->db;
	_tmp32_ = dino_database_get_message (_tmp31_);
	_tmp33_ = _tmp32_;
	_tmp34_ = _tmp33_->counterpart_id;
	_tmp35_ = qlite_query_builder_with (_tmp30_, G_TYPE_INT, NULL, NULL, _tmp34_, "=", (gpointer) ((gintptr) counterpart_jid_id));
	_tmp36_ = _tmp35_;
	_tmp37_ = self->priv->db;
	_tmp38_ = dino_database_get_message_correction (_tmp37_);
	_tmp39_ = _tmp38_;
	_tmp40_ = _tmp39_->to_stanza_id;
	_tmp41_ = qlite_query_builder_with (_tmp36_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp40_, "=", stanza_id);
	_tmp42_ = _tmp41_;
	_tmp43_ = self->priv->db;
	_tmp44_ = dino_database_get_message (_tmp43_);
	_tmp45_ = _tmp44_;
	_tmp46_ = _tmp45_->time;
	_tmp47_ = qlite_query_builder_order_by (_tmp42_, _tmp46_, "DESC");
	_tmp48_ = _tmp47_;
	_qlite_statement_builder_unref0 (_tmp42_);
	_qlite_statement_builder_unref0 (_tmp36_);
	_qlite_statement_builder_unref0 (_tmp30_);
	_qlite_statement_builder_unref0 (_tmp24_);
	_qlite_statement_builder_unref0 (_tmp11_);
	_tmp9_ = (_vala_array_free (_tmp9_, _tmp9__length1, (GDestroyNotify) qlite_column_unref), NULL);
	qry = _tmp48_;
	if (counterpart_resource != NULL) {
		QliteQueryBuilder* _tmp49_;
		DinoDatabase* _tmp50_;
		DinoDatabaseMessageTable* _tmp51_;
		DinoDatabaseMessageTable* _tmp52_;
		QliteColumn* _tmp53_;
		QliteQueryBuilder* _tmp54_;
		QliteQueryBuilder* _tmp55_;
		_tmp49_ = qry;
		_tmp50_ = self->priv->db;
		_tmp51_ = dino_database_get_message (_tmp50_);
		_tmp52_ = _tmp51_;
		_tmp53_ = _tmp52_->counterpart_resource;
		_tmp54_ = qlite_query_builder_with (_tmp49_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp53_, "=", counterpart_resource);
		_tmp55_ = _tmp54_;
		_qlite_statement_builder_unref0 (_tmp55_);
	}
	_tmp56_ = qry;
	_tmp57_ = qlite_query_builder_single (_tmp56_);
	_tmp58_ = _tmp57_;
	_tmp59_ = qlite_query_builder_row (_tmp58_);
	_tmp60_ = _tmp59_;
	_qlite_statement_builder_unref0 (_tmp58_);
	row = _tmp60_;
	_tmp61_ = row;
	if (qlite_row_option_is_present (_tmp61_)) {
		QliteRowOption* _tmp62_;
		DinoDatabase* _tmp63_;
		DinoDatabaseMessageTable* _tmp64_;
		DinoDatabaseMessageTable* _tmp65_;
		QliteColumn* _tmp66_;
		gpointer _tmp67_;
		_tmp62_ = row;
		_tmp63_ = self->priv->db;
		_tmp64_ = dino_database_get_message (_tmp63_);
		_tmp65_ = _tmp64_;
		_tmp66_ = _tmp65_->id;
		_tmp67_ = qlite_row_option_get (_tmp62_, G_TYPE_INT, NULL, NULL, _tmp66_, NULL);
		result = (gint) ((gintptr) _tmp67_);
		_qlite_row_option_unref0 (row);
		_qlite_statement_builder_unref0 (qry);
		return result;
	}
	result = -1;
	_qlite_row_option_unref0 (row);
	_qlite_statement_builder_unref0 (qry);
	return result;
}

static void
dino_message_correction_on_account_added (DinoMessageCorrection* self,
                                          DinoEntitiesAccount* account)
{
	GeeList* conversations = NULL;
	DinoStreamInteractor* _tmp0_;
	DinoModuleIdentity* _tmp1_;
	gpointer _tmp2_;
	DinoConversationManager* _tmp3_;
	GeeList* _tmp4_;
	GeeList* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	_tmp0_ = self->priv->stream_interactor;
	_tmp1_ = dino_conversation_manager_IDENTITY;
	_tmp2_ = dino_stream_interactor_get_module (_tmp0_, DINO_TYPE_CONVERSATION_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp1_);
	_tmp3_ = (DinoConversationManager*) _tmp2_;
	_tmp4_ = dino_conversation_manager_get_active_conversations (_tmp3_, account);
	_tmp5_ = _tmp4_;
	_g_object_unref0 (_tmp3_);
	conversations = _tmp5_;
	{
		GeeList* _conversation_list = NULL;
		GeeList* _tmp6_;
		gint _conversation_size = 0;
		GeeList* _tmp7_;
		gint _tmp8_;
		gint _tmp9_;
		gint _conversation_index = 0;
		_tmp6_ = conversations;
		_conversation_list = _tmp6_;
		_tmp7_ = _conversation_list;
		_tmp8_ = gee_collection_get_size ((GeeCollection*) _tmp7_);
		_tmp9_ = _tmp8_;
		_conversation_size = _tmp9_;
		_conversation_index = -1;
		while (TRUE) {
			gint _tmp10_;
			gint _tmp11_;
			DinoEntitiesConversation* conversation = NULL;
			GeeList* _tmp12_;
			gpointer _tmp13_;
			DinoEntitiesConversation* _tmp14_;
			DinoEntitiesConversationType _tmp15_;
			DinoEntitiesConversationType _tmp16_;
			GeeHashMap* last_conversation_messages = NULL;
			GeeHashMap* _tmp17_;
			GeeList* messages = NULL;
			DinoStreamInteractor* _tmp18_;
			DinoModuleIdentity* _tmp19_;
			gpointer _tmp20_;
			DinoMessageStorage* _tmp21_;
			DinoEntitiesConversation* _tmp22_;
			GeeList* _tmp23_;
			GeeList* _tmp24_;
			GeeHashMap* _tmp44_;
			DinoEntitiesConversation* _tmp45_;
			GeeHashMap* _tmp46_;
			_conversation_index = _conversation_index + 1;
			_tmp10_ = _conversation_index;
			_tmp11_ = _conversation_size;
			if (!(_tmp10_ < _tmp11_)) {
				break;
			}
			_tmp12_ = _conversation_list;
			_tmp13_ = gee_list_get (_tmp12_, _conversation_index);
			conversation = (DinoEntitiesConversation*) _tmp13_;
			_tmp14_ = conversation;
			_tmp15_ = dino_entities_conversation_get_type_ (_tmp14_);
			_tmp16_ = _tmp15_;
			if (_tmp16_ != DINO_ENTITIES_CONVERSATION_TYPE_CHAT) {
				_g_object_unref0 (conversation);
				continue;
			}
			_tmp17_ = gee_hash_map_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, DINO_ENTITIES_TYPE_MESSAGE, (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);
			last_conversation_messages = _tmp17_;
			_tmp18_ = self->priv->stream_interactor;
			_tmp19_ = dino_message_storage_IDENTITY;
			_tmp20_ = dino_stream_interactor_get_module (_tmp18_, DINO_TYPE_MESSAGE_STORAGE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp19_);
			_tmp21_ = (DinoMessageStorage*) _tmp20_;
			_tmp22_ = conversation;
			_tmp23_ = dino_message_storage_get_messages (_tmp21_, _tmp22_, 50);
			_tmp24_ = _tmp23_;
			_g_object_unref0 (_tmp21_);
			messages = _tmp24_;
			{
				gint i = 0;
				GeeList* _tmp25_;
				gint _tmp26_;
				gint _tmp27_;
				_tmp25_ = messages;
				_tmp26_ = gee_collection_get_size ((GeeCollection*) _tmp25_);
				_tmp27_ = _tmp26_;
				i = _tmp27_ - 1;
				{
					gboolean _tmp28_ = FALSE;
					_tmp28_ = TRUE;
					while (TRUE) {
						DinoEntitiesMessage* message = NULL;
						GeeList* _tmp30_;
						gpointer _tmp31_;
						gboolean _tmp32_ = FALSE;
						GeeHashMap* _tmp33_;
						DinoEntitiesMessage* _tmp34_;
						XmppJid* _tmp35_;
						XmppJid* _tmp36_;
						if (!_tmp28_) {
							gint _tmp29_;
							_tmp29_ = i;
							i = _tmp29_ - 1;
						}
						_tmp28_ = FALSE;
						if (!(i > 0)) {
							break;
						}
						_tmp30_ = messages;
						_tmp31_ = gee_list_get (_tmp30_, i);
						message = (DinoEntitiesMessage*) _tmp31_;
						_tmp33_ = last_conversation_messages;
						_tmp34_ = message;
						_tmp35_ = dino_entities_message_get_from (_tmp34_);
						_tmp36_ = _tmp35_;
						if (!gee_abstract_map_has_key ((GeeAbstractMap*) _tmp33_, _tmp36_)) {
							DinoEntitiesMessage* _tmp37_;
							const gchar* _tmp38_;
							_tmp37_ = message;
							_tmp38_ = _tmp37_->edit_to;
							_tmp32_ = _tmp38_ == NULL;
						} else {
							_tmp32_ = FALSE;
						}
						if (_tmp32_) {
							GeeHashMap* _tmp39_;
							DinoEntitiesMessage* _tmp40_;
							XmppJid* _tmp41_;
							XmppJid* _tmp42_;
							DinoEntitiesMessage* _tmp43_;
							_tmp39_ = last_conversation_messages;
							_tmp40_ = message;
							_tmp41_ = dino_entities_message_get_from (_tmp40_);
							_tmp42_ = _tmp41_;
							_tmp43_ = message;
							gee_abstract_map_set ((GeeAbstractMap*) _tmp39_, _tmp42_, _tmp43_);
						}
						_g_object_unref0 (message);
					}
				}
			}
			_tmp44_ = self->priv->last_messages;
			_tmp45_ = conversation;
			_tmp46_ = last_conversation_messages;
			gee_abstract_map_set ((GeeAbstractMap*) _tmp44_, _tmp45_, _tmp46_);
			_g_object_unref0 (messages);
			_g_object_unref0 (last_conversation_messages);
			_g_object_unref0 (conversation);
		}
	}
	_g_object_unref0 (conversations);
}

static const gchar*
dino_message_correction_real_get_id (DinoStreamInteractionModule* base)
{
	const gchar* result;
	DinoMessageCorrection* self;
	DinoModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	self = (DinoMessageCorrection*) base;
	_tmp0_ = dino_message_correction_IDENTITY;
	_tmp1_ = dino_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

static const gchar*
dino_message_correction_real_get_action_group (XmppOrderedListener* base)
{
	const gchar* result;
	DinoMessageCorrection* self;
	self = (DinoMessageCorrection*) base;
	result = "CORRECTION";
	return result;
}

static gchar**
dino_message_correction_real_get_after_actions (XmppOrderedListener* base,
                                                gint* result_length1)
{
	gchar** result;
	DinoMessageCorrection* self;
	gchar** _tmp0_;
	gint _tmp0__length1;
	gchar** _tmp1_;
	gint _tmp1__length1;
	self = (DinoMessageCorrection*) 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_message_correction_class_init (DinoMessageCorrectionClass * klass,
                                    gpointer klass_data)
{
	DinoModuleIdentity* _tmp0_;
	dino_message_correction_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoMessageCorrection_private_offset);
	((DinoMessageListenerClass *) klass)->run = (void (*) (DinoMessageListener*, DinoEntitiesMessage*, XmppMessageStanza*, DinoEntitiesConversation*, GAsyncReadyCallback, gpointer)) dino_message_correction_real_run;
	((DinoMessageListenerClass *) klass)->run_finish = (gboolean (*) (DinoMessageListener*, GAsyncResult*)) dino_message_correction_run_finish;
	XMPP_ORDERED_LISTENER_CLASS (klass)->get_action_group = (const gchar* (*) (XmppOrderedListener*)) dino_message_correction_real_get_action_group;
	XMPP_ORDERED_LISTENER_CLASS (klass)->get_after_actions = (gchar** (*) (XmppOrderedListener*, gint*)) dino_message_correction_real_get_after_actions;
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_message_correction_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_message_correction_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_MESSAGE_CORRECTION_ID_PROPERTY, dino_message_correction_properties[DINO_MESSAGE_CORRECTION_ID_PROPERTY] = g_param_spec_string ("id", "id", "id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_MESSAGE_CORRECTION_ACTION_GROUP_PROPERTY, dino_message_correction_properties[DINO_MESSAGE_CORRECTION_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_MESSAGE_CORRECTION_AFTER_ACTIONS_PROPERTY, dino_message_correction_properties[DINO_MESSAGE_CORRECTION_AFTER_ACTIONS_PROPERTY] = g_param_spec_boxed ("after-actions", "after-actions", "after-actions", G_TYPE_STRV, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	dino_message_correction_signals[DINO_MESSAGE_CORRECTION_RECEIVED_CORRECTION_SIGNAL] = g_signal_new ("received-correction", DINO_TYPE_MESSAGE_CORRECTION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, DINO_TYPE_CONTENT_ITEM);
	_tmp0_ = dino_module_identity_new (DINO_TYPE_MESSAGE_CORRECTION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, "message_correction");
	dino_message_correction_IDENTITY = _tmp0_;
}

static void
dino_message_correction_dino_stream_interaction_module_interface_init (DinoStreamInteractionModuleIface * iface,
                                                                       gpointer iface_data)
{
	dino_message_correction_dino_stream_interaction_module_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_id = dino_message_correction_real_get_id;
}

static void
dino_message_correction_instance_init (DinoMessageCorrection * self,
                                       gpointer klass)
{
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar** _tmp5_;
	self->priv = dino_message_correction_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, _dino_entities_conversation_hash_func_gee_hash_data_func, NULL, NULL, _dino_entities_conversation_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->priv->last_messages = _tmp0_;
	_tmp1_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->outstanding_correction_nodes = _tmp1_;
	_tmp2_ = g_strdup ("DEDUPLICATE");
	_tmp3_ = g_strdup ("DECRYPT");
	_tmp4_ = g_strdup ("FILTER_EMPTY");
	_tmp5_ = g_new0 (gchar*, 3 + 1);
	_tmp5_[0] = _tmp2_;
	_tmp5_[1] = _tmp3_;
	_tmp5_[2] = _tmp4_;
	self->after_actions_const = _tmp5_;
	self->after_actions_const_length1 = 3;
}

static void
dino_message_correction_finalize (GObject * obj)
{
	DinoMessageCorrection * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_MESSAGE_CORRECTION, DinoMessageCorrection);
	_g_object_unref0 (self->priv->stream_interactor);
	_qlite_database_unref0 (self->priv->db);
	_g_object_unref0 (self->priv->last_messages);
	_g_object_unref0 (self->priv->outstanding_correction_nodes);
	self->after_actions_const = (_vala_array_free (self->after_actions_const, self->after_actions_const_length1, (GDestroyNotify) g_free), NULL);
	G_OBJECT_CLASS (dino_message_correction_parent_class)->finalize (obj);
}

static GType
dino_message_correction_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoMessageCorrectionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_message_correction_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoMessageCorrection), 0, (GInstanceInitFunc) dino_message_correction_instance_init, NULL };
	static const GInterfaceInfo dino_stream_interaction_module_info = { (GInterfaceInitFunc) dino_message_correction_dino_stream_interaction_module_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_message_correction_type_id;
	dino_message_correction_type_id = g_type_register_static (DINO_TYPE_MESSAGE_LISTENER, "DinoMessageCorrection", &g_define_type_info, 0);
	g_type_add_interface_static (dino_message_correction_type_id, DINO_TYPE_STREAM_INTERACTION_MODULE, &dino_stream_interaction_module_info);
	DinoMessageCorrection_private_offset = g_type_add_instance_private (dino_message_correction_type_id, sizeof (DinoMessageCorrectionPrivate));
	return dino_message_correction_type_id;
}

GType
dino_message_correction_get_type (void)
{
	static volatile gsize dino_message_correction_type_id__once = 0;
	if (g_once_init_enter (&dino_message_correction_type_id__once)) {
		GType dino_message_correction_type_id;
		dino_message_correction_type_id = dino_message_correction_get_type_once ();
		g_once_init_leave (&dino_message_correction_type_id__once, dino_message_correction_type_id);
	}
	return dino_message_correction_type_id__once;
}

static void
_vala_dino_message_correction_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec)
{
	DinoMessageCorrection * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_TYPE_MESSAGE_CORRECTION, DinoMessageCorrection);
	switch (property_id) {
		case DINO_MESSAGE_CORRECTION_ID_PROPERTY:
		g_value_set_string (value, dino_stream_interaction_module_get_id ((DinoStreamInteractionModule*) self));
		break;
		case DINO_MESSAGE_CORRECTION_ACTION_GROUP_PROPERTY:
		g_value_set_string (value, xmpp_ordered_listener_get_action_group ((XmppOrderedListener*) self));
		break;
		case DINO_MESSAGE_CORRECTION_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
_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;
}

