/* history_sync.c generated by valac 0.56.19, the Vala compiler
 * generated from history_sync.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 <gio/gio.h>
#include "qlite.h"
#include <gobject/gvaluecollector.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

typedef enum  {
	DINO_HISTORY_SYNC_PAGE_RESULT_MorePagesAvailable,
	DINO_HISTORY_SYNC_PAGE_RESULT_TargetReached,
	DINO_HISTORY_SYNC_PAGE_RESULT_NoMoreMessages,
	DINO_HISTORY_SYNC_PAGE_RESULT_Error,
	DINO_HISTORY_SYNC_PAGE_RESULT_Cancelled
} DinoHistorySyncPageResult;

#define DINO_HISTORY_SYNC_TYPE_PAGE_RESULT (dino_history_sync_page_result_get_type ())
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _qlite_database_unref0(var) ((var == NULL) ? NULL : (var = (qlite_database_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _qlite_statement_builder_unref0(var) ((var == NULL) ? NULL : (var = (qlite_statement_builder_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _xmpp_stanza_entry_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_entry_unref (var), NULL)))
#define _dino_history_sync_unref0(var) ((var == NULL) ? NULL : (var = (dino_history_sync_unref (var), NULL)))
#define _qlite_row_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_unref (var), NULL)))
#define _qlite_row_option_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_option_unref (var), NULL)))
typedef struct _DinoHistorySyncFetchEverythingData DinoHistorySyncFetchEverythingData;

#define DINO_HISTORY_SYNC_TYPE_PAGE_REQUEST_RESULT (dino_history_sync_page_request_result_get_type ())
#define DINO_HISTORY_SYNC_PAGE_REQUEST_RESULT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_HISTORY_SYNC_TYPE_PAGE_REQUEST_RESULT, DinoHistorySyncPageRequestResult))
#define DINO_HISTORY_SYNC_PAGE_REQUEST_RESULT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_HISTORY_SYNC_TYPE_PAGE_REQUEST_RESULT, DinoHistorySyncPageRequestResultClass))
#define DINO_HISTORY_SYNC_IS_PAGE_REQUEST_RESULT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_HISTORY_SYNC_TYPE_PAGE_REQUEST_RESULT))
#define DINO_HISTORY_SYNC_IS_PAGE_REQUEST_RESULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_HISTORY_SYNC_TYPE_PAGE_REQUEST_RESULT))
#define DINO_HISTORY_SYNC_PAGE_REQUEST_RESULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_HISTORY_SYNC_TYPE_PAGE_REQUEST_RESULT, DinoHistorySyncPageRequestResultClass))

typedef struct _DinoHistorySyncPageRequestResult DinoHistorySyncPageRequestResult;
typedef struct _DinoHistorySyncPageRequestResultClass DinoHistorySyncPageRequestResultClass;
#define _dino_history_sync_page_request_result_unref0(var) ((var == NULL) ? NULL : (var = (dino_history_sync_page_request_result_unref (var), NULL)))
#define _xmpp_message_archive_management_v2_mam_query_params_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_message_archive_management_v2_mam_query_params_unref (var), NULL)))
typedef struct _DinoHistorySyncFetchLatestPageData DinoHistorySyncFetchLatestPageData;
typedef struct _DinoHistorySyncFetchBetweenRangesData DinoHistorySyncFetchBetweenRangesData;
typedef struct _DinoHistorySyncFetchBeforeRangeData DinoHistorySyncFetchBeforeRangeData;
typedef struct _DinoHistorySyncFetchQueryData DinoHistorySyncFetchQueryData;
#define _xmpp_message_archive_management_query_result_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_message_archive_management_query_result_unref (var), NULL)))
typedef struct _DinoHistorySyncGetMamPageData DinoHistorySyncGetMamPageData;
typedef struct _DinoHistorySyncProcessQueryResultData DinoHistorySyncProcessQueryResultData;
typedef struct _DinoHistorySyncSendMessagesBackIntoPipelineData DinoHistorySyncSendMessagesBackIntoPipelineData;
typedef struct _Block16Data Block16Data;
typedef struct _Block17Data Block17Data;

#define DINO_HISTORY_SYNC_TYPE_MAM_RANGE (dino_history_sync_mam_range_get_type ())
#define DINO_HISTORY_SYNC_MAM_RANGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DINO_HISTORY_SYNC_TYPE_MAM_RANGE, DinoHistorySyncMamRange))
#define DINO_HISTORY_SYNC_MAM_RANGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DINO_HISTORY_SYNC_TYPE_MAM_RANGE, DinoHistorySyncMamRangeClass))
#define DINO_HISTORY_SYNC_IS_MAM_RANGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DINO_HISTORY_SYNC_TYPE_MAM_RANGE))
#define DINO_HISTORY_SYNC_IS_MAM_RANGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DINO_HISTORY_SYNC_TYPE_MAM_RANGE))
#define DINO_HISTORY_SYNC_MAM_RANGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DINO_HISTORY_SYNC_TYPE_MAM_RANGE, DinoHistorySyncMamRangeClass))

typedef struct _DinoHistorySyncMamRange DinoHistorySyncMamRange;
typedef struct _DinoHistorySyncMamRangeClass DinoHistorySyncMamRangeClass;
typedef struct _DinoHistorySyncMamRangePrivate DinoHistorySyncMamRangePrivate;
#define _dino_history_sync_mam_range_unref0(var) ((var == NULL) ? NULL : (var = (dino_history_sync_mam_range_unref (var), NULL)))
#define _qlite_row_iterator_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_iterator_unref (var), NULL)))
typedef struct _DinoHistorySyncParamSpecMamRange DinoHistorySyncParamSpecMamRange;
typedef struct _DinoHistorySyncPageRequestResultPrivate DinoHistorySyncPageRequestResultPrivate;
typedef struct _DinoHistorySyncParamSpecPageRequestResult DinoHistorySyncParamSpecPageRequestResult;
typedef struct _DinoParamSpecHistorySync DinoParamSpecHistorySync;

struct _DinoHistorySyncPrivate {
	DinoStreamInteractor* stream_interactor;
	DinoDatabase* db;
	GeeHashMap* stanzas;
};

struct _DinoHistorySyncFetchEverythingData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoHistorySync* self;
	DinoEntitiesAccount* account;
	XmppJid* mam_server;
	GCancellable* cancellable;
	GDateTime* until_earliest_time;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	XmppJid* _tmp5_;
	XmppJid* _tmp6_;
	XmppJid* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	QliteRowOption* latest_row_opt;
	DinoDatabase* _tmp12_;
	DinoDatabaseMamCatchupTable* _tmp13_;
	DinoDatabaseMamCatchupTable* _tmp14_;
	QliteQueryBuilder* _tmp15_;
	QliteQueryBuilder* _tmp16_;
	DinoDatabase* _tmp17_;
	DinoDatabaseMamCatchupTable* _tmp18_;
	DinoDatabaseMamCatchupTable* _tmp19_;
	QliteColumn* _tmp20_;
	gint _tmp21_;
	gint _tmp22_;
	QliteQueryBuilder* _tmp23_;
	QliteQueryBuilder* _tmp24_;
	DinoDatabase* _tmp25_;
	DinoDatabaseMamCatchupTable* _tmp26_;
	DinoDatabaseMamCatchupTable* _tmp27_;
	QliteColumn* _tmp28_;
	gchar* _tmp29_;
	gchar* _tmp30_;
	QliteQueryBuilder* _tmp31_;
	QliteQueryBuilder* _tmp32_;
	DinoDatabase* _tmp33_;
	DinoDatabaseMamCatchupTable* _tmp34_;
	DinoDatabaseMamCatchupTable* _tmp35_;
	QliteColumn* _tmp36_;
	QliteQueryBuilder* _tmp37_;
	QliteQueryBuilder* _tmp38_;
	DinoDatabase* _tmp39_;
	DinoDatabaseMamCatchupTable* _tmp40_;
	DinoDatabaseMamCatchupTable* _tmp41_;
	QliteColumn* _tmp42_;
	QliteQueryBuilder* _tmp43_;
	QliteQueryBuilder* _tmp44_;
	QliteQueryBuilder* _tmp45_;
	QliteQueryBuilder* _tmp46_;
	QliteRowOption* _tmp47_;
	QliteRowOption* _tmp48_;
	QliteRow* _tmp49_;
	QliteRowOption* _tmp50_;
	QliteRowOption* _tmp51_;
	QliteRow* _tmp52_;
	QliteRow* _tmp53_;
	QliteRow* latest_row;
	QliteRow* _tmp54_;
	QliteRow* new_row;
	QliteRow* _tmp55_;
	QliteRow* _tmp56_;
	QliteRow* _tmp57_;
	GeeHashMap* _tmp58_;
	gpointer _tmp59_;
	GeeHashMap* _tmp60_;
	QliteRow* _tmp61_;
	DinoDatabase* _tmp62_;
	DinoDatabaseMamCatchupTable* _tmp63_;
	DinoDatabaseMamCatchupTable* _tmp64_;
	QliteColumn* _tmp65_;
	gpointer _tmp66_;
	QliteRow* _tmp67_;
	GeeHashMap* _tmp68_;
	gpointer _tmp69_;
	GeeHashMap* _tmp70_;
	QliteRow* _tmp71_;
	DinoDatabase* _tmp72_;
	DinoDatabaseMamCatchupTable* _tmp73_;
	DinoDatabaseMamCatchupTable* _tmp74_;
	QliteColumn* _tmp75_;
	gpointer _tmp76_;
	QliteRow* previous_row;
	QliteRow* current_row;
	QliteRow* _tmp77_;
	QliteRow* _tmp78_;
	QliteRow* _tmp79_;
	QliteRow* _tmp80_;
	QliteRow* _tmp81_;
	QliteRow* _tmp82_;
	QliteRow* _tmp83_;
	QliteRow* _tmp84_;
	QliteRowOption* previous_row_opt;
	DinoDatabase* _tmp85_;
	DinoDatabaseMamCatchupTable* _tmp86_;
	DinoDatabaseMamCatchupTable* _tmp87_;
	QliteQueryBuilder* _tmp88_;
	QliteQueryBuilder* _tmp89_;
	DinoDatabase* _tmp90_;
	DinoDatabaseMamCatchupTable* _tmp91_;
	DinoDatabaseMamCatchupTable* _tmp92_;
	QliteColumn* _tmp93_;
	gint _tmp94_;
	gint _tmp95_;
	QliteQueryBuilder* _tmp96_;
	QliteQueryBuilder* _tmp97_;
	DinoDatabase* _tmp98_;
	DinoDatabaseMamCatchupTable* _tmp99_;
	DinoDatabaseMamCatchupTable* _tmp100_;
	QliteColumn* _tmp101_;
	gchar* _tmp102_;
	gchar* _tmp103_;
	QliteQueryBuilder* _tmp104_;
	QliteQueryBuilder* _tmp105_;
	DinoDatabase* _tmp106_;
	DinoDatabaseMamCatchupTable* _tmp107_;
	DinoDatabaseMamCatchupTable* _tmp108_;
	QliteColumn* _tmp109_;
	QliteRow* _tmp110_;
	DinoDatabase* _tmp111_;
	DinoDatabaseMamCatchupTable* _tmp112_;
	DinoDatabaseMamCatchupTable* _tmp113_;
	QliteColumn* _tmp114_;
	gpointer _tmp115_;
	QliteQueryBuilder* _tmp116_;
	QliteQueryBuilder* _tmp117_;
	DinoDatabase* _tmp118_;
	DinoDatabaseMamCatchupTable* _tmp119_;
	DinoDatabaseMamCatchupTable* _tmp120_;
	QliteColumn* _tmp121_;
	QliteQueryBuilder* _tmp122_;
	QliteQueryBuilder* _tmp123_;
	DinoDatabase* _tmp124_;
	DinoDatabaseMamCatchupTable* _tmp125_;
	DinoDatabaseMamCatchupTable* _tmp126_;
	QliteColumn* _tmp127_;
	QliteQueryBuilder* _tmp128_;
	QliteQueryBuilder* _tmp129_;
	QliteQueryBuilder* _tmp130_;
	QliteQueryBuilder* _tmp131_;
	QliteRowOption* _tmp132_;
	QliteRowOption* _tmp133_;
	QliteRow* _tmp134_;
	QliteRowOption* _tmp135_;
	QliteRowOption* _tmp136_;
	QliteRow* _tmp137_;
	QliteRow* _tmp138_;
	QliteRow* _tmp139_;
	gboolean _tmp140_;
	QliteRow* _tmp141_;
	QliteRow* _tmp142_;
	QliteRow* _tmp143_;
	DinoDatabase* _tmp144_;
	DinoDatabaseMamCatchupTable* _tmp145_;
	DinoDatabaseMamCatchupTable* _tmp146_;
	QliteColumn* _tmp147_;
	gpointer _tmp148_;
	XmppJid* _tmp149_;
	XmppJid* _tmp150_;
	XmppJid* _tmp151_;
	gchar* _tmp152_;
	gchar* _tmp153_;
	gchar* _tmp154_;
	gchar* _tmp155_;
	QliteRow* _tmp156_;
	DinoDatabase* _tmp157_;
	DinoDatabaseMamCatchupTable* _tmp158_;
	DinoDatabaseMamCatchupTable* _tmp159_;
	QliteColumn* _tmp160_;
	gpointer _tmp161_;
	gchar* _tmp162_;
	gchar* _tmp163_;
	XmppJid* _tmp164_;
	XmppJid* _tmp165_;
	XmppJid* _tmp166_;
	gchar* _tmp167_;
	gchar* _tmp168_;
	gchar* _tmp169_;
	gchar* _tmp170_;
	QliteRow* _tmp171_;
	DinoDatabase* _tmp172_;
	DinoDatabaseMamCatchupTable* _tmp173_;
	DinoDatabaseMamCatchupTable* _tmp174_;
	QliteColumn* _tmp175_;
	gpointer _tmp176_;
	gchar* _tmp177_;
	gchar* _tmp178_;
	QliteRow* _tmp179_;
	DinoDatabase* _tmp180_;
	DinoDatabaseMamCatchupTable* _tmp181_;
	DinoDatabaseMamCatchupTable* _tmp182_;
	QliteColumn* _tmp183_;
	gpointer _tmp184_;
	gchar* _tmp185_;
	gchar* _tmp186_;
	QliteRow* _tmp187_;
	QliteRow* _tmp188_;
	QliteRow* _tmp189_;
	QliteRow* _tmp190_;
	QliteRowOption* _vala1_previous_row_opt;
	DinoDatabase* _tmp191_;
	DinoDatabaseMamCatchupTable* _tmp192_;
	DinoDatabaseMamCatchupTable* _tmp193_;
	QliteQueryBuilder* _tmp194_;
	QliteQueryBuilder* _tmp195_;
	DinoDatabase* _tmp196_;
	DinoDatabaseMamCatchupTable* _tmp197_;
	DinoDatabaseMamCatchupTable* _tmp198_;
	QliteColumn* _tmp199_;
	gint _tmp200_;
	gint _tmp201_;
	QliteQueryBuilder* _tmp202_;
	QliteQueryBuilder* _tmp203_;
	DinoDatabase* _tmp204_;
	DinoDatabaseMamCatchupTable* _tmp205_;
	DinoDatabaseMamCatchupTable* _tmp206_;
	QliteColumn* _tmp207_;
	gchar* _tmp208_;
	gchar* _tmp209_;
	QliteQueryBuilder* _tmp210_;
	QliteQueryBuilder* _tmp211_;
	DinoDatabase* _tmp212_;
	DinoDatabaseMamCatchupTable* _tmp213_;
	DinoDatabaseMamCatchupTable* _tmp214_;
	QliteColumn* _tmp215_;
	QliteRow* _tmp216_;
	DinoDatabase* _tmp217_;
	DinoDatabaseMamCatchupTable* _tmp218_;
	DinoDatabaseMamCatchupTable* _tmp219_;
	QliteColumn* _tmp220_;
	gpointer _tmp221_;
	QliteQueryBuilder* _tmp222_;
	QliteQueryBuilder* _tmp223_;
	DinoDatabase* _tmp224_;
	DinoDatabaseMamCatchupTable* _tmp225_;
	DinoDatabaseMamCatchupTable* _tmp226_;
	QliteColumn* _tmp227_;
	QliteQueryBuilder* _tmp228_;
	QliteQueryBuilder* _tmp229_;
	DinoDatabase* _tmp230_;
	DinoDatabaseMamCatchupTable* _tmp231_;
	DinoDatabaseMamCatchupTable* _tmp232_;
	QliteColumn* _tmp233_;
	QliteQueryBuilder* _tmp234_;
	QliteQueryBuilder* _tmp235_;
	QliteQueryBuilder* _tmp236_;
	QliteQueryBuilder* _tmp237_;
	QliteRowOption* _tmp238_;
	QliteRowOption* _tmp239_;
	QliteRow* _tmp240_;
	QliteRowOption* _tmp241_;
	QliteRowOption* _tmp242_;
	QliteRow* _tmp243_;
	QliteRow* _tmp244_;
	QliteRow* _tmp245_;
	QliteRow* _tmp246_;
	XmppJid* _tmp247_;
	XmppJid* _tmp248_;
	XmppJid* _tmp249_;
	gchar* _tmp250_;
	gchar* _tmp251_;
	gchar* _tmp252_;
	gchar* _tmp253_;
	QliteRow* _tmp254_;
	DinoDatabase* _tmp255_;
	DinoDatabaseMamCatchupTable* _tmp256_;
	DinoDatabaseMamCatchupTable* _tmp257_;
	QliteColumn* _tmp258_;
	gpointer _tmp259_;
	XmppJid* _tmp260_;
	XmppJid* _tmp261_;
	XmppJid* _tmp262_;
	gchar* _tmp263_;
	gchar* _tmp264_;
	gchar* _tmp265_;
	gchar* _tmp266_;
	QliteRow* _tmp267_;
	DinoDatabase* _tmp268_;
	DinoDatabaseMamCatchupTable* _tmp269_;
	DinoDatabaseMamCatchupTable* _tmp270_;
	QliteColumn* _tmp271_;
	gpointer _tmp272_;
	gchar* _tmp273_;
	gchar* _tmp274_;
	gboolean _tmp275_;
	QliteRow* _tmp276_;
	DinoDatabase* _tmp277_;
	DinoDatabaseMamCatchupTable* _tmp278_;
	DinoDatabaseMamCatchupTable* _tmp279_;
	QliteColumn* _tmp280_;
	gpointer _tmp281_;
	XmppJid* _tmp282_;
	XmppJid* _tmp283_;
	XmppJid* _tmp284_;
	gchar* _tmp285_;
	gchar* _tmp286_;
	gchar* _tmp287_;
	gchar* _tmp288_;
	QliteRow* _tmp289_;
	DinoDatabase* _tmp290_;
	DinoDatabaseMamCatchupTable* _tmp291_;
	DinoDatabaseMamCatchupTable* _tmp292_;
	QliteColumn* _tmp293_;
	gpointer _tmp294_;
	gchar* _tmp295_;
	gchar* _tmp296_;
	gchar* _tmp297_;
	gchar* _tmp298_;
	QliteRow* _tmp299_;
};

struct _DinoHistorySyncFetchLatestPageData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoHistorySync* self;
	DinoEntitiesAccount* account;
	XmppJid* mam_server;
	QliteRow* latest_row;
	GDateTime* until_earliest_time;
	GCancellable* cancellable;
	QliteRow* result;
	XmppJid* _tmp0_;
	XmppJid* _tmp1_;
	XmppJid* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gint latest_row_id;
	GDateTime* latest_message_time;
	GDateTime* _tmp7_;
	gchar* latest_message_id;
	DinoDatabase* _tmp8_;
	DinoDatabaseMamCatchupTable* _tmp9_;
	DinoDatabaseMamCatchupTable* _tmp10_;
	QliteColumn* _tmp11_;
	gpointer _tmp12_;
	DinoDatabase* _tmp13_;
	DinoDatabaseMamCatchupTable* _tmp14_;
	DinoDatabaseMamCatchupTable* _tmp15_;
	QliteColumn* _tmp16_;
	gpointer _tmp17_;
	GDateTime* _tmp18_;
	GDateTime* _tmp19_;
	GDateTime* _tmp20_;
	DinoDatabase* _tmp21_;
	DinoDatabaseMamCatchupTable* _tmp22_;
	DinoDatabaseMamCatchupTable* _tmp23_;
	QliteColumn* _tmp24_;
	gpointer _tmp25_;
	gboolean _tmp26_;
	GDateTime* _tmp27_;
	GDateTime* _tmp28_;
	XmppMessageArchiveManagementV2MamQueryParams* query_params;
	GDateTime* _tmp29_;
	const gchar* _tmp30_;
	XmppMessageArchiveManagementV2MamQueryParams* _tmp31_;
	DinoHistorySyncPageRequestResult* page_result;
	XmppMessageArchiveManagementV2MamQueryParams* _tmp32_;
	DinoHistorySyncPageRequestResult* _tmp33_;
	XmppJid* _tmp34_;
	XmppJid* _tmp35_;
	XmppJid* _tmp36_;
	gchar* _tmp37_;
	gchar* _tmp38_;
	gchar* _tmp39_;
	gchar* _tmp40_;
	DinoHistorySyncPageRequestResult* _tmp41_;
	DinoHistorySyncPageResult _tmp42_;
	DinoHistorySyncPageResult _tmp43_;
	GEnumValue* _tmp44_;
	gboolean _tmp45_;
	DinoHistorySyncPageRequestResult* _tmp46_;
	DinoHistorySyncPageResult _tmp47_;
	DinoHistorySyncPageResult _tmp48_;
	DinoHistorySyncPageRequestResult* _tmp49_;
	DinoHistorySyncPageResult _tmp50_;
	DinoHistorySyncPageResult _tmp51_;
	gboolean _tmp52_;
	DinoHistorySyncPageRequestResult* _tmp53_;
	DinoHistorySyncPageResult _tmp54_;
	DinoHistorySyncPageResult _tmp55_;
	DinoHistorySyncPageResult* _tmp56_;
	DinoHistorySyncPageResult* _tmp57_;
	gint _tmp57__length1;
	DinoHistorySyncPageRequestResult* _tmp58_;
	GeeList* _tmp59_;
	GeeList* _tmp60_;
	gchar* latest_mam_id;
	DinoHistorySyncPageRequestResult* _tmp61_;
	XmppMessageArchiveManagementQueryResult* _tmp62_;
	XmppMessageArchiveManagementQueryResult* _tmp63_;
	const gchar* _tmp64_;
	const gchar* _tmp65_;
	gchar* _tmp66_;
	glong latest_mam_time;
	GeeHashMap* _tmp67_;
	gpointer _tmp68_;
	GeeHashMap* _tmp69_;
	const gchar* _tmp70_;
	gpointer _tmp71_;
	GDateTime* _tmp72_;
	glong _tmp73_;
	QliteUpdateBuilder* query;
	DinoDatabase* _tmp74_;
	DinoDatabaseMamCatchupTable* _tmp75_;
	DinoDatabaseMamCatchupTable* _tmp76_;
	QliteUpdateBuilder* _tmp77_;
	QliteUpdateBuilder* _tmp78_;
	DinoDatabase* _tmp79_;
	DinoDatabaseMamCatchupTable* _tmp80_;
	DinoDatabaseMamCatchupTable* _tmp81_;
	QliteColumn* _tmp82_;
	QliteUpdateBuilder* _tmp83_;
	QliteUpdateBuilder* _tmp84_;
	DinoDatabase* _tmp85_;
	DinoDatabaseMamCatchupTable* _tmp86_;
	DinoDatabaseMamCatchupTable* _tmp87_;
	QliteColumn* _tmp88_;
	QliteUpdateBuilder* _tmp89_;
	QliteUpdateBuilder* _tmp90_;
	DinoDatabase* _tmp91_;
	DinoDatabaseMamCatchupTable* _tmp92_;
	DinoDatabaseMamCatchupTable* _tmp93_;
	QliteColumn* _tmp94_;
	const gchar* _tmp95_;
	QliteUpdateBuilder* _tmp96_;
	QliteUpdateBuilder* _tmp97_;
	DinoHistorySyncPageRequestResult* _tmp98_;
	DinoHistorySyncPageResult _tmp99_;
	DinoHistorySyncPageResult _tmp100_;
	QliteUpdateBuilder* _tmp101_;
	DinoDatabase* _tmp102_;
	DinoDatabaseMamCatchupTable* _tmp103_;
	DinoDatabaseMamCatchupTable* _tmp104_;
	QliteColumn* _tmp105_;
	QliteUpdateBuilder* _tmp106_;
	QliteUpdateBuilder* _tmp107_;
	QliteUpdateBuilder* _tmp108_;
	gboolean _tmp109_;
	DinoHistorySyncPageRequestResult* _tmp110_;
	XmppMessageArchiveManagementQueryResult* _tmp111_;
	XmppMessageArchiveManagementQueryResult* _tmp112_;
	const gchar* _tmp113_;
	const gchar* _tmp114_;
	DinoHistorySyncPageRequestResult* _tmp115_;
	XmppMessageArchiveManagementQueryResult* _tmp116_;
	XmppMessageArchiveManagementQueryResult* _tmp117_;
	const gchar* _tmp118_;
	const gchar* _tmp119_;
	XmppJid* _tmp120_;
	XmppJid* _tmp121_;
	XmppJid* _tmp122_;
	gchar* _tmp123_;
	gchar* _tmp124_;
	gchar* _tmp125_;
	gchar* _tmp126_;
	gchar* from_id;
	DinoHistorySyncPageRequestResult* _tmp127_;
	XmppMessageArchiveManagementQueryResult* _tmp128_;
	XmppMessageArchiveManagementQueryResult* _tmp129_;
	const gchar* _tmp130_;
	const gchar* _tmp131_;
	gchar* _tmp132_;
	gchar* to_id;
	DinoHistorySyncPageRequestResult* _tmp133_;
	XmppMessageArchiveManagementQueryResult* _tmp134_;
	XmppMessageArchiveManagementQueryResult* _tmp135_;
	const gchar* _tmp136_;
	const gchar* _tmp137_;
	gchar* _tmp138_;
	gboolean _tmp139_;
	GeeHashMap* _tmp140_;
	gpointer _tmp141_;
	GeeHashMap* _tmp142_;
	const gchar* _tmp143_;
	gboolean _tmp144_;
	GeeHashMap* _tmp145_;
	gpointer _tmp146_;
	GeeHashMap* _tmp147_;
	const gchar* _tmp148_;
	const gchar* _tmp149_;
	const gchar* _tmp150_;
	glong from_time;
	GeeHashMap* _tmp151_;
	gpointer _tmp152_;
	GeeHashMap* _tmp153_;
	const gchar* _tmp154_;
	gpointer _tmp155_;
	GDateTime* _tmp156_;
	glong _tmp157_;
	glong to_time;
	GeeHashMap* _tmp158_;
	gpointer _tmp159_;
	GeeHashMap* _tmp160_;
	const gchar* _tmp161_;
	gpointer _tmp162_;
	GDateTime* _tmp163_;
	glong _tmp164_;
	gint new_row_id;
	DinoDatabase* _tmp165_;
	DinoDatabaseMamCatchupTable* _tmp166_;
	DinoDatabaseMamCatchupTable* _tmp167_;
	QliteInsertBuilder* _tmp168_;
	QliteInsertBuilder* _tmp169_;
	DinoDatabase* _tmp170_;
	DinoDatabaseMamCatchupTable* _tmp171_;
	DinoDatabaseMamCatchupTable* _tmp172_;
	QliteColumn* _tmp173_;
	gint _tmp174_;
	gint _tmp175_;
	QliteInsertBuilder* _tmp176_;
	QliteInsertBuilder* _tmp177_;
	DinoDatabase* _tmp178_;
	DinoDatabaseMamCatchupTable* _tmp179_;
	DinoDatabaseMamCatchupTable* _tmp180_;
	QliteColumn* _tmp181_;
	gchar* _tmp182_;
	gchar* _tmp183_;
	QliteInsertBuilder* _tmp184_;
	QliteInsertBuilder* _tmp185_;
	DinoDatabase* _tmp186_;
	DinoDatabaseMamCatchupTable* _tmp187_;
	DinoDatabaseMamCatchupTable* _tmp188_;
	QliteColumn* _tmp189_;
	const gchar* _tmp190_;
	QliteInsertBuilder* _tmp191_;
	QliteInsertBuilder* _tmp192_;
	DinoDatabase* _tmp193_;
	DinoDatabaseMamCatchupTable* _tmp194_;
	DinoDatabaseMamCatchupTable* _tmp195_;
	QliteColumn* _tmp196_;
	QliteInsertBuilder* _tmp197_;
	QliteInsertBuilder* _tmp198_;
	DinoDatabase* _tmp199_;
	DinoDatabaseMamCatchupTable* _tmp200_;
	DinoDatabaseMamCatchupTable* _tmp201_;
	QliteColumn* _tmp202_;
	DinoHistorySyncPageRequestResult* _tmp203_;
	DinoHistorySyncPageResult _tmp204_;
	DinoHistorySyncPageResult _tmp205_;
	QliteInsertBuilder* _tmp206_;
	QliteInsertBuilder* _tmp207_;
	DinoDatabase* _tmp208_;
	DinoDatabaseMamCatchupTable* _tmp209_;
	DinoDatabaseMamCatchupTable* _tmp210_;
	QliteColumn* _tmp211_;
	const gchar* _tmp212_;
	QliteInsertBuilder* _tmp213_;
	QliteInsertBuilder* _tmp214_;
	DinoDatabase* _tmp215_;
	DinoDatabaseMamCatchupTable* _tmp216_;
	DinoDatabaseMamCatchupTable* _tmp217_;
	QliteColumn* _tmp218_;
	QliteInsertBuilder* _tmp219_;
	QliteInsertBuilder* _tmp220_;
	gint _tmp221_;
	DinoDatabase* _tmp222_;
	DinoDatabaseMamCatchupTable* _tmp223_;
	DinoDatabaseMamCatchupTable* _tmp224_;
	QliteQueryBuilder* _tmp225_;
	QliteQueryBuilder* _tmp226_;
	DinoDatabase* _tmp227_;
	DinoDatabaseMamCatchupTable* _tmp228_;
	DinoDatabaseMamCatchupTable* _tmp229_;
	QliteColumn* _tmp230_;
	QliteQueryBuilder* _tmp231_;
	QliteQueryBuilder* _tmp232_;
	QliteQueryBuilder* _tmp233_;
	QliteQueryBuilder* _tmp234_;
	QliteRowOption* _tmp235_;
	QliteRowOption* _tmp236_;
	QliteRow* _tmp237_;
	QliteRow* _tmp238_;
	QliteRow* _tmp239_;
	QliteRow* _tmp240_;
};

struct _DinoHistorySyncFetchBetweenRangesData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoHistorySync* self;
	DinoEntitiesAccount* account;
	XmppJid* mam_server;
	QliteRow* earlier_range;
	QliteRow* later_range;
	GCancellable* cancellable;
	QliteRow* result;
	gint later_range_id;
	DinoDatabase* _tmp0_;
	DinoDatabaseMamCatchupTable* _tmp1_;
	DinoDatabaseMamCatchupTable* _tmp2_;
	QliteColumn* _tmp3_;
	gpointer _tmp4_;
	GDateTime* earliest_time;
	DinoDatabase* _tmp5_;
	DinoDatabaseMamCatchupTable* _tmp6_;
	DinoDatabaseMamCatchupTable* _tmp7_;
	QliteColumn* _tmp8_;
	gpointer _tmp9_;
	GDateTime* _tmp10_;
	GDateTime* latest_time;
	DinoDatabase* _tmp11_;
	DinoDatabaseMamCatchupTable* _tmp12_;
	DinoDatabaseMamCatchupTable* _tmp13_;
	QliteColumn* _tmp14_;
	gpointer _tmp15_;
	GDateTime* _tmp16_;
	XmppJid* _tmp17_;
	XmppJid* _tmp18_;
	XmppJid* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	GDateTime* _tmp24_;
	gchar* _tmp25_;
	gchar* _tmp26_;
	DinoDatabase* _tmp27_;
	DinoDatabaseMamCatchupTable* _tmp28_;
	DinoDatabaseMamCatchupTable* _tmp29_;
	QliteColumn* _tmp30_;
	gpointer _tmp31_;
	gchar* _tmp32_;
	GDateTime* _tmp33_;
	gchar* _tmp34_;
	gchar* _tmp35_;
	DinoDatabase* _tmp36_;
	DinoDatabaseMamCatchupTable* _tmp37_;
	DinoDatabaseMamCatchupTable* _tmp38_;
	QliteColumn* _tmp39_;
	gpointer _tmp40_;
	gchar* _tmp41_;
	XmppMessageArchiveManagementV2MamQueryParams* query_params;
	GDateTime* _tmp42_;
	DinoDatabase* _tmp43_;
	DinoDatabaseMamCatchupTable* _tmp44_;
	DinoDatabaseMamCatchupTable* _tmp45_;
	QliteColumn* _tmp46_;
	gpointer _tmp47_;
	gchar* _tmp48_;
	GDateTime* _tmp49_;
	DinoDatabase* _tmp50_;
	DinoDatabaseMamCatchupTable* _tmp51_;
	DinoDatabaseMamCatchupTable* _tmp52_;
	QliteColumn* _tmp53_;
	gpointer _tmp54_;
	gchar* _tmp55_;
	XmppMessageArchiveManagementV2MamQueryParams* _tmp56_;
	XmppMessageArchiveManagementV2MamQueryParams* _tmp57_;
	DinoHistorySyncPageRequestResult* page_result;
	XmppMessageArchiveManagementV2MamQueryParams* _tmp58_;
	DinoHistorySyncPageRequestResult* _tmp59_;
	gboolean _tmp60_;
	DinoHistorySyncPageRequestResult* _tmp61_;
	DinoHistorySyncPageResult _tmp62_;
	DinoHistorySyncPageResult _tmp63_;
	DinoHistorySyncPageRequestResult* _tmp64_;
	DinoHistorySyncPageResult _tmp65_;
	DinoHistorySyncPageResult _tmp66_;
	XmppJid* _tmp67_;
	XmppJid* _tmp68_;
	XmppJid* _tmp69_;
	gchar* _tmp70_;
	gchar* _tmp71_;
	gchar* _tmp72_;
	gchar* _tmp73_;
	DinoDatabase* _tmp74_;
	DinoDatabaseMamCatchupTable* _tmp75_;
	DinoDatabaseMamCatchupTable* _tmp76_;
	QliteColumn* _tmp77_;
	gpointer _tmp78_;
	DinoDatabase* _tmp79_;
	DinoDatabaseMamCatchupTable* _tmp80_;
	DinoDatabaseMamCatchupTable* _tmp81_;
	QliteUpdateBuilder* _tmp82_;
	QliteUpdateBuilder* _tmp83_;
	DinoDatabase* _tmp84_;
	DinoDatabaseMamCatchupTable* _tmp85_;
	DinoDatabaseMamCatchupTable* _tmp86_;
	QliteColumn* _tmp87_;
	QliteUpdateBuilder* _tmp88_;
	QliteUpdateBuilder* _tmp89_;
	DinoDatabase* _tmp90_;
	DinoDatabaseMamCatchupTable* _tmp91_;
	DinoDatabaseMamCatchupTable* _tmp92_;
	QliteColumn* _tmp93_;
	DinoDatabase* _tmp94_;
	DinoDatabaseMamCatchupTable* _tmp95_;
	DinoDatabaseMamCatchupTable* _tmp96_;
	QliteColumn* _tmp97_;
	gpointer _tmp98_;
	QliteUpdateBuilder* _tmp99_;
	QliteUpdateBuilder* _tmp100_;
	DinoDatabase* _tmp101_;
	DinoDatabaseMamCatchupTable* _tmp102_;
	DinoDatabaseMamCatchupTable* _tmp103_;
	QliteColumn* _tmp104_;
	DinoDatabase* _tmp105_;
	DinoDatabaseMamCatchupTable* _tmp106_;
	DinoDatabaseMamCatchupTable* _tmp107_;
	QliteColumn* _tmp108_;
	gpointer _tmp109_;
	gchar* _tmp110_;
	QliteUpdateBuilder* _tmp111_;
	QliteUpdateBuilder* _tmp112_;
	DinoDatabase* _tmp113_;
	DinoDatabaseMamCatchupTable* _tmp114_;
	DinoDatabaseMamCatchupTable* _tmp115_;
	QliteColumn* _tmp116_;
	DinoDatabase* _tmp117_;
	DinoDatabaseMamCatchupTable* _tmp118_;
	DinoDatabaseMamCatchupTable* _tmp119_;
	QliteColumn* _tmp120_;
	gpointer _tmp121_;
	QliteUpdateBuilder* _tmp122_;
	QliteUpdateBuilder* _tmp123_;
	DinoDatabase* _tmp124_;
	DinoDatabaseMamCatchupTable* _tmp125_;
	DinoDatabaseMamCatchupTable* _tmp126_;
	QliteDeleteBuilder* _tmp127_;
	QliteDeleteBuilder* _tmp128_;
	DinoDatabase* _tmp129_;
	DinoDatabaseMamCatchupTable* _tmp130_;
	DinoDatabaseMamCatchupTable* _tmp131_;
	QliteColumn* _tmp132_;
	DinoDatabase* _tmp133_;
	DinoDatabaseMamCatchupTable* _tmp134_;
	DinoDatabaseMamCatchupTable* _tmp135_;
	QliteColumn* _tmp136_;
	gpointer _tmp137_;
	QliteDeleteBuilder* _tmp138_;
	QliteDeleteBuilder* _tmp139_;
	DinoDatabase* _tmp140_;
	DinoDatabaseMamCatchupTable* _tmp141_;
	DinoDatabaseMamCatchupTable* _tmp142_;
	QliteQueryBuilder* _tmp143_;
	QliteQueryBuilder* _tmp144_;
	DinoDatabase* _tmp145_;
	DinoDatabaseMamCatchupTable* _tmp146_;
	DinoDatabaseMamCatchupTable* _tmp147_;
	QliteColumn* _tmp148_;
	QliteQueryBuilder* _tmp149_;
	QliteQueryBuilder* _tmp150_;
	QliteQueryBuilder* _tmp151_;
	QliteQueryBuilder* _tmp152_;
	QliteRowOption* _tmp153_;
	QliteRowOption* _tmp154_;
	QliteRow* _tmp155_;
	QliteRow* _tmp156_;
	QliteRow* _tmp157_;
	QliteRow* _tmp158_;
};

struct _DinoHistorySyncFetchBeforeRangeData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoHistorySync* self;
	DinoEntitiesAccount* account;
	XmppJid* mam_server;
	QliteRow* range;
	GDateTime* until_earliest_time;
	GCancellable* cancellable;
	GDateTime* latest_time;
	DinoDatabase* _tmp0_;
	DinoDatabaseMamCatchupTable* _tmp1_;
	DinoDatabaseMamCatchupTable* _tmp2_;
	QliteColumn* _tmp3_;
	gpointer _tmp4_;
	GDateTime* _tmp5_;
	gchar* latest_id;
	DinoDatabase* _tmp6_;
	DinoDatabaseMamCatchupTable* _tmp7_;
	DinoDatabaseMamCatchupTable* _tmp8_;
	QliteColumn* _tmp9_;
	gpointer _tmp10_;
	XmppJid* _tmp11_;
	XmppJid* _tmp12_;
	XmppJid* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* _tmp17_;
	GDateTime* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	const gchar* _tmp21_;
	XmppMessageArchiveManagementV2MamQueryParams* query_params;
	GDateTime* _tmp22_;
	const gchar* _tmp23_;
	XmppMessageArchiveManagementV2MamQueryParams* _tmp24_;
	GDateTime* _tmp25_;
	const gchar* _tmp26_;
	XmppMessageArchiveManagementV2MamQueryParams* _tmp27_;
	XmppMessageArchiveManagementV2MamQueryParams* _tmp28_;
	DinoDatabase* _tmp29_;
	DinoDatabaseMamCatchupTable* _tmp30_;
	DinoDatabaseMamCatchupTable* _tmp31_;
	QliteColumn* _tmp32_;
	gpointer _tmp33_;
	DinoHistorySyncPageRequestResult* _tmp34_;
	DinoHistorySyncPageRequestResult* _tmp35_;
};

struct _DinoHistorySyncFetchQueryData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoHistorySync* self;
	DinoEntitiesAccount* account;
	XmppMessageArchiveManagementV2MamQueryParams* query_params;
	gint db_id;
	GCancellable* cancellable;
	DinoHistorySyncPageRequestResult* result;
	gchar* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	GDateTime* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	GDateTime* _tmp8_;
	GDateTime* _tmp9_;
	GDateTime* _tmp10_;
	GDateTime* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	XmppJid* _tmp14_;
	XmppJid* _tmp15_;
	XmppJid* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	XmppJid* _tmp19_;
	XmppJid* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	DinoHistorySyncPageRequestResult* page_result;
	gboolean _tmp23_;
	DinoHistorySyncPageRequestResult* _tmp24_;
	DinoHistorySyncPageResult _tmp25_;
	DinoHistorySyncPageResult _tmp26_;
	DinoHistorySyncPageRequestResult* _tmp27_;
	DinoHistorySyncPageRequestResult* _tmp28_;
	XmppJid* _tmp29_;
	XmppJid* _tmp30_;
	XmppJid* _tmp31_;
	gchar* _tmp32_;
	gchar* _tmp33_;
	XmppJid* _tmp34_;
	XmppJid* _tmp35_;
	gchar* _tmp36_;
	gchar* _tmp37_;
	DinoHistorySyncPageRequestResult* _tmp38_;
	DinoHistorySyncPageResult _tmp39_;
	DinoHistorySyncPageResult _tmp40_;
	GEnumValue* _tmp41_;
	DinoHistorySyncPageRequestResult* _tmp42_;
	GeeList* _tmp43_;
	GeeList* _tmp44_;
	gchar* _tmp45_;
	gchar* _tmp46_;
	gboolean _tmp47_;
	DinoHistorySyncPageRequestResult* _tmp48_;
	DinoHistorySyncPageResult _tmp49_;
	DinoHistorySyncPageResult _tmp50_;
	DinoHistorySyncPageRequestResult* _tmp51_;
	DinoHistorySyncPageResult _tmp52_;
	DinoHistorySyncPageResult _tmp53_;
	gchar* earliest_mam_id;
	DinoHistorySyncPageRequestResult* _tmp54_;
	XmppMessageArchiveManagementQueryResult* _tmp55_;
	XmppMessageArchiveManagementQueryResult* _tmp56_;
	const gchar* _tmp57_;
	const gchar* _tmp58_;
	gchar* _tmp59_;
	glong _tmp60_;
	const gchar* _tmp61_;
	GeeHashMap* _tmp62_;
	gpointer _tmp63_;
	GeeHashMap* _tmp64_;
	const gchar* _tmp65_;
	gpointer _tmp66_;
	GDateTime* _tmp67_;
	glong earliest_mam_time;
	QliteUpdateBuilder* query;
	DinoDatabase* _tmp68_;
	DinoDatabaseMamCatchupTable* _tmp69_;
	DinoDatabaseMamCatchupTable* _tmp70_;
	QliteUpdateBuilder* _tmp71_;
	QliteUpdateBuilder* _tmp72_;
	DinoDatabase* _tmp73_;
	DinoDatabaseMamCatchupTable* _tmp74_;
	DinoDatabaseMamCatchupTable* _tmp75_;
	QliteColumn* _tmp76_;
	QliteUpdateBuilder* _tmp77_;
	QliteUpdateBuilder* _tmp78_;
	const gchar* _tmp79_;
	XmppJid* _tmp80_;
	XmppJid* _tmp81_;
	XmppJid* _tmp82_;
	gchar* _tmp83_;
	gchar* _tmp84_;
	XmppJid* _tmp85_;
	XmppJid* _tmp86_;
	gchar* _tmp87_;
	gchar* _tmp88_;
	gchar* _tmp89_;
	gchar* _tmp90_;
	const gchar* _tmp91_;
	QliteUpdateBuilder* _tmp92_;
	DinoDatabase* _tmp93_;
	DinoDatabaseMamCatchupTable* _tmp94_;
	DinoDatabaseMamCatchupTable* _tmp95_;
	QliteColumn* _tmp96_;
	const gchar* _tmp97_;
	QliteUpdateBuilder* _tmp98_;
	QliteUpdateBuilder* _tmp99_;
	gboolean _tmp100_;
	gboolean _tmp101_;
	DinoHistorySyncPageRequestResult* _tmp102_;
	DinoHistorySyncPageResult _tmp103_;
	DinoHistorySyncPageResult _tmp104_;
	GDateTime* _tmp105_;
	GDateTime* _tmp106_;
	GDateTime* _tmp107_;
	GDateTime* _tmp108_;
	QliteUpdateBuilder* _tmp109_;
	DinoDatabase* _tmp110_;
	DinoDatabaseMamCatchupTable* _tmp111_;
	DinoDatabaseMamCatchupTable* _tmp112_;
	QliteColumn* _tmp113_;
	QliteUpdateBuilder* _tmp114_;
	QliteUpdateBuilder* _tmp115_;
	DinoHistorySyncPageRequestResult* _tmp116_;
	DinoHistorySyncPageResult _tmp117_;
	DinoHistorySyncPageResult _tmp118_;
	GDateTime* _tmp119_;
	GDateTime* _tmp120_;
	XmppJid* _tmp121_;
	XmppJid* _tmp122_;
	XmppJid* _tmp123_;
	gchar* _tmp124_;
	gchar* _tmp125_;
	XmppJid* _tmp126_;
	XmppJid* _tmp127_;
	gchar* _tmp128_;
	gchar* _tmp129_;
	GDateTime* _tmp130_;
	GDateTime* _tmp131_;
	gchar* _tmp132_;
	gchar* _tmp133_;
	QliteUpdateBuilder* _tmp134_;
	DinoDatabase* _tmp135_;
	DinoDatabaseMamCatchupTable* _tmp136_;
	DinoDatabaseMamCatchupTable* _tmp137_;
	QliteColumn* _tmp138_;
	GDateTime* _tmp139_;
	GDateTime* _tmp140_;
	QliteUpdateBuilder* _tmp141_;
	QliteUpdateBuilder* _tmp142_;
	QliteUpdateBuilder* _tmp143_;
	DinoDatabase* _tmp144_;
	DinoDatabaseMamCatchupTable* _tmp145_;
	DinoDatabaseMamCatchupTable* _tmp146_;
	QliteColumn* _tmp147_;
	QliteUpdateBuilder* _tmp148_;
	QliteUpdateBuilder* _tmp149_;
	QliteUpdateBuilder* _tmp150_;
};

struct _DinoHistorySyncGetMamPageData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoHistorySync* self;
	DinoEntitiesAccount* account;
	XmppMessageArchiveManagementV2MamQueryParams* query_params;
	DinoHistorySyncPageRequestResult* prev_page_result;
	GCancellable* cancellable;
	DinoHistorySyncPageRequestResult* result;
	XmppXmppStream* stream;
	DinoStreamInteractor* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppMessageArchiveManagementQueryResult* query_result;
	XmppXmppStream* _tmp2_;
	XmppMessageArchiveManagementQueryResult* _tmp3_;
	XmppXmppStream* _tmp4_;
	XmppMessageArchiveManagementQueryResult* _tmp5_;
	XmppMessageArchiveManagementQueryResult* _tmp6_;
	XmppMessageArchiveManagementQueryResult* _tmp7_;
	XmppMessageArchiveManagementQueryResult* _tmp8_;
	DinoHistorySyncPageRequestResult* _tmp9_;
};

struct _DinoHistorySyncProcessQueryResultData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoHistorySync* self;
	DinoEntitiesAccount* account;
	XmppMessageArchiveManagementV2MamQueryParams* query_params;
	XmppMessageArchiveManagementQueryResult* query_result;
	GCancellable* cancellable;
	DinoHistorySyncPageRequestResult* result;
	DinoHistorySyncPageResult page_result;
	gboolean _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp5_;
	gboolean _tmp6_;
	gchar* query_id;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* after_id;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	GeeList* _tmp12_;
	gboolean _tmp13_;
	GeeHashMap* _tmp14_;
	const gchar* _tmp15_;
	GeeHashMap* _tmp16_;
	const gchar* _tmp17_;
	gpointer _tmp18_;
	GeeList* _tmp19_;
	gboolean _tmp20_;
	gboolean _tmp21_;
	GeeHashMap* _tmp22_;
	const gchar* _tmp23_;
	gpointer _tmp24_;
	GeeList* stanzas_for_query;
	GeeList* _tmp25_;
	gboolean _tmp26_;
	GeeHashMap* _tmp27_;
	const gchar* _tmp28_;
	GeeList* _tmp29_;
	DinoHistorySyncPageRequestResult* _tmp30_;
	GeeList* _tmp31_;
	GeeList* _message_list;
	GeeList* _tmp32_;
	gint _message_size;
	GeeList* _tmp33_;
	gint _tmp34_;
	gint _tmp35_;
	gint _message_index;
	gint _tmp36_;
	gint _tmp37_;
	XmppMessageStanza* message;
	GeeList* _tmp38_;
	gpointer _tmp39_;
	XmppMessageArchiveManagementMessageFlag* mam_message_flag;
	XmppMessageStanza* _tmp40_;
	XmppMessageArchiveManagementMessageFlag* _tmp41_;
	gboolean _tmp42_;
	XmppMessageArchiveManagementMessageFlag* _tmp43_;
	XmppMessageArchiveManagementMessageFlag* _tmp44_;
	const gchar* _tmp45_;
	const gchar* _tmp46_;
	gboolean _tmp47_;
	const gchar* _tmp48_;
	XmppMessageArchiveManagementMessageFlag* _tmp49_;
	const gchar* _tmp50_;
	const gchar* _tmp51_;
	const gchar* _tmp52_;
	const gchar* _tmp53_;
	gboolean _tmp54_;
	GeeList* _tmp55_;
	DinoHistorySyncPageRequestResult* _tmp56_;
	GeeList* _tmp57_;
	DinoHistorySyncPageRequestResult* _tmp58_;
	gboolean _tmp59_;
	GeeHashMap* _tmp60_;
	const gchar* _tmp61_;
	GeeHashMap* _tmp62_;
	const gchar* _tmp63_;
	gpointer _tmp64_;
	const gchar* _tmp65_;
	gboolean _tmp66_;
	GeeList* _tmp67_;
	DinoHistorySyncPageRequestResult* _tmp68_;
	GeeList* _tmp69_;
	DinoHistorySyncPageRequestResult* _tmp70_;
	const gchar* _tmp71_;
	gboolean _tmp72_;
	GeeList* _tmp73_;
	DinoHistorySyncPageRequestResult* _tmp74_;
};

struct _DinoHistorySyncSendMessagesBackIntoPipelineData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoHistorySync* self;
	DinoEntitiesAccount* account;
	gchar* query_id;
	GCancellable* cancellable;
	GeeHashMap* _tmp0_;
	GeeList* _message_list;
	GeeHashMap* _tmp1_;
	gpointer _tmp2_;
	gint _message_size;
	GeeList* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	gint _message_index;
	gint _tmp6_;
	gint _tmp7_;
	XmppMessageStanza* message;
	GeeList* _tmp8_;
	gpointer _tmp9_;
	gboolean _tmp10_;
	DinoStreamInteractor* _tmp11_;
	DinoModuleIdentity* _tmp12_;
	gpointer _tmp13_;
	DinoMessageProcessor* _tmp14_;
	XmppMessageStanza* _tmp15_;
	GeeHashMap* _tmp16_;
};

struct _Block16Data {
	int _ref_count_;
	DinoHistorySync* self;
	DinoEntitiesAccount* account;
};

struct _Block17Data {
	int _ref_count_;
	DinoHistorySync* self;
	DinoEntitiesAccount* account;
};

struct _DinoHistorySyncMamRange {
	GTypeInstance parent_instance;
	volatile int ref_count;
	DinoHistorySyncMamRangePrivate * priv;
	gint id;
	XmppJid* server_jid;
	glong from_time;
	gchar* from_id;
	gboolean from_end;
	glong to_time;
	gchar* to_id;
};

struct _DinoHistorySyncMamRangeClass {
	GTypeClass parent_class;
	void (*finalize) (DinoHistorySyncMamRange *self);
};

struct _DinoHistorySyncParamSpecMamRange {
	GParamSpec parent_instance;
};

struct _DinoHistorySyncPageRequestResult {
	GTypeInstance parent_instance;
	volatile int ref_count;
	DinoHistorySyncPageRequestResultPrivate * priv;
};

struct _DinoHistorySyncPageRequestResultClass {
	GTypeClass parent_class;
	void (*finalize) (DinoHistorySyncPageRequestResult *self);
};

struct _DinoHistorySyncPageRequestResultPrivate {
	GeeList* _stanzas;
	DinoHistorySyncPageResult _page_result;
	XmppMessageArchiveManagementQueryResult* _query_result;
};

struct _DinoHistorySyncParamSpecPageRequestResult {
	GParamSpec parent_instance;
};

struct _DinoParamSpecHistorySync {
	GParamSpec parent_instance;
};

static gint DinoHistorySync_private_offset;
static gpointer dino_history_sync_parent_class = NULL;
static gpointer dino_history_sync_mam_range_parent_class = NULL;
static gint DinoHistorySyncPageRequestResult_private_offset;
static gpointer dino_history_sync_page_request_result_parent_class = NULL;

static GType dino_history_sync_page_result_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static guint _dino_entities_account_hash_func_gee_hash_data_func (gconstpointer v,
                                                           gpointer self);
static gboolean _dino_entities_account_equals_func_gee_equal_data_func (gconstpointer a,
                                                                 gconstpointer b,
                                                                 gpointer self);
static void dino_history_sync_on_account_added (DinoHistorySync* self,
                                         DinoEntitiesAccount* account);
static void _dino_history_sync_on_account_added_dino_stream_interactor_account_added (DinoStreamInteractor* _sender,
                                                                               DinoEntitiesAccount* account,
                                                                               gpointer self);
static void __lambda36_ (DinoHistorySync* self,
                  DinoEntitiesAccount* account,
                  XmppXmppStream* stream);
static void ___lambda36__dino_stream_interactor_stream_negotiated (DinoStreamInteractor* _sender,
                                                            DinoEntitiesAccount* account,
                                                            XmppXmppStream* stream,
                                                            gpointer self);
static void dino_history_sync_on_unprocessed_message (DinoHistorySync* self,
                                               DinoEntitiesAccount* account,
                                               XmppXmppStream* stream,
                                               XmppMessageStanza* message);
static void dino_history_sync_fetch_everything_data_free (gpointer _data);
static gboolean dino_history_sync_fetch_everything_co (DinoHistorySyncFetchEverythingData* _data_);
static void dino_history_sync_fetch_everything_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_);
static void dino_history_sync_fetch_between_ranges (DinoHistorySync* self,
                                             DinoEntitiesAccount* account,
                                             XmppJid* mam_server,
                                             QliteRow* earlier_range,
                                             QliteRow* later_range,
                                             GCancellable* cancellable,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
static QliteRow* dino_history_sync_fetch_between_ranges_finish (DinoHistorySync* self,
                                                         GAsyncResult* _res_);
static void dino_history_sync_fetch_before_range (DinoHistorySync* self,
                                           DinoEntitiesAccount* account,
                                           XmppJid* mam_server,
                                           QliteRow* range,
                                           GDateTime* until_earliest_time,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_);
static void dino_history_sync_fetch_before_range_finish (DinoHistorySync* self,
                                                  GAsyncResult* _res_);
static void dino_history_sync_fetch_latest_page_data_free (gpointer _data);
static gboolean dino_history_sync_fetch_latest_page_co (DinoHistorySyncFetchLatestPageData* _data_);
static gpointer dino_history_sync_page_request_result_ref (gpointer instance);
static void dino_history_sync_page_request_result_unref (gpointer instance);
static GParamSpec* dino_history_sync_param_spec_page_request_result (const gchar* name,
                                                              const gchar* nick,
                                                              const gchar* blurb,
                                                              GType object_type,
                                                              GParamFlags flags) G_GNUC_UNUSED ;
static void dino_history_sync_value_set_page_request_result (GValue* value,
                                                      gpointer v_object) G_GNUC_UNUSED ;
static void dino_history_sync_value_take_page_request_result (GValue* value,
                                                       gpointer v_object) G_GNUC_UNUSED ;
static gpointer dino_history_sync_value_get_page_request_result (const GValue* value) G_GNUC_UNUSED ;
static GType dino_history_sync_page_request_result_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static void dino_history_sync_get_mam_page (DinoHistorySync* self,
                                     DinoEntitiesAccount* account,
                                     XmppMessageArchiveManagementV2MamQueryParams* query_params,
                                     DinoHistorySyncPageRequestResult* prev_page_result,
                                     GCancellable* cancellable,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_);
static DinoHistorySyncPageRequestResult* dino_history_sync_get_mam_page_finish (DinoHistorySync* self,
                                                                         GAsyncResult* _res_);
static void dino_history_sync_fetch_latest_page_ready (GObject* source_object,
                                                GAsyncResult* _res_,
                                                gpointer _user_data_);
static DinoHistorySyncPageResult dino_history_sync_page_request_result_get_page_result (DinoHistorySyncPageRequestResult* self);
static gboolean _vala_dino_history_sync_page_result_array_contains (DinoHistorySyncPageResult * stack,
                                                             gssize stack_length,
                                                             const DinoHistorySyncPageResult needle);
static GeeList* dino_history_sync_page_request_result_get_stanzas (DinoHistorySyncPageRequestResult* self);
static XmppMessageArchiveManagementQueryResult* dino_history_sync_page_request_result_get_query_result (DinoHistorySyncPageRequestResult* self);
static void dino_history_sync_fetch_between_ranges_data_free (gpointer _data);
static gboolean dino_history_sync_fetch_between_ranges_co (DinoHistorySyncFetchBetweenRangesData* _data_);
static void dino_history_sync_fetch_query (DinoHistorySync* self,
                                    DinoEntitiesAccount* account,
                                    XmppMessageArchiveManagementV2MamQueryParams* query_params,
                                    gint db_id,
                                    GCancellable* cancellable,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_);
static DinoHistorySyncPageRequestResult* dino_history_sync_fetch_query_finish (DinoHistorySync* self,
                                                                        GAsyncResult* _res_);
static void dino_history_sync_fetch_between_ranges_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_);
static void dino_history_sync_fetch_before_range_data_free (gpointer _data);
static gboolean dino_history_sync_fetch_before_range_co (DinoHistorySyncFetchBeforeRangeData* _data_);
static void dino_history_sync_fetch_before_range_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_);
static void dino_history_sync_fetch_query_data_free (gpointer _data);
static gboolean dino_history_sync_fetch_query_co (DinoHistorySyncFetchQueryData* _data_);
static void dino_history_sync_fetch_query_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_);
static void dino_history_sync_get_mam_page_data_free (gpointer _data);
static gboolean dino_history_sync_get_mam_page_co (DinoHistorySyncGetMamPageData* _data_);
static void dino_history_sync_get_mam_page_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_);
static void dino_history_sync_process_query_result (DinoHistorySync* self,
                                             DinoEntitiesAccount* account,
                                             XmppMessageArchiveManagementV2MamQueryParams* query_params,
                                             XmppMessageArchiveManagementQueryResult* query_result,
                                             GCancellable* cancellable,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
static DinoHistorySyncPageRequestResult* dino_history_sync_process_query_result_finish (DinoHistorySync* self,
                                                                                 GAsyncResult* _res_);
static void dino_history_sync_process_query_result_data_free (gpointer _data);
static gboolean dino_history_sync_process_query_result_co (DinoHistorySyncProcessQueryResultData* _data_);
static gboolean _dino_history_sync_process_query_result_co_gsource_func (gpointer self);
static DinoHistorySyncPageRequestResult* dino_history_sync_page_request_result_new (DinoHistorySyncPageResult page_result,
                                                                             XmppMessageArchiveManagementQueryResult* query_result,
                                                                             GeeList* stanzas);
static DinoHistorySyncPageRequestResult* dino_history_sync_page_request_result_construct (GType object_type,
                                                                                   DinoHistorySyncPageResult page_result,
                                                                                   XmppMessageArchiveManagementQueryResult* query_result,
                                                                                   GeeList* stanzas);
static void dino_history_sync_send_messages_back_into_pipeline (DinoHistorySync* self,
                                                         DinoEntitiesAccount* account,
                                                         const gchar* query_id,
                                                         GCancellable* cancellable,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_);
static void dino_history_sync_send_messages_back_into_pipeline_finish (DinoHistorySync* self,
                                                                GAsyncResult* _res_);
static void dino_history_sync_process_query_result_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_);
static void dino_history_sync_send_messages_back_into_pipeline_data_free (gpointer _data);
static gboolean dino_history_sync_send_messages_back_into_pipeline_co (DinoHistorySyncSendMessagesBackIntoPipelineData* _data_);
static void dino_history_sync_send_messages_back_into_pipeline_ready (GObject* source_object,
                                                               GAsyncResult* _res_,
                                                               gpointer _user_data_);
static Block16Data* block16_data_ref (Block16Data* _data16_);
static void block16_data_unref (void * _userdata_);
static void __lambda32_ (DinoHistorySync* self,
                  DinoEntitiesAccount* account,
                  XmppXmppStream* stream);
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 ___lambda32__dino_connection_manager_stream_attached_modules (DinoConnectionManager* _sender,
                                                                   DinoEntitiesAccount* account,
                                                                   XmppXmppStream* stream,
                                                                   gpointer self);
static void __lambda33_ (Block16Data* _data16_,
                  XmppXmppStream* stream);
static void dino_history_sync_consider_fetch_everything (DinoHistorySync* self,
                                                  DinoEntitiesAccount* account,
                                                  XmppXmppStream* stream);
static void ___lambda33__xmpp_message_archive_management_module_feature_available (XmppMessageArchiveManagementModule* _sender,
                                                                            XmppXmppStream* stream,
                                                                            gpointer self);
static void __lambda35_ (Block16Data* _data16_,
                  XmppXmppStream* stream,
                  XmppMessageStanza* message);
static void ___lambda35__xmpp_message_module_received_message_unprocessed (XmppMessageModule* _sender,
                                                                    XmppXmppStream* stream,
                                                                    XmppMessageStanza* message,
                                                                    gpointer self);
static Block17Data* block17_data_ref (Block17Data* _data17_);
static void block17_data_unref (void * _userdata_);
static void __lambda34_ (Block17Data* _data17_,
                  GObject* _,
                  GAsyncResult* res);
static void ___lambda34__gasync_ready_callback (GObject* source_object,
                                         GAsyncResult* res,
                                         gpointer self);
static gpointer dino_history_sync_mam_range_ref (gpointer instance);
static void dino_history_sync_mam_range_unref (gpointer instance);
static GParamSpec* dino_history_sync_param_spec_mam_range (const gchar* name,
                                                    const gchar* nick,
                                                    const gchar* blurb,
                                                    GType object_type,
                                                    GParamFlags flags) G_GNUC_UNUSED ;
static void dino_history_sync_value_set_mam_range (GValue* value,
                                            gpointer v_object) G_GNUC_UNUSED ;
static void dino_history_sync_value_take_mam_range (GValue* value,
                                             gpointer v_object) G_GNUC_UNUSED ;
static gpointer dino_history_sync_value_get_mam_range (const GValue* value) G_GNUC_UNUSED ;
static GType dino_history_sync_mam_range_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static DinoHistorySyncMamRange* dino_history_sync_mam_range_new (void);
static DinoHistorySyncMamRange* dino_history_sync_mam_range_construct (GType object_type);
static void dino_history_sync_mam_range_finalize (DinoHistorySyncMamRange * obj);
static GType dino_history_sync_mam_range_get_type_once (void);
static void dino_history_sync_page_request_result_set_page_result (DinoHistorySyncPageRequestResult* self,
                                                            DinoHistorySyncPageResult value);
static void dino_history_sync_page_request_result_set_query_result (DinoHistorySyncPageRequestResult* self,
                                                             XmppMessageArchiveManagementQueryResult* value);
static void dino_history_sync_page_request_result_set_stanzas (DinoHistorySyncPageRequestResult* self,
                                                        GeeList* value);
static void dino_history_sync_page_request_result_finalize (DinoHistorySyncPageRequestResult * obj);
static GType dino_history_sync_page_request_result_get_type_once (void);
static void dino_history_sync_finalize (DinoHistorySync * obj);
static GType dino_history_sync_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_history_sync_get_instance_private (DinoHistorySync* self)
{
	return G_STRUCT_MEMBER_P (self, DinoHistorySync_private_offset);
}

static GType
dino_history_sync_page_result_get_type_once (void)
{
	static const GEnumValue values[] = {{DINO_HISTORY_SYNC_PAGE_RESULT_MorePagesAvailable, "DINO_HISTORY_SYNC_PAGE_RESULT_MorePagesAvailable", "morepagesavailable"}, {DINO_HISTORY_SYNC_PAGE_RESULT_TargetReached, "DINO_HISTORY_SYNC_PAGE_RESULT_TargetReached", "targetreached"}, {DINO_HISTORY_SYNC_PAGE_RESULT_NoMoreMessages, "DINO_HISTORY_SYNC_PAGE_RESULT_NoMoreMessages", "nomoremessages"}, {DINO_HISTORY_SYNC_PAGE_RESULT_Error, "DINO_HISTORY_SYNC_PAGE_RESULT_Error", "error"}, {DINO_HISTORY_SYNC_PAGE_RESULT_Cancelled, "DINO_HISTORY_SYNC_PAGE_RESULT_Cancelled", "cancelled"}, {0, NULL, NULL}};
	GType dino_history_sync_page_result_type_id;
	dino_history_sync_page_result_type_id = g_enum_register_static ("DinoHistorySyncPageResult", values);
	return dino_history_sync_page_result_type_id;
}

static GType
dino_history_sync_page_result_get_type (void)
{
	static volatile gsize dino_history_sync_page_result_type_id__once = 0;
	if (g_once_init_enter (&dino_history_sync_page_result_type_id__once)) {
		GType dino_history_sync_page_result_type_id;
		dino_history_sync_page_result_type_id = dino_history_sync_page_result_get_type_once ();
		g_once_init_leave (&dino_history_sync_page_result_type_id__once, dino_history_sync_page_result_type_id);
	}
	return dino_history_sync_page_result_type_id__once;
}

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

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

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

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

static void
_dino_history_sync_on_account_added_dino_stream_interactor_account_added (DinoStreamInteractor* _sender,
                                                                          DinoEntitiesAccount* account,
                                                                          gpointer self)
{
	dino_history_sync_on_account_added ((DinoHistorySync*) self, account);
}

static void
__lambda36_ (DinoHistorySync* self,
             DinoEntitiesAccount* account,
             XmppXmppStream* stream)
{
	GeeHashMap* _tmp0_;
	g_return_if_fail (account != NULL);
	g_return_if_fail (stream != NULL);
	_tmp0_ = self->current_catchup_id;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp0_, account)) {
		XmppJid* _tmp1_;
		XmppJid* _tmp2_;
		XmppJid* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		GeeHashMap* _tmp6_;
		gpointer _tmp7_;
		GeeHashMap* _tmp8_;
		_tmp1_ = dino_entities_account_get_bare_jid (account);
		_tmp2_ = _tmp1_;
		_tmp3_ = _tmp2_;
		_tmp4_ = xmpp_jid_to_string (_tmp3_);
		_tmp5_ = _tmp4_;
		g_debug ("history_sync.vala:34: MAM: [%s] Reset catchup_id", _tmp5_);
		_g_free0 (_tmp5_);
		_xmpp_jid_unref0 (_tmp3_);
		_tmp6_ = self->current_catchup_id;
		_tmp7_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp6_, account);
		_tmp8_ = (GeeHashMap*) _tmp7_;
		gee_abstract_map_clear ((GeeAbstractMap*) _tmp8_);
		_g_object_unref0 (_tmp8_);
	}
}

static void
___lambda36__dino_stream_interactor_stream_negotiated (DinoStreamInteractor* _sender,
                                                       DinoEntitiesAccount* account,
                                                       XmppXmppStream* stream,
                                                       gpointer self)
{
	__lambda36_ ((DinoHistorySync*) self, account, stream);
}

DinoHistorySync*
dino_history_sync_construct (GType object_type,
                             DinoDatabase* db,
                             DinoStreamInteractor* stream_interactor)
{
	DinoHistorySync* self = NULL;
	DinoStreamInteractor* _tmp0_;
	DinoDatabase* _tmp1_;
	g_return_val_if_fail (db != NULL, NULL);
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	self = (DinoHistorySync*) g_type_create_instance (object_type);
	_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_;
	g_signal_connect (stream_interactor, "account-added", (GCallback) _dino_history_sync_on_account_added_dino_stream_interactor_account_added, self);
	g_signal_connect (stream_interactor, "stream-negotiated", (GCallback) ___lambda36__dino_stream_interactor_stream_negotiated, self);
	return self;
}

DinoHistorySync*
dino_history_sync_new (DinoDatabase* db,
                       DinoStreamInteractor* stream_interactor)
{
	return dino_history_sync_construct (DINO_TYPE_HISTORY_SYNC, db, stream_interactor);
}

gboolean
dino_history_sync_process (DinoHistorySync* self,
                           DinoEntitiesAccount* account,
                           XmppMessageStanza* message_stanza)
{
	XmppMessageArchiveManagementMessageFlag* mam_flag = NULL;
	XmppMessageArchiveManagementMessageFlag* _tmp0_;
	XmppMessageArchiveManagementMessageFlag* _tmp1_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (account != NULL, FALSE);
	g_return_val_if_fail (message_stanza != NULL, FALSE);
	_tmp0_ = xmpp_message_archive_management_message_flag_get_flag (message_stanza);
	mam_flag = _tmp0_;
	_tmp1_ = mam_flag;
	if (_tmp1_ != NULL) {
		XmppMessageArchiveManagementMessageFlag* _tmp2_;
		_tmp2_ = mam_flag;
		dino_history_sync_process_mam_message (self, account, message_stanza, _tmp2_);
		result = TRUE;
		_g_object_unref0 (mam_flag);
		return result;
	} else {
		dino_history_sync_update_latest_db_range (self, account, message_stanza);
		result = FALSE;
		_g_object_unref0 (mam_flag);
		return result;
	}
}

void
dino_history_sync_update_latest_db_range (DinoHistorySync* self,
                                          DinoEntitiesAccount* account,
                                          XmppMessageStanza* message_stanza)
{
	XmppJid* _tmp0_ = NULL;
	DinoStreamInteractor* _tmp1_;
	DinoModuleIdentity* _tmp2_;
	gpointer _tmp3_;
	DinoMucManager* _tmp4_;
	XmppJid* _tmp5_;
	XmppJid* _tmp6_;
	XmppJid* _tmp7_;
	XmppJid* _tmp8_;
	XmppJid* _tmp9_;
	XmppJid* _tmp10_;
	gboolean _tmp11_;
	XmppJid* mam_server = NULL;
	XmppJid* _tmp19_;
	gboolean _tmp20_ = FALSE;
	GeeHashMap* _tmp21_;
	gchar* stanza_id = NULL;
	XmppJid* _tmp26_;
	gchar* _tmp27_;
	const gchar* _tmp28_;
	DinoDatabase* _tmp29_;
	DinoDatabaseMamCatchupTable* _tmp30_;
	DinoDatabaseMamCatchupTable* _tmp31_;
	QliteUpdateBuilder* _tmp32_;
	QliteUpdateBuilder* _tmp33_;
	DinoDatabase* _tmp34_;
	DinoDatabaseMamCatchupTable* _tmp35_;
	DinoDatabaseMamCatchupTable* _tmp36_;
	QliteColumn* _tmp37_;
	GeeHashMap* _tmp38_;
	gpointer _tmp39_;
	GeeHashMap* _tmp40_;
	XmppJid* _tmp41_;
	gpointer _tmp42_;
	QliteUpdateBuilder* _tmp43_;
	QliteUpdateBuilder* _tmp44_;
	DinoDatabase* _tmp45_;
	DinoDatabaseMamCatchupTable* _tmp46_;
	DinoDatabaseMamCatchupTable* _tmp47_;
	QliteColumn* _tmp48_;
	GDateTime* _tmp49_;
	GDateTime* _tmp50_;
	QliteUpdateBuilder* _tmp51_;
	QliteUpdateBuilder* _tmp52_;
	DinoDatabase* _tmp53_;
	DinoDatabaseMamCatchupTable* _tmp54_;
	DinoDatabaseMamCatchupTable* _tmp55_;
	QliteColumn* _tmp56_;
	const gchar* _tmp57_;
	QliteUpdateBuilder* _tmp58_;
	QliteUpdateBuilder* _tmp59_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (message_stanza != NULL);
	_tmp1_ = self->priv->stream_interactor;
	_tmp2_ = dino_muc_manager_IDENTITY;
	_tmp3_ = dino_stream_interactor_get_module (_tmp1_, DINO_TYPE_MUC_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp2_);
	_tmp4_ = (DinoMucManager*) _tmp3_;
	_tmp5_ = xmpp_stanza_get_from ((XmppStanza*) message_stanza);
	_tmp6_ = _tmp5_;
	_tmp7_ = _tmp6_;
	_tmp8_ = xmpp_jid_get_bare_jid (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = _tmp9_;
	_tmp11_ = dino_muc_manager_might_be_groupchat (_tmp4_, _tmp10_, account);
	_xmpp_jid_unref0 (_tmp10_);
	_xmpp_jid_unref0 (_tmp7_);
	_g_object_unref0 (_tmp4_);
	if (_tmp11_) {
		XmppJid* _tmp12_;
		XmppJid* _tmp13_;
		XmppJid* _tmp14_;
		XmppJid* _tmp15_;
		XmppJid* _tmp16_;
		_tmp12_ = xmpp_stanza_get_from ((XmppStanza*) message_stanza);
		_tmp13_ = _tmp12_;
		_tmp14_ = _tmp13_;
		_tmp15_ = xmpp_jid_get_bare_jid (_tmp14_);
		_tmp16_ = _tmp15_;
		_xmpp_jid_unref0 (_tmp0_);
		_tmp0_ = _tmp16_;
		_xmpp_jid_unref0 (_tmp14_);
	} else {
		XmppJid* _tmp17_;
		XmppJid* _tmp18_;
		_tmp17_ = dino_entities_account_get_bare_jid (account);
		_tmp18_ = _tmp17_;
		_xmpp_jid_unref0 (_tmp0_);
		_tmp0_ = _tmp18_;
	}
	_tmp19_ = _tmp0_;
	_tmp0_ = NULL;
	mam_server = _tmp19_;
	_tmp21_ = self->current_catchup_id;
	if (!gee_abstract_map_has_key ((GeeAbstractMap*) _tmp21_, account)) {
		_tmp20_ = TRUE;
	} else {
		GeeHashMap* _tmp22_;
		gpointer _tmp23_;
		GeeHashMap* _tmp24_;
		XmppJid* _tmp25_;
		_tmp22_ = self->current_catchup_id;
		_tmp23_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp22_, account);
		_tmp24_ = (GeeHashMap*) _tmp23_;
		_tmp25_ = mam_server;
		_tmp20_ = !gee_abstract_map_has_key ((GeeAbstractMap*) _tmp24_, _tmp25_);
		_g_object_unref0 (_tmp24_);
	}
	if (_tmp20_) {
		_xmpp_jid_unref0 (mam_server);
		_xmpp_jid_unref0 (_tmp0_);
		return;
	}
	_tmp26_ = mam_server;
	_tmp27_ = xmpp_xep_unique_stable_stanza_ids_get_stanza_id (message_stanza, _tmp26_);
	stanza_id = _tmp27_;
	_tmp28_ = stanza_id;
	if (_tmp28_ == NULL) {
		_g_free0 (stanza_id);
		_xmpp_jid_unref0 (mam_server);
		_xmpp_jid_unref0 (_tmp0_);
		return;
	}
	_tmp29_ = self->priv->db;
	_tmp30_ = dino_database_get_mam_catchup (_tmp29_);
	_tmp31_ = _tmp30_;
	_tmp32_ = qlite_table_update ((QliteTable*) _tmp31_);
	_tmp33_ = _tmp32_;
	_tmp34_ = self->priv->db;
	_tmp35_ = dino_database_get_mam_catchup (_tmp34_);
	_tmp36_ = _tmp35_;
	_tmp37_ = _tmp36_->id;
	_tmp38_ = self->current_catchup_id;
	_tmp39_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp38_, account);
	_tmp40_ = (GeeHashMap*) _tmp39_;
	_tmp41_ = mam_server;
	_tmp42_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp40_, _tmp41_);
	_tmp43_ = qlite_update_builder_with (_tmp33_, G_TYPE_INT, NULL, NULL, _tmp37_, "=", (gpointer) ((gintptr) _tmp42_));
	_tmp44_ = _tmp43_;
	_tmp45_ = self->priv->db;
	_tmp46_ = dino_database_get_mam_catchup (_tmp45_);
	_tmp47_ = _tmp46_;
	_tmp48_ = _tmp47_->to_time;
	_tmp49_ = g_date_time_new_now_utc ();
	_tmp50_ = _tmp49_;
	_tmp51_ = qlite_update_builder_set (_tmp44_, G_TYPE_LONG, NULL, NULL, _tmp48_, (gpointer) ((gintptr) g_date_time_to_unix (_tmp50_)));
	_tmp52_ = _tmp51_;
	_tmp53_ = self->priv->db;
	_tmp54_ = dino_database_get_mam_catchup (_tmp53_);
	_tmp55_ = _tmp54_;
	_tmp56_ = _tmp55_->to_id;
	_tmp57_ = stanza_id;
	_tmp58_ = qlite_update_builder_set (_tmp52_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp56_, _tmp57_);
	_tmp59_ = _tmp58_;
	qlite_update_builder_perform (_tmp59_);
	_qlite_statement_builder_unref0 (_tmp59_);
	_qlite_statement_builder_unref0 (_tmp52_);
	_g_date_time_unref0 (_tmp50_);
	_qlite_statement_builder_unref0 (_tmp44_);
	_g_object_unref0 (_tmp40_);
	_qlite_statement_builder_unref0 (_tmp33_);
	_g_free0 (stanza_id);
	_xmpp_jid_unref0 (mam_server);
	_xmpp_jid_unref0 (_tmp0_);
}

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

void
dino_history_sync_process_mam_message (DinoHistorySync* self,
                                       DinoEntitiesAccount* account,
                                       XmppMessageStanza* message_stanza,
                                       XmppMessageArchiveManagementMessageFlag* mam_flag)
{
	XmppJid* mam_server = NULL;
	XmppJid* _tmp0_;
	XmppJid* _tmp1_;
	XmppJid* _tmp2_;
	XmppJid* message_author = NULL;
	XmppJid* _tmp3_;
	XmppJid* _tmp4_;
	gboolean _tmp5_ = FALSE;
	DinoStreamInteractor* _tmp6_;
	DinoModuleIdentity* _tmp7_;
	gpointer _tmp8_;
	DinoMucManager* _tmp9_;
	XmppJid* _tmp10_;
	gboolean _tmp11_;
	gboolean is_muc_mam = FALSE;
	gboolean from_our_server = FALSE;
	XmppJid* _tmp14_;
	XmppJid* _tmp15_;
	XmppJid* _tmp16_;
	XmppJid* _tmp17_;
	gboolean _tmp18_;
	gboolean _tmp19_ = FALSE;
	GeeHashMap* _tmp23_;
	const gchar* _tmp24_;
	const gchar* _tmp25_;
	GeeHashMap* _tmp31_;
	const gchar* _tmp32_;
	const gchar* _tmp33_;
	gpointer _tmp34_;
	GeeList* _tmp35_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (message_stanza != NULL);
	g_return_if_fail (mam_flag != NULL);
	_tmp0_ = xmpp_message_archive_management_message_flag_get_sender_jid (mam_flag);
	_tmp1_ = _tmp0_;
	_tmp2_ = _xmpp_jid_ref0 (_tmp1_);
	mam_server = _tmp2_;
	_tmp3_ = xmpp_stanza_get_from ((XmppStanza*) message_stanza);
	_tmp4_ = _tmp3_;
	message_author = _tmp4_;
	_tmp6_ = self->priv->stream_interactor;
	_tmp7_ = dino_muc_manager_IDENTITY;
	_tmp8_ = dino_stream_interactor_get_module (_tmp6_, DINO_TYPE_MUC_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp7_);
	_tmp9_ = (DinoMucManager*) _tmp8_;
	_tmp10_ = mam_server;
	_tmp11_ = dino_muc_manager_might_be_groupchat (_tmp9_, _tmp10_, account);
	_g_object_unref0 (_tmp9_);
	if (_tmp11_) {
		XmppJid* _tmp12_;
		XmppJid* _tmp13_;
		_tmp12_ = message_author;
		_tmp13_ = mam_server;
		_tmp5_ = xmpp_jid_equals_bare (_tmp12_, _tmp13_);
	} else {
		_tmp5_ = FALSE;
	}
	is_muc_mam = _tmp5_;
	_tmp14_ = mam_server;
	_tmp15_ = dino_entities_account_get_bare_jid (account);
	_tmp16_ = _tmp15_;
	_tmp17_ = _tmp16_;
	_tmp18_ = xmpp_jid_equals_bare (_tmp14_, _tmp17_);
	_xmpp_jid_unref0 (_tmp17_);
	from_our_server = _tmp18_;
	if (!is_muc_mam) {
		_tmp19_ = !from_our_server;
	} else {
		_tmp19_ = FALSE;
	}
	if (_tmp19_) {
		XmppJid* _tmp20_;
		gchar* _tmp21_;
		gchar* _tmp22_;
		_tmp20_ = mam_server;
		_tmp21_ = xmpp_jid_to_string (_tmp20_);
		_tmp22_ = _tmp21_;
		g_warning ("history_sync.vala:78: Received alleged MAM message from %s, ignoring", _tmp22_);
		_g_free0 (_tmp22_);
		_xmpp_jid_unref0 (message_author);
		_xmpp_jid_unref0 (mam_server);
		return;
	}
	_tmp23_ = self->priv->stanzas;
	_tmp24_ = xmpp_message_archive_management_message_flag_get_query_id (mam_flag);
	_tmp25_ = _tmp24_;
	if (!gee_abstract_map_has_key ((GeeAbstractMap*) _tmp23_, _tmp25_)) {
		GeeHashMap* _tmp26_;
		const gchar* _tmp27_;
		const gchar* _tmp28_;
		GeeArrayList* _tmp29_;
		GeeArrayList* _tmp30_;
		_tmp26_ = self->priv->stanzas;
		_tmp27_ = xmpp_message_archive_management_message_flag_get_query_id (mam_flag);
		_tmp28_ = _tmp27_;
		_tmp29_ = gee_array_list_new (XMPP_TYPE_MESSAGE_STANZA, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
		_tmp30_ = _tmp29_;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp26_, _tmp28_, (GeeList*) _tmp30_);
		_g_object_unref0 (_tmp30_);
	}
	_tmp31_ = self->priv->stanzas;
	_tmp32_ = xmpp_message_archive_management_message_flag_get_query_id (mam_flag);
	_tmp33_ = _tmp32_;
	_tmp34_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp31_, _tmp33_);
	_tmp35_ = (GeeList*) _tmp34_;
	gee_collection_add ((GeeCollection*) _tmp35_, message_stanza);
	_g_object_unref0 (_tmp35_);
	_xmpp_jid_unref0 (message_author);
	_xmpp_jid_unref0 (mam_server);
}

static void
dino_history_sync_on_unprocessed_message (DinoHistorySync* self,
                                          DinoEntitiesAccount* account,
                                          XmppXmppStream* stream,
                                          XmppMessageStanza* message)
{
	gboolean is_muc_mam = FALSE;
	DinoStreamInteractor* _tmp0_;
	DinoModuleIdentity* _tmp1_;
	gpointer _tmp2_;
	DinoMucManager* _tmp3_;
	XmppJid* _tmp4_;
	XmppJid* _tmp5_;
	XmppJid* _tmp6_;
	gboolean _tmp7_;
	gboolean from_our_server = FALSE;
	XmppJid* _tmp8_;
	XmppJid* _tmp9_;
	XmppJid* _tmp10_;
	XmppJid* _tmp11_;
	XmppJid* _tmp12_;
	XmppJid* _tmp13_;
	gboolean _tmp14_;
	gboolean _tmp15_ = FALSE;
	gchar* id = NULL;
	XmppStanzaNode* _tmp16_;
	const gchar* _tmp17_;
	gchar* _tmp18_;
	const gchar* _tmp19_;
	XmppStanzaNode* delay_node = NULL;
	XmppStanzaNode* _tmp20_;
	XmppStanzaNode* _tmp21_;
	XmppStanzaNode* _tmp22_;
	GDateTime* time = NULL;
	XmppStanzaNode* _tmp26_;
	GDateTime* _tmp27_;
	GDateTime* _tmp28_;
	GeeHashMap* _tmp29_;
	gpointer _tmp30_;
	GeeHashMap* _tmp31_;
	const gchar* _tmp32_;
	GDateTime* _tmp33_;
	gchar* query_id = NULL;
	XmppStanzaNode* _tmp34_;
	const gchar* _tmp35_;
	gchar* _tmp36_;
	gboolean _tmp37_ = FALSE;
	const gchar* _tmp38_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (message != NULL);
	_tmp0_ = self->priv->stream_interactor;
	_tmp1_ = dino_muc_manager_IDENTITY;
	_tmp2_ = dino_stream_interactor_get_module (_tmp0_, DINO_TYPE_MUC_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp1_);
	_tmp3_ = (DinoMucManager*) _tmp2_;
	_tmp4_ = xmpp_stanza_get_from ((XmppStanza*) message);
	_tmp5_ = _tmp4_;
	_tmp6_ = _tmp5_;
	_tmp7_ = dino_muc_manager_might_be_groupchat (_tmp3_, _tmp6_, account);
	_xmpp_jid_unref0 (_tmp6_);
	_g_object_unref0 (_tmp3_);
	is_muc_mam = _tmp7_;
	_tmp8_ = xmpp_stanza_get_from ((XmppStanza*) message);
	_tmp9_ = _tmp8_;
	_tmp10_ = _tmp9_;
	_tmp11_ = dino_entities_account_get_bare_jid (account);
	_tmp12_ = _tmp11_;
	_tmp13_ = _tmp12_;
	_tmp14_ = xmpp_jid_equals_bare (_tmp10_, _tmp13_);
	_xmpp_jid_unref0 (_tmp13_);
	_xmpp_jid_unref0 (_tmp10_);
	from_our_server = _tmp14_;
	if (!is_muc_mam) {
		_tmp15_ = !from_our_server;
	} else {
		_tmp15_ = FALSE;
	}
	if (_tmp15_) {
		return;
	}
	_tmp16_ = ((XmppStanza*) message)->stanza;
	_tmp17_ = xmpp_stanza_node_get_deep_attribute (_tmp16_, XMPP_MESSAGE_ARCHIVE_MANAGEMENT_NS_URI ":result", "id", NULL);
	_tmp18_ = g_strdup (_tmp17_);
	id = _tmp18_;
	_tmp19_ = id;
	if (_tmp19_ == NULL) {
		_g_free0 (id);
		return;
	}
	_tmp20_ = ((XmppStanza*) message)->stanza;
	_tmp21_ = xmpp_stanza_node_get_deep_subnode (_tmp20_, XMPP_MESSAGE_ARCHIVE_MANAGEMENT_NS_URI ":result", XMPP_STANZA_FORWARDING_NS_URI ":forwarded", XMPP_XEP_DELAYED_DELIVERY_NS_URI ":delay", NULL);
	delay_node = _tmp21_;
	_tmp22_ = delay_node;
	if (_tmp22_ == NULL) {
		XmppStanzaNode* _tmp23_;
		gchar* _tmp24_;
		gchar* _tmp25_;
		_tmp23_ = ((XmppStanza*) message)->stanza;
		_tmp24_ = xmpp_stanza_entry_to_string ((XmppStanzaEntry*) _tmp23_, 0);
		_tmp25_ = _tmp24_;
		g_warning ("history_sync.vala:97: MAM result did not contain delayed time %s", _tmp25_);
		_g_free0 (_tmp25_);
		_xmpp_stanza_entry_unref0 (delay_node);
		_g_free0 (id);
		return;
	}
	_tmp26_ = delay_node;
	_tmp27_ = xmpp_xep_delayed_delivery_get_time_for_node (_tmp26_);
	time = _tmp27_;
	_tmp28_ = time;
	if (_tmp28_ == NULL) {
		_g_date_time_unref0 (time);
		_xmpp_stanza_entry_unref0 (delay_node);
		_g_free0 (id);
		return;
	}
	_tmp29_ = self->mam_times;
	_tmp30_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp29_, account);
	_tmp31_ = (GeeHashMap*) _tmp30_;
	_tmp32_ = id;
	_tmp33_ = time;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp31_, _tmp32_, _tmp33_);
	_g_object_unref0 (_tmp31_);
	_tmp34_ = ((XmppStanza*) message)->stanza;
	_tmp35_ = xmpp_stanza_node_get_deep_attribute (_tmp34_, XMPP_MESSAGE_ARCHIVE_MANAGEMENT_NS_URI ":result", XMPP_MESSAGE_ARCHIVE_MANAGEMENT_NS_URI ":queryid", NULL);
	_tmp36_ = g_strdup (_tmp35_);
	query_id = _tmp36_;
	_tmp38_ = query_id;
	if (_tmp38_ != NULL) {
		const gchar* _tmp39_;
		GeeHashMap* _tmp40_;
		gpointer _tmp41_;
		gchar* _tmp42_;
		_tmp39_ = id;
		_tmp40_ = self->catchup_until_id;
		_tmp41_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp40_, account);
		_tmp42_ = (gchar*) _tmp41_;
		_tmp37_ = g_strcmp0 (_tmp39_, _tmp42_) == 0;
		_g_free0 (_tmp42_);
	} else {
		_tmp37_ = FALSE;
	}
	if (_tmp37_) {
		XmppJid* _tmp43_;
		XmppJid* _tmp44_;
		XmppJid* _tmp45_;
		gchar* _tmp46_;
		gchar* _tmp47_;
		const gchar* _tmp48_;
		GeeHashMap* _tmp49_;
		const gchar* _tmp50_;
		_tmp43_ = dino_entities_account_get_bare_jid (account);
		_tmp44_ = _tmp43_;
		_tmp45_ = _tmp44_;
		_tmp46_ = xmpp_jid_to_string (_tmp45_);
		_tmp47_ = _tmp46_;
		_tmp48_ = id;
		g_debug ("history_sync.vala:107: [%s] Hitted range (id) %s", _tmp47_, _tmp48_);
		_g_free0 (_tmp47_);
		_xmpp_jid_unref0 (_tmp45_);
		_tmp49_ = self->hitted_range;
		_tmp50_ = query_id;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp49_, _tmp50_, (gpointer) ((gintptr) -2));
	}
	_g_free0 (query_id);
	_g_date_time_unref0 (time);
	_xmpp_stanza_entry_unref0 (delay_node);
	_g_free0 (id);
}

void
dino_history_sync_on_server_id_duplicate (DinoHistorySync* self,
                                          DinoEntitiesAccount* account,
                                          XmppMessageStanza* message_stanza,
                                          DinoEntitiesMessage* message)
{
	XmppMessageArchiveManagementMessageFlag* mam_flag = NULL;
	XmppMessageArchiveManagementMessageFlag* _tmp0_;
	XmppMessageArchiveManagementMessageFlag* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GeeHashMap* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (message_stanza != NULL);
	g_return_if_fail (message != NULL);
	_tmp0_ = xmpp_message_archive_management_message_flag_get_flag (message_stanza);
	mam_flag = _tmp0_;
	_tmp1_ = mam_flag;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (mam_flag);
		return;
	}
	_tmp3_ = self->catchup_until_time;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp3_, account)) {
		XmppMessageArchiveManagementMessageFlag* _tmp4_;
		GDateTime* _tmp5_;
		GDateTime* _tmp6_;
		GeeHashMap* _tmp7_;
		gpointer _tmp8_;
		GDateTime* _tmp9_;
		_tmp4_ = mam_flag;
		_tmp5_ = xmpp_message_archive_management_message_flag_get_server_time (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = self->catchup_until_time;
		_tmp8_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp7_, account);
		_tmp9_ = (GDateTime*) _tmp8_;
		_tmp2_ = g_date_time_compare (_tmp6_, _tmp9_) < 0;
		_g_date_time_unref0 (_tmp9_);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		GeeHashMap* _tmp10_;
		XmppMessageArchiveManagementMessageFlag* _tmp11_;
		const gchar* _tmp12_;
		const gchar* _tmp13_;
		_tmp10_ = self->hitted_range;
		_tmp11_ = mam_flag;
		_tmp12_ = xmpp_message_archive_management_message_flag_get_query_id (_tmp11_);
		_tmp13_ = _tmp12_;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp10_, _tmp13_, (gpointer) ((gintptr) -1));
	}
	_g_object_unref0 (mam_flag);
}

static void
dino_history_sync_fetch_everything_data_free (gpointer _data)
{
	DinoHistorySyncFetchEverythingData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->account);
	_xmpp_jid_unref0 (_data_->mam_server);
	_g_object_unref0 (_data_->cancellable);
	_g_date_time_unref0 (_data_->until_earliest_time);
	_dino_history_sync_unref0 (_data_->self);
	g_slice_free (DinoHistorySyncFetchEverythingData, _data_);
}

static gpointer
_dino_history_sync_ref0 (gpointer self)
{
	return self ? dino_history_sync_ref (self) : NULL;
}

static gpointer
_g_date_time_ref0 (gpointer self)
{
	return self ? g_date_time_ref (self) : NULL;
}

void
dino_history_sync_fetch_everything (DinoHistorySync* self,
                                    DinoEntitiesAccount* account,
                                    XmppJid* mam_server,
                                    GCancellable* cancellable,
                                    GDateTime* until_earliest_time,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_)
{
	DinoHistorySyncFetchEverythingData* _data_;
	DinoHistorySync* _tmp0_;
	DinoEntitiesAccount* _tmp1_;
	XmppJid* _tmp2_;
	GCancellable* _tmp3_;
	GDateTime* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (mam_server != NULL);
	g_return_if_fail (until_earliest_time != NULL);
	_data_ = g_slice_new0 (DinoHistorySyncFetchEverythingData);
	_data_->_async_result = g_task_new (NULL, cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_history_sync_fetch_everything_data_free);
	_tmp0_ = _dino_history_sync_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (account);
	_g_object_unref0 (_data_->account);
	_data_->account = _tmp1_;
	_tmp2_ = _xmpp_jid_ref0 (mam_server);
	_xmpp_jid_unref0 (_data_->mam_server);
	_data_->mam_server = _tmp2_;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	_tmp4_ = _g_date_time_ref0 (until_earliest_time);
	_g_date_time_unref0 (_data_->until_earliest_time);
	_data_->until_earliest_time = _tmp4_;
	dino_history_sync_fetch_everything_co (_data_);
}

void
dino_history_sync_fetch_everything_finish (DinoHistorySync* self,
                                           GAsyncResult* _res_)
{
	DinoHistorySyncFetchEverythingData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return;
	}
}

static gchar*
g_date_time_to_string (GDateTime* self)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_date_time_format (self, "%FT%H:%M:%S%z");
	result = _tmp0_;
	return result;
}

static gpointer
_qlite_row_ref0 (gpointer self)
{
	return self ? qlite_row_ref (self) : NULL;
}

static void
dino_history_sync_fetch_everything_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_)
{
	DinoHistorySyncFetchEverythingData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_history_sync_fetch_everything_co (_data_);
}

static gboolean
dino_history_sync_fetch_everything_co (DinoHistorySyncFetchEverythingData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->until_earliest_time != NULL) {
		_data_->_tmp1_ = g_date_time_to_string (_data_->until_earliest_time);
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_tmp3_ = g_strconcat ("(until ", _data_->_tmp2_, ")", NULL);
		_g_free0 (_data_->_tmp0_);
		_data_->_tmp0_ = _data_->_tmp3_;
		_g_free0 (_data_->_tmp2_);
	} else {
		_data_->_tmp4_ = g_strdup ("");
		_g_free0 (_data_->_tmp0_);
		_data_->_tmp0_ = _data_->_tmp4_;
	}
	_data_->_tmp5_ = dino_entities_account_get_bare_jid (_data_->account);
	_data_->_tmp6_ = _data_->_tmp5_;
	_data_->_tmp7_ = _data_->_tmp6_;
	_data_->_tmp8_ = xmpp_jid_to_string (_data_->_tmp7_);
	_data_->_tmp9_ = _data_->_tmp8_;
	_data_->_tmp10_ = xmpp_jid_to_string (_data_->mam_server);
	_data_->_tmp11_ = _data_->_tmp10_;
	g_debug ("history_sync.vala:124: [%s | %s] Fetch everything %s", _data_->_tmp9_, _data_->_tmp11_, _data_->_tmp0_);
	_g_free0 (_data_->_tmp11_);
	_g_free0 (_data_->_tmp9_);
	_xmpp_jid_unref0 (_data_->_tmp7_);
	_data_->_tmp12_ = _data_->self->priv->db;
	_data_->_tmp13_ = dino_database_get_mam_catchup (_data_->_tmp12_);
	_data_->_tmp14_ = _data_->_tmp13_;
	_data_->_tmp15_ = qlite_table_select ((QliteTable*) _data_->_tmp14_, NULL, (gint) 0);
	_data_->_tmp16_ = _data_->_tmp15_;
	_data_->_tmp17_ = _data_->self->priv->db;
	_data_->_tmp18_ = dino_database_get_mam_catchup (_data_->_tmp17_);
	_data_->_tmp19_ = _data_->_tmp18_;
	_data_->_tmp20_ = _data_->_tmp19_->account_id;
	_data_->_tmp21_ = dino_entities_account_get_id (_data_->account);
	_data_->_tmp22_ = _data_->_tmp21_;
	_data_->_tmp23_ = qlite_query_builder_with (_data_->_tmp16_, G_TYPE_INT, NULL, NULL, _data_->_tmp20_, "=", (gpointer) ((gintptr) _data_->_tmp22_));
	_data_->_tmp24_ = _data_->_tmp23_;
	_data_->_tmp25_ = _data_->self->priv->db;
	_data_->_tmp26_ = dino_database_get_mam_catchup (_data_->_tmp25_);
	_data_->_tmp27_ = _data_->_tmp26_;
	_data_->_tmp28_ = _data_->_tmp27_->server_jid;
	_data_->_tmp29_ = xmpp_jid_to_string (_data_->mam_server);
	_data_->_tmp30_ = _data_->_tmp29_;
	_data_->_tmp31_ = qlite_query_builder_with (_data_->_tmp24_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp28_, "=", _data_->_tmp30_);
	_data_->_tmp32_ = _data_->_tmp31_;
	_data_->_tmp33_ = _data_->self->priv->db;
	_data_->_tmp34_ = dino_database_get_mam_catchup (_data_->_tmp33_);
	_data_->_tmp35_ = _data_->_tmp34_;
	_data_->_tmp36_ = _data_->_tmp35_->to_time;
	_data_->_tmp37_ = qlite_query_builder_with (_data_->_tmp32_, G_TYPE_LONG, NULL, NULL, _data_->_tmp36_, ">=", (gpointer) ((gintptr) g_date_time_to_unix (_data_->until_earliest_time)));
	_data_->_tmp38_ = _data_->_tmp37_;
	_data_->_tmp39_ = _data_->self->priv->db;
	_data_->_tmp40_ = dino_database_get_mam_catchup (_data_->_tmp39_);
	_data_->_tmp41_ = _data_->_tmp40_;
	_data_->_tmp42_ = _data_->_tmp41_->to_time;
	_data_->_tmp43_ = qlite_query_builder_order_by (_data_->_tmp38_, _data_->_tmp42_, "DESC");
	_data_->_tmp44_ = _data_->_tmp43_;
	_data_->_tmp45_ = qlite_query_builder_single (_data_->_tmp44_);
	_data_->_tmp46_ = _data_->_tmp45_;
	_data_->_tmp47_ = qlite_query_builder_row (_data_->_tmp46_);
	_data_->_tmp48_ = _data_->_tmp47_;
	_qlite_statement_builder_unref0 (_data_->_tmp46_);
	_qlite_statement_builder_unref0 (_data_->_tmp44_);
	_qlite_statement_builder_unref0 (_data_->_tmp38_);
	_qlite_statement_builder_unref0 (_data_->_tmp32_);
	_g_free0 (_data_->_tmp30_);
	_qlite_statement_builder_unref0 (_data_->_tmp24_);
	_qlite_statement_builder_unref0 (_data_->_tmp16_);
	_data_->latest_row_opt = _data_->_tmp48_;
	_data_->_tmp50_ = _data_->latest_row_opt;
	if (qlite_row_option_is_present (_data_->_tmp50_)) {
		_data_->_tmp51_ = _data_->latest_row_opt;
		_data_->_tmp52_ = qlite_row_option_get_inner (_data_->_tmp51_);
		_data_->_tmp53_ = _data_->_tmp52_;
		_data_->_tmp49_ = _data_->_tmp53_;
	} else {
		_data_->_tmp49_ = NULL;
	}
	_data_->_tmp54_ = _qlite_row_ref0 (_data_->_tmp49_);
	_data_->latest_row = _data_->_tmp54_;
	_data_->_tmp55_ = _data_->latest_row;
	_data_->_state_ = 1;
	dino_history_sync_fetch_latest_page (_data_->self, _data_->account, _data_->mam_server, _data_->_tmp55_, _data_->until_earliest_time, _data_->cancellable, dino_history_sync_fetch_everything_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp56_ = dino_history_sync_fetch_latest_page_finish (_data_->self, _data_->_res_);
	_data_->new_row = _data_->_tmp56_;
	_data_->_tmp57_ = _data_->new_row;
	if (_data_->_tmp57_ != NULL) {
		_data_->_tmp58_ = _data_->self->current_catchup_id;
		_data_->_tmp59_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp58_, _data_->account);
		_data_->_tmp60_ = (GeeHashMap*) _data_->_tmp59_;
		_data_->_tmp61_ = _data_->new_row;
		_data_->_tmp62_ = _data_->self->priv->db;
		_data_->_tmp63_ = dino_database_get_mam_catchup (_data_->_tmp62_);
		_data_->_tmp64_ = _data_->_tmp63_;
		_data_->_tmp65_ = _data_->_tmp64_->id;
		_data_->_tmp66_ = qlite_row_get (_data_->_tmp61_, G_TYPE_INT, NULL, NULL, _data_->_tmp65_);
		gee_abstract_map_set ((GeeAbstractMap*) _data_->_tmp60_, _data_->mam_server, (gpointer) ((gintptr) _data_->_tmp66_));
		_g_object_unref0 (_data_->_tmp60_);
	} else {
		_data_->_tmp67_ = _data_->latest_row;
		if (_data_->_tmp67_ != NULL) {
			_data_->_tmp68_ = _data_->self->current_catchup_id;
			_data_->_tmp69_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp68_, _data_->account);
			_data_->_tmp70_ = (GeeHashMap*) _data_->_tmp69_;
			_data_->_tmp71_ = _data_->latest_row;
			_data_->_tmp72_ = _data_->self->priv->db;
			_data_->_tmp73_ = dino_database_get_mam_catchup (_data_->_tmp72_);
			_data_->_tmp74_ = _data_->_tmp73_;
			_data_->_tmp75_ = _data_->_tmp74_->id;
			_data_->_tmp76_ = qlite_row_get (_data_->_tmp71_, G_TYPE_INT, NULL, NULL, _data_->_tmp75_);
			gee_abstract_map_set ((GeeAbstractMap*) _data_->_tmp70_, _data_->mam_server, (gpointer) ((gintptr) _data_->_tmp76_));
			_g_object_unref0 (_data_->_tmp70_);
		}
	}
	_data_->previous_row = NULL;
	_data_->current_row = NULL;
	_data_->_tmp77_ = _data_->new_row;
	if (_data_->_tmp77_ != NULL) {
		_data_->_tmp78_ = _data_->new_row;
		_data_->_tmp79_ = _qlite_row_ref0 (_data_->_tmp78_);
		_qlite_row_unref0 (_data_->current_row);
		_data_->current_row = _data_->_tmp79_;
		_data_->_tmp80_ = _data_->latest_row;
		_data_->_tmp81_ = _qlite_row_ref0 (_data_->_tmp80_);
		_qlite_row_unref0 (_data_->previous_row);
		_data_->previous_row = _data_->_tmp81_;
	} else {
		_data_->_tmp82_ = _data_->latest_row;
		if (_data_->_tmp82_ != NULL) {
			_data_->_tmp83_ = _data_->latest_row;
			_data_->_tmp84_ = _qlite_row_ref0 (_data_->_tmp83_);
			_qlite_row_unref0 (_data_->current_row);
			_data_->current_row = _data_->_tmp84_;
			_data_->_tmp85_ = _data_->self->priv->db;
			_data_->_tmp86_ = dino_database_get_mam_catchup (_data_->_tmp85_);
			_data_->_tmp87_ = _data_->_tmp86_;
			_data_->_tmp88_ = qlite_table_select ((QliteTable*) _data_->_tmp87_, NULL, (gint) 0);
			_data_->_tmp89_ = _data_->_tmp88_;
			_data_->_tmp90_ = _data_->self->priv->db;
			_data_->_tmp91_ = dino_database_get_mam_catchup (_data_->_tmp90_);
			_data_->_tmp92_ = _data_->_tmp91_;
			_data_->_tmp93_ = _data_->_tmp92_->account_id;
			_data_->_tmp94_ = dino_entities_account_get_id (_data_->account);
			_data_->_tmp95_ = _data_->_tmp94_;
			_data_->_tmp96_ = qlite_query_builder_with (_data_->_tmp89_, G_TYPE_INT, NULL, NULL, _data_->_tmp93_, "=", (gpointer) ((gintptr) _data_->_tmp95_));
			_data_->_tmp97_ = _data_->_tmp96_;
			_data_->_tmp98_ = _data_->self->priv->db;
			_data_->_tmp99_ = dino_database_get_mam_catchup (_data_->_tmp98_);
			_data_->_tmp100_ = _data_->_tmp99_;
			_data_->_tmp101_ = _data_->_tmp100_->server_jid;
			_data_->_tmp102_ = xmpp_jid_to_string (_data_->mam_server);
			_data_->_tmp103_ = _data_->_tmp102_;
			_data_->_tmp104_ = qlite_query_builder_with (_data_->_tmp97_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp101_, "=", _data_->_tmp103_);
			_data_->_tmp105_ = _data_->_tmp104_;
			_data_->_tmp106_ = _data_->self->priv->db;
			_data_->_tmp107_ = dino_database_get_mam_catchup (_data_->_tmp106_);
			_data_->_tmp108_ = _data_->_tmp107_;
			_data_->_tmp109_ = _data_->_tmp108_->to_time;
			_data_->_tmp110_ = _data_->current_row;
			_data_->_tmp111_ = _data_->self->priv->db;
			_data_->_tmp112_ = dino_database_get_mam_catchup (_data_->_tmp111_);
			_data_->_tmp113_ = _data_->_tmp112_;
			_data_->_tmp114_ = _data_->_tmp113_->from_time;
			_data_->_tmp115_ = qlite_row_get (_data_->_tmp110_, G_TYPE_LONG, NULL, NULL, _data_->_tmp114_);
			_data_->_tmp116_ = qlite_query_builder_with (_data_->_tmp105_, G_TYPE_LONG, NULL, NULL, _data_->_tmp109_, "<", (gpointer) ((gintptr) _data_->_tmp115_));
			_data_->_tmp117_ = _data_->_tmp116_;
			_data_->_tmp118_ = _data_->self->priv->db;
			_data_->_tmp119_ = dino_database_get_mam_catchup (_data_->_tmp118_);
			_data_->_tmp120_ = _data_->_tmp119_;
			_data_->_tmp121_ = _data_->_tmp120_->to_time;
			_data_->_tmp122_ = qlite_query_builder_with (_data_->_tmp117_, G_TYPE_LONG, NULL, NULL, _data_->_tmp121_, ">=", (gpointer) ((gintptr) g_date_time_to_unix (_data_->until_earliest_time)));
			_data_->_tmp123_ = _data_->_tmp122_;
			_data_->_tmp124_ = _data_->self->priv->db;
			_data_->_tmp125_ = dino_database_get_mam_catchup (_data_->_tmp124_);
			_data_->_tmp126_ = _data_->_tmp125_;
			_data_->_tmp127_ = _data_->_tmp126_->to_time;
			_data_->_tmp128_ = qlite_query_builder_order_by (_data_->_tmp123_, _data_->_tmp127_, "DESC");
			_data_->_tmp129_ = _data_->_tmp128_;
			_data_->_tmp130_ = qlite_query_builder_single (_data_->_tmp129_);
			_data_->_tmp131_ = _data_->_tmp130_;
			_data_->_tmp132_ = qlite_query_builder_row (_data_->_tmp131_);
			_data_->_tmp133_ = _data_->_tmp132_;
			_qlite_statement_builder_unref0 (_data_->_tmp131_);
			_qlite_statement_builder_unref0 (_data_->_tmp129_);
			_qlite_statement_builder_unref0 (_data_->_tmp123_);
			_qlite_statement_builder_unref0 (_data_->_tmp117_);
			_qlite_statement_builder_unref0 (_data_->_tmp105_);
			_g_free0 (_data_->_tmp103_);
			_qlite_statement_builder_unref0 (_data_->_tmp97_);
			_qlite_statement_builder_unref0 (_data_->_tmp89_);
			_data_->previous_row_opt = _data_->_tmp133_;
			_data_->_tmp135_ = _data_->previous_row_opt;
			if (qlite_row_option_is_present (_data_->_tmp135_)) {
				_data_->_tmp136_ = _data_->previous_row_opt;
				_data_->_tmp137_ = qlite_row_option_get_inner (_data_->_tmp136_);
				_data_->_tmp138_ = _data_->_tmp137_;
				_data_->_tmp134_ = _data_->_tmp138_;
			} else {
				_data_->_tmp134_ = NULL;
			}
			_data_->_tmp139_ = _qlite_row_ref0 (_data_->_tmp134_);
			_qlite_row_unref0 (_data_->previous_row);
			_data_->previous_row = _data_->_tmp139_;
			_qlite_row_option_unref0 (_data_->previous_row_opt);
		}
	}
	while (TRUE) {
		_data_->_tmp141_ = _data_->current_row;
		if (_data_->_tmp141_ != NULL) {
			_data_->_tmp142_ = _data_->previous_row;
			_data_->_tmp140_ = _data_->_tmp142_ != NULL;
		} else {
			_data_->_tmp140_ = FALSE;
		}
		if (!_data_->_tmp140_) {
			break;
		}
		_data_->_tmp143_ = _data_->current_row;
		_data_->_tmp144_ = _data_->self->priv->db;
		_data_->_tmp145_ = dino_database_get_mam_catchup (_data_->_tmp144_);
		_data_->_tmp146_ = _data_->_tmp145_;
		_data_->_tmp147_ = _data_->_tmp146_->from_end;
		_data_->_tmp148_ = qlite_row_get (_data_->_tmp143_, G_TYPE_BOOLEAN, NULL, NULL, _data_->_tmp147_);
		if ((gboolean) ((gintptr) _data_->_tmp148_)) {
			_data_->_tmp149_ = dino_entities_account_get_bare_jid (_data_->account);
			_data_->_tmp150_ = _data_->_tmp149_;
			_data_->_tmp151_ = _data_->_tmp150_;
			_data_->_tmp152_ = xmpp_jid_to_string (_data_->_tmp151_);
			_data_->_tmp153_ = _data_->_tmp152_;
			_data_->_tmp154_ = xmpp_jid_to_string (_data_->mam_server);
			_data_->_tmp155_ = _data_->_tmp154_;
			_data_->_tmp156_ = _data_->current_row;
			_data_->_tmp157_ = _data_->self->priv->db;
			_data_->_tmp158_ = dino_database_get_mam_catchup (_data_->_tmp157_);
			_data_->_tmp159_ = _data_->_tmp158_;
			_data_->_tmp160_ = _data_->_tmp159_->from_time;
			_data_->_tmp161_ = qlite_row_get (_data_->_tmp156_, G_TYPE_LONG, NULL, NULL, _data_->_tmp160_);
			_data_->_tmp162_ = g_strdup_printf ("%li", (glong) ((gintptr) _data_->_tmp161_));
			_data_->_tmp163_ = _data_->_tmp162_;
			g_debug ("history_sync.vala:162: [%s | %s] No logs on server before %s, aborting" \
" sync.", _data_->_tmp153_, _data_->_tmp155_, _data_->_tmp163_);
			_g_free0 (_data_->_tmp163_);
			_g_free0 (_data_->_tmp155_);
			_g_free0 (_data_->_tmp153_);
			_xmpp_jid_unref0 (_data_->_tmp151_);
			_qlite_row_unref0 (_data_->current_row);
			_qlite_row_unref0 (_data_->previous_row);
			_qlite_row_unref0 (_data_->new_row);
			_qlite_row_unref0 (_data_->latest_row);
			_qlite_row_option_unref0 (_data_->latest_row_opt);
			_g_free0 (_data_->_tmp0_);
			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_->_tmp164_ = dino_entities_account_get_bare_jid (_data_->account);
		_data_->_tmp165_ = _data_->_tmp164_;
		_data_->_tmp166_ = _data_->_tmp165_;
		_data_->_tmp167_ = xmpp_jid_to_string (_data_->_tmp166_);
		_data_->_tmp168_ = _data_->_tmp167_;
		_data_->_tmp169_ = xmpp_jid_to_string (_data_->mam_server);
		_data_->_tmp170_ = _data_->_tmp169_;
		_data_->_tmp171_ = _data_->previous_row;
		_data_->_tmp172_ = _data_->self->priv->db;
		_data_->_tmp173_ = dino_database_get_mam_catchup (_data_->_tmp172_);
		_data_->_tmp174_ = _data_->_tmp173_;
		_data_->_tmp175_ = _data_->_tmp174_->to_time;
		_data_->_tmp176_ = qlite_row_get (_data_->_tmp171_, G_TYPE_LONG, NULL, NULL, _data_->_tmp175_);
		_data_->_tmp177_ = g_strdup_printf ("%li", (glong) ((gintptr) _data_->_tmp176_));
		_data_->_tmp178_ = _data_->_tmp177_;
		_data_->_tmp179_ = _data_->current_row;
		_data_->_tmp180_ = _data_->self->priv->db;
		_data_->_tmp181_ = dino_database_get_mam_catchup (_data_->_tmp180_);
		_data_->_tmp182_ = _data_->_tmp181_;
		_data_->_tmp183_ = _data_->_tmp182_->from_time;
		_data_->_tmp184_ = qlite_row_get (_data_->_tmp179_, G_TYPE_LONG, NULL, NULL, _data_->_tmp183_);
		_data_->_tmp185_ = g_strdup_printf ("%li", (glong) ((gintptr) _data_->_tmp184_));
		_data_->_tmp186_ = _data_->_tmp185_;
		g_debug ("history_sync.vala:166: [%s | %s] Fetching between ranges %s - %s", _data_->_tmp168_, _data_->_tmp170_, _data_->_tmp178_, _data_->_tmp186_);
		_g_free0 (_data_->_tmp186_);
		_g_free0 (_data_->_tmp178_);
		_g_free0 (_data_->_tmp170_);
		_g_free0 (_data_->_tmp168_);
		_xmpp_jid_unref0 (_data_->_tmp166_);
		_data_->_tmp187_ = _data_->previous_row;
		_data_->_tmp188_ = _data_->current_row;
		_data_->_state_ = 2;
		dino_history_sync_fetch_between_ranges (_data_->self, _data_->account, _data_->mam_server, _data_->_tmp187_, _data_->_tmp188_, _data_->cancellable, dino_history_sync_fetch_everything_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp189_ = dino_history_sync_fetch_between_ranges_finish (_data_->self, _data_->_res_);
		_qlite_row_unref0 (_data_->current_row);
		_data_->current_row = _data_->_tmp189_;
		_data_->_tmp190_ = _data_->current_row;
		if (_data_->_tmp190_ == NULL) {
			_qlite_row_unref0 (_data_->current_row);
			_qlite_row_unref0 (_data_->previous_row);
			_qlite_row_unref0 (_data_->new_row);
			_qlite_row_unref0 (_data_->latest_row);
			_qlite_row_option_unref0 (_data_->latest_row_opt);
			_g_free0 (_data_->_tmp0_);
			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_->_tmp191_ = _data_->self->priv->db;
		_data_->_tmp192_ = dino_database_get_mam_catchup (_data_->_tmp191_);
		_data_->_tmp193_ = _data_->_tmp192_;
		_data_->_tmp194_ = qlite_table_select ((QliteTable*) _data_->_tmp193_, NULL, (gint) 0);
		_data_->_tmp195_ = _data_->_tmp194_;
		_data_->_tmp196_ = _data_->self->priv->db;
		_data_->_tmp197_ = dino_database_get_mam_catchup (_data_->_tmp196_);
		_data_->_tmp198_ = _data_->_tmp197_;
		_data_->_tmp199_ = _data_->_tmp198_->account_id;
		_data_->_tmp200_ = dino_entities_account_get_id (_data_->account);
		_data_->_tmp201_ = _data_->_tmp200_;
		_data_->_tmp202_ = qlite_query_builder_with (_data_->_tmp195_, G_TYPE_INT, NULL, NULL, _data_->_tmp199_, "=", (gpointer) ((gintptr) _data_->_tmp201_));
		_data_->_tmp203_ = _data_->_tmp202_;
		_data_->_tmp204_ = _data_->self->priv->db;
		_data_->_tmp205_ = dino_database_get_mam_catchup (_data_->_tmp204_);
		_data_->_tmp206_ = _data_->_tmp205_;
		_data_->_tmp207_ = _data_->_tmp206_->server_jid;
		_data_->_tmp208_ = xmpp_jid_to_string (_data_->mam_server);
		_data_->_tmp209_ = _data_->_tmp208_;
		_data_->_tmp210_ = qlite_query_builder_with (_data_->_tmp203_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp207_, "=", _data_->_tmp209_);
		_data_->_tmp211_ = _data_->_tmp210_;
		_data_->_tmp212_ = _data_->self->priv->db;
		_data_->_tmp213_ = dino_database_get_mam_catchup (_data_->_tmp212_);
		_data_->_tmp214_ = _data_->_tmp213_;
		_data_->_tmp215_ = _data_->_tmp214_->to_time;
		_data_->_tmp216_ = _data_->current_row;
		_data_->_tmp217_ = _data_->self->priv->db;
		_data_->_tmp218_ = dino_database_get_mam_catchup (_data_->_tmp217_);
		_data_->_tmp219_ = _data_->_tmp218_;
		_data_->_tmp220_ = _data_->_tmp219_->from_time;
		_data_->_tmp221_ = qlite_row_get (_data_->_tmp216_, G_TYPE_LONG, NULL, NULL, _data_->_tmp220_);
		_data_->_tmp222_ = qlite_query_builder_with (_data_->_tmp211_, G_TYPE_LONG, NULL, NULL, _data_->_tmp215_, "<", (gpointer) ((gintptr) _data_->_tmp221_));
		_data_->_tmp223_ = _data_->_tmp222_;
		_data_->_tmp224_ = _data_->self->priv->db;
		_data_->_tmp225_ = dino_database_get_mam_catchup (_data_->_tmp224_);
		_data_->_tmp226_ = _data_->_tmp225_;
		_data_->_tmp227_ = _data_->_tmp226_->to_time;
		_data_->_tmp228_ = qlite_query_builder_with (_data_->_tmp223_, G_TYPE_LONG, NULL, NULL, _data_->_tmp227_, ">=", (gpointer) ((gintptr) g_date_time_to_unix (_data_->until_earliest_time)));
		_data_->_tmp229_ = _data_->_tmp228_;
		_data_->_tmp230_ = _data_->self->priv->db;
		_data_->_tmp231_ = dino_database_get_mam_catchup (_data_->_tmp230_);
		_data_->_tmp232_ = _data_->_tmp231_;
		_data_->_tmp233_ = _data_->_tmp232_->to_time;
		_data_->_tmp234_ = qlite_query_builder_order_by (_data_->_tmp229_, _data_->_tmp233_, "DESC");
		_data_->_tmp235_ = _data_->_tmp234_;
		_data_->_tmp236_ = qlite_query_builder_single (_data_->_tmp235_);
		_data_->_tmp237_ = _data_->_tmp236_;
		_data_->_tmp238_ = qlite_query_builder_row (_data_->_tmp237_);
		_data_->_tmp239_ = _data_->_tmp238_;
		_qlite_statement_builder_unref0 (_data_->_tmp237_);
		_qlite_statement_builder_unref0 (_data_->_tmp235_);
		_qlite_statement_builder_unref0 (_data_->_tmp229_);
		_qlite_statement_builder_unref0 (_data_->_tmp223_);
		_qlite_statement_builder_unref0 (_data_->_tmp211_);
		_g_free0 (_data_->_tmp209_);
		_qlite_statement_builder_unref0 (_data_->_tmp203_);
		_qlite_statement_builder_unref0 (_data_->_tmp195_);
		_data_->_vala1_previous_row_opt = _data_->_tmp239_;
		_data_->_tmp241_ = _data_->_vala1_previous_row_opt;
		if (qlite_row_option_is_present (_data_->_tmp241_)) {
			_data_->_tmp242_ = _data_->_vala1_previous_row_opt;
			_data_->_tmp243_ = qlite_row_option_get_inner (_data_->_tmp242_);
			_data_->_tmp244_ = _data_->_tmp243_;
			_data_->_tmp240_ = _data_->_tmp244_;
		} else {
			_data_->_tmp240_ = NULL;
		}
		_data_->_tmp245_ = _qlite_row_ref0 (_data_->_tmp240_);
		_qlite_row_unref0 (_data_->previous_row);
		_data_->previous_row = _data_->_tmp245_;
		_qlite_row_option_unref0 (_data_->_vala1_previous_row_opt);
	}
	_data_->_tmp246_ = _data_->current_row;
	if (_data_->_tmp246_ == NULL) {
		_data_->_tmp247_ = dino_entities_account_get_bare_jid (_data_->account);
		_data_->_tmp248_ = _data_->_tmp247_;
		_data_->_tmp249_ = _data_->_tmp248_;
		_data_->_tmp250_ = xmpp_jid_to_string (_data_->_tmp249_);
		_data_->_tmp251_ = _data_->_tmp250_;
		_data_->_tmp252_ = xmpp_jid_to_string (_data_->mam_server);
		_data_->_tmp253_ = _data_->_tmp252_;
		g_debug ("history_sync.vala:182: [%s | %s] No current range, aborting sync.", _data_->_tmp251_, _data_->_tmp253_);
		_g_free0 (_data_->_tmp253_);
		_g_free0 (_data_->_tmp251_);
		_xmpp_jid_unref0 (_data_->_tmp249_);
		_qlite_row_unref0 (_data_->current_row);
		_qlite_row_unref0 (_data_->previous_row);
		_qlite_row_unref0 (_data_->new_row);
		_qlite_row_unref0 (_data_->latest_row);
		_qlite_row_option_unref0 (_data_->latest_row_opt);
		_g_free0 (_data_->_tmp0_);
		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;
	} else {
		_data_->_tmp254_ = _data_->current_row;
		_data_->_tmp255_ = _data_->self->priv->db;
		_data_->_tmp256_ = dino_database_get_mam_catchup (_data_->_tmp255_);
		_data_->_tmp257_ = _data_->_tmp256_;
		_data_->_tmp258_ = _data_->_tmp257_->from_end;
		_data_->_tmp259_ = qlite_row_get (_data_->_tmp254_, G_TYPE_BOOLEAN, NULL, NULL, _data_->_tmp258_);
		if ((gboolean) ((gintptr) _data_->_tmp259_)) {
			_data_->_tmp260_ = dino_entities_account_get_bare_jid (_data_->account);
			_data_->_tmp261_ = _data_->_tmp260_;
			_data_->_tmp262_ = _data_->_tmp261_;
			_data_->_tmp263_ = xmpp_jid_to_string (_data_->_tmp262_);
			_data_->_tmp264_ = _data_->_tmp263_;
			_data_->_tmp265_ = xmpp_jid_to_string (_data_->mam_server);
			_data_->_tmp266_ = _data_->_tmp265_;
			_data_->_tmp267_ = _data_->current_row;
			_data_->_tmp268_ = _data_->self->priv->db;
			_data_->_tmp269_ = dino_database_get_mam_catchup (_data_->_tmp268_);
			_data_->_tmp270_ = _data_->_tmp269_;
			_data_->_tmp271_ = _data_->_tmp270_->from_time;
			_data_->_tmp272_ = qlite_row_get (_data_->_tmp267_, G_TYPE_LONG, NULL, NULL, _data_->_tmp271_);
			_data_->_tmp273_ = g_strdup_printf ("%li", (glong) ((gintptr) _data_->_tmp272_));
			_data_->_tmp274_ = _data_->_tmp273_;
			g_debug ("history_sync.vala:185: [%s | %s] No logs on server before %s, aborting" \
" sync.", _data_->_tmp264_, _data_->_tmp266_, _data_->_tmp274_);
			_g_free0 (_data_->_tmp274_);
			_g_free0 (_data_->_tmp266_);
			_g_free0 (_data_->_tmp264_);
			_xmpp_jid_unref0 (_data_->_tmp262_);
			_qlite_row_unref0 (_data_->current_row);
			_qlite_row_unref0 (_data_->previous_row);
			_qlite_row_unref0 (_data_->new_row);
			_qlite_row_unref0 (_data_->latest_row);
			_qlite_row_option_unref0 (_data_->latest_row_opt);
			_g_free0 (_data_->_tmp0_);
			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;
		}
	}
	if (_data_->until_earliest_time != NULL) {
		_data_->_tmp276_ = _data_->current_row;
		_data_->_tmp277_ = _data_->self->priv->db;
		_data_->_tmp278_ = dino_database_get_mam_catchup (_data_->_tmp277_);
		_data_->_tmp279_ = _data_->_tmp278_;
		_data_->_tmp280_ = _data_->_tmp279_->from_time;
		_data_->_tmp281_ = qlite_row_get (_data_->_tmp276_, G_TYPE_LONG, NULL, NULL, _data_->_tmp280_);
		_data_->_tmp275_ = ((gint64) ((glong) ((gintptr) _data_->_tmp281_))) <= g_date_time_to_unix (_data_->until_earliest_time);
	} else {
		_data_->_tmp275_ = FALSE;
	}
	if (_data_->_tmp275_) {
		_data_->_tmp282_ = dino_entities_account_get_bare_jid (_data_->account);
		_data_->_tmp283_ = _data_->_tmp282_;
		_data_->_tmp284_ = _data_->_tmp283_;
		_data_->_tmp285_ = xmpp_jid_to_string (_data_->_tmp284_);
		_data_->_tmp286_ = _data_->_tmp285_;
		_data_->_tmp287_ = xmpp_jid_to_string (_data_->mam_server);
		_data_->_tmp288_ = _data_->_tmp287_;
		_data_->_tmp289_ = _data_->current_row;
		_data_->_tmp290_ = _data_->self->priv->db;
		_data_->_tmp291_ = dino_database_get_mam_catchup (_data_->_tmp290_);
		_data_->_tmp292_ = _data_->_tmp291_;
		_data_->_tmp293_ = _data_->_tmp292_->from_time;
		_data_->_tmp294_ = qlite_row_get (_data_->_tmp289_, G_TYPE_LONG, NULL, NULL, _data_->_tmp293_);
		_data_->_tmp295_ = g_strdup_printf ("%li", (glong) ((gintptr) _data_->_tmp294_));
		_data_->_tmp296_ = _data_->_tmp295_;
		_data_->_tmp297_ = g_strdup_printf ("%" G_GINT64_FORMAT, g_date_time_to_unix (_data_->until_earliest_time));
		_data_->_tmp298_ = _data_->_tmp297_;
		g_debug ("history_sync.vala:191: [%s | %s] Current range starting %s is before l" \
"imit %s, aborting sync.", _data_->_tmp286_, _data_->_tmp288_, _data_->_tmp296_, _data_->_tmp298_);
		_g_free0 (_data_->_tmp298_);
		_g_free0 (_data_->_tmp296_);
		_g_free0 (_data_->_tmp288_);
		_g_free0 (_data_->_tmp286_);
		_xmpp_jid_unref0 (_data_->_tmp284_);
		_qlite_row_unref0 (_data_->current_row);
		_qlite_row_unref0 (_data_->previous_row);
		_qlite_row_unref0 (_data_->new_row);
		_qlite_row_unref0 (_data_->latest_row);
		_qlite_row_option_unref0 (_data_->latest_row_opt);
		_g_free0 (_data_->_tmp0_);
		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_->_tmp299_ = _data_->current_row;
	_data_->_state_ = 3;
	dino_history_sync_fetch_before_range (_data_->self, _data_->account, _data_->mam_server, _data_->_tmp299_, _data_->until_earliest_time, NULL, dino_history_sync_fetch_everything_ready, _data_);
	return FALSE;
	_state_3:
	dino_history_sync_fetch_before_range_finish (_data_->self, _data_->_res_);
	_qlite_row_unref0 (_data_->current_row);
	_qlite_row_unref0 (_data_->previous_row);
	_qlite_row_unref0 (_data_->new_row);
	_qlite_row_unref0 (_data_->latest_row);
	_qlite_row_option_unref0 (_data_->latest_row_opt);
	_g_free0 (_data_->_tmp0_);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
dino_history_sync_fetch_latest_page_data_free (gpointer _data)
{
	DinoHistorySyncFetchLatestPageData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->account);
	_xmpp_jid_unref0 (_data_->mam_server);
	_qlite_row_unref0 (_data_->latest_row);
	_g_date_time_unref0 (_data_->until_earliest_time);
	_g_object_unref0 (_data_->cancellable);
	_qlite_row_unref0 (_data_->result);
	_dino_history_sync_unref0 (_data_->self);
	g_slice_free (DinoHistorySyncFetchLatestPageData, _data_);
}

void
dino_history_sync_fetch_latest_page (DinoHistorySync* self,
                                     DinoEntitiesAccount* account,
                                     XmppJid* mam_server,
                                     QliteRow* latest_row,
                                     GDateTime* until_earliest_time,
                                     GCancellable* cancellable,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_)
{
	DinoHistorySyncFetchLatestPageData* _data_;
	DinoHistorySync* _tmp0_;
	DinoEntitiesAccount* _tmp1_;
	XmppJid* _tmp2_;
	QliteRow* _tmp3_;
	GDateTime* _tmp4_;
	GCancellable* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (mam_server != NULL);
	_data_ = g_slice_new0 (DinoHistorySyncFetchLatestPageData);
	_data_->_async_result = g_task_new (NULL, cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_history_sync_fetch_latest_page_data_free);
	_tmp0_ = _dino_history_sync_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (account);
	_g_object_unref0 (_data_->account);
	_data_->account = _tmp1_;
	_tmp2_ = _xmpp_jid_ref0 (mam_server);
	_xmpp_jid_unref0 (_data_->mam_server);
	_data_->mam_server = _tmp2_;
	_tmp3_ = _qlite_row_ref0 (latest_row);
	_qlite_row_unref0 (_data_->latest_row);
	_data_->latest_row = _tmp3_;
	_tmp4_ = _g_date_time_ref0 (until_earliest_time);
	_g_date_time_unref0 (_data_->until_earliest_time);
	_data_->until_earliest_time = _tmp4_;
	_tmp5_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp5_;
	dino_history_sync_fetch_latest_page_co (_data_);
}

QliteRow*
dino_history_sync_fetch_latest_page_finish (DinoHistorySync* self,
                                            GAsyncResult* _res_)
{
	QliteRow* result;
	DinoHistorySyncFetchLatestPageData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
dino_history_sync_fetch_latest_page_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_)
{
	DinoHistorySyncFetchLatestPageData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_history_sync_fetch_latest_page_co (_data_);
}

static gboolean
_vala_dino_history_sync_page_result_array_contains (DinoHistorySyncPageResult * stack,
                                                    gssize stack_length,
                                                    const DinoHistorySyncPageResult needle)
{
	gssize i;
	for (i = 0; i < stack_length; i++) {
		if (needle == stack[i]) {
			return TRUE;
		}
	}
	return FALSE;
}

static gboolean
dino_history_sync_fetch_latest_page_co (DinoHistorySyncFetchLatestPageData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = dino_entities_account_get_bare_jid (_data_->account);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = _data_->_tmp1_;
	_data_->_tmp3_ = xmpp_jid_to_string (_data_->_tmp2_);
	_data_->_tmp4_ = _data_->_tmp3_;
	_data_->_tmp5_ = xmpp_jid_to_string (_data_->mam_server);
	_data_->_tmp6_ = _data_->_tmp5_;
	g_debug ("history_sync.vala:199: [%s | %s] Fetching latest page", _data_->_tmp4_, _data_->_tmp6_);
	_g_free0 (_data_->_tmp6_);
	_g_free0 (_data_->_tmp4_);
	_xmpp_jid_unref0 (_data_->_tmp2_);
	_data_->latest_row_id = -1;
	_data_->_tmp7_ = _g_date_time_ref0 (_data_->until_earliest_time);
	_data_->latest_message_time = _data_->_tmp7_;
	_data_->latest_message_id = NULL;
	if (_data_->latest_row != NULL) {
		_data_->_tmp8_ = _data_->self->priv->db;
		_data_->_tmp9_ = dino_database_get_mam_catchup (_data_->_tmp8_);
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->_tmp11_ = _data_->_tmp10_->id;
		_data_->_tmp12_ = qlite_row_get (_data_->latest_row, G_TYPE_INT, NULL, NULL, _data_->_tmp11_);
		_data_->latest_row_id = (gint) ((gintptr) _data_->_tmp12_);
		_data_->_tmp13_ = _data_->self->priv->db;
		_data_->_tmp14_ = dino_database_get_mam_catchup (_data_->_tmp13_);
		_data_->_tmp15_ = _data_->_tmp14_;
		_data_->_tmp16_ = _data_->_tmp15_->to_time;
		_data_->_tmp17_ = qlite_row_get (_data_->latest_row, G_TYPE_LONG, NULL, NULL, _data_->_tmp16_);
		_data_->_tmp18_ = g_date_time_new_from_unix_utc ((gint64) ((glong) ((gintptr) _data_->_tmp17_)));
		_data_->_tmp19_ = _data_->_tmp18_;
		_data_->_tmp20_ = g_date_time_add_minutes (_data_->_tmp19_, -5);
		_g_date_time_unref0 (_data_->latest_message_time);
		_data_->latest_message_time = _data_->_tmp20_;
		_g_date_time_unref0 (_data_->_tmp19_);
		_data_->_tmp21_ = _data_->self->priv->db;
		_data_->_tmp22_ = dino_database_get_mam_catchup (_data_->_tmp21_);
		_data_->_tmp23_ = _data_->_tmp22_;
		_data_->_tmp24_ = _data_->_tmp23_->to_id;
		_data_->_tmp25_ = qlite_row_get (_data_->latest_row, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp24_);
		_g_free0 (_data_->latest_message_id);
		_data_->latest_message_id = (gchar*) _data_->_tmp25_;
		if (_data_->until_earliest_time != NULL) {
			_data_->_tmp27_ = _data_->latest_message_time;
			_data_->_tmp26_ = g_date_time_compare (_data_->_tmp27_, _data_->until_earliest_time) < 0;
		} else {
			_data_->_tmp26_ = FALSE;
		}
		if (_data_->_tmp26_) {
			_data_->_tmp28_ = g_date_time_add_minutes (_data_->until_earliest_time, -5);
			_g_date_time_unref0 (_data_->latest_message_time);
			_data_->latest_message_time = _data_->_tmp28_;
			_g_free0 (_data_->latest_message_id);
			_data_->latest_message_id = NULL;
		}
	}
	_data_->_tmp29_ = _data_->latest_message_time;
	_data_->_tmp30_ = _data_->latest_message_id;
	_data_->_tmp31_ = xmpp_message_archive_management_v2_mam_query_params_new_query_latest (_data_->mam_server, _data_->_tmp29_, _data_->_tmp30_);
	_data_->query_params = _data_->_tmp31_;
	_data_->_tmp32_ = _data_->query_params;
	_data_->_state_ = 1;
	dino_history_sync_get_mam_page (_data_->self, _data_->account, _data_->_tmp32_, NULL, _data_->cancellable, dino_history_sync_fetch_latest_page_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp33_ = dino_history_sync_get_mam_page_finish (_data_->self, _data_->_res_);
	_data_->page_result = _data_->_tmp33_;
	_data_->_tmp34_ = dino_entities_account_get_bare_jid (_data_->account);
	_data_->_tmp35_ = _data_->_tmp34_;
	_data_->_tmp36_ = _data_->_tmp35_;
	_data_->_tmp37_ = xmpp_jid_to_string (_data_->_tmp36_);
	_data_->_tmp38_ = _data_->_tmp37_;
	_data_->_tmp39_ = xmpp_jid_to_string (_data_->mam_server);
	_data_->_tmp40_ = _data_->_tmp39_;
	_data_->_tmp41_ = _data_->page_result;
	_data_->_tmp42_ = dino_history_sync_page_request_result_get_page_result (_data_->_tmp41_);
	_data_->_tmp43_ = _data_->_tmp42_;
	_data_->_tmp44_ = g_enum_get_value (g_type_class_ref (DINO_HISTORY_SYNC_TYPE_PAGE_RESULT), _data_->_tmp43_);
	g_debug ("history_sync.vala:220: [%s | %s] Latest page result: %s", _data_->_tmp38_, _data_->_tmp40_, (_data_->_tmp44_ != NULL) ? _data_->_tmp44_->value_name : NULL);
	_g_free0 (_data_->_tmp40_);
	_g_free0 (_data_->_tmp38_);
	_xmpp_jid_unref0 (_data_->_tmp36_);
	_data_->_tmp46_ = _data_->page_result;
	_data_->_tmp47_ = dino_history_sync_page_request_result_get_page_result (_data_->_tmp46_);
	_data_->_tmp48_ = _data_->_tmp47_;
	if (_data_->_tmp48_ == DINO_HISTORY_SYNC_PAGE_RESULT_Error) {
		_data_->_tmp45_ = TRUE;
	} else {
		_data_->_tmp49_ = _data_->page_result;
		_data_->_tmp50_ = dino_history_sync_page_request_result_get_page_result (_data_->_tmp49_);
		_data_->_tmp51_ = _data_->_tmp50_;
		_data_->_tmp45_ = _data_->_tmp51_ == DINO_HISTORY_SYNC_PAGE_RESULT_Cancelled;
	}
	if (_data_->_tmp45_) {
		_data_->result = NULL;
		_dino_history_sync_page_request_result_unref0 (_data_->page_result);
		_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
		_g_free0 (_data_->latest_message_id);
		_g_date_time_unref0 (_data_->latest_message_time);
		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;
	}
	if (_data_->latest_row_id != -1) {
		_data_->_tmp53_ = _data_->page_result;
		_data_->_tmp54_ = dino_history_sync_page_request_result_get_page_result (_data_->_tmp53_);
		_data_->_tmp55_ = _data_->_tmp54_;
		_data_->_tmp56_ = g_new0 (DinoHistorySyncPageResult, 2);
		_data_->_tmp56_[0] = DINO_HISTORY_SYNC_PAGE_RESULT_TargetReached;
		_data_->_tmp56_[1] = DINO_HISTORY_SYNC_PAGE_RESULT_NoMoreMessages;
		_data_->_tmp57_ = _data_->_tmp56_;
		_data_->_tmp57__length1 = 2;
		_data_->_tmp52_ = _vala_dino_history_sync_page_result_array_contains (_data_->_tmp57_, 2, _data_->_tmp55_);
		_data_->_tmp57_ = (g_free (_data_->_tmp57_), NULL);
	} else {
		_data_->_tmp52_ = FALSE;
	}
	if (_data_->_tmp52_) {
		_data_->_tmp58_ = _data_->page_result;
		_data_->_tmp59_ = dino_history_sync_page_request_result_get_stanzas (_data_->_tmp58_);
		_data_->_tmp60_ = _data_->_tmp59_;
		if (_data_->_tmp60_ == NULL) {
			_data_->result = NULL;
			_dino_history_sync_page_request_result_unref0 (_data_->page_result);
			_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
			_g_free0 (_data_->latest_message_id);
			_g_date_time_unref0 (_data_->latest_message_time);
			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_->_tmp61_ = _data_->page_result;
		_data_->_tmp62_ = dino_history_sync_page_request_result_get_query_result (_data_->_tmp61_);
		_data_->_tmp63_ = _data_->_tmp62_;
		_data_->_tmp64_ = xmpp_message_archive_management_query_result_get_last (_data_->_tmp63_);
		_data_->_tmp65_ = _data_->_tmp64_;
		_data_->_tmp66_ = g_strdup (_data_->_tmp65_);
		_data_->latest_mam_id = _data_->_tmp66_;
		_data_->_tmp67_ = _data_->self->mam_times;
		_data_->_tmp68_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp67_, _data_->account);
		_data_->_tmp69_ = (GeeHashMap*) _data_->_tmp68_;
		_data_->_tmp70_ = _data_->latest_mam_id;
		_data_->_tmp71_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp69_, _data_->_tmp70_);
		_data_->_tmp72_ = (GDateTime*) _data_->_tmp71_;
		_data_->_tmp73_ = (glong) g_date_time_to_unix (_data_->_tmp72_);
		_g_date_time_unref0 (_data_->_tmp72_);
		_g_object_unref0 (_data_->_tmp69_);
		_data_->latest_mam_time = _data_->_tmp73_;
		_data_->_tmp74_ = _data_->self->priv->db;
		_data_->_tmp75_ = dino_database_get_mam_catchup (_data_->_tmp74_);
		_data_->_tmp76_ = _data_->_tmp75_;
		_data_->_tmp77_ = qlite_table_update ((QliteTable*) _data_->_tmp76_);
		_data_->_tmp78_ = _data_->_tmp77_;
		_data_->_tmp79_ = _data_->self->priv->db;
		_data_->_tmp80_ = dino_database_get_mam_catchup (_data_->_tmp79_);
		_data_->_tmp81_ = _data_->_tmp80_;
		_data_->_tmp82_ = _data_->_tmp81_->id;
		_data_->_tmp83_ = qlite_update_builder_with (_data_->_tmp78_, G_TYPE_INT, NULL, NULL, _data_->_tmp82_, "=", (gpointer) ((gintptr) _data_->latest_row_id));
		_data_->_tmp84_ = _data_->_tmp83_;
		_data_->_tmp85_ = _data_->self->priv->db;
		_data_->_tmp86_ = dino_database_get_mam_catchup (_data_->_tmp85_);
		_data_->_tmp87_ = _data_->_tmp86_;
		_data_->_tmp88_ = _data_->_tmp87_->to_time;
		_data_->_tmp89_ = qlite_update_builder_set (_data_->_tmp84_, G_TYPE_LONG, NULL, NULL, _data_->_tmp88_, (gpointer) ((gintptr) _data_->latest_mam_time));
		_data_->_tmp90_ = _data_->_tmp89_;
		_data_->_tmp91_ = _data_->self->priv->db;
		_data_->_tmp92_ = dino_database_get_mam_catchup (_data_->_tmp91_);
		_data_->_tmp93_ = _data_->_tmp92_;
		_data_->_tmp94_ = _data_->_tmp93_->to_id;
		_data_->_tmp95_ = _data_->latest_mam_id;
		_data_->_tmp96_ = qlite_update_builder_set (_data_->_tmp90_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp94_, _data_->_tmp95_);
		_data_->_tmp97_ = _data_->_tmp96_;
		_qlite_statement_builder_unref0 (_data_->_tmp90_);
		_qlite_statement_builder_unref0 (_data_->_tmp84_);
		_qlite_statement_builder_unref0 (_data_->_tmp78_);
		_data_->query = _data_->_tmp97_;
		_data_->_tmp98_ = _data_->page_result;
		_data_->_tmp99_ = dino_history_sync_page_request_result_get_page_result (_data_->_tmp98_);
		_data_->_tmp100_ = _data_->_tmp99_;
		if (_data_->_tmp100_ == DINO_HISTORY_SYNC_PAGE_RESULT_NoMoreMessages) {
			_data_->_tmp101_ = _data_->query;
			_data_->_tmp102_ = _data_->self->priv->db;
			_data_->_tmp103_ = dino_database_get_mam_catchup (_data_->_tmp102_);
			_data_->_tmp104_ = _data_->_tmp103_;
			_data_->_tmp105_ = _data_->_tmp104_->from_end;
			_data_->_tmp106_ = qlite_update_builder_set (_data_->_tmp101_, G_TYPE_BOOLEAN, NULL, NULL, _data_->_tmp105_, (gpointer) ((gintptr) TRUE));
			_data_->_tmp107_ = _data_->_tmp106_;
			_qlite_statement_builder_unref0 (_data_->_tmp107_);
		}
		_data_->_tmp108_ = _data_->query;
		qlite_update_builder_perform (_data_->_tmp108_);
		_data_->result = NULL;
		_qlite_statement_builder_unref0 (_data_->query);
		_g_free0 (_data_->latest_mam_id);
		_dino_history_sync_page_request_result_unref0 (_data_->page_result);
		_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
		_g_free0 (_data_->latest_message_id);
		_g_date_time_unref0 (_data_->latest_message_time);
		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_->_tmp110_ = _data_->page_result;
	_data_->_tmp111_ = dino_history_sync_page_request_result_get_query_result (_data_->_tmp110_);
	_data_->_tmp112_ = _data_->_tmp111_;
	_data_->_tmp113_ = xmpp_message_archive_management_query_result_get_first (_data_->_tmp112_);
	_data_->_tmp114_ = _data_->_tmp113_;
	if (_data_->_tmp114_ == NULL) {
		_data_->_tmp109_ = TRUE;
	} else {
		_data_->_tmp115_ = _data_->page_result;
		_data_->_tmp116_ = dino_history_sync_page_request_result_get_query_result (_data_->_tmp115_);
		_data_->_tmp117_ = _data_->_tmp116_;
		_data_->_tmp118_ = xmpp_message_archive_management_query_result_get_last (_data_->_tmp117_);
		_data_->_tmp119_ = _data_->_tmp118_;
		_data_->_tmp109_ = _data_->_tmp119_ == NULL;
	}
	if (_data_->_tmp109_) {
		_data_->result = NULL;
		_dino_history_sync_page_request_result_unref0 (_data_->page_result);
		_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
		_g_free0 (_data_->latest_message_id);
		_g_date_time_unref0 (_data_->latest_message_time);
		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_->_tmp120_ = dino_entities_account_get_bare_jid (_data_->account);
	_data_->_tmp121_ = _data_->_tmp120_;
	_data_->_tmp122_ = _data_->_tmp121_;
	_data_->_tmp123_ = xmpp_jid_to_string (_data_->_tmp122_);
	_data_->_tmp124_ = _data_->_tmp123_;
	_data_->_tmp125_ = xmpp_jid_to_string (_data_->mam_server);
	_data_->_tmp126_ = _data_->_tmp125_;
	g_debug ("history_sync.vala:253: [%s | %s] Creating new db range for latest page", _data_->_tmp124_, _data_->_tmp126_);
	_g_free0 (_data_->_tmp126_);
	_g_free0 (_data_->_tmp124_);
	_xmpp_jid_unref0 (_data_->_tmp122_);
	_data_->_tmp127_ = _data_->page_result;
	_data_->_tmp128_ = dino_history_sync_page_request_result_get_query_result (_data_->_tmp127_);
	_data_->_tmp129_ = _data_->_tmp128_;
	_data_->_tmp130_ = xmpp_message_archive_management_query_result_get_first (_data_->_tmp129_);
	_data_->_tmp131_ = _data_->_tmp130_;
	_data_->_tmp132_ = g_strdup (_data_->_tmp131_);
	_data_->from_id = _data_->_tmp132_;
	_data_->_tmp133_ = _data_->page_result;
	_data_->_tmp134_ = dino_history_sync_page_request_result_get_query_result (_data_->_tmp133_);
	_data_->_tmp135_ = _data_->_tmp134_;
	_data_->_tmp136_ = xmpp_message_archive_management_query_result_get_last (_data_->_tmp135_);
	_data_->_tmp137_ = _data_->_tmp136_;
	_data_->_tmp138_ = g_strdup (_data_->_tmp137_);
	_data_->to_id = _data_->_tmp138_;
	_data_->_tmp140_ = _data_->self->mam_times;
	_data_->_tmp141_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp140_, _data_->account);
	_data_->_tmp142_ = (GeeHashMap*) _data_->_tmp141_;
	_data_->_tmp143_ = _data_->from_id;
	_data_->_tmp144_ = !gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp142_, _data_->_tmp143_);
	_g_object_unref0 (_data_->_tmp142_);
	if (_data_->_tmp144_) {
		_data_->_tmp139_ = TRUE;
	} else {
		_data_->_tmp145_ = _data_->self->mam_times;
		_data_->_tmp146_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp145_, _data_->account);
		_data_->_tmp147_ = (GeeHashMap*) _data_->_tmp146_;
		_data_->_tmp148_ = _data_->to_id;
		_data_->_tmp139_ = !gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp147_, _data_->_tmp148_);
		_g_object_unref0 (_data_->_tmp147_);
	}
	if (_data_->_tmp139_) {
		_data_->_tmp149_ = _data_->from_id;
		_data_->_tmp150_ = _data_->to_id;
		g_debug ("history_sync.vala:259: Missing from/to id %s %s", _data_->_tmp149_, _data_->_tmp150_);
		_data_->result = NULL;
		_g_free0 (_data_->to_id);
		_g_free0 (_data_->from_id);
		_dino_history_sync_page_request_result_unref0 (_data_->page_result);
		_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
		_g_free0 (_data_->latest_message_id);
		_g_date_time_unref0 (_data_->latest_message_time);
		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_->_tmp151_ = _data_->self->mam_times;
	_data_->_tmp152_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp151_, _data_->account);
	_data_->_tmp153_ = (GeeHashMap*) _data_->_tmp152_;
	_data_->_tmp154_ = _data_->from_id;
	_data_->_tmp155_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp153_, _data_->_tmp154_);
	_data_->_tmp156_ = (GDateTime*) _data_->_tmp155_;
	_data_->_tmp157_ = (glong) g_date_time_to_unix (_data_->_tmp156_);
	_g_date_time_unref0 (_data_->_tmp156_);
	_g_object_unref0 (_data_->_tmp153_);
	_data_->from_time = _data_->_tmp157_;
	_data_->_tmp158_ = _data_->self->mam_times;
	_data_->_tmp159_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp158_, _data_->account);
	_data_->_tmp160_ = (GeeHashMap*) _data_->_tmp159_;
	_data_->_tmp161_ = _data_->to_id;
	_data_->_tmp162_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp160_, _data_->_tmp161_);
	_data_->_tmp163_ = (GDateTime*) _data_->_tmp162_;
	_data_->_tmp164_ = (glong) g_date_time_to_unix (_data_->_tmp163_);
	_g_date_time_unref0 (_data_->_tmp163_);
	_g_object_unref0 (_data_->_tmp160_);
	_data_->to_time = _data_->_tmp164_;
	_data_->_tmp165_ = _data_->self->priv->db;
	_data_->_tmp166_ = dino_database_get_mam_catchup (_data_->_tmp165_);
	_data_->_tmp167_ = _data_->_tmp166_;
	_data_->_tmp168_ = qlite_table_insert ((QliteTable*) _data_->_tmp167_);
	_data_->_tmp169_ = _data_->_tmp168_;
	_data_->_tmp170_ = _data_->self->priv->db;
	_data_->_tmp171_ = dino_database_get_mam_catchup (_data_->_tmp170_);
	_data_->_tmp172_ = _data_->_tmp171_;
	_data_->_tmp173_ = _data_->_tmp172_->account_id;
	_data_->_tmp174_ = dino_entities_account_get_id (_data_->account);
	_data_->_tmp175_ = _data_->_tmp174_;
	_data_->_tmp176_ = qlite_insert_builder_value (_data_->_tmp169_, G_TYPE_INT, NULL, NULL, _data_->_tmp173_, (gpointer) ((gintptr) _data_->_tmp175_));
	_data_->_tmp177_ = _data_->_tmp176_;
	_data_->_tmp178_ = _data_->self->priv->db;
	_data_->_tmp179_ = dino_database_get_mam_catchup (_data_->_tmp178_);
	_data_->_tmp180_ = _data_->_tmp179_;
	_data_->_tmp181_ = _data_->_tmp180_->server_jid;
	_data_->_tmp182_ = xmpp_jid_to_string (_data_->mam_server);
	_data_->_tmp183_ = _data_->_tmp182_;
	_data_->_tmp184_ = qlite_insert_builder_value (_data_->_tmp177_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp181_, _data_->_tmp183_);
	_data_->_tmp185_ = _data_->_tmp184_;
	_data_->_tmp186_ = _data_->self->priv->db;
	_data_->_tmp187_ = dino_database_get_mam_catchup (_data_->_tmp186_);
	_data_->_tmp188_ = _data_->_tmp187_;
	_data_->_tmp189_ = _data_->_tmp188_->from_id;
	_data_->_tmp190_ = _data_->from_id;
	_data_->_tmp191_ = qlite_insert_builder_value (_data_->_tmp185_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp189_, _data_->_tmp190_);
	_data_->_tmp192_ = _data_->_tmp191_;
	_data_->_tmp193_ = _data_->self->priv->db;
	_data_->_tmp194_ = dino_database_get_mam_catchup (_data_->_tmp193_);
	_data_->_tmp195_ = _data_->_tmp194_;
	_data_->_tmp196_ = _data_->_tmp195_->from_time;
	_data_->_tmp197_ = qlite_insert_builder_value (_data_->_tmp192_, G_TYPE_LONG, NULL, NULL, _data_->_tmp196_, (gpointer) ((gintptr) _data_->from_time));
	_data_->_tmp198_ = _data_->_tmp197_;
	_data_->_tmp199_ = _data_->self->priv->db;
	_data_->_tmp200_ = dino_database_get_mam_catchup (_data_->_tmp199_);
	_data_->_tmp201_ = _data_->_tmp200_;
	_data_->_tmp202_ = _data_->_tmp201_->from_end;
	_data_->_tmp203_ = _data_->page_result;
	_data_->_tmp204_ = dino_history_sync_page_request_result_get_page_result (_data_->_tmp203_);
	_data_->_tmp205_ = _data_->_tmp204_;
	_data_->_tmp206_ = qlite_insert_builder_value (_data_->_tmp198_, G_TYPE_BOOLEAN, NULL, NULL, _data_->_tmp202_, (gpointer) ((gintptr) (_data_->_tmp205_ == DINO_HISTORY_SYNC_PAGE_RESULT_NoMoreMessages)));
	_data_->_tmp207_ = _data_->_tmp206_;
	_data_->_tmp208_ = _data_->self->priv->db;
	_data_->_tmp209_ = dino_database_get_mam_catchup (_data_->_tmp208_);
	_data_->_tmp210_ = _data_->_tmp209_;
	_data_->_tmp211_ = _data_->_tmp210_->to_id;
	_data_->_tmp212_ = _data_->to_id;
	_data_->_tmp213_ = qlite_insert_builder_value (_data_->_tmp207_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp211_, _data_->_tmp212_);
	_data_->_tmp214_ = _data_->_tmp213_;
	_data_->_tmp215_ = _data_->self->priv->db;
	_data_->_tmp216_ = dino_database_get_mam_catchup (_data_->_tmp215_);
	_data_->_tmp217_ = _data_->_tmp216_;
	_data_->_tmp218_ = _data_->_tmp217_->to_time;
	_data_->_tmp219_ = qlite_insert_builder_value (_data_->_tmp214_, G_TYPE_LONG, NULL, NULL, _data_->_tmp218_, (gpointer) ((gintptr) _data_->to_time));
	_data_->_tmp220_ = _data_->_tmp219_;
	_data_->_tmp221_ = (gint) qlite_insert_builder_perform (_data_->_tmp220_);
	_qlite_statement_builder_unref0 (_data_->_tmp220_);
	_qlite_statement_builder_unref0 (_data_->_tmp214_);
	_qlite_statement_builder_unref0 (_data_->_tmp207_);
	_qlite_statement_builder_unref0 (_data_->_tmp198_);
	_qlite_statement_builder_unref0 (_data_->_tmp192_);
	_qlite_statement_builder_unref0 (_data_->_tmp185_);
	_g_free0 (_data_->_tmp183_);
	_qlite_statement_builder_unref0 (_data_->_tmp177_);
	_qlite_statement_builder_unref0 (_data_->_tmp169_);
	_data_->new_row_id = _data_->_tmp221_;
	_data_->_tmp222_ = _data_->self->priv->db;
	_data_->_tmp223_ = dino_database_get_mam_catchup (_data_->_tmp222_);
	_data_->_tmp224_ = _data_->_tmp223_;
	_data_->_tmp225_ = qlite_table_select ((QliteTable*) _data_->_tmp224_, NULL, (gint) 0);
	_data_->_tmp226_ = _data_->_tmp225_;
	_data_->_tmp227_ = _data_->self->priv->db;
	_data_->_tmp228_ = dino_database_get_mam_catchup (_data_->_tmp227_);
	_data_->_tmp229_ = _data_->_tmp228_;
	_data_->_tmp230_ = _data_->_tmp229_->id;
	_data_->_tmp231_ = qlite_query_builder_with (_data_->_tmp226_, G_TYPE_INT, NULL, NULL, _data_->_tmp230_, "=", (gpointer) ((gintptr) _data_->new_row_id));
	_data_->_tmp232_ = _data_->_tmp231_;
	_data_->_tmp233_ = qlite_query_builder_single (_data_->_tmp232_);
	_data_->_tmp234_ = _data_->_tmp233_;
	_data_->_tmp235_ = qlite_query_builder_row (_data_->_tmp234_);
	_data_->_tmp236_ = _data_->_tmp235_;
	_data_->_tmp237_ = qlite_row_option_get_inner (_data_->_tmp236_);
	_data_->_tmp238_ = _data_->_tmp237_;
	_data_->_tmp239_ = _qlite_row_ref0 (_data_->_tmp238_);
	_data_->_tmp240_ = _data_->_tmp239_;
	_qlite_row_option_unref0 (_data_->_tmp236_);
	_qlite_statement_builder_unref0 (_data_->_tmp234_);
	_qlite_statement_builder_unref0 (_data_->_tmp232_);
	_qlite_statement_builder_unref0 (_data_->_tmp226_);
	_data_->result = _data_->_tmp240_;
	_g_free0 (_data_->to_id);
	_g_free0 (_data_->from_id);
	_dino_history_sync_page_request_result_unref0 (_data_->page_result);
	_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
	_g_free0 (_data_->latest_message_id);
	_g_date_time_unref0 (_data_->latest_message_time);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
dino_history_sync_fetch_between_ranges_data_free (gpointer _data)
{
	DinoHistorySyncFetchBetweenRangesData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->account);
	_xmpp_jid_unref0 (_data_->mam_server);
	_qlite_row_unref0 (_data_->earlier_range);
	_qlite_row_unref0 (_data_->later_range);
	_g_object_unref0 (_data_->cancellable);
	_qlite_row_unref0 (_data_->result);
	_dino_history_sync_unref0 (_data_->self);
	g_slice_free (DinoHistorySyncFetchBetweenRangesData, _data_);
}

static void
dino_history_sync_fetch_between_ranges (DinoHistorySync* self,
                                        DinoEntitiesAccount* account,
                                        XmppJid* mam_server,
                                        QliteRow* earlier_range,
                                        QliteRow* later_range,
                                        GCancellable* cancellable,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	DinoHistorySyncFetchBetweenRangesData* _data_;
	DinoHistorySync* _tmp0_;
	DinoEntitiesAccount* _tmp1_;
	XmppJid* _tmp2_;
	QliteRow* _tmp3_;
	QliteRow* _tmp4_;
	GCancellable* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (mam_server != NULL);
	g_return_if_fail (earlier_range != NULL);
	g_return_if_fail (later_range != NULL);
	_data_ = g_slice_new0 (DinoHistorySyncFetchBetweenRangesData);
	_data_->_async_result = g_task_new (NULL, cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_history_sync_fetch_between_ranges_data_free);
	_tmp0_ = _dino_history_sync_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (account);
	_g_object_unref0 (_data_->account);
	_data_->account = _tmp1_;
	_tmp2_ = _xmpp_jid_ref0 (mam_server);
	_xmpp_jid_unref0 (_data_->mam_server);
	_data_->mam_server = _tmp2_;
	_tmp3_ = _qlite_row_ref0 (earlier_range);
	_qlite_row_unref0 (_data_->earlier_range);
	_data_->earlier_range = _tmp3_;
	_tmp4_ = _qlite_row_ref0 (later_range);
	_qlite_row_unref0 (_data_->later_range);
	_data_->later_range = _tmp4_;
	_tmp5_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp5_;
	dino_history_sync_fetch_between_ranges_co (_data_);
}

static QliteRow*
dino_history_sync_fetch_between_ranges_finish (DinoHistorySync* self,
                                               GAsyncResult* _res_)
{
	QliteRow* result;
	DinoHistorySyncFetchBetweenRangesData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/** Fetches messages between the end of `earlier_range` and start of `later_range`
     ** Merges the `earlier_range` db row into the `later_range` db row.
     ** @return The resulting range comprising `earlier_range`, `later_rage`, and everything in between. null if fetching/merge failed.
     **/
static void
dino_history_sync_fetch_between_ranges_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_)
{
	DinoHistorySyncFetchBetweenRangesData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_history_sync_fetch_between_ranges_co (_data_);
}

static gboolean
dino_history_sync_fetch_between_ranges_co (DinoHistorySyncFetchBetweenRangesData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_tmp1_ = dino_database_get_mam_catchup (_data_->_tmp0_);
	_data_->_tmp2_ = _data_->_tmp1_;
	_data_->_tmp3_ = _data_->_tmp2_->id;
	_data_->_tmp4_ = qlite_row_get (_data_->later_range, G_TYPE_INT, NULL, NULL, _data_->_tmp3_);
	_data_->later_range_id = (gint) ((gint) ((gintptr) _data_->_tmp4_));
	_data_->_tmp5_ = _data_->self->priv->db;
	_data_->_tmp6_ = dino_database_get_mam_catchup (_data_->_tmp5_);
	_data_->_tmp7_ = _data_->_tmp6_;
	_data_->_tmp8_ = _data_->_tmp7_->to_time;
	_data_->_tmp9_ = qlite_row_get (_data_->earlier_range, G_TYPE_LONG, NULL, NULL, _data_->_tmp8_);
	_data_->_tmp10_ = g_date_time_new_from_unix_utc ((gint64) ((glong) ((gintptr) _data_->_tmp9_)));
	_data_->earliest_time = _data_->_tmp10_;
	_data_->_tmp11_ = _data_->self->priv->db;
	_data_->_tmp12_ = dino_database_get_mam_catchup (_data_->_tmp11_);
	_data_->_tmp13_ = _data_->_tmp12_;
	_data_->_tmp14_ = _data_->_tmp13_->from_time;
	_data_->_tmp15_ = qlite_row_get (_data_->later_range, G_TYPE_LONG, NULL, NULL, _data_->_tmp14_);
	_data_->_tmp16_ = g_date_time_new_from_unix_utc ((gint64) ((glong) ((gintptr) _data_->_tmp15_)));
	_data_->latest_time = _data_->_tmp16_;
	_data_->_tmp17_ = dino_entities_account_get_bare_jid (_data_->account);
	_data_->_tmp18_ = _data_->_tmp17_;
	_data_->_tmp19_ = _data_->_tmp18_;
	_data_->_tmp20_ = xmpp_jid_to_string (_data_->_tmp19_);
	_data_->_tmp21_ = _data_->_tmp20_;
	_data_->_tmp22_ = xmpp_jid_to_string (_data_->mam_server);
	_data_->_tmp23_ = _data_->_tmp22_;
	_data_->_tmp24_ = _data_->earliest_time;
	_data_->_tmp25_ = g_date_time_to_string (_data_->_tmp24_);
	_data_->_tmp26_ = _data_->_tmp25_;
	_data_->_tmp27_ = _data_->self->priv->db;
	_data_->_tmp28_ = dino_database_get_mam_catchup (_data_->_tmp27_);
	_data_->_tmp29_ = _data_->_tmp28_;
	_data_->_tmp30_ = _data_->_tmp29_->to_id;
	_data_->_tmp31_ = qlite_row_get (_data_->earlier_range, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp30_);
	_data_->_tmp32_ = (gchar*) _data_->_tmp31_;
	_data_->_tmp33_ = _data_->latest_time;
	_data_->_tmp34_ = g_date_time_to_string (_data_->_tmp33_);
	_data_->_tmp35_ = _data_->_tmp34_;
	_data_->_tmp36_ = _data_->self->priv->db;
	_data_->_tmp37_ = dino_database_get_mam_catchup (_data_->_tmp36_);
	_data_->_tmp38_ = _data_->_tmp37_;
	_data_->_tmp39_ = _data_->_tmp38_->from_id;
	_data_->_tmp40_ = qlite_row_get (_data_->later_range, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp39_);
	_data_->_tmp41_ = (gchar*) _data_->_tmp40_;
	g_debug ("history_sync.vala:286: [%s | %s] Fetching between %s (%s) and %s (%s)", _data_->_tmp21_, _data_->_tmp23_, _data_->_tmp26_, _data_->_tmp32_, _data_->_tmp35_, _data_->_tmp41_);
	_g_free0 (_data_->_tmp41_);
	_g_free0 (_data_->_tmp35_);
	_g_free0 (_data_->_tmp32_);
	_g_free0 (_data_->_tmp26_);
	_g_free0 (_data_->_tmp23_);
	_g_free0 (_data_->_tmp21_);
	_xmpp_jid_unref0 (_data_->_tmp19_);
	_data_->_tmp42_ = _data_->earliest_time;
	_data_->_tmp43_ = _data_->self->priv->db;
	_data_->_tmp44_ = dino_database_get_mam_catchup (_data_->_tmp43_);
	_data_->_tmp45_ = _data_->_tmp44_;
	_data_->_tmp46_ = _data_->_tmp45_->to_id;
	_data_->_tmp47_ = qlite_row_get (_data_->earlier_range, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp46_);
	_data_->_tmp48_ = (gchar*) _data_->_tmp47_;
	_data_->_tmp49_ = _data_->latest_time;
	_data_->_tmp50_ = _data_->self->priv->db;
	_data_->_tmp51_ = dino_database_get_mam_catchup (_data_->_tmp50_);
	_data_->_tmp52_ = _data_->_tmp51_;
	_data_->_tmp53_ = _data_->_tmp52_->from_id;
	_data_->_tmp54_ = qlite_row_get (_data_->later_range, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp53_);
	_data_->_tmp55_ = (gchar*) _data_->_tmp54_;
	_data_->_tmp56_ = xmpp_message_archive_management_v2_mam_query_params_new_query_between (_data_->mam_server, _data_->_tmp42_, _data_->_tmp48_, _data_->_tmp49_, _data_->_tmp55_);
	_data_->_tmp57_ = _data_->_tmp56_;
	_g_free0 (_data_->_tmp55_);
	_g_free0 (_data_->_tmp48_);
	_data_->query_params = _data_->_tmp57_;
	_data_->_tmp58_ = _data_->query_params;
	_data_->_state_ = 1;
	dino_history_sync_fetch_query (_data_->self, _data_->account, _data_->_tmp58_, _data_->later_range_id, _data_->cancellable, dino_history_sync_fetch_between_ranges_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp59_ = dino_history_sync_fetch_query_finish (_data_->self, _data_->_res_);
	_data_->page_result = _data_->_tmp59_;
	_data_->_tmp61_ = _data_->page_result;
	_data_->_tmp62_ = dino_history_sync_page_request_result_get_page_result (_data_->_tmp61_);
	_data_->_tmp63_ = _data_->_tmp62_;
	if (_data_->_tmp63_ == DINO_HISTORY_SYNC_PAGE_RESULT_TargetReached) {
		_data_->_tmp60_ = TRUE;
	} else {
		_data_->_tmp64_ = _data_->page_result;
		_data_->_tmp65_ = dino_history_sync_page_request_result_get_page_result (_data_->_tmp64_);
		_data_->_tmp66_ = _data_->_tmp65_;
		_data_->_tmp60_ = _data_->_tmp66_ == DINO_HISTORY_SYNC_PAGE_RESULT_NoMoreMessages;
	}
	if (_data_->_tmp60_) {
		_data_->_tmp67_ = dino_entities_account_get_bare_jid (_data_->account);
		_data_->_tmp68_ = _data_->_tmp67_;
		_data_->_tmp69_ = _data_->_tmp68_;
		_data_->_tmp70_ = xmpp_jid_to_string (_data_->_tmp69_);
		_data_->_tmp71_ = _data_->_tmp70_;
		_data_->_tmp72_ = xmpp_jid_to_string (_data_->mam_server);
		_data_->_tmp73_ = _data_->_tmp72_;
		_data_->_tmp74_ = _data_->self->priv->db;
		_data_->_tmp75_ = dino_database_get_mam_catchup (_data_->_tmp74_);
		_data_->_tmp76_ = _data_->_tmp75_;
		_data_->_tmp77_ = _data_->_tmp76_->id;
		_data_->_tmp78_ = qlite_row_get (_data_->earlier_range, G_TYPE_INT, NULL, NULL, _data_->_tmp77_);
		g_debug ("history_sync.vala:295: [%s | %s] Merging range %i into %i", _data_->_tmp71_, _data_->_tmp73_, (gint) ((gintptr) _data_->_tmp78_), _data_->later_range_id);
		_g_free0 (_data_->_tmp73_);
		_g_free0 (_data_->_tmp71_);
		_xmpp_jid_unref0 (_data_->_tmp69_);
		_data_->_tmp79_ = _data_->self->priv->db;
		_data_->_tmp80_ = dino_database_get_mam_catchup (_data_->_tmp79_);
		_data_->_tmp81_ = _data_->_tmp80_;
		_data_->_tmp82_ = qlite_table_update ((QliteTable*) _data_->_tmp81_);
		_data_->_tmp83_ = _data_->_tmp82_;
		_data_->_tmp84_ = _data_->self->priv->db;
		_data_->_tmp85_ = dino_database_get_mam_catchup (_data_->_tmp84_);
		_data_->_tmp86_ = _data_->_tmp85_;
		_data_->_tmp87_ = _data_->_tmp86_->id;
		_data_->_tmp88_ = qlite_update_builder_with (_data_->_tmp83_, G_TYPE_INT, NULL, NULL, _data_->_tmp87_, "=", (gpointer) ((gintptr) _data_->later_range_id));
		_data_->_tmp89_ = _data_->_tmp88_;
		_data_->_tmp90_ = _data_->self->priv->db;
		_data_->_tmp91_ = dino_database_get_mam_catchup (_data_->_tmp90_);
		_data_->_tmp92_ = _data_->_tmp91_;
		_data_->_tmp93_ = _data_->_tmp92_->from_time;
		_data_->_tmp94_ = _data_->self->priv->db;
		_data_->_tmp95_ = dino_database_get_mam_catchup (_data_->_tmp94_);
		_data_->_tmp96_ = _data_->_tmp95_;
		_data_->_tmp97_ = _data_->_tmp96_->from_time;
		_data_->_tmp98_ = qlite_row_get (_data_->earlier_range, G_TYPE_LONG, NULL, NULL, _data_->_tmp97_);
		_data_->_tmp99_ = qlite_update_builder_set (_data_->_tmp89_, G_TYPE_LONG, NULL, NULL, _data_->_tmp93_, (gpointer) ((gintptr) _data_->_tmp98_));
		_data_->_tmp100_ = _data_->_tmp99_;
		_data_->_tmp101_ = _data_->self->priv->db;
		_data_->_tmp102_ = dino_database_get_mam_catchup (_data_->_tmp101_);
		_data_->_tmp103_ = _data_->_tmp102_;
		_data_->_tmp104_ = _data_->_tmp103_->from_id;
		_data_->_tmp105_ = _data_->self->priv->db;
		_data_->_tmp106_ = dino_database_get_mam_catchup (_data_->_tmp105_);
		_data_->_tmp107_ = _data_->_tmp106_;
		_data_->_tmp108_ = _data_->_tmp107_->from_id;
		_data_->_tmp109_ = qlite_row_get (_data_->earlier_range, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp108_);
		_data_->_tmp110_ = (gchar*) _data_->_tmp109_;
		_data_->_tmp111_ = qlite_update_builder_set (_data_->_tmp100_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp104_, _data_->_tmp110_);
		_data_->_tmp112_ = _data_->_tmp111_;
		_data_->_tmp113_ = _data_->self->priv->db;
		_data_->_tmp114_ = dino_database_get_mam_catchup (_data_->_tmp113_);
		_data_->_tmp115_ = _data_->_tmp114_;
		_data_->_tmp116_ = _data_->_tmp115_->from_end;
		_data_->_tmp117_ = _data_->self->priv->db;
		_data_->_tmp118_ = dino_database_get_mam_catchup (_data_->_tmp117_);
		_data_->_tmp119_ = _data_->_tmp118_;
		_data_->_tmp120_ = _data_->_tmp119_->from_end;
		_data_->_tmp121_ = qlite_row_get (_data_->earlier_range, G_TYPE_BOOLEAN, NULL, NULL, _data_->_tmp120_);
		_data_->_tmp122_ = qlite_update_builder_set (_data_->_tmp112_, G_TYPE_BOOLEAN, NULL, NULL, _data_->_tmp116_, (gpointer) ((gintptr) _data_->_tmp121_));
		_data_->_tmp123_ = _data_->_tmp122_;
		qlite_update_builder_perform (_data_->_tmp123_);
		_qlite_statement_builder_unref0 (_data_->_tmp123_);
		_qlite_statement_builder_unref0 (_data_->_tmp112_);
		_g_free0 (_data_->_tmp110_);
		_qlite_statement_builder_unref0 (_data_->_tmp100_);
		_qlite_statement_builder_unref0 (_data_->_tmp89_);
		_qlite_statement_builder_unref0 (_data_->_tmp83_);
		_data_->_tmp124_ = _data_->self->priv->db;
		_data_->_tmp125_ = dino_database_get_mam_catchup (_data_->_tmp124_);
		_data_->_tmp126_ = _data_->_tmp125_;
		_data_->_tmp127_ = qlite_table_delete ((QliteTable*) _data_->_tmp126_);
		_data_->_tmp128_ = _data_->_tmp127_;
		_data_->_tmp129_ = _data_->self->priv->db;
		_data_->_tmp130_ = dino_database_get_mam_catchup (_data_->_tmp129_);
		_data_->_tmp131_ = _data_->_tmp130_;
		_data_->_tmp132_ = _data_->_tmp131_->id;
		_data_->_tmp133_ = _data_->self->priv->db;
		_data_->_tmp134_ = dino_database_get_mam_catchup (_data_->_tmp133_);
		_data_->_tmp135_ = _data_->_tmp134_;
		_data_->_tmp136_ = _data_->_tmp135_->id;
		_data_->_tmp137_ = qlite_row_get (_data_->earlier_range, G_TYPE_INT, NULL, NULL, _data_->_tmp136_);
		_data_->_tmp138_ = qlite_delete_builder_with (_data_->_tmp128_, G_TYPE_INT, NULL, NULL, _data_->_tmp132_, "=", (gpointer) ((gintptr) _data_->_tmp137_));
		_data_->_tmp139_ = _data_->_tmp138_;
		qlite_delete_builder_perform (_data_->_tmp139_);
		_qlite_statement_builder_unref0 (_data_->_tmp139_);
		_qlite_statement_builder_unref0 (_data_->_tmp128_);
		_data_->_tmp140_ = _data_->self->priv->db;
		_data_->_tmp141_ = dino_database_get_mam_catchup (_data_->_tmp140_);
		_data_->_tmp142_ = _data_->_tmp141_;
		_data_->_tmp143_ = qlite_table_select ((QliteTable*) _data_->_tmp142_, NULL, (gint) 0);
		_data_->_tmp144_ = _data_->_tmp143_;
		_data_->_tmp145_ = _data_->self->priv->db;
		_data_->_tmp146_ = dino_database_get_mam_catchup (_data_->_tmp145_);
		_data_->_tmp147_ = _data_->_tmp146_;
		_data_->_tmp148_ = _data_->_tmp147_->id;
		_data_->_tmp149_ = qlite_query_builder_with (_data_->_tmp144_, G_TYPE_INT, NULL, NULL, _data_->_tmp148_, "=", (gpointer) ((gintptr) _data_->later_range_id));
		_data_->_tmp150_ = _data_->_tmp149_;
		_data_->_tmp151_ = qlite_query_builder_single (_data_->_tmp150_);
		_data_->_tmp152_ = _data_->_tmp151_;
		_data_->_tmp153_ = qlite_query_builder_row (_data_->_tmp152_);
		_data_->_tmp154_ = _data_->_tmp153_;
		_data_->_tmp155_ = qlite_row_option_get_inner (_data_->_tmp154_);
		_data_->_tmp156_ = _data_->_tmp155_;
		_data_->_tmp157_ = _qlite_row_ref0 (_data_->_tmp156_);
		_data_->_tmp158_ = _data_->_tmp157_;
		_qlite_row_option_unref0 (_data_->_tmp154_);
		_qlite_statement_builder_unref0 (_data_->_tmp152_);
		_qlite_statement_builder_unref0 (_data_->_tmp150_);
		_qlite_statement_builder_unref0 (_data_->_tmp144_);
		_data_->result = _data_->_tmp158_;
		_dino_history_sync_page_request_result_unref0 (_data_->page_result);
		_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
		_g_date_time_unref0 (_data_->latest_time);
		_g_date_time_unref0 (_data_->earliest_time);
		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 = NULL;
	_dino_history_sync_page_request_result_unref0 (_data_->page_result);
	_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
	_g_date_time_unref0 (_data_->latest_time);
	_g_date_time_unref0 (_data_->earliest_time);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
dino_history_sync_fetch_before_range_data_free (gpointer _data)
{
	DinoHistorySyncFetchBeforeRangeData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->account);
	_xmpp_jid_unref0 (_data_->mam_server);
	_qlite_row_unref0 (_data_->range);
	_g_date_time_unref0 (_data_->until_earliest_time);
	_g_object_unref0 (_data_->cancellable);
	_dino_history_sync_unref0 (_data_->self);
	g_slice_free (DinoHistorySyncFetchBeforeRangeData, _data_);
}

static void
dino_history_sync_fetch_before_range (DinoHistorySync* self,
                                      DinoEntitiesAccount* account,
                                      XmppJid* mam_server,
                                      QliteRow* range,
                                      GDateTime* until_earliest_time,
                                      GCancellable* cancellable,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_)
{
	DinoHistorySyncFetchBeforeRangeData* _data_;
	DinoHistorySync* _tmp0_;
	DinoEntitiesAccount* _tmp1_;
	XmppJid* _tmp2_;
	QliteRow* _tmp3_;
	GDateTime* _tmp4_;
	GCancellable* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (mam_server != NULL);
	g_return_if_fail (range != NULL);
	_data_ = g_slice_new0 (DinoHistorySyncFetchBeforeRangeData);
	_data_->_async_result = g_task_new (NULL, cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_history_sync_fetch_before_range_data_free);
	_tmp0_ = _dino_history_sync_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (account);
	_g_object_unref0 (_data_->account);
	_data_->account = _tmp1_;
	_tmp2_ = _xmpp_jid_ref0 (mam_server);
	_xmpp_jid_unref0 (_data_->mam_server);
	_data_->mam_server = _tmp2_;
	_tmp3_ = _qlite_row_ref0 (range);
	_qlite_row_unref0 (_data_->range);
	_data_->range = _tmp3_;
	_tmp4_ = _g_date_time_ref0 (until_earliest_time);
	_g_date_time_unref0 (_data_->until_earliest_time);
	_data_->until_earliest_time = _tmp4_;
	_tmp5_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp5_;
	dino_history_sync_fetch_before_range_co (_data_);
}

static void
dino_history_sync_fetch_before_range_finish (DinoHistorySync* self,
                                             GAsyncResult* _res_)
{
	DinoHistorySyncFetchBeforeRangeData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return;
	}
}

static void
dino_history_sync_fetch_before_range_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_)
{
	DinoHistorySyncFetchBeforeRangeData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_history_sync_fetch_before_range_co (_data_);
}

static gboolean
dino_history_sync_fetch_before_range_co (DinoHistorySyncFetchBeforeRangeData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->db;
	_data_->_tmp1_ = dino_database_get_mam_catchup (_data_->_tmp0_);
	_data_->_tmp2_ = _data_->_tmp1_;
	_data_->_tmp3_ = _data_->_tmp2_->from_time;
	_data_->_tmp4_ = qlite_row_get (_data_->range, G_TYPE_LONG, NULL, NULL, _data_->_tmp3_);
	_data_->_tmp5_ = g_date_time_new_from_unix_utc ((gint64) ((glong) ((gintptr) _data_->_tmp4_)));
	_data_->latest_time = _data_->_tmp5_;
	_data_->_tmp6_ = _data_->self->priv->db;
	_data_->_tmp7_ = dino_database_get_mam_catchup (_data_->_tmp6_);
	_data_->_tmp8_ = _data_->_tmp7_;
	_data_->_tmp9_ = _data_->_tmp8_->from_id;
	_data_->_tmp10_ = qlite_row_get (_data_->range, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp9_);
	_data_->latest_id = (gchar*) _data_->_tmp10_;
	_data_->_tmp11_ = dino_entities_account_get_bare_jid (_data_->account);
	_data_->_tmp12_ = _data_->_tmp11_;
	_data_->_tmp13_ = _data_->_tmp12_;
	_data_->_tmp14_ = xmpp_jid_to_string (_data_->_tmp13_);
	_data_->_tmp15_ = _data_->_tmp14_;
	_data_->_tmp16_ = xmpp_jid_to_string (_data_->mam_server);
	_data_->_tmp17_ = _data_->_tmp16_;
	_data_->_tmp18_ = _data_->latest_time;
	_data_->_tmp19_ = g_date_time_to_string (_data_->_tmp18_);
	_data_->_tmp20_ = _data_->_tmp19_;
	_data_->_tmp21_ = _data_->latest_id;
	g_debug ("history_sync.vala:316: [%s | %s] Fetching before range < %s, %s", _data_->_tmp15_, _data_->_tmp17_, _data_->_tmp20_, _data_->_tmp21_);
	_g_free0 (_data_->_tmp20_);
	_g_free0 (_data_->_tmp17_);
	_g_free0 (_data_->_tmp15_);
	_xmpp_jid_unref0 (_data_->_tmp13_);
	if (_data_->until_earliest_time == NULL) {
		_data_->_tmp22_ = _data_->latest_time;
		_data_->_tmp23_ = _data_->latest_id;
		_data_->_tmp24_ = xmpp_message_archive_management_v2_mam_query_params_new_query_before (_data_->mam_server, _data_->_tmp22_, _data_->_tmp23_);
		_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
		_data_->query_params = _data_->_tmp24_;
	} else {
		_data_->_tmp25_ = _data_->latest_time;
		_data_->_tmp26_ = _data_->latest_id;
		_data_->_tmp27_ = xmpp_message_archive_management_v2_mam_query_params_new_query_between (_data_->mam_server, _data_->until_earliest_time, NULL, _data_->_tmp25_, _data_->_tmp26_);
		_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
		_data_->query_params = _data_->_tmp27_;
	}
	_data_->_tmp28_ = _data_->query_params;
	_data_->_tmp29_ = _data_->self->priv->db;
	_data_->_tmp30_ = dino_database_get_mam_catchup (_data_->_tmp29_);
	_data_->_tmp31_ = _data_->_tmp30_;
	_data_->_tmp32_ = _data_->_tmp31_->id;
	_data_->_tmp33_ = qlite_row_get (_data_->range, G_TYPE_INT, NULL, NULL, _data_->_tmp32_);
	_data_->_state_ = 1;
	dino_history_sync_fetch_query (_data_->self, _data_->account, _data_->_tmp28_, (gint) ((gintptr) _data_->_tmp33_), _data_->cancellable, dino_history_sync_fetch_before_range_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp34_ = dino_history_sync_fetch_query_finish (_data_->self, _data_->_res_);
	_data_->_tmp35_ = _data_->_tmp34_;
	_dino_history_sync_page_request_result_unref0 (_data_->_tmp35_);
	_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
	_g_free0 (_data_->latest_id);
	_g_date_time_unref0 (_data_->latest_time);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
dino_history_sync_fetch_query_data_free (gpointer _data)
{
	DinoHistorySyncFetchQueryData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->account);
	_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
	_g_object_unref0 (_data_->cancellable);
	_dino_history_sync_page_request_result_unref0 (_data_->result);
	_dino_history_sync_unref0 (_data_->self);
	g_slice_free (DinoHistorySyncFetchQueryData, _data_);
}

static gpointer
_xmpp_message_archive_management_v2_mam_query_params_ref0 (gpointer self)
{
	return self ? xmpp_message_archive_management_v2_mam_query_params_ref (self) : NULL;
}

static void
dino_history_sync_fetch_query (DinoHistorySync* self,
                               DinoEntitiesAccount* account,
                               XmppMessageArchiveManagementV2MamQueryParams* query_params,
                               gint db_id,
                               GCancellable* cancellable,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_)
{
	DinoHistorySyncFetchQueryData* _data_;
	DinoHistorySync* _tmp0_;
	DinoEntitiesAccount* _tmp1_;
	XmppMessageArchiveManagementV2MamQueryParams* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (query_params != NULL);
	_data_ = g_slice_new0 (DinoHistorySyncFetchQueryData);
	_data_->_async_result = g_task_new (NULL, cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_history_sync_fetch_query_data_free);
	_tmp0_ = _dino_history_sync_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (account);
	_g_object_unref0 (_data_->account);
	_data_->account = _tmp1_;
	_tmp2_ = _xmpp_message_archive_management_v2_mam_query_params_ref0 (query_params);
	_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
	_data_->query_params = _tmp2_;
	_data_->db_id = db_id;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	dino_history_sync_fetch_query_co (_data_);
}

static DinoHistorySyncPageRequestResult*
dino_history_sync_fetch_query_finish (DinoHistorySync* self,
                                      GAsyncResult* _res_)
{
	DinoHistorySyncPageRequestResult* result;
	DinoHistorySyncFetchQueryData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/**
     * Iteratively fetches all pages returned for a query (until a PageResult other than MorePagesAvailable is returned)
     * @return The last PageRequestResult result
     **/
static void
dino_history_sync_fetch_query_ready (GObject* source_object,
                                     GAsyncResult* _res_,
                                     gpointer _user_data_)
{
	DinoHistorySyncFetchQueryData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_history_sync_fetch_query_co (_data_);
}

static gchar*
bool_to_string (gboolean self)
{
	gchar* result;
	if (self) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup ("true");
		result = _tmp0_;
		return result;
	} else {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("false");
		result = _tmp1_;
		return result;
	}
}

static gboolean
dino_history_sync_fetch_query_co (DinoHistorySyncFetchQueryData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp1_ = xmpp_message_archive_management_v2_mam_query_params_get_start (_data_->query_params);
	_data_->_tmp2_ = _data_->_tmp1_;
	if (_data_->_tmp2_ != NULL) {
		_data_->_tmp3_ = xmpp_message_archive_management_v2_mam_query_params_get_start (_data_->query_params);
		_data_->_tmp4_ = _data_->_tmp3_;
		_data_->_tmp5_ = g_date_time_to_string (_data_->_tmp4_);
		_g_free0 (_data_->_tmp0_);
		_data_->_tmp0_ = _data_->_tmp5_;
	} else {
		_data_->_tmp6_ = g_strdup ("");
		_g_free0 (_data_->_tmp0_);
		_data_->_tmp0_ = _data_->_tmp6_;
	}
	_data_->_tmp8_ = xmpp_message_archive_management_v2_mam_query_params_get_end (_data_->query_params);
	_data_->_tmp9_ = _data_->_tmp8_;
	if (_data_->_tmp9_ != NULL) {
		_data_->_tmp10_ = xmpp_message_archive_management_v2_mam_query_params_get_end (_data_->query_params);
		_data_->_tmp11_ = _data_->_tmp10_;
		_data_->_tmp12_ = g_date_time_to_string (_data_->_tmp11_);
		_g_free0 (_data_->_tmp7_);
		_data_->_tmp7_ = _data_->_tmp12_;
	} else {
		_data_->_tmp13_ = g_strdup ("");
		_g_free0 (_data_->_tmp7_);
		_data_->_tmp7_ = _data_->_tmp13_;
	}
	_data_->_tmp14_ = dino_entities_account_get_bare_jid (_data_->account);
	_data_->_tmp15_ = _data_->_tmp14_;
	_data_->_tmp16_ = _data_->_tmp15_;
	_data_->_tmp17_ = xmpp_jid_to_string (_data_->_tmp16_);
	_data_->_tmp18_ = _data_->_tmp17_;
	_data_->_tmp19_ = xmpp_message_archive_management_v2_mam_query_params_get_mam_server (_data_->query_params);
	_data_->_tmp20_ = _data_->_tmp19_;
	_data_->_tmp21_ = xmpp_jid_to_string (_data_->_tmp20_);
	_data_->_tmp22_ = _data_->_tmp21_;
	g_debug ("history_sync.vala:336: [%s | %s] Fetch query %s - %s", _data_->_tmp18_, _data_->_tmp22_, _data_->_tmp0_, _data_->_tmp7_);
	_g_free0 (_data_->_tmp22_);
	_g_free0 (_data_->_tmp18_);
	_xmpp_jid_unref0 (_data_->_tmp16_);
	_data_->page_result = NULL;
	{
		_data_->_tmp23_ = TRUE;
		while (TRUE) {
			if (!_data_->_tmp23_) {
				_data_->_tmp24_ = _data_->page_result;
				_data_->_tmp25_ = dino_history_sync_page_request_result_get_page_result (_data_->_tmp24_);
				_data_->_tmp26_ = _data_->_tmp25_;
				if (!(_data_->_tmp26_ == DINO_HISTORY_SYNC_PAGE_RESULT_MorePagesAvailable)) {
					break;
				}
			}
			_data_->_tmp23_ = FALSE;
			_data_->_tmp27_ = _data_->page_result;
			_data_->_state_ = 1;
			dino_history_sync_get_mam_page (_data_->self, _data_->account, _data_->query_params, _data_->_tmp27_, _data_->cancellable, dino_history_sync_fetch_query_ready, _data_);
			return FALSE;
			_state_1:
			_data_->_tmp28_ = dino_history_sync_get_mam_page_finish (_data_->self, _data_->_res_);
			_dino_history_sync_page_request_result_unref0 (_data_->page_result);
			_data_->page_result = _data_->_tmp28_;
			_data_->_tmp29_ = dino_entities_account_get_bare_jid (_data_->account);
			_data_->_tmp30_ = _data_->_tmp29_;
			_data_->_tmp31_ = _data_->_tmp30_;
			_data_->_tmp32_ = xmpp_jid_to_string (_data_->_tmp31_);
			_data_->_tmp33_ = _data_->_tmp32_;
			_data_->_tmp34_ = xmpp_message_archive_management_v2_mam_query_params_get_mam_server (_data_->query_params);
			_data_->_tmp35_ = _data_->_tmp34_;
			_data_->_tmp36_ = xmpp_jid_to_string (_data_->_tmp35_);
			_data_->_tmp37_ = _data_->_tmp36_;
			_data_->_tmp38_ = _data_->page_result;
			_data_->_tmp39_ = dino_history_sync_page_request_result_get_page_result (_data_->_tmp38_);
			_data_->_tmp40_ = _data_->_tmp39_;
			_data_->_tmp41_ = g_enum_get_value (g_type_class_ref (DINO_HISTORY_SYNC_TYPE_PAGE_RESULT), _data_->_tmp40_);
			_data_->_tmp42_ = _data_->page_result;
			_data_->_tmp43_ = dino_history_sync_page_request_result_get_stanzas (_data_->_tmp42_);
			_data_->_tmp44_ = _data_->_tmp43_;
			_data_->_tmp45_ = bool_to_string (_data_->_tmp44_ != NULL);
			_data_->_tmp46_ = _data_->_tmp45_;
			g_debug ("history_sync.vala:340: [%s | %s] Page result %s (got stanzas: %s)", _data_->_tmp33_, _data_->_tmp37_, (_data_->_tmp41_ != NULL) ? _data_->_tmp41_->value_name : NULL, _data_->_tmp46_);
			_g_free0 (_data_->_tmp46_);
			_g_free0 (_data_->_tmp37_);
			_g_free0 (_data_->_tmp33_);
			_xmpp_jid_unref0 (_data_->_tmp31_);
			_data_->_tmp48_ = _data_->page_result;
			_data_->_tmp49_ = dino_history_sync_page_request_result_get_page_result (_data_->_tmp48_);
			_data_->_tmp50_ = _data_->_tmp49_;
			if (_data_->_tmp50_ == DINO_HISTORY_SYNC_PAGE_RESULT_Error) {
				_data_->_tmp47_ = TRUE;
			} else {
				_data_->_tmp51_ = _data_->page_result;
				_data_->_tmp52_ = dino_history_sync_page_request_result_get_page_result (_data_->_tmp51_);
				_data_->_tmp53_ = _data_->_tmp52_;
				_data_->_tmp47_ = _data_->_tmp53_ == DINO_HISTORY_SYNC_PAGE_RESULT_Cancelled;
			}
			if (_data_->_tmp47_) {
				_data_->result = _data_->page_result;
				_g_free0 (_data_->_tmp7_);
				_g_free0 (_data_->_tmp0_);
				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_->_tmp54_ = _data_->page_result;
			_data_->_tmp55_ = dino_history_sync_page_request_result_get_query_result (_data_->_tmp54_);
			_data_->_tmp56_ = _data_->_tmp55_;
			_data_->_tmp57_ = xmpp_message_archive_management_query_result_get_first (_data_->_tmp56_);
			_data_->_tmp58_ = _data_->_tmp57_;
			_data_->_tmp59_ = g_strdup (_data_->_tmp58_);
			_data_->earliest_mam_id = _data_->_tmp59_;
			_data_->_tmp61_ = _data_->earliest_mam_id;
			if (_data_->_tmp61_ != NULL) {
				_data_->_tmp62_ = _data_->self->mam_times;
				_data_->_tmp63_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp62_, _data_->account);
				_data_->_tmp64_ = (GeeHashMap*) _data_->_tmp63_;
				_data_->_tmp65_ = _data_->earliest_mam_id;
				_data_->_tmp66_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp64_, _data_->_tmp65_);
				_data_->_tmp67_ = (GDateTime*) _data_->_tmp66_;
				_data_->_tmp60_ = (glong) g_date_time_to_unix (_data_->_tmp67_);
				_g_date_time_unref0 (_data_->_tmp67_);
				_g_object_unref0 (_data_->_tmp64_);
			} else {
				_data_->_tmp60_ = (glong) 0;
			}
			_data_->earliest_mam_time = _data_->_tmp60_;
			_data_->_tmp68_ = _data_->self->priv->db;
			_data_->_tmp69_ = dino_database_get_mam_catchup (_data_->_tmp68_);
			_data_->_tmp70_ = _data_->_tmp69_;
			_data_->_tmp71_ = qlite_table_update ((QliteTable*) _data_->_tmp70_);
			_data_->_tmp72_ = _data_->_tmp71_;
			_data_->_tmp73_ = _data_->self->priv->db;
			_data_->_tmp74_ = dino_database_get_mam_catchup (_data_->_tmp73_);
			_data_->_tmp75_ = _data_->_tmp74_;
			_data_->_tmp76_ = _data_->_tmp75_->id;
			_data_->_tmp77_ = qlite_update_builder_with (_data_->_tmp72_, G_TYPE_INT, NULL, NULL, _data_->_tmp76_, "=", (gpointer) ((gintptr) _data_->db_id));
			_data_->_tmp78_ = _data_->_tmp77_;
			_qlite_statement_builder_unref0 (_data_->_tmp72_);
			_data_->query = _data_->_tmp78_;
			_data_->_tmp79_ = _data_->earliest_mam_id;
			if (_data_->_tmp79_ != NULL) {
				_data_->_tmp80_ = dino_entities_account_get_bare_jid (_data_->account);
				_data_->_tmp81_ = _data_->_tmp80_;
				_data_->_tmp82_ = _data_->_tmp81_;
				_data_->_tmp83_ = xmpp_jid_to_string (_data_->_tmp82_);
				_data_->_tmp84_ = _data_->_tmp83_;
				_data_->_tmp85_ = xmpp_message_archive_management_v2_mam_query_params_get_mam_server (_data_->query_params);
				_data_->_tmp86_ = _data_->_tmp85_;
				_data_->_tmp87_ = xmpp_jid_to_string (_data_->_tmp86_);
				_data_->_tmp88_ = _data_->_tmp87_;
				_data_->_tmp89_ = g_strdup_printf ("%li", _data_->earliest_mam_time);
				_data_->_tmp90_ = _data_->_tmp89_;
				_data_->_tmp91_ = _data_->earliest_mam_id;
				g_debug ("history_sync.vala:350: [%s | %s] Updating to %s, %s", _data_->_tmp84_, _data_->_tmp88_, _data_->_tmp90_, _data_->_tmp91_);
				_g_free0 (_data_->_tmp90_);
				_g_free0 (_data_->_tmp88_);
				_g_free0 (_data_->_tmp84_);
				_xmpp_jid_unref0 (_data_->_tmp82_);
				_data_->_tmp92_ = _data_->query;
				_data_->_tmp93_ = _data_->self->priv->db;
				_data_->_tmp94_ = dino_database_get_mam_catchup (_data_->_tmp93_);
				_data_->_tmp95_ = _data_->_tmp94_;
				_data_->_tmp96_ = _data_->_tmp95_->from_id;
				_data_->_tmp97_ = _data_->earliest_mam_id;
				_data_->_tmp98_ = qlite_update_builder_set (_data_->_tmp92_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _data_->_tmp96_, _data_->_tmp97_);
				_data_->_tmp99_ = _data_->_tmp98_;
				_qlite_statement_builder_unref0 (_data_->_tmp99_);
				_data_->_tmp102_ = _data_->page_result;
				_data_->_tmp103_ = dino_history_sync_page_request_result_get_page_result (_data_->_tmp102_);
				_data_->_tmp104_ = _data_->_tmp103_;
				if (_data_->_tmp104_ != DINO_HISTORY_SYNC_PAGE_RESULT_NoMoreMessages) {
					_data_->_tmp101_ = TRUE;
				} else {
					_data_->_tmp105_ = xmpp_message_archive_management_v2_mam_query_params_get_start (_data_->query_params);
					_data_->_tmp106_ = _data_->_tmp105_;
					_data_->_tmp101_ = _data_->_tmp106_ != NULL;
				}
				if (_data_->_tmp101_) {
					_data_->_tmp100_ = TRUE;
				} else {
					_data_->_tmp107_ = xmpp_message_archive_management_v2_mam_query_params_get_start (_data_->query_params);
					_data_->_tmp108_ = _data_->_tmp107_;
					_data_->_tmp100_ = ((gint64) _data_->earliest_mam_time) < g_date_time_to_unix (_data_->_tmp108_);
				}
				if (_data_->_tmp100_) {
					_data_->_tmp109_ = _data_->query;
					_data_->_tmp110_ = _data_->self->priv->db;
					_data_->_tmp111_ = dino_database_get_mam_catchup (_data_->_tmp110_);
					_data_->_tmp112_ = _data_->_tmp111_;
					_data_->_tmp113_ = _data_->_tmp112_->from_time;
					_data_->_tmp114_ = qlite_update_builder_set (_data_->_tmp109_, G_TYPE_LONG, NULL, NULL, _data_->_tmp113_, (gpointer) ((gintptr) _data_->earliest_mam_time));
					_data_->_tmp115_ = _data_->_tmp114_;
					_qlite_statement_builder_unref0 (_data_->_tmp115_);
				}
			}
			_data_->_tmp116_ = _data_->page_result;
			_data_->_tmp117_ = dino_history_sync_page_request_result_get_page_result (_data_->_tmp116_);
			_data_->_tmp118_ = _data_->_tmp117_;
			if (_data_->_tmp118_ == DINO_HISTORY_SYNC_PAGE_RESULT_NoMoreMessages) {
				_data_->_tmp119_ = xmpp_message_archive_management_v2_mam_query_params_get_start (_data_->query_params);
				_data_->_tmp120_ = _data_->_tmp119_;
				if (_data_->_tmp120_ != NULL) {
					_data_->_tmp121_ = dino_entities_account_get_bare_jid (_data_->account);
					_data_->_tmp122_ = _data_->_tmp121_;
					_data_->_tmp123_ = _data_->_tmp122_;
					_data_->_tmp124_ = xmpp_jid_to_string (_data_->_tmp123_);
					_data_->_tmp125_ = _data_->_tmp124_;
					_data_->_tmp126_ = xmpp_message_archive_management_v2_mam_query_params_get_mam_server (_data_->query_params);
					_data_->_tmp127_ = _data_->_tmp126_;
					_data_->_tmp128_ = xmpp_jid_to_string (_data_->_tmp127_);
					_data_->_tmp129_ = _data_->_tmp128_;
					_data_->_tmp130_ = xmpp_message_archive_management_v2_mam_query_params_get_start (_data_->query_params);
					_data_->_tmp131_ = _data_->_tmp130_;
					_data_->_tmp132_ = g_date_time_to_string (_data_->_tmp131_);
					_data_->_tmp133_ = _data_->_tmp132_;
					g_debug ("history_sync.vala:360: [%s | %s] Updating to %s based on query", _data_->_tmp125_, _data_->_tmp129_, _data_->_tmp133_);
					_g_free0 (_data_->_tmp133_);
					_g_free0 (_data_->_tmp129_);
					_g_free0 (_data_->_tmp125_);
					_xmpp_jid_unref0 (_data_->_tmp123_);
					_data_->_tmp134_ = _data_->query;
					_data_->_tmp135_ = _data_->self->priv->db;
					_data_->_tmp136_ = dino_database_get_mam_catchup (_data_->_tmp135_);
					_data_->_tmp137_ = _data_->_tmp136_;
					_data_->_tmp138_ = _data_->_tmp137_->from_time;
					_data_->_tmp139_ = xmpp_message_archive_management_v2_mam_query_params_get_start (_data_->query_params);
					_data_->_tmp140_ = _data_->_tmp139_;
					_data_->_tmp141_ = qlite_update_builder_set (_data_->_tmp134_, G_TYPE_LONG, NULL, NULL, _data_->_tmp138_, (gpointer) ((gintptr) g_date_time_to_unix (_data_->_tmp140_)));
					_data_->_tmp142_ = _data_->_tmp141_;
					_qlite_statement_builder_unref0 (_data_->_tmp142_);
				} else {
					_data_->_tmp143_ = _data_->query;
					_data_->_tmp144_ = _data_->self->priv->db;
					_data_->_tmp145_ = dino_database_get_mam_catchup (_data_->_tmp144_);
					_data_->_tmp146_ = _data_->_tmp145_;
					_data_->_tmp147_ = _data_->_tmp146_->from_end;
					_data_->_tmp148_ = qlite_update_builder_set (_data_->_tmp143_, G_TYPE_BOOLEAN, NULL, NULL, _data_->_tmp147_, (gpointer) ((gintptr) TRUE));
					_data_->_tmp149_ = _data_->_tmp148_;
					_qlite_statement_builder_unref0 (_data_->_tmp149_);
				}
			}
			_data_->_tmp150_ = _data_->query;
			qlite_update_builder_perform (_data_->_tmp150_);
			_qlite_statement_builder_unref0 (_data_->query);
			_g_free0 (_data_->earliest_mam_id);
		}
	}
	_data_->result = _data_->page_result;
	_g_free0 (_data_->_tmp7_);
	_g_free0 (_data_->_tmp0_);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
dino_history_sync_get_mam_page_data_free (gpointer _data)
{
	DinoHistorySyncGetMamPageData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->account);
	_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
	_dino_history_sync_page_request_result_unref0 (_data_->prev_page_result);
	_g_object_unref0 (_data_->cancellable);
	_dino_history_sync_page_request_result_unref0 (_data_->result);
	_dino_history_sync_unref0 (_data_->self);
	g_slice_free (DinoHistorySyncGetMamPageData, _data_);
}

static gpointer
_dino_history_sync_page_request_result_ref0 (gpointer self)
{
	return self ? dino_history_sync_page_request_result_ref (self) : NULL;
}

static void
dino_history_sync_get_mam_page (DinoHistorySync* self,
                                DinoEntitiesAccount* account,
                                XmppMessageArchiveManagementV2MamQueryParams* query_params,
                                DinoHistorySyncPageRequestResult* prev_page_result,
                                GCancellable* cancellable,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_)
{
	DinoHistorySyncGetMamPageData* _data_;
	DinoHistorySync* _tmp0_;
	DinoEntitiesAccount* _tmp1_;
	XmppMessageArchiveManagementV2MamQueryParams* _tmp2_;
	DinoHistorySyncPageRequestResult* _tmp3_;
	GCancellable* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (query_params != NULL);
	_data_ = g_slice_new0 (DinoHistorySyncGetMamPageData);
	_data_->_async_result = g_task_new (NULL, cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_history_sync_get_mam_page_data_free);
	_tmp0_ = _dino_history_sync_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (account);
	_g_object_unref0 (_data_->account);
	_data_->account = _tmp1_;
	_tmp2_ = _xmpp_message_archive_management_v2_mam_query_params_ref0 (query_params);
	_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
	_data_->query_params = _tmp2_;
	_tmp3_ = _dino_history_sync_page_request_result_ref0 (prev_page_result);
	_dino_history_sync_page_request_result_unref0 (_data_->prev_page_result);
	_data_->prev_page_result = _tmp3_;
	_tmp4_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp4_;
	dino_history_sync_get_mam_page_co (_data_);
}

static DinoHistorySyncPageRequestResult*
dino_history_sync_get_mam_page_finish (DinoHistorySync* self,
                                       GAsyncResult* _res_)
{
	DinoHistorySyncPageRequestResult* result;
	DinoHistorySyncGetMamPageData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/**
     * prev_page_result: null if this is the first page request
     **/
static void
dino_history_sync_get_mam_page_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_)
{
	DinoHistorySyncGetMamPageData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_history_sync_get_mam_page_co (_data_);
}

static gboolean
dino_history_sync_get_mam_page_co (DinoHistorySyncGetMamPageData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->stream_interactor;
	_data_->_tmp1_ = dino_stream_interactor_get_stream (_data_->_tmp0_, _data_->account);
	_data_->stream = _data_->_tmp1_;
	_data_->query_result = NULL;
	if (_data_->prev_page_result == NULL) {
		_data_->_tmp2_ = _data_->stream;
		_data_->_state_ = 1;
		xmpp_message_archive_management_v2_query_archive (_data_->_tmp2_, _data_->query_params, _data_->cancellable, dino_history_sync_get_mam_page_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp3_ = xmpp_message_archive_management_v2_query_archive_finish (_data_->_res_);
		_xmpp_message_archive_management_query_result_unref0 (_data_->query_result);
		_data_->query_result = _data_->_tmp3_;
	} else {
		_data_->_tmp4_ = _data_->stream;
		_data_->_tmp5_ = dino_history_sync_page_request_result_get_query_result (_data_->prev_page_result);
		_data_->_tmp6_ = _data_->_tmp5_;
		_data_->_state_ = 2;
		xmpp_message_archive_management_v2_page_through_results (_data_->_tmp4_, _data_->query_params, _data_->_tmp6_, _data_->cancellable, dino_history_sync_get_mam_page_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp7_ = xmpp_message_archive_management_v2_page_through_results_finish (_data_->_res_);
		_xmpp_message_archive_management_query_result_unref0 (_data_->query_result);
		_data_->query_result = _data_->_tmp7_;
	}
	_data_->_tmp8_ = _data_->query_result;
	_data_->_state_ = 3;
	dino_history_sync_process_query_result (_data_->self, _data_->account, _data_->query_params, _data_->_tmp8_, _data_->cancellable, dino_history_sync_get_mam_page_ready, _data_);
	return FALSE;
	_state_3:
	_data_->_tmp9_ = dino_history_sync_process_query_result_finish (_data_->self, _data_->_res_);
	_data_->result = _data_->_tmp9_;
	_xmpp_message_archive_management_query_result_unref0 (_data_->query_result);
	_g_object_unref0 (_data_->stream);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
dino_history_sync_process_query_result_data_free (gpointer _data)
{
	DinoHistorySyncProcessQueryResultData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->account);
	_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
	_xmpp_message_archive_management_query_result_unref0 (_data_->query_result);
	_g_object_unref0 (_data_->cancellable);
	_dino_history_sync_page_request_result_unref0 (_data_->result);
	_dino_history_sync_unref0 (_data_->self);
	g_slice_free (DinoHistorySyncProcessQueryResultData, _data_);
}

static gpointer
_xmpp_message_archive_management_query_result_ref0 (gpointer self)
{
	return self ? xmpp_message_archive_management_query_result_ref (self) : NULL;
}

static void
dino_history_sync_process_query_result (DinoHistorySync* self,
                                        DinoEntitiesAccount* account,
                                        XmppMessageArchiveManagementV2MamQueryParams* query_params,
                                        XmppMessageArchiveManagementQueryResult* query_result,
                                        GCancellable* cancellable,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	DinoHistorySyncProcessQueryResultData* _data_;
	DinoHistorySync* _tmp0_;
	DinoEntitiesAccount* _tmp1_;
	XmppMessageArchiveManagementV2MamQueryParams* _tmp2_;
	XmppMessageArchiveManagementQueryResult* _tmp3_;
	GCancellable* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (query_params != NULL);
	g_return_if_fail (query_result != NULL);
	_data_ = g_slice_new0 (DinoHistorySyncProcessQueryResultData);
	_data_->_async_result = g_task_new (NULL, cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_history_sync_process_query_result_data_free);
	_tmp0_ = _dino_history_sync_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (account);
	_g_object_unref0 (_data_->account);
	_data_->account = _tmp1_;
	_tmp2_ = _xmpp_message_archive_management_v2_mam_query_params_ref0 (query_params);
	_xmpp_message_archive_management_v2_mam_query_params_unref0 (_data_->query_params);
	_data_->query_params = _tmp2_;
	_tmp3_ = _xmpp_message_archive_management_query_result_ref0 (query_result);
	_xmpp_message_archive_management_query_result_unref0 (_data_->query_result);
	_data_->query_result = _tmp3_;
	_tmp4_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp4_;
	dino_history_sync_process_query_result_co (_data_);
}

static DinoHistorySyncPageRequestResult*
dino_history_sync_process_query_result_finish (DinoHistorySync* self,
                                               GAsyncResult* _res_)
{
	DinoHistorySyncPageRequestResult* result;
	DinoHistorySyncProcessQueryResultData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static gboolean
_dino_history_sync_process_query_result_co_gsource_func (gpointer self)
{
	gboolean result;
	result = dino_history_sync_process_query_result_co (self);
	return result;
}

static void
dino_history_sync_process_query_result_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_)
{
	DinoHistorySyncProcessQueryResultData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_history_sync_process_query_result_co (_data_);
}

static gboolean
dino_history_sync_process_query_result_co (DinoHistorySyncProcessQueryResultData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->page_result = DINO_HISTORY_SYNC_PAGE_RESULT_MorePagesAvailable;
	_data_->_tmp1_ = xmpp_message_archive_management_query_result_get_malformed (_data_->query_result);
	_data_->_tmp2_ = _data_->_tmp1_;
	if (_data_->_tmp2_) {
		_data_->_tmp0_ = TRUE;
	} else {
		_data_->_tmp3_ = xmpp_message_archive_management_query_result_get_error (_data_->query_result);
		_data_->_tmp4_ = _data_->_tmp3_;
		_data_->_tmp0_ = _data_->_tmp4_;
	}
	if (_data_->_tmp0_) {
		_data_->page_result = DINO_HISTORY_SYNC_PAGE_RESULT_Error;
	}
	g_idle_add_full (G_PRIORITY_LOW, _dino_history_sync_process_query_result_co_gsource_func, _data_, NULL);
	_data_->_state_ = 1;
	return FALSE;
	_state_1:
	;
	_data_->_tmp5_ = xmpp_message_archive_management_query_result_get_complete (_data_->query_result);
	_data_->_tmp6_ = _data_->_tmp5_;
	if (_data_->_tmp6_) {
		_data_->page_result = DINO_HISTORY_SYNC_PAGE_RESULT_NoMoreMessages;
	}
	_data_->_tmp7_ = _data_->query_params->query_id;
	_data_->_tmp8_ = g_strdup (_data_->_tmp7_);
	_data_->query_id = _data_->_tmp8_;
	_data_->_tmp9_ = xmpp_message_archive_management_v2_mam_query_params_get_start_id (_data_->query_params);
	_data_->_tmp10_ = _data_->_tmp9_;
	_data_->_tmp11_ = g_strdup (_data_->_tmp10_);
	_data_->after_id = _data_->_tmp11_;
	_data_->_tmp14_ = _data_->self->priv->stanzas;
	_data_->_tmp15_ = _data_->query_id;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp14_, _data_->_tmp15_)) {
		_data_->_tmp16_ = _data_->self->priv->stanzas;
		_data_->_tmp17_ = _data_->query_id;
		_data_->_tmp18_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp16_, _data_->_tmp17_);
		_data_->_tmp19_ = (GeeList*) _data_->_tmp18_;
		_data_->_tmp20_ = gee_collection_get_is_empty ((GeeCollection*) _data_->_tmp19_);
		_data_->_tmp21_ = _data_->_tmp20_;
		_data_->_tmp13_ = !_data_->_tmp21_;
		_g_object_unref0 (_data_->_tmp19_);
	} else {
		_data_->_tmp13_ = FALSE;
	}
	if (_data_->_tmp13_) {
		_data_->_tmp22_ = _data_->self->priv->stanzas;
		_data_->_tmp23_ = _data_->query_id;
		_data_->_tmp24_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp22_, _data_->_tmp23_);
		_g_object_unref0 (_data_->_tmp12_);
		_data_->_tmp12_ = (GeeList*) _data_->_tmp24_;
	} else {
		_g_object_unref0 (_data_->_tmp12_);
		_data_->_tmp12_ = NULL;
	}
	_data_->_tmp25_ = _data_->_tmp12_;
	_data_->_tmp12_ = NULL;
	_data_->stanzas_for_query = _data_->_tmp25_;
	if (_data_->cancellable != NULL) {
		_data_->_tmp26_ = g_cancellable_is_cancelled (_data_->cancellable);
	} else {
		_data_->_tmp26_ = FALSE;
	}
	if (_data_->_tmp26_) {
		_data_->_tmp27_ = _data_->self->priv->stanzas;
		_data_->_tmp28_ = _data_->query_id;
		gee_abstract_map_unset ((GeeAbstractMap*) _data_->_tmp27_, _data_->_tmp28_, NULL);
		_data_->_tmp29_ = _data_->stanzas_for_query;
		_data_->_tmp30_ = dino_history_sync_page_request_result_new (DINO_HISTORY_SYNC_PAGE_RESULT_Cancelled, _data_->query_result, _data_->_tmp29_);
		_data_->result = _data_->_tmp30_;
		_g_object_unref0 (_data_->stanzas_for_query);
		_g_object_unref0 (_data_->_tmp12_);
		_g_free0 (_data_->after_id);
		_g_free0 (_data_->query_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_->stanzas_for_query;
	if (_data_->_tmp31_ != NULL) {
		{
			_data_->_tmp32_ = _data_->stanzas_for_query;
			_data_->_message_list = _data_->_tmp32_;
			_data_->_tmp33_ = _data_->_message_list;
			_data_->_tmp34_ = gee_collection_get_size ((GeeCollection*) _data_->_tmp33_);
			_data_->_tmp35_ = _data_->_tmp34_;
			_data_->_message_size = _data_->_tmp35_;
			_data_->_message_index = -1;
			while (TRUE) {
				_data_->_message_index = _data_->_message_index + 1;
				_data_->_tmp36_ = _data_->_message_index;
				_data_->_tmp37_ = _data_->_message_size;
				if (!(_data_->_tmp36_ < _data_->_tmp37_)) {
					break;
				}
				_data_->_tmp38_ = _data_->_message_list;
				_data_->_tmp39_ = gee_list_get (_data_->_tmp38_, _data_->_message_index);
				_data_->message = (XmppMessageStanza*) _data_->_tmp39_;
				_data_->_tmp40_ = _data_->message;
				_data_->_tmp41_ = xmpp_message_archive_management_message_flag_get_flag (_data_->_tmp40_);
				_data_->mam_message_flag = _data_->_tmp41_;
				_data_->_tmp43_ = _data_->mam_message_flag;
				if (_data_->_tmp43_ != NULL) {
					_data_->_tmp44_ = _data_->mam_message_flag;
					_data_->_tmp45_ = xmpp_message_archive_management_message_flag_get_mam_id (_data_->_tmp44_);
					_data_->_tmp46_ = _data_->_tmp45_;
					_data_->_tmp42_ = _data_->_tmp46_ != NULL;
				} else {
					_data_->_tmp42_ = FALSE;
				}
				if (_data_->_tmp42_) {
					_data_->_tmp48_ = _data_->after_id;
					if (_data_->_tmp48_ != NULL) {
						_data_->_tmp49_ = _data_->mam_message_flag;
						_data_->_tmp50_ = xmpp_message_archive_management_message_flag_get_mam_id (_data_->_tmp49_);
						_data_->_tmp51_ = _data_->_tmp50_;
						_data_->_tmp52_ = _data_->after_id;
						_data_->_tmp47_ = g_strcmp0 (_data_->_tmp51_, _data_->_tmp52_) == 0;
					} else {
						_data_->_tmp47_ = FALSE;
					}
					if (_data_->_tmp47_) {
						_data_->_tmp53_ = _data_->query_id;
						_data_->_state_ = 2;
						dino_history_sync_send_messages_back_into_pipeline (_data_->self, _data_->account, _data_->_tmp53_, _data_->cancellable, dino_history_sync_process_query_result_ready, _data_);
						return FALSE;
						_state_2:
						dino_history_sync_send_messages_back_into_pipeline_finish (_data_->self, _data_->_res_);
						if (_data_->cancellable != NULL) {
							_data_->_tmp54_ = g_cancellable_is_cancelled (_data_->cancellable);
						} else {
							_data_->_tmp54_ = FALSE;
						}
						if (_data_->_tmp54_) {
							_data_->_tmp55_ = _data_->stanzas_for_query;
							_data_->_tmp56_ = dino_history_sync_page_request_result_new (DINO_HISTORY_SYNC_PAGE_RESULT_Cancelled, _data_->query_result, _data_->_tmp55_);
							_data_->result = _data_->_tmp56_;
							_g_object_unref0 (_data_->mam_message_flag);
							_g_object_unref0 (_data_->message);
							_g_object_unref0 (_data_->stanzas_for_query);
							_g_object_unref0 (_data_->_tmp12_);
							_g_free0 (_data_->after_id);
							_g_free0 (_data_->query_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_->_tmp57_ = _data_->stanzas_for_query;
						_data_->_tmp58_ = dino_history_sync_page_request_result_new (DINO_HISTORY_SYNC_PAGE_RESULT_TargetReached, _data_->query_result, _data_->_tmp57_);
						_data_->result = _data_->_tmp58_;
						_g_object_unref0 (_data_->mam_message_flag);
						_g_object_unref0 (_data_->message);
						_g_object_unref0 (_data_->stanzas_for_query);
						_g_object_unref0 (_data_->_tmp12_);
						_g_free0 (_data_->after_id);
						_g_free0 (_data_->query_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;
					}
				}
				_g_object_unref0 (_data_->mam_message_flag);
				_g_object_unref0 (_data_->message);
			}
		}
		_data_->_tmp60_ = _data_->self->hitted_range;
		_data_->_tmp61_ = _data_->query_id;
		if (gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp60_, _data_->_tmp61_)) {
			_data_->_tmp62_ = _data_->self->hitted_range;
			_data_->_tmp63_ = _data_->query_id;
			_data_->_tmp64_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp62_, _data_->_tmp63_);
			_data_->_tmp59_ = ((gint) ((gintptr) _data_->_tmp64_)) == -2;
		} else {
			_data_->_tmp59_ = FALSE;
		}
		if (_data_->_tmp59_) {
			_data_->_tmp65_ = _data_->query_id;
			_data_->_state_ = 3;
			dino_history_sync_send_messages_back_into_pipeline (_data_->self, _data_->account, _data_->_tmp65_, NULL, dino_history_sync_process_query_result_ready, _data_);
			return FALSE;
			_state_3:
			dino_history_sync_send_messages_back_into_pipeline_finish (_data_->self, _data_->_res_);
			if (_data_->cancellable != NULL) {
				_data_->_tmp66_ = g_cancellable_is_cancelled (_data_->cancellable);
			} else {
				_data_->_tmp66_ = FALSE;
			}
			if (_data_->_tmp66_) {
				_data_->_tmp67_ = _data_->stanzas_for_query;
				_data_->_tmp68_ = dino_history_sync_page_request_result_new (DINO_HISTORY_SYNC_PAGE_RESULT_Cancelled, _data_->query_result, _data_->_tmp67_);
				_data_->result = _data_->_tmp68_;
				_g_object_unref0 (_data_->stanzas_for_query);
				_g_object_unref0 (_data_->_tmp12_);
				_g_free0 (_data_->after_id);
				_g_free0 (_data_->query_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_->_tmp69_ = _data_->stanzas_for_query;
			_data_->_tmp70_ = dino_history_sync_page_request_result_new (DINO_HISTORY_SYNC_PAGE_RESULT_TargetReached, _data_->query_result, _data_->_tmp69_);
			_data_->result = _data_->_tmp70_;
			_g_object_unref0 (_data_->stanzas_for_query);
			_g_object_unref0 (_data_->_tmp12_);
			_g_free0 (_data_->after_id);
			_g_free0 (_data_->query_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_->_tmp71_ = _data_->query_id;
	_data_->_state_ = 4;
	dino_history_sync_send_messages_back_into_pipeline (_data_->self, _data_->account, _data_->_tmp71_, NULL, dino_history_sync_process_query_result_ready, _data_);
	return FALSE;
	_state_4:
	dino_history_sync_send_messages_back_into_pipeline_finish (_data_->self, _data_->_res_);
	if (_data_->cancellable != NULL) {
		_data_->_tmp72_ = g_cancellable_is_cancelled (_data_->cancellable);
	} else {
		_data_->_tmp72_ = FALSE;
	}
	if (_data_->_tmp72_) {
		_data_->page_result = DINO_HISTORY_SYNC_PAGE_RESULT_Cancelled;
	}
	_data_->_tmp73_ = _data_->stanzas_for_query;
	_data_->_tmp74_ = dino_history_sync_page_request_result_new (_data_->page_result, _data_->query_result, _data_->_tmp73_);
	_data_->result = _data_->_tmp74_;
	_g_object_unref0 (_data_->stanzas_for_query);
	_g_object_unref0 (_data_->_tmp12_);
	_g_free0 (_data_->after_id);
	_g_free0 (_data_->query_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;
}

static void
dino_history_sync_send_messages_back_into_pipeline_data_free (gpointer _data)
{
	DinoHistorySyncSendMessagesBackIntoPipelineData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->account);
	_g_free0 (_data_->query_id);
	_g_object_unref0 (_data_->cancellable);
	_dino_history_sync_unref0 (_data_->self);
	g_slice_free (DinoHistorySyncSendMessagesBackIntoPipelineData, _data_);
}

static void
dino_history_sync_send_messages_back_into_pipeline (DinoHistorySync* self,
                                                    DinoEntitiesAccount* account,
                                                    const gchar* query_id,
                                                    GCancellable* cancellable,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_)
{
	DinoHistorySyncSendMessagesBackIntoPipelineData* _data_;
	DinoHistorySync* _tmp0_;
	DinoEntitiesAccount* _tmp1_;
	gchar* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (query_id != NULL);
	_data_ = g_slice_new0 (DinoHistorySyncSendMessagesBackIntoPipelineData);
	_data_->_async_result = g_task_new (NULL, cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_history_sync_send_messages_back_into_pipeline_data_free);
	_tmp0_ = _dino_history_sync_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (account);
	_g_object_unref0 (_data_->account);
	_data_->account = _tmp1_;
	_tmp2_ = g_strdup (query_id);
	_g_free0 (_data_->query_id);
	_data_->query_id = _tmp2_;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	dino_history_sync_send_messages_back_into_pipeline_co (_data_);
}

static void
dino_history_sync_send_messages_back_into_pipeline_finish (DinoHistorySync* self,
                                                           GAsyncResult* _res_)
{
	DinoHistorySyncSendMessagesBackIntoPipelineData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return;
	}
}

static void
dino_history_sync_send_messages_back_into_pipeline_ready (GObject* source_object,
                                                          GAsyncResult* _res_,
                                                          gpointer _user_data_)
{
	DinoHistorySyncSendMessagesBackIntoPipelineData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_history_sync_send_messages_back_into_pipeline_co (_data_);
}

static gboolean
dino_history_sync_send_messages_back_into_pipeline_co (DinoHistorySyncSendMessagesBackIntoPipelineData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->stanzas;
	if (!gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp0_, _data_->query_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_->_tmp1_ = _data_->self->priv->stanzas;
		_data_->_tmp2_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp1_, _data_->query_id);
		_data_->_message_list = (GeeList*) _data_->_tmp2_;
		_data_->_tmp3_ = _data_->_message_list;
		_data_->_tmp4_ = gee_collection_get_size ((GeeCollection*) _data_->_tmp3_);
		_data_->_tmp5_ = _data_->_tmp4_;
		_data_->_message_size = _data_->_tmp5_;
		_data_->_message_index = -1;
		while (TRUE) {
			_data_->_message_index = _data_->_message_index + 1;
			_data_->_tmp6_ = _data_->_message_index;
			_data_->_tmp7_ = _data_->_message_size;
			if (!(_data_->_tmp6_ < _data_->_tmp7_)) {
				break;
			}
			_data_->_tmp8_ = _data_->_message_list;
			_data_->_tmp9_ = gee_list_get (_data_->_tmp8_, _data_->_message_index);
			_data_->message = (XmppMessageStanza*) _data_->_tmp9_;
			if (_data_->cancellable != NULL) {
				_data_->_tmp10_ = g_cancellable_is_cancelled (_data_->cancellable);
			} else {
				_data_->_tmp10_ = FALSE;
			}
			if (_data_->_tmp10_) {
				_g_object_unref0 (_data_->message);
				break;
			}
			_data_->_tmp11_ = _data_->self->priv->stream_interactor;
			_data_->_tmp12_ = dino_message_processor_IDENTITY;
			_data_->_tmp13_ = dino_stream_interactor_get_module (_data_->_tmp11_, DINO_TYPE_MESSAGE_PROCESSOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp12_);
			_data_->_tmp14_ = (DinoMessageProcessor*) _data_->_tmp13_;
			_data_->_tmp15_ = _data_->message;
			_data_->_state_ = 1;
			dino_message_processor_run_pipeline_announce (_data_->_tmp14_, _data_->account, _data_->_tmp15_, dino_history_sync_send_messages_back_into_pipeline_ready, _data_);
			return FALSE;
			_state_1:
			dino_message_processor_run_pipeline_announce_finish (_data_->_tmp14_, _data_->_res_);
			_g_object_unref0 (_data_->_tmp14_);
			_g_object_unref0 (_data_->message);
		}
		_g_object_unref0 (_data_->_message_list);
	}
	_data_->_tmp16_ = _data_->self->priv->stanzas;
	gee_abstract_map_unset ((GeeAbstractMap*) _data_->_tmp16_, _data_->query_id, NULL);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static Block16Data*
block16_data_ref (Block16Data* _data16_)
{
	g_atomic_int_inc (&_data16_->_ref_count_);
	return _data16_;
}

static void
block16_data_unref (void * _userdata_)
{
	Block16Data* _data16_;
	_data16_ = (Block16Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data16_->_ref_count_)) {
		DinoHistorySync* self;
		self = _data16_->self;
		_g_object_unref0 (_data16_->account);
		_dino_history_sync_unref0 (self);
		g_slice_free (Block16Data, _data16_);
	}
}

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
__lambda32_ (DinoHistorySync* self,
             DinoEntitiesAccount* account,
             XmppXmppStream* stream)
{
	GeeHashMap* _tmp0_;
	g_return_if_fail (account != NULL);
	g_return_if_fail (stream != NULL);
	_tmp0_ = self->current_catchup_id;
	if (!gee_abstract_map_has_key ((GeeAbstractMap*) _tmp0_, account)) {
		GeeHashMap* _tmp1_;
		GeeHashMap* _tmp2_;
		GeeHashMap* _tmp3_;
		_tmp1_ = self->current_catchup_id;
		_tmp2_ = gee_hash_map_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, G_TYPE_INT, NULL, NULL, _xmpp_jid_hash_func_gee_hash_data_func, NULL, NULL, _xmpp_jid_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
		_tmp3_ = _tmp2_;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp1_, account, _tmp3_);
		_g_object_unref0 (_tmp3_);
	} else {
		GeeHashMap* _tmp4_;
		gpointer _tmp5_;
		GeeHashMap* _tmp6_;
		_tmp4_ = self->current_catchup_id;
		_tmp5_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp4_, account);
		_tmp6_ = (GeeHashMap*) _tmp5_;
		gee_abstract_map_clear ((GeeAbstractMap*) _tmp6_);
		_g_object_unref0 (_tmp6_);
	}
}

static void
___lambda32__dino_connection_manager_stream_attached_modules (DinoConnectionManager* _sender,
                                                              DinoEntitiesAccount* account,
                                                              XmppXmppStream* stream,
                                                              gpointer self)
{
	__lambda32_ ((DinoHistorySync*) self, account, stream);
}

static void
__lambda33_ (Block16Data* _data16_,
             XmppXmppStream* stream)
{
	DinoHistorySync* self;
	self = _data16_->self;
	g_return_if_fail (stream != NULL);
	dino_history_sync_consider_fetch_everything (self, _data16_->account, stream);
}

static void
___lambda33__xmpp_message_archive_management_module_feature_available (XmppMessageArchiveManagementModule* _sender,
                                                                       XmppXmppStream* stream,
                                                                       gpointer self)
{
	__lambda33_ (self, stream);
}

static void
__lambda35_ (Block16Data* _data16_,
             XmppXmppStream* stream,
             XmppMessageStanza* message)
{
	DinoHistorySync* self;
	self = _data16_->self;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (message != NULL);
	dino_history_sync_on_unprocessed_message (self, _data16_->account, stream, message);
}

static void
___lambda35__xmpp_message_module_received_message_unprocessed (XmppMessageModule* _sender,
                                                               XmppXmppStream* stream,
                                                               XmppMessageStanza* message,
                                                               gpointer self)
{
	__lambda35_ (self, stream, message);
}

static void
dino_history_sync_on_account_added (DinoHistorySync* self,
                                    DinoEntitiesAccount* account)
{
	Block16Data* _data16_;
	DinoEntitiesAccount* _tmp0_;
	DinoDatabase* _tmp1_;
	GeeHashMap* _tmp2_;
	GeeHashMap* _tmp3_;
	GeeHashMap* _tmp4_;
	DinoStreamInteractor* _tmp5_;
	DinoConnectionManager* _tmp6_;
	DinoStreamInteractor* _tmp7_;
	DinoModuleManager* _tmp8_;
	XmppModuleIdentity* _tmp9_;
	gpointer _tmp10_;
	XmppMessageArchiveManagementModule* _tmp11_;
	DinoStreamInteractor* _tmp12_;
	DinoModuleManager* _tmp13_;
	XmppModuleIdentity* _tmp14_;
	gpointer _tmp15_;
	XmppMessageModule* _tmp16_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	_data16_ = g_slice_new0 (Block16Data);
	_data16_->_ref_count_ = 1;
	_data16_->self = dino_history_sync_ref (self);
	_tmp0_ = _g_object_ref0 (account);
	_g_object_unref0 (_data16_->account);
	_data16_->account = _tmp0_;
	_tmp1_ = self->priv->db;
	dino_history_sync_cleanup_db_ranges (_tmp1_, _data16_->account);
	_tmp2_ = self->mam_times;
	_tmp3_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_DATE_TIME, (GBoxedCopyFunc) g_date_time_ref, (GDestroyNotify) g_date_time_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_tmp4_ = _tmp3_;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp2_, _data16_->account, _tmp4_);
	_g_object_unref0 (_tmp4_);
	_tmp5_ = self->priv->stream_interactor;
	_tmp6_ = _tmp5_->connection_manager;
	g_signal_connect (_tmp6_, "stream-attached-modules", (GCallback) ___lambda32__dino_connection_manager_stream_attached_modules, self);
	_tmp7_ = self->priv->stream_interactor;
	_tmp8_ = _tmp7_->module_manager;
	_tmp9_ = xmpp_message_archive_management_module_IDENTITY;
	_tmp10_ = dino_module_manager_get_module (_tmp8_, XMPP_MESSAGE_ARCHIVE_MANAGEMENT_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data16_->account, _tmp9_);
	_tmp11_ = (XmppMessageArchiveManagementModule*) _tmp10_;
	g_signal_connect_data (_tmp11_, "feature-available", (GCallback) ___lambda33__xmpp_message_archive_management_module_feature_available, block16_data_ref (_data16_), (GClosureNotify) block16_data_unref, 0);
	_g_object_unref0 (_tmp11_);
	_tmp12_ = self->priv->stream_interactor;
	_tmp13_ = _tmp12_->module_manager;
	_tmp14_ = xmpp_message_module_IDENTITY;
	_tmp15_ = dino_module_manager_get_module (_tmp13_, XMPP_TYPE_MESSAGE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data16_->account, _tmp14_);
	_tmp16_ = (XmppMessageModule*) _tmp15_;
	g_signal_connect_data (_tmp16_, "received-message-unprocessed", (GCallback) ___lambda35__xmpp_message_module_received_message_unprocessed, block16_data_ref (_data16_), (GClosureNotify) block16_data_unref, 0);
	_g_object_unref0 (_tmp16_);
	block16_data_unref (_data16_);
	_data16_ = NULL;
}

static Block17Data*
block17_data_ref (Block17Data* _data17_)
{
	g_atomic_int_inc (&_data17_->_ref_count_);
	return _data17_;
}

static void
block17_data_unref (void * _userdata_)
{
	Block17Data* _data17_;
	_data17_ = (Block17Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data17_->_ref_count_)) {
		DinoHistorySync* self;
		self = _data17_->self;
		_g_object_unref0 (_data17_->account);
		_dino_history_sync_unref0 (self);
		g_slice_free (Block17Data, _data17_);
	}
}

static void
__lambda34_ (Block17Data* _data17_,
             GObject* _,
             GAsyncResult* res)
{
	DinoHistorySync* self;
	GeeHashMap* _tmp0_;
	gpointer _tmp1_;
	GeeHashMap* _tmp2_;
	XmppJid* _tmp3_;
	XmppJid* _tmp4_;
	XmppJid* _tmp5_;
	self = _data17_->self;
	g_return_if_fail (res != NULL);
	dino_history_sync_fetch_everything_finish (self, res);
	_tmp0_ = self->cancellables;
	_tmp1_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp0_, _data17_->account);
	_tmp2_ = (GeeHashMap*) _tmp1_;
	_tmp3_ = dino_entities_account_get_bare_jid (_data17_->account);
	_tmp4_ = _tmp3_;
	_tmp5_ = _tmp4_;
	gee_abstract_map_unset ((GeeAbstractMap*) _tmp2_, _tmp5_, NULL);
	_xmpp_jid_unref0 (_tmp5_);
	_g_object_unref0 (_tmp2_);
}

static void
___lambda34__gasync_ready_callback (GObject* source_object,
                                    GAsyncResult* res,
                                    gpointer self)
{
	__lambda34_ (self, source_object, res);
	block17_data_unref (self);
}

static void
dino_history_sync_consider_fetch_everything (DinoHistorySync* self,
                                             DinoEntitiesAccount* account,
                                             XmppXmppStream* stream)
{
	Block17Data* _data17_;
	DinoEntitiesAccount* _tmp0_;
	WeakMap* _tmp1_;
	XmppJid* _tmp2_;
	XmppJid* _tmp3_;
	XmppJid* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	WeakMap* _tmp7_;
	GeeHashMap* _tmp8_;
	GeeHashMap* _tmp12_;
	gpointer _tmp13_;
	GeeHashMap* _tmp14_;
	XmppJid* _tmp15_;
	XmppJid* _tmp16_;
	XmppJid* _tmp17_;
	gboolean _tmp18_;
	GeeHashMap* _tmp27_;
	gpointer _tmp28_;
	GeeHashMap* _tmp29_;
	XmppJid* _tmp30_;
	XmppJid* _tmp31_;
	XmppJid* _tmp32_;
	GCancellable* _tmp33_;
	GCancellable* _tmp34_;
	XmppJid* _tmp35_;
	XmppJid* _tmp36_;
	XmppJid* _tmp37_;
	GeeHashMap* _tmp38_;
	gpointer _tmp39_;
	GeeHashMap* _tmp40_;
	XmppJid* _tmp41_;
	XmppJid* _tmp42_;
	XmppJid* _tmp43_;
	gpointer _tmp44_;
	GCancellable* _tmp45_;
	GDateTime* _tmp46_;
	GDateTime* _tmp47_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (stream != NULL);
	_data17_ = g_slice_new0 (Block17Data);
	_data17_->_ref_count_ = 1;
	_data17_->self = dino_history_sync_ref (self);
	_tmp0_ = _g_object_ref0 (account);
	_g_object_unref0 (_data17_->account);
	_data17_->account = _tmp0_;
	_tmp1_ = self->sync_streams;
	if (gee_abstract_map_has ((GeeAbstractMap*) _tmp1_, _data17_->account, stream)) {
		block17_data_unref (_data17_);
		_data17_ = NULL;
		return;
	}
	_tmp2_ = dino_entities_account_get_bare_jid (_data17_->account);
	_tmp3_ = _tmp2_;
	_tmp4_ = _tmp3_;
	_tmp5_ = xmpp_jid_to_string (_tmp4_);
	_tmp6_ = _tmp5_;
	g_debug ("history_sync.vala:488: [%s] MAM available", _tmp6_);
	_g_free0 (_tmp6_);
	_xmpp_jid_unref0 (_tmp4_);
	_tmp7_ = self->sync_streams;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp7_, _data17_->account, stream);
	_tmp8_ = self->cancellables;
	if (!gee_abstract_map_has_key ((GeeAbstractMap*) _tmp8_, _data17_->account)) {
		GeeHashMap* _tmp9_;
		GeeHashMap* _tmp10_;
		GeeHashMap* _tmp11_;
		_tmp9_ = self->cancellables;
		_tmp10_ = gee_hash_map_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, g_cancellable_get_type (), (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
		_tmp11_ = _tmp10_;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp9_, _data17_->account, _tmp11_);
		_g_object_unref0 (_tmp11_);
	}
	_tmp12_ = self->cancellables;
	_tmp13_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp12_, _data17_->account);
	_tmp14_ = (GeeHashMap*) _tmp13_;
	_tmp15_ = dino_entities_account_get_bare_jid (_data17_->account);
	_tmp16_ = _tmp15_;
	_tmp17_ = _tmp16_;
	_tmp18_ = gee_abstract_map_has_key ((GeeAbstractMap*) _tmp14_, _tmp17_);
	_xmpp_jid_unref0 (_tmp17_);
	_g_object_unref0 (_tmp14_);
	if (_tmp18_) {
		GeeHashMap* _tmp19_;
		gpointer _tmp20_;
		GeeHashMap* _tmp21_;
		XmppJid* _tmp22_;
		XmppJid* _tmp23_;
		XmppJid* _tmp24_;
		gpointer _tmp25_;
		GCancellable* _tmp26_;
		_tmp19_ = self->cancellables;
		_tmp20_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp19_, _data17_->account);
		_tmp21_ = (GeeHashMap*) _tmp20_;
		_tmp22_ = dino_entities_account_get_bare_jid (_data17_->account);
		_tmp23_ = _tmp22_;
		_tmp24_ = _tmp23_;
		_tmp25_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp21_, _tmp24_);
		_tmp26_ = (GCancellable*) _tmp25_;
		g_cancellable_cancel (_tmp26_);
		_g_object_unref0 (_tmp26_);
		_xmpp_jid_unref0 (_tmp24_);
		_g_object_unref0 (_tmp21_);
	}
	_tmp27_ = self->cancellables;
	_tmp28_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp27_, _data17_->account);
	_tmp29_ = (GeeHashMap*) _tmp28_;
	_tmp30_ = dino_entities_account_get_bare_jid (_data17_->account);
	_tmp31_ = _tmp30_;
	_tmp32_ = _tmp31_;
	_tmp33_ = g_cancellable_new ();
	_tmp34_ = _tmp33_;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp29_, _tmp32_, _tmp34_);
	_g_object_unref0 (_tmp34_);
	_xmpp_jid_unref0 (_tmp32_);
	_g_object_unref0 (_tmp29_);
	_tmp35_ = dino_entities_account_get_bare_jid (_data17_->account);
	_tmp36_ = _tmp35_;
	_tmp37_ = _tmp36_;
	_tmp38_ = self->cancellables;
	_tmp39_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp38_, _data17_->account);
	_tmp40_ = (GeeHashMap*) _tmp39_;
	_tmp41_ = dino_entities_account_get_bare_jid (_data17_->account);
	_tmp42_ = _tmp41_;
	_tmp43_ = _tmp42_;
	_tmp44_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp40_, _tmp43_);
	_tmp45_ = (GCancellable*) _tmp44_;
	_tmp46_ = g_date_time_new_from_unix_utc ((gint64) 0);
	_tmp47_ = _tmp46_;
	dino_history_sync_fetch_everything (self, _data17_->account, _tmp37_, _tmp45_, _tmp47_, ___lambda34__gasync_ready_callback, block17_data_ref (_data17_));
	_g_date_time_unref0 (_tmp47_);
	_g_object_unref0 (_tmp45_);
	_xmpp_jid_unref0 (_tmp43_);
	_g_object_unref0 (_tmp40_);
	_xmpp_jid_unref0 (_tmp37_);
	block17_data_unref (_data17_);
	_data17_ = NULL;
}

void
dino_history_sync_cleanup_db_ranges (DinoDatabase* db,
                                     DinoEntitiesAccount* account)
{
	GeeHashMap* ranges = NULL;
	GeeHashMap* _tmp0_;
	GeeArrayList* to_delete = NULL;
	GeeArrayList* _tmp79_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (db != NULL);
	g_return_if_fail (account != NULL);
	_tmp0_ = gee_hash_map_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, GEE_TYPE_ARRAY_LIST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _xmpp_jid_hash_func_gee_hash_data_func, NULL, NULL, _xmpp_jid_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	ranges = _tmp0_;
	{
		QliteRowIterator* _row_it = NULL;
		DinoDatabaseMamCatchupTable* _tmp1_;
		DinoDatabaseMamCatchupTable* _tmp2_;
		QliteQueryBuilder* _tmp3_;
		QliteQueryBuilder* _tmp4_;
		DinoDatabaseMamCatchupTable* _tmp5_;
		DinoDatabaseMamCatchupTable* _tmp6_;
		QliteColumn* _tmp7_;
		gint _tmp8_;
		gint _tmp9_;
		QliteQueryBuilder* _tmp10_;
		QliteQueryBuilder* _tmp11_;
		QliteRowIterator* _tmp12_;
		QliteRowIterator* _tmp13_;
		_tmp1_ = dino_database_get_mam_catchup (db);
		_tmp2_ = _tmp1_;
		_tmp3_ = qlite_table_select ((QliteTable*) _tmp2_, NULL, (gint) 0);
		_tmp4_ = _tmp3_;
		_tmp5_ = dino_database_get_mam_catchup (db);
		_tmp6_ = _tmp5_;
		_tmp7_ = _tmp6_->account_id;
		_tmp8_ = dino_entities_account_get_id (account);
		_tmp9_ = _tmp8_;
		_tmp10_ = qlite_query_builder_with (_tmp4_, G_TYPE_INT, NULL, NULL, _tmp7_, "=", (gpointer) ((gintptr) _tmp9_));
		_tmp11_ = _tmp10_;
		_tmp12_ = qlite_query_builder_iterator (_tmp11_);
		_tmp13_ = _tmp12_;
		_qlite_statement_builder_unref0 (_tmp11_);
		_qlite_statement_builder_unref0 (_tmp4_);
		_row_it = _tmp13_;
		while (TRUE) {
			QliteRowIterator* _tmp14_;
			QliteRow* row = NULL;
			QliteRowIterator* _tmp15_;
			QliteRow* _tmp16_;
			DinoHistorySyncMamRange* mam_range = NULL;
			DinoHistorySyncMamRange* _tmp17_;
			DinoHistorySyncMamRange* _tmp18_;
			QliteRow* _tmp19_;
			DinoDatabaseMamCatchupTable* _tmp20_;
			DinoDatabaseMamCatchupTable* _tmp21_;
			QliteColumn* _tmp22_;
			gpointer _tmp23_;
			XmppJid* _tmp24_ = NULL;
			QliteRow* _tmp25_;
			DinoDatabaseMamCatchupTable* _tmp26_;
			DinoDatabaseMamCatchupTable* _tmp27_;
			QliteColumn* _tmp28_;
			gpointer _tmp29_;
			gchar* _tmp30_;
			XmppJid* _tmp31_;
			XmppJid* _tmp32_;
			DinoHistorySyncMamRange* _tmp33_;
			XmppJid* _tmp34_;
			DinoHistorySyncMamRange* _tmp35_;
			QliteRow* _tmp36_;
			DinoDatabaseMamCatchupTable* _tmp37_;
			DinoDatabaseMamCatchupTable* _tmp38_;
			QliteColumn* _tmp39_;
			gpointer _tmp40_;
			DinoHistorySyncMamRange* _tmp41_;
			QliteRow* _tmp42_;
			DinoDatabaseMamCatchupTable* _tmp43_;
			DinoDatabaseMamCatchupTable* _tmp44_;
			QliteColumn* _tmp45_;
			gpointer _tmp46_;
			DinoHistorySyncMamRange* _tmp47_;
			QliteRow* _tmp48_;
			DinoDatabaseMamCatchupTable* _tmp49_;
			DinoDatabaseMamCatchupTable* _tmp50_;
			QliteColumn* _tmp51_;
			gpointer _tmp52_;
			DinoHistorySyncMamRange* _tmp53_;
			QliteRow* _tmp54_;
			DinoDatabaseMamCatchupTable* _tmp55_;
			DinoDatabaseMamCatchupTable* _tmp56_;
			QliteColumn* _tmp57_;
			gpointer _tmp58_;
			DinoHistorySyncMamRange* _tmp59_;
			QliteRow* _tmp60_;
			DinoDatabaseMamCatchupTable* _tmp61_;
			DinoDatabaseMamCatchupTable* _tmp62_;
			QliteColumn* _tmp63_;
			gpointer _tmp64_;
			GeeHashMap* _tmp65_;
			DinoHistorySyncMamRange* _tmp66_;
			XmppJid* _tmp67_;
			GeeHashMap* _tmp73_;
			DinoHistorySyncMamRange* _tmp74_;
			XmppJid* _tmp75_;
			gpointer _tmp76_;
			GeeArrayList* _tmp77_;
			DinoHistorySyncMamRange* _tmp78_;
			_tmp14_ = _row_it;
			if (!qlite_row_iterator_next (_tmp14_)) {
				break;
			}
			_tmp15_ = _row_it;
			_tmp16_ = qlite_row_iterator_get (_tmp15_);
			row = _tmp16_;
			_tmp17_ = dino_history_sync_mam_range_new ();
			mam_range = _tmp17_;
			_tmp18_ = mam_range;
			_tmp19_ = row;
			_tmp20_ = dino_database_get_mam_catchup (db);
			_tmp21_ = _tmp20_;
			_tmp22_ = _tmp21_->id;
			_tmp23_ = qlite_row_get (_tmp19_, G_TYPE_INT, NULL, NULL, _tmp22_);
			_tmp18_->id = (gint) ((gintptr) _tmp23_);
			_tmp25_ = row;
			_tmp26_ = dino_database_get_mam_catchup (db);
			_tmp27_ = _tmp26_;
			_tmp28_ = _tmp27_->server_jid;
			_tmp29_ = qlite_row_get (_tmp25_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp28_);
			_tmp30_ = (gchar*) _tmp29_;
			_tmp31_ = xmpp_jid_new (_tmp30_, &_inner_error0_);
			_tmp32_ = _tmp31_;
			_g_free0 (_tmp30_);
			_tmp24_ = _tmp32_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_dino_history_sync_mam_range_unref0 (mam_range);
				_qlite_row_unref0 (row);
				_qlite_row_iterator_unref0 (_row_it);
				_g_object_unref0 (ranges);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return;
			}
			_tmp33_ = mam_range;
			_tmp34_ = _tmp24_;
			_tmp24_ = NULL;
			_xmpp_jid_unref0 (_tmp33_->server_jid);
			_tmp33_->server_jid = _tmp34_;
			_tmp35_ = mam_range;
			_tmp36_ = row;
			_tmp37_ = dino_database_get_mam_catchup (db);
			_tmp38_ = _tmp37_;
			_tmp39_ = _tmp38_->from_time;
			_tmp40_ = qlite_row_get (_tmp36_, G_TYPE_LONG, NULL, NULL, _tmp39_);
			_tmp35_->from_time = (glong) ((gintptr) _tmp40_);
			_tmp41_ = mam_range;
			_tmp42_ = row;
			_tmp43_ = dino_database_get_mam_catchup (db);
			_tmp44_ = _tmp43_;
			_tmp45_ = _tmp44_->from_id;
			_tmp46_ = qlite_row_get (_tmp42_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp45_);
			_g_free0 (_tmp41_->from_id);
			_tmp41_->from_id = (gchar*) _tmp46_;
			_tmp47_ = mam_range;
			_tmp48_ = row;
			_tmp49_ = dino_database_get_mam_catchup (db);
			_tmp50_ = _tmp49_;
			_tmp51_ = _tmp50_->from_end;
			_tmp52_ = qlite_row_get (_tmp48_, G_TYPE_BOOLEAN, NULL, NULL, _tmp51_);
			_tmp47_->from_end = (gboolean) ((gintptr) _tmp52_);
			_tmp53_ = mam_range;
			_tmp54_ = row;
			_tmp55_ = dino_database_get_mam_catchup (db);
			_tmp56_ = _tmp55_;
			_tmp57_ = _tmp56_->to_time;
			_tmp58_ = qlite_row_get (_tmp54_, G_TYPE_LONG, NULL, NULL, _tmp57_);
			_tmp53_->to_time = (glong) ((gintptr) _tmp58_);
			_tmp59_ = mam_range;
			_tmp60_ = row;
			_tmp61_ = dino_database_get_mam_catchup (db);
			_tmp62_ = _tmp61_;
			_tmp63_ = _tmp62_->to_id;
			_tmp64_ = qlite_row_get (_tmp60_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp63_);
			_g_free0 (_tmp59_->to_id);
			_tmp59_->to_id = (gchar*) _tmp64_;
			_tmp65_ = ranges;
			_tmp66_ = mam_range;
			_tmp67_ = _tmp66_->server_jid;
			if (!gee_abstract_map_has_key ((GeeAbstractMap*) _tmp65_, _tmp67_)) {
				GeeHashMap* _tmp68_;
				DinoHistorySyncMamRange* _tmp69_;
				XmppJid* _tmp70_;
				GeeArrayList* _tmp71_;
				GeeArrayList* _tmp72_;
				_tmp68_ = ranges;
				_tmp69_ = mam_range;
				_tmp70_ = _tmp69_->server_jid;
				_tmp71_ = gee_array_list_new (DINO_HISTORY_SYNC_TYPE_MAM_RANGE, (GBoxedCopyFunc) dino_history_sync_mam_range_ref, (GDestroyNotify) dino_history_sync_mam_range_unref, NULL, NULL, NULL);
				_tmp72_ = _tmp71_;
				gee_abstract_map_set ((GeeAbstractMap*) _tmp68_, _tmp70_, _tmp72_);
				_g_object_unref0 (_tmp72_);
			}
			_tmp73_ = ranges;
			_tmp74_ = mam_range;
			_tmp75_ = _tmp74_->server_jid;
			_tmp76_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp73_, _tmp75_);
			_tmp77_ = (GeeArrayList*) _tmp76_;
			_tmp78_ = mam_range;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp77_, _tmp78_);
			_g_object_unref0 (_tmp77_);
			_xmpp_jid_unref0 (_tmp24_);
			_dino_history_sync_mam_range_unref0 (mam_range);
			_qlite_row_unref0 (row);
		}
		_qlite_row_iterator_unref0 (_row_it);
	}
	_tmp79_ = gee_array_list_new (DINO_HISTORY_SYNC_TYPE_MAM_RANGE, (GBoxedCopyFunc) dino_history_sync_mam_range_ref, (GDestroyNotify) dino_history_sync_mam_range_unref, NULL, NULL, NULL);
	to_delete = _tmp79_;
	{
		GeeIterator* _server_jid_it = NULL;
		GeeHashMap* _tmp80_;
		GeeSet* _tmp81_;
		GeeSet* _tmp82_;
		GeeSet* _tmp83_;
		GeeIterator* _tmp84_;
		GeeIterator* _tmp85_;
		_tmp80_ = ranges;
		_tmp81_ = gee_abstract_map_get_keys ((GeeAbstractMap*) _tmp80_);
		_tmp82_ = _tmp81_;
		_tmp83_ = _tmp82_;
		_tmp84_ = gee_iterable_iterator ((GeeIterable*) _tmp83_);
		_tmp85_ = _tmp84_;
		_g_object_unref0 (_tmp83_);
		_server_jid_it = _tmp85_;
		while (TRUE) {
			GeeIterator* _tmp86_;
			XmppJid* server_jid = NULL;
			GeeIterator* _tmp87_;
			gpointer _tmp88_;
			_tmp86_ = _server_jid_it;
			if (!gee_iterator_next (_tmp86_)) {
				break;
			}
			_tmp87_ = _server_jid_it;
			_tmp88_ = gee_iterator_get (_tmp87_);
			server_jid = (XmppJid*) _tmp88_;
			{
				GeeArrayList* _range1_list = NULL;
				GeeHashMap* _tmp89_;
				XmppJid* _tmp90_;
				gpointer _tmp91_;
				gint _range1_size = 0;
				GeeArrayList* _tmp92_;
				gint _tmp93_;
				gint _tmp94_;
				gint _range1_index = 0;
				_tmp89_ = ranges;
				_tmp90_ = server_jid;
				_tmp91_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp89_, _tmp90_);
				_range1_list = (GeeArrayList*) _tmp91_;
				_tmp92_ = _range1_list;
				_tmp93_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp92_);
				_tmp94_ = _tmp93_;
				_range1_size = _tmp94_;
				_range1_index = -1;
				while (TRUE) {
					gint _tmp95_;
					gint _tmp96_;
					DinoHistorySyncMamRange* range1 = NULL;
					GeeArrayList* _tmp97_;
					gpointer _tmp98_;
					GeeArrayList* _tmp99_;
					DinoHistorySyncMamRange* _tmp100_;
					_range1_index = _range1_index + 1;
					_tmp95_ = _range1_index;
					_tmp96_ = _range1_size;
					if (!(_tmp95_ < _tmp96_)) {
						break;
					}
					_tmp97_ = _range1_list;
					_tmp98_ = gee_abstract_list_get ((GeeAbstractList*) _tmp97_, _range1_index);
					range1 = (DinoHistorySyncMamRange*) _tmp98_;
					_tmp99_ = to_delete;
					_tmp100_ = range1;
					if (gee_abstract_collection_contains ((GeeAbstractCollection*) _tmp99_, _tmp100_)) {
						_dino_history_sync_mam_range_unref0 (range1);
						continue;
					}
					{
						GeeArrayList* _range2_list = NULL;
						GeeHashMap* _tmp101_;
						XmppJid* _tmp102_;
						gpointer _tmp103_;
						gint _range2_size = 0;
						GeeArrayList* _tmp104_;
						gint _tmp105_;
						gint _tmp106_;
						gint _range2_index = 0;
						_tmp101_ = ranges;
						_tmp102_ = server_jid;
						_tmp103_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp101_, _tmp102_);
						_range2_list = (GeeArrayList*) _tmp103_;
						_tmp104_ = _range2_list;
						_tmp105_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp104_);
						_tmp106_ = _tmp105_;
						_range2_size = _tmp106_;
						_range2_index = -1;
						while (TRUE) {
							gint _tmp107_;
							gint _tmp108_;
							DinoHistorySyncMamRange* range2 = NULL;
							GeeArrayList* _tmp109_;
							gpointer _tmp110_;
							XmppJid* _tmp111_;
							XmppJid* _tmp112_;
							XmppJid* _tmp113_;
							gchar* _tmp114_;
							gchar* _tmp115_;
							XmppJid* _tmp116_;
							gchar* _tmp117_;
							gchar* _tmp118_;
							DinoHistorySyncMamRange* _tmp119_;
							gchar* _tmp120_;
							gchar* _tmp121_;
							DinoHistorySyncMamRange* _tmp122_;
							gchar* _tmp123_;
							gchar* _tmp124_;
							DinoHistorySyncMamRange* _tmp125_;
							gchar* _tmp126_;
							gchar* _tmp127_;
							DinoHistorySyncMamRange* _tmp128_;
							gchar* _tmp129_;
							gchar* _tmp130_;
							gboolean _tmp131_ = FALSE;
							DinoHistorySyncMamRange* _tmp132_;
							DinoHistorySyncMamRange* _tmp133_;
							gboolean _tmp136_ = FALSE;
							DinoHistorySyncMamRange* _tmp137_;
							DinoHistorySyncMamRange* _tmp138_;
							gboolean _tmp145_ = FALSE;
							DinoHistorySyncMamRange* _tmp146_;
							DinoHistorySyncMamRange* _tmp147_;
							DinoHistorySyncMamRange* _tmp148_;
							glong _tmp149_;
							_range2_index = _range2_index + 1;
							_tmp107_ = _range2_index;
							_tmp108_ = _range2_size;
							if (!(_tmp107_ < _tmp108_)) {
								break;
							}
							_tmp109_ = _range2_list;
							_tmp110_ = gee_abstract_list_get ((GeeAbstractList*) _tmp109_, _range2_index);
							range2 = (DinoHistorySyncMamRange*) _tmp110_;
							_tmp111_ = dino_entities_account_get_bare_jid (account);
							_tmp112_ = _tmp111_;
							_tmp113_ = _tmp112_;
							_tmp114_ = xmpp_jid_to_string (_tmp113_);
							_tmp115_ = _tmp114_;
							_tmp116_ = server_jid;
							_tmp117_ = xmpp_jid_to_string (_tmp116_);
							_tmp118_ = _tmp117_;
							_tmp119_ = range1;
							_tmp120_ = g_strdup_printf ("%li", _tmp119_->from_time);
							_tmp121_ = _tmp120_;
							_tmp122_ = range1;
							_tmp123_ = g_strdup_printf ("%li", _tmp122_->to_time);
							_tmp124_ = _tmp123_;
							_tmp125_ = range2;
							_tmp126_ = g_strdup_printf ("%li", _tmp125_->from_time);
							_tmp127_ = _tmp126_;
							_tmp128_ = range2;
							_tmp129_ = g_strdup_printf ("%li", _tmp128_->to_time);
							_tmp130_ = _tmp129_;
							g_debug ("history_sync.vala:526: [%s | %s] | %s - %s vs %s - %s", _tmp115_, _tmp118_, _tmp121_, _tmp124_, _tmp127_, _tmp130_);
							_g_free0 (_tmp130_);
							_g_free0 (_tmp127_);
							_g_free0 (_tmp124_);
							_g_free0 (_tmp121_);
							_g_free0 (_tmp118_);
							_g_free0 (_tmp115_);
							_xmpp_jid_unref0 (_tmp113_);
							_tmp132_ = range1;
							_tmp133_ = range2;
							if (_tmp132_ == _tmp133_) {
								_tmp131_ = TRUE;
							} else {
								GeeArrayList* _tmp134_;
								DinoHistorySyncMamRange* _tmp135_;
								_tmp134_ = to_delete;
								_tmp135_ = range2;
								_tmp131_ = gee_abstract_collection_contains ((GeeAbstractCollection*) _tmp134_, _tmp135_);
							}
							if (_tmp131_) {
								_dino_history_sync_mam_range_unref0 (range2);
								continue;
							}
							_tmp137_ = range1;
							_tmp138_ = range2;
							if (_tmp137_->from_time <= _tmp138_->from_time) {
								DinoHistorySyncMamRange* _tmp139_;
								DinoHistorySyncMamRange* _tmp140_;
								_tmp139_ = range1;
								_tmp140_ = range2;
								_tmp136_ = _tmp139_->to_time >= _tmp140_->to_time;
							} else {
								_tmp136_ = FALSE;
							}
							if (_tmp136_) {
								DinoHistorySyncMamRange* _tmp141_;
								DinoHistorySyncMamRange* _tmp142_;
								GeeArrayList* _tmp143_;
								DinoHistorySyncMamRange* _tmp144_;
								_tmp141_ = range1;
								_tmp142_ = range1;
								g_warning ("history_sync.vala:533: Removing db range which is a subset of %li-%li", _tmp141_->from_time, _tmp142_->to_time);
								_tmp143_ = to_delete;
								_tmp144_ = range2;
								gee_abstract_collection_add ((GeeAbstractCollection*) _tmp143_, _tmp144_);
								_dino_history_sync_mam_range_unref0 (range2);
								continue;
							}
							_tmp146_ = range1;
							_tmp147_ = range2;
							_tmp148_ = range1;
							_tmp149_ = _tmp147_->to_time;
							if ((_tmp146_->from_time <= _tmp149_) && (_tmp149_ <= _tmp148_->to_time)) {
								DinoHistorySyncMamRange* _tmp150_;
								DinoHistorySyncMamRange* _tmp151_;
								_tmp150_ = range2;
								_tmp151_ = range1;
								_tmp145_ = _tmp150_->from_time <= _tmp151_->from_time;
							} else {
								_tmp145_ = FALSE;
							}
							if (_tmp145_) {
								DinoHistorySyncMamRange* _tmp152_;
								DinoHistorySyncMamRange* _tmp153_;
								DinoDatabaseMamCatchupTable* _tmp154_;
								DinoDatabaseMamCatchupTable* _tmp155_;
								QliteUpdateBuilder* _tmp156_;
								QliteUpdateBuilder* _tmp157_;
								DinoDatabaseMamCatchupTable* _tmp158_;
								DinoDatabaseMamCatchupTable* _tmp159_;
								QliteColumn* _tmp160_;
								DinoHistorySyncMamRange* _tmp161_;
								QliteUpdateBuilder* _tmp162_;
								QliteUpdateBuilder* _tmp163_;
								DinoDatabaseMamCatchupTable* _tmp164_;
								DinoDatabaseMamCatchupTable* _tmp165_;
								QliteColumn* _tmp166_;
								DinoHistorySyncMamRange* _tmp167_;
								const gchar* _tmp168_;
								QliteUpdateBuilder* _tmp169_;
								QliteUpdateBuilder* _tmp170_;
								DinoDatabaseMamCatchupTable* _tmp171_;
								DinoDatabaseMamCatchupTable* _tmp172_;
								QliteColumn* _tmp173_;
								DinoHistorySyncMamRange* _tmp174_;
								QliteUpdateBuilder* _tmp175_;
								QliteUpdateBuilder* _tmp176_;
								DinoDatabaseMamCatchupTable* _tmp177_;
								DinoDatabaseMamCatchupTable* _tmp178_;
								QliteColumn* _tmp179_;
								DinoHistorySyncMamRange* _tmp180_;
								QliteUpdateBuilder* _tmp181_;
								QliteUpdateBuilder* _tmp182_;
								GeeArrayList* _tmp183_;
								DinoHistorySyncMamRange* _tmp184_;
								_tmp152_ = range1;
								_tmp153_ = range1;
								g_warning ("history_sync.vala:542: Removing db range that overlapped %li-%li (towa" \
"rds earlier)", _tmp152_->from_time, _tmp153_->to_time);
								_tmp154_ = dino_database_get_mam_catchup (db);
								_tmp155_ = _tmp154_;
								_tmp156_ = qlite_table_update ((QliteTable*) _tmp155_);
								_tmp157_ = _tmp156_;
								_tmp158_ = dino_database_get_mam_catchup (db);
								_tmp159_ = _tmp158_;
								_tmp160_ = _tmp159_->id;
								_tmp161_ = range1;
								_tmp162_ = qlite_update_builder_with (_tmp157_, G_TYPE_INT, NULL, NULL, _tmp160_, "=", (gpointer) ((gintptr) _tmp161_->id));
								_tmp163_ = _tmp162_;
								_tmp164_ = dino_database_get_mam_catchup (db);
								_tmp165_ = _tmp164_;
								_tmp166_ = _tmp165_->from_id;
								_tmp167_ = range2;
								_tmp168_ = _tmp167_->from_id;
								_tmp169_ = qlite_update_builder_set (_tmp163_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp166_, _tmp168_);
								_tmp170_ = _tmp169_;
								_tmp171_ = dino_database_get_mam_catchup (db);
								_tmp172_ = _tmp171_;
								_tmp173_ = _tmp172_->from_time;
								_tmp174_ = range2;
								_tmp175_ = qlite_update_builder_set (_tmp170_, G_TYPE_LONG, NULL, NULL, _tmp173_, (gpointer) ((gintptr) _tmp174_->from_time));
								_tmp176_ = _tmp175_;
								_tmp177_ = dino_database_get_mam_catchup (db);
								_tmp178_ = _tmp177_;
								_tmp179_ = _tmp178_->from_end;
								_tmp180_ = range2;
								_tmp181_ = qlite_update_builder_set (_tmp176_, G_TYPE_BOOLEAN, NULL, NULL, _tmp179_, (gpointer) ((gintptr) _tmp180_->from_end));
								_tmp182_ = _tmp181_;
								qlite_update_builder_perform (_tmp182_);
								_qlite_statement_builder_unref0 (_tmp182_);
								_qlite_statement_builder_unref0 (_tmp176_);
								_qlite_statement_builder_unref0 (_tmp170_);
								_qlite_statement_builder_unref0 (_tmp163_);
								_qlite_statement_builder_unref0 (_tmp157_);
								_tmp183_ = to_delete;
								_tmp184_ = range2;
								gee_abstract_collection_add ((GeeAbstractCollection*) _tmp183_, _tmp184_);
								_dino_history_sync_mam_range_unref0 (range2);
								continue;
							}
							_dino_history_sync_mam_range_unref0 (range2);
						}
						_g_object_unref0 (_range2_list);
					}
					_dino_history_sync_mam_range_unref0 (range1);
				}
				_g_object_unref0 (_range1_list);
			}
			_xmpp_jid_unref0 (server_jid);
		}
		_g_object_unref0 (_server_jid_it);
	}
	{
		GeeArrayList* _row_list = NULL;
		GeeArrayList* _tmp185_;
		gint _row_size = 0;
		GeeArrayList* _tmp186_;
		gint _tmp187_;
		gint _tmp188_;
		gint _row_index = 0;
		_tmp185_ = to_delete;
		_row_list = _tmp185_;
		_tmp186_ = _row_list;
		_tmp187_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp186_);
		_tmp188_ = _tmp187_;
		_row_size = _tmp188_;
		_row_index = -1;
		while (TRUE) {
			gint _tmp189_;
			gint _tmp190_;
			DinoHistorySyncMamRange* row = NULL;
			GeeArrayList* _tmp191_;
			gpointer _tmp192_;
			DinoDatabaseMamCatchupTable* _tmp193_;
			DinoDatabaseMamCatchupTable* _tmp194_;
			QliteDeleteBuilder* _tmp195_;
			QliteDeleteBuilder* _tmp196_;
			DinoDatabaseMamCatchupTable* _tmp197_;
			DinoDatabaseMamCatchupTable* _tmp198_;
			QliteColumn* _tmp199_;
			DinoHistorySyncMamRange* _tmp200_;
			QliteDeleteBuilder* _tmp201_;
			QliteDeleteBuilder* _tmp202_;
			DinoHistorySyncMamRange* _tmp203_;
			XmppJid* _tmp204_;
			gchar* _tmp205_;
			gchar* _tmp206_;
			DinoHistorySyncMamRange* _tmp207_;
			DinoHistorySyncMamRange* _tmp208_;
			_row_index = _row_index + 1;
			_tmp189_ = _row_index;
			_tmp190_ = _row_size;
			if (!(_tmp189_ < _tmp190_)) {
				break;
			}
			_tmp191_ = _row_list;
			_tmp192_ = gee_abstract_list_get ((GeeAbstractList*) _tmp191_, _row_index);
			row = (DinoHistorySyncMamRange*) _tmp192_;
			_tmp193_ = dino_database_get_mam_catchup (db);
			_tmp194_ = _tmp193_;
			_tmp195_ = qlite_table_delete ((QliteTable*) _tmp194_);
			_tmp196_ = _tmp195_;
			_tmp197_ = dino_database_get_mam_catchup (db);
			_tmp198_ = _tmp197_;
			_tmp199_ = _tmp198_->id;
			_tmp200_ = row;
			_tmp201_ = qlite_delete_builder_with (_tmp196_, G_TYPE_INT, NULL, NULL, _tmp199_, "=", (gpointer) ((gintptr) _tmp200_->id));
			_tmp202_ = _tmp201_;
			qlite_delete_builder_perform (_tmp202_);
			_qlite_statement_builder_unref0 (_tmp202_);
			_qlite_statement_builder_unref0 (_tmp196_);
			_tmp203_ = row;
			_tmp204_ = _tmp203_->server_jid;
			_tmp205_ = xmpp_jid_to_string (_tmp204_);
			_tmp206_ = _tmp205_;
			_tmp207_ = row;
			_tmp208_ = row;
			g_warning ("history_sync.vala:558: Removing db range %s %li-%li", _tmp206_, _tmp207_->from_time, _tmp208_->to_time);
			_g_free0 (_tmp206_);
			_dino_history_sync_mam_range_unref0 (row);
		}
	}
	_g_object_unref0 (to_delete);
	_g_object_unref0 (ranges);
}

static DinoHistorySyncMamRange*
dino_history_sync_mam_range_construct (GType object_type)
{
	DinoHistorySyncMamRange* self = NULL;
	self = (DinoHistorySyncMamRange*) g_type_create_instance (object_type);
	return self;
}

static DinoHistorySyncMamRange*
dino_history_sync_mam_range_new (void)
{
	return dino_history_sync_mam_range_construct (DINO_HISTORY_SYNC_TYPE_MAM_RANGE);
}

static void
dino_history_sync_value_mam_range_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
dino_history_sync_value_mam_range_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		dino_history_sync_mam_range_unref (value->data[0].v_pointer);
	}
}

static void
dino_history_sync_value_mam_range_copy_value (const GValue* src_value,
                                              GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = dino_history_sync_mam_range_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
dino_history_sync_value_mam_range_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
dino_history_sync_value_mam_range_collect_value (GValue* value,
                                                 guint n_collect_values,
                                                 GTypeCValue* collect_values,
                                                 guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		DinoHistorySyncMamRange * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = dino_history_sync_mam_range_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
dino_history_sync_value_mam_range_lcopy_value (const GValue* value,
                                               guint n_collect_values,
                                               GTypeCValue* collect_values,
                                               guint collect_flags)
{
	DinoHistorySyncMamRange ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = dino_history_sync_mam_range_ref (value->data[0].v_pointer);
	}
	return NULL;
}

static GParamSpec*
dino_history_sync_param_spec_mam_range (const gchar* name,
                                        const gchar* nick,
                                        const gchar* blurb,
                                        GType object_type,
                                        GParamFlags flags)
{
	DinoHistorySyncParamSpecMamRange* spec;
	g_return_val_if_fail (g_type_is_a (object_type, DINO_HISTORY_SYNC_TYPE_MAM_RANGE), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

static gpointer
dino_history_sync_value_get_mam_range (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_HISTORY_SYNC_TYPE_MAM_RANGE), NULL);
	return value->data[0].v_pointer;
}

static void
dino_history_sync_value_set_mam_range (GValue* value,
                                       gpointer v_object)
{
	DinoHistorySyncMamRange * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_HISTORY_SYNC_TYPE_MAM_RANGE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DINO_HISTORY_SYNC_TYPE_MAM_RANGE));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		dino_history_sync_mam_range_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dino_history_sync_mam_range_unref (old);
	}
}

static void
dino_history_sync_value_take_mam_range (GValue* value,
                                        gpointer v_object)
{
	DinoHistorySyncMamRange * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_HISTORY_SYNC_TYPE_MAM_RANGE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DINO_HISTORY_SYNC_TYPE_MAM_RANGE));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dino_history_sync_mam_range_unref (old);
	}
}

static void
dino_history_sync_mam_range_class_init (DinoHistorySyncMamRangeClass * klass,
                                        gpointer klass_data)
{
	dino_history_sync_mam_range_parent_class = g_type_class_peek_parent (klass);
	((DinoHistorySyncMamRangeClass *) klass)->finalize = dino_history_sync_mam_range_finalize;
}

static void
dino_history_sync_mam_range_instance_init (DinoHistorySyncMamRange * self,
                                           gpointer klass)
{
	self->ref_count = 1;
}

static void
dino_history_sync_mam_range_finalize (DinoHistorySyncMamRange * obj)
{
	DinoHistorySyncMamRange * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_HISTORY_SYNC_TYPE_MAM_RANGE, DinoHistorySyncMamRange);
	g_signal_handlers_destroy (self);
	_xmpp_jid_unref0 (self->server_jid);
	_g_free0 (self->from_id);
	_g_free0 (self->to_id);
}

static GType
dino_history_sync_mam_range_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { dino_history_sync_value_mam_range_init, dino_history_sync_value_mam_range_free_value, dino_history_sync_value_mam_range_copy_value, dino_history_sync_value_mam_range_peek_pointer, "p", dino_history_sync_value_mam_range_collect_value, "p", dino_history_sync_value_mam_range_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (DinoHistorySyncMamRangeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_history_sync_mam_range_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoHistorySyncMamRange), 0, (GInstanceInitFunc) dino_history_sync_mam_range_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType dino_history_sync_mam_range_type_id;
	dino_history_sync_mam_range_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DinoHistorySyncMamRange", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return dino_history_sync_mam_range_type_id;
}

static GType
dino_history_sync_mam_range_get_type (void)
{
	static volatile gsize dino_history_sync_mam_range_type_id__once = 0;
	if (g_once_init_enter (&dino_history_sync_mam_range_type_id__once)) {
		GType dino_history_sync_mam_range_type_id;
		dino_history_sync_mam_range_type_id = dino_history_sync_mam_range_get_type_once ();
		g_once_init_leave (&dino_history_sync_mam_range_type_id__once, dino_history_sync_mam_range_type_id);
	}
	return dino_history_sync_mam_range_type_id__once;
}

static gpointer
dino_history_sync_mam_range_ref (gpointer instance)
{
	DinoHistorySyncMamRange * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

static void
dino_history_sync_mam_range_unref (gpointer instance)
{
	DinoHistorySyncMamRange * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DINO_HISTORY_SYNC_MAM_RANGE_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static inline gpointer
dino_history_sync_page_request_result_get_instance_private (DinoHistorySyncPageRequestResult* self)
{
	return G_STRUCT_MEMBER_P (self, DinoHistorySyncPageRequestResult_private_offset);
}

static DinoHistorySyncPageRequestResult*
dino_history_sync_page_request_result_construct (GType object_type,
                                                 DinoHistorySyncPageResult page_result,
                                                 XmppMessageArchiveManagementQueryResult* query_result,
                                                 GeeList* stanzas)
{
	DinoHistorySyncPageRequestResult* self = NULL;
	g_return_val_if_fail (query_result != NULL, NULL);
	self = (DinoHistorySyncPageRequestResult*) g_type_create_instance (object_type);
	dino_history_sync_page_request_result_set_page_result (self, page_result);
	dino_history_sync_page_request_result_set_query_result (self, query_result);
	dino_history_sync_page_request_result_set_stanzas (self, stanzas);
	return self;
}

static DinoHistorySyncPageRequestResult*
dino_history_sync_page_request_result_new (DinoHistorySyncPageResult page_result,
                                           XmppMessageArchiveManagementQueryResult* query_result,
                                           GeeList* stanzas)
{
	return dino_history_sync_page_request_result_construct (DINO_HISTORY_SYNC_TYPE_PAGE_REQUEST_RESULT, page_result, query_result, stanzas);
}

static GeeList*
dino_history_sync_page_request_result_get_stanzas (DinoHistorySyncPageRequestResult* self)
{
	GeeList* result;
	GeeList* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_stanzas;
	result = _tmp0_;
	return result;
}

static void
dino_history_sync_page_request_result_set_stanzas (DinoHistorySyncPageRequestResult* self,
                                                   GeeList* value)
{
	GeeList* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_stanzas);
	self->priv->_stanzas = _tmp0_;
}

static DinoHistorySyncPageResult
dino_history_sync_page_request_result_get_page_result (DinoHistorySyncPageRequestResult* self)
{
	DinoHistorySyncPageResult result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_page_result;
	return result;
}

static void
dino_history_sync_page_request_result_set_page_result (DinoHistorySyncPageRequestResult* self,
                                                       DinoHistorySyncPageResult value)
{
	g_return_if_fail (self != NULL);
	self->priv->_page_result = value;
}

static XmppMessageArchiveManagementQueryResult*
dino_history_sync_page_request_result_get_query_result (DinoHistorySyncPageRequestResult* self)
{
	XmppMessageArchiveManagementQueryResult* result;
	XmppMessageArchiveManagementQueryResult* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_query_result;
	result = _tmp0_;
	return result;
}

static void
dino_history_sync_page_request_result_set_query_result (DinoHistorySyncPageRequestResult* self,
                                                        XmppMessageArchiveManagementQueryResult* value)
{
	XmppMessageArchiveManagementQueryResult* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _xmpp_message_archive_management_query_result_ref0 (value);
	_xmpp_message_archive_management_query_result_unref0 (self->priv->_query_result);
	self->priv->_query_result = _tmp0_;
}

static void
dino_history_sync_value_page_request_result_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
dino_history_sync_value_page_request_result_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		dino_history_sync_page_request_result_unref (value->data[0].v_pointer);
	}
}

static void
dino_history_sync_value_page_request_result_copy_value (const GValue* src_value,
                                                        GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = dino_history_sync_page_request_result_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
dino_history_sync_value_page_request_result_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
dino_history_sync_value_page_request_result_collect_value (GValue* value,
                                                           guint n_collect_values,
                                                           GTypeCValue* collect_values,
                                                           guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		DinoHistorySyncPageRequestResult * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = dino_history_sync_page_request_result_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
dino_history_sync_value_page_request_result_lcopy_value (const GValue* value,
                                                         guint n_collect_values,
                                                         GTypeCValue* collect_values,
                                                         guint collect_flags)
{
	DinoHistorySyncPageRequestResult ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = dino_history_sync_page_request_result_ref (value->data[0].v_pointer);
	}
	return NULL;
}

static GParamSpec*
dino_history_sync_param_spec_page_request_result (const gchar* name,
                                                  const gchar* nick,
                                                  const gchar* blurb,
                                                  GType object_type,
                                                  GParamFlags flags)
{
	DinoHistorySyncParamSpecPageRequestResult* spec;
	g_return_val_if_fail (g_type_is_a (object_type, DINO_HISTORY_SYNC_TYPE_PAGE_REQUEST_RESULT), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

static gpointer
dino_history_sync_value_get_page_request_result (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_HISTORY_SYNC_TYPE_PAGE_REQUEST_RESULT), NULL);
	return value->data[0].v_pointer;
}

static void
dino_history_sync_value_set_page_request_result (GValue* value,
                                                 gpointer v_object)
{
	DinoHistorySyncPageRequestResult * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_HISTORY_SYNC_TYPE_PAGE_REQUEST_RESULT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DINO_HISTORY_SYNC_TYPE_PAGE_REQUEST_RESULT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		dino_history_sync_page_request_result_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dino_history_sync_page_request_result_unref (old);
	}
}

static void
dino_history_sync_value_take_page_request_result (GValue* value,
                                                  gpointer v_object)
{
	DinoHistorySyncPageRequestResult * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_HISTORY_SYNC_TYPE_PAGE_REQUEST_RESULT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DINO_HISTORY_SYNC_TYPE_PAGE_REQUEST_RESULT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dino_history_sync_page_request_result_unref (old);
	}
}

static void
dino_history_sync_page_request_result_class_init (DinoHistorySyncPageRequestResultClass * klass,
                                                  gpointer klass_data)
{
	dino_history_sync_page_request_result_parent_class = g_type_class_peek_parent (klass);
	((DinoHistorySyncPageRequestResultClass *) klass)->finalize = dino_history_sync_page_request_result_finalize;
	g_type_class_adjust_private_offset (klass, &DinoHistorySyncPageRequestResult_private_offset);
}

static void
dino_history_sync_page_request_result_instance_init (DinoHistorySyncPageRequestResult * self,
                                                     gpointer klass)
{
	self->priv = dino_history_sync_page_request_result_get_instance_private (self);
	self->ref_count = 1;
}

static void
dino_history_sync_page_request_result_finalize (DinoHistorySyncPageRequestResult * obj)
{
	DinoHistorySyncPageRequestResult * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_HISTORY_SYNC_TYPE_PAGE_REQUEST_RESULT, DinoHistorySyncPageRequestResult);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->_stanzas);
	_xmpp_message_archive_management_query_result_unref0 (self->priv->_query_result);
}

static GType
dino_history_sync_page_request_result_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { dino_history_sync_value_page_request_result_init, dino_history_sync_value_page_request_result_free_value, dino_history_sync_value_page_request_result_copy_value, dino_history_sync_value_page_request_result_peek_pointer, "p", dino_history_sync_value_page_request_result_collect_value, "p", dino_history_sync_value_page_request_result_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (DinoHistorySyncPageRequestResultClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_history_sync_page_request_result_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoHistorySyncPageRequestResult), 0, (GInstanceInitFunc) dino_history_sync_page_request_result_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType dino_history_sync_page_request_result_type_id;
	dino_history_sync_page_request_result_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DinoHistorySyncPageRequestResult", &g_define_type_info, &g_define_type_fundamental_info, 0);
	DinoHistorySyncPageRequestResult_private_offset = g_type_add_instance_private (dino_history_sync_page_request_result_type_id, sizeof (DinoHistorySyncPageRequestResultPrivate));
	return dino_history_sync_page_request_result_type_id;
}

static GType
dino_history_sync_page_request_result_get_type (void)
{
	static volatile gsize dino_history_sync_page_request_result_type_id__once = 0;
	if (g_once_init_enter (&dino_history_sync_page_request_result_type_id__once)) {
		GType dino_history_sync_page_request_result_type_id;
		dino_history_sync_page_request_result_type_id = dino_history_sync_page_request_result_get_type_once ();
		g_once_init_leave (&dino_history_sync_page_request_result_type_id__once, dino_history_sync_page_request_result_type_id);
	}
	return dino_history_sync_page_request_result_type_id__once;
}

static gpointer
dino_history_sync_page_request_result_ref (gpointer instance)
{
	DinoHistorySyncPageRequestResult * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

static void
dino_history_sync_page_request_result_unref (gpointer instance)
{
	DinoHistorySyncPageRequestResult * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DINO_HISTORY_SYNC_PAGE_REQUEST_RESULT_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
dino_value_history_sync_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
dino_value_history_sync_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		dino_history_sync_unref (value->data[0].v_pointer);
	}
}

static void
dino_value_history_sync_copy_value (const GValue* src_value,
                                    GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = dino_history_sync_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
dino_value_history_sync_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
dino_value_history_sync_collect_value (GValue* value,
                                       guint n_collect_values,
                                       GTypeCValue* collect_values,
                                       guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		DinoHistorySync * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = dino_history_sync_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
dino_value_history_sync_lcopy_value (const GValue* value,
                                     guint n_collect_values,
                                     GTypeCValue* collect_values,
                                     guint collect_flags)
{
	DinoHistorySync ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = dino_history_sync_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
dino_param_spec_history_sync (const gchar* name,
                              const gchar* nick,
                              const gchar* blurb,
                              GType object_type,
                              GParamFlags flags)
{
	DinoParamSpecHistorySync* spec;
	g_return_val_if_fail (g_type_is_a (object_type, DINO_TYPE_HISTORY_SYNC), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
dino_value_get_history_sync (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_TYPE_HISTORY_SYNC), NULL);
	return value->data[0].v_pointer;
}

void
dino_value_set_history_sync (GValue* value,
                             gpointer v_object)
{
	DinoHistorySync * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_TYPE_HISTORY_SYNC));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DINO_TYPE_HISTORY_SYNC));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		dino_history_sync_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dino_history_sync_unref (old);
	}
}

void
dino_value_take_history_sync (GValue* value,
                              gpointer v_object)
{
	DinoHistorySync * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_TYPE_HISTORY_SYNC));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DINO_TYPE_HISTORY_SYNC));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dino_history_sync_unref (old);
	}
}

static void
dino_history_sync_class_init (DinoHistorySyncClass * klass,
                              gpointer klass_data)
{
	dino_history_sync_parent_class = g_type_class_peek_parent (klass);
	((DinoHistorySyncClass *) klass)->finalize = dino_history_sync_finalize;
	g_type_class_adjust_private_offset (klass, &DinoHistorySync_private_offset);
}

static void
dino_history_sync_instance_init (DinoHistorySync * self,
                                 gpointer klass)
{
	GeeHashMap* _tmp0_;
	WeakMap* _tmp1_;
	GeeHashMap* _tmp2_;
	GeeHashMap* _tmp3_;
	GeeHashMap* _tmp4_;
	GeeHashMap* _tmp5_;
	GeeHashMap* _tmp6_;
	GeeHashMap* _tmp7_;
	self->priv = dino_history_sync_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (DINO_ENTITIES_TYPE_ACCOUNT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEE_TYPE_HASH_MAP, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _dino_entities_account_hash_func_gee_hash_data_func, NULL, NULL, _dino_entities_account_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->current_catchup_id = _tmp0_;
	_tmp1_ = weak_map_new (DINO_ENTITIES_TYPE_ACCOUNT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, XMPP_TYPE_XMPP_STREAM, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _dino_entities_account_hash_func_gee_hash_data_func, NULL, NULL, _dino_entities_account_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->sync_streams = _tmp1_;
	_tmp2_ = gee_hash_map_new (DINO_ENTITIES_TYPE_ACCOUNT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEE_TYPE_HASH_MAP, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _dino_entities_account_hash_func_gee_hash_data_func, NULL, NULL, _dino_entities_account_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->cancellables = _tmp2_;
	_tmp3_ = gee_hash_map_new (DINO_ENTITIES_TYPE_ACCOUNT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, GEE_TYPE_HASH_MAP, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->mam_times = _tmp3_;
	_tmp4_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_INT, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->hitted_range = _tmp4_;
	_tmp5_ = gee_hash_map_new (DINO_ENTITIES_TYPE_ACCOUNT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _dino_entities_account_hash_func_gee_hash_data_func, NULL, NULL, _dino_entities_account_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->catchup_until_id = _tmp5_;
	_tmp6_ = gee_hash_map_new (DINO_ENTITIES_TYPE_ACCOUNT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, G_TYPE_DATE_TIME, (GBoxedCopyFunc) g_date_time_ref, (GDestroyNotify) g_date_time_unref, _dino_entities_account_hash_func_gee_hash_data_func, NULL, NULL, _dino_entities_account_equals_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->catchup_until_time = _tmp6_;
	_tmp7_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, GEE_TYPE_LIST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->stanzas = _tmp7_;
	self->ref_count = 1;
}

static void
dino_history_sync_finalize (DinoHistorySync * obj)
{
	DinoHistorySync * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_HISTORY_SYNC, DinoHistorySync);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->stream_interactor);
	_qlite_database_unref0 (self->priv->db);
	_g_object_unref0 (self->current_catchup_id);
	_g_object_unref0 (self->sync_streams);
	_g_object_unref0 (self->cancellables);
	_g_object_unref0 (self->mam_times);
	_g_object_unref0 (self->hitted_range);
	_g_object_unref0 (self->catchup_until_id);
	_g_object_unref0 (self->catchup_until_time);
	_g_object_unref0 (self->priv->stanzas);
}

static GType
dino_history_sync_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { dino_value_history_sync_init, dino_value_history_sync_free_value, dino_value_history_sync_copy_value, dino_value_history_sync_peek_pointer, "p", dino_value_history_sync_collect_value, "p", dino_value_history_sync_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (DinoHistorySyncClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_history_sync_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoHistorySync), 0, (GInstanceInitFunc) dino_history_sync_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType dino_history_sync_type_id;
	dino_history_sync_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DinoHistorySync", &g_define_type_info, &g_define_type_fundamental_info, 0);
	DinoHistorySync_private_offset = g_type_add_instance_private (dino_history_sync_type_id, sizeof (DinoHistorySyncPrivate));
	return dino_history_sync_type_id;
}

GType
dino_history_sync_get_type (void)
{
	static volatile gsize dino_history_sync_type_id__once = 0;
	if (g_once_init_enter (&dino_history_sync_type_id__once)) {
		GType dino_history_sync_type_id;
		dino_history_sync_type_id = dino_history_sync_get_type_once ();
		g_once_init_leave (&dino_history_sync_type_id__once, dino_history_sync_type_id);
	}
	return dino_history_sync_type_id__once;
}

gpointer
dino_history_sync_ref (gpointer instance)
{
	DinoHistorySync * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
dino_history_sync_unref (gpointer instance)
{
	DinoHistorySync * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DINO_HISTORY_SYNC_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

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

