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

#include <glib-object.h>
#include <gio/gio.h>
#include <glib.h>
#include <json-glib/json-glib.h>
#include <stdlib.h>
#include <string.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define DC_TYPE_EVENT_HANDLER (dc_event_handler_get_type ())
#define DC_EVENT_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_EVENT_HANDLER, DcEventHandler))
#define DC_EVENT_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_EVENT_HANDLER, DcEventHandlerClass))
#define DC_IS_EVENT_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_EVENT_HANDLER))
#define DC_IS_EVENT_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_EVENT_HANDLER))
#define DC_EVENT_HANDLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_EVENT_HANDLER, DcEventHandlerClass))

typedef struct _DcEventHandler DcEventHandler;
typedef struct _DcEventHandlerClass DcEventHandlerClass;
typedef struct _DcEventHandlerPrivate DcEventHandlerPrivate;

#define DC_TYPE_RPC_CLIENT (dc_rpc_client_get_type ())
#define DC_RPC_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_RPC_CLIENT, DcRpcClient))
#define DC_RPC_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_RPC_CLIENT, DcRpcClientClass))
#define DC_IS_RPC_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_RPC_CLIENT))
#define DC_IS_RPC_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_RPC_CLIENT))
#define DC_RPC_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_RPC_CLIENT, DcRpcClientClass))

typedef struct _DcRpcClient DcRpcClient;
typedef struct _DcRpcClientClass DcRpcClientClass;
enum  {
	DC_EVENT_HANDLER_0_PROPERTY,
	DC_EVENT_HANDLER_ACTIVE_CHAT_ID_PROPERTY,
	DC_EVENT_HANDLER_IS_LISTENING_PROPERTY,
	DC_EVENT_HANDLER_NUM_PROPERTIES
};
static GParamSpec* dc_event_handler_properties[DC_EVENT_HANDLER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _json_object_unref0(var) ((var == NULL) ? NULL : (var = (json_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _DcEventHandlerStartData DcEventHandlerStartData;

#define DC_TYPE_MESSAGE (dc_message_get_type ())
#define DC_MESSAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_MESSAGE, DcMessage))
#define DC_MESSAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_MESSAGE, DcMessageClass))
#define DC_IS_MESSAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_MESSAGE))
#define DC_IS_MESSAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_MESSAGE))
#define DC_MESSAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_MESSAGE, DcMessageClass))

typedef struct _DcMessage DcMessage;
typedef struct _DcMessageClass DcMessageClass;
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
typedef struct _DcEventHandlerSendNotificationData DcEventHandlerSendNotificationData;
typedef struct _DcEventHandlerNapData DcEventHandlerNapData;
enum  {
	DC_EVENT_HANDLER_CHATS_RELOAD_FIRED_SIGNAL,
	DC_EVENT_HANDLER_MESSAGES_RELOAD_FIRED_SIGNAL,
	DC_EVENT_HANDLER_INCOMING_MSG_RECEIVED_SIGNAL,
	DC_EVENT_HANDLER_ACCOUNT_UNREAD_CHANGED_SIGNAL,
	DC_EVENT_HANDLER_IMEX_PROGRESS_SIGNAL,
	DC_EVENT_HANDLER_CONFIGURE_PROGRESS_SIGNAL,
	DC_EVENT_HANDLER_NUM_SIGNALS
};
static guint dc_event_handler_signals[DC_EVENT_HANDLER_NUM_SIGNALS] = {0};

struct _DcEventHandler {
	GObject parent_instance;
	DcEventHandlerPrivate * priv;
};

struct _DcEventHandlerClass {
	GObjectClass parent_class;
};

struct _DcEventHandlerPrivate {
	DcRpcClient* rpc;
	GApplication* app;
	gboolean _listening;
	guint chats_reload_timer;
	guint messages_reload_timer;
	gint _active_chat_id;
};

struct _DcEventHandlerStartData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcEventHandler* self;
	DcRpcClient* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	JsonObject* ev;
	DcRpcClient* _tmp3_;
	JsonObject* _tmp4_;
	JsonObject* _tmp5_;
	gint ctx;
	JsonObject* _tmp6_;
	JsonObject* event;
	JsonObject* _tmp7_;
	JsonObject* _tmp8_;
	JsonObject* _tmp9_;
	JsonObject* _tmp10_;
	gchar* kind;
	JsonObject* _tmp11_;
	const gchar* _tmp12_;
	gchar* _tmp13_;
	const gchar* _tmp14_;
	gint progress;
	JsonObject* _tmp15_;
	const gchar* _tmp16_;
	gint _vala1_progress;
	JsonObject* _tmp17_;
	gchar* comment;
	gboolean _tmp18_;
	JsonObject* _tmp19_;
	JsonObject* _tmp20_;
	JsonNode* _tmp21_;
	JsonObject* _tmp22_;
	const gchar* _tmp23_;
	gchar* _tmp24_;
	const gchar* _tmp25_;
	DcRpcClient* _tmp26_;
	gint _tmp27_;
	gint _tmp28_;
	const gchar* _tmp29_;
	JsonObject* _tmp30_;
	const gchar* _tmp31_;
	JsonObject* _tmp32_;
	GError* e;
	DcRpcClient* _tmp33_;
	gboolean _tmp34_;
	gboolean _tmp35_;
	GError* _tmp36_;
	const gchar* _tmp37_;
	GError* _inner_error0_;
};

struct _DcEventHandlerSendNotificationData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcEventHandler* self;
	gint acct_id;
	gint chat_id;
	gint msg_id;
	GApplication* _tmp0_;
	DcMessage* msg;
	DcRpcClient* _tmp1_;
	DcMessage* _tmp2_;
	DcMessage* _tmp3_;
	gboolean _tmp4_;
	DcMessage* _tmp5_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	DcMessage* _tmp8_;
	gboolean _tmp9_;
	gboolean _tmp10_;
	const gchar* _tmp11_;
	DcMessage* _tmp12_;
	const gchar* _tmp13_;
	const gchar* _tmp14_;
	const gchar* _tmp15_;
	DcMessage* _tmp16_;
	const gchar* _tmp17_;
	const gchar* _tmp18_;
	gchar* title;
	gchar* _tmp19_;
	JsonObject* chat_obj;
	DcRpcClient* _tmp20_;
	JsonObject* _tmp21_;
	gboolean _tmp22_;
	JsonObject* _tmp23_;
	JsonObject* _tmp24_;
	gchar* chat_name;
	JsonObject* _tmp25_;
	const gchar* _tmp26_;
	gchar* _tmp27_;
	gboolean _tmp28_;
	gboolean _tmp29_;
	const gchar* _tmp30_;
	const gchar* _tmp31_;
	gint _tmp32_;
	gint _tmp33_;
	const gchar* _tmp34_;
	const gchar* _tmp35_;
	const gchar* _tmp36_;
	const gchar* _tmp37_;
	gchar* _tmp38_;
	DcRpcClient* _tmp39_;
	gint _tmp40_;
	gint _tmp41_;
	gchar* acct_name;
	DcRpcClient* _tmp42_;
	gchar* _tmp43_;
	gboolean _tmp44_;
	const gchar* _tmp45_;
	const gchar* _tmp46_;
	gint _tmp47_;
	gint _tmp48_;
	gchar* _tmp49_;
	DcRpcClient* _tmp50_;
	gchar* _tmp51_;
	gchar* _tmp52_;
	gboolean _tmp53_;
	const gchar* _tmp54_;
	const gchar* _tmp55_;
	gint _tmp56_;
	gint _tmp57_;
	const gchar* _tmp58_;
	const gchar* _tmp59_;
	gchar* _tmp60_;
	const gchar* _tmp61_;
	gboolean _tmp62_;
	DcMessage* _tmp63_;
	const gchar* _tmp64_;
	const gchar* _tmp65_;
	DcMessage* _tmp66_;
	const gchar* _tmp67_;
	const gchar* _tmp68_;
	gint _tmp69_;
	gint _tmp70_;
	DcMessage* _tmp71_;
	const gchar* _tmp72_;
	const gchar* _tmp73_;
	const gchar* _tmp74_;
	gboolean _tmp75_;
	DcMessage* _tmp76_;
	const gchar* _tmp77_;
	const gchar* _tmp78_;
	DcMessage* _tmp79_;
	const gchar* _tmp80_;
	const gchar* _tmp81_;
	gint _tmp82_;
	gint _tmp83_;
	DcMessage* _tmp84_;
	const gchar* _tmp85_;
	const gchar* _tmp86_;
	gchar* body;
	gchar* _tmp87_;
	GNotification* n;
	const gchar* _tmp88_;
	GNotification* _tmp89_;
	GNotification* _tmp90_;
	const gchar* _tmp91_;
	GNotification* _tmp92_;
	GNotification* _tmp93_;
	GVariant* _tmp94_;
	GVariant* _tmp95_;
	GApplication* _tmp96_;
	gchar* _tmp97_;
	gchar* _tmp98_;
	GNotification* _tmp99_;
	GError* e;
	GError* _tmp100_;
	const gchar* _tmp101_;
	GError* _inner_error0_;
};

struct _DcEventHandlerNapData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcEventHandler* self;
	guint ms;
};

static gint DcEventHandler_private_offset;
static gpointer dc_event_handler_parent_class = NULL;

VALA_EXTERN GType dc_event_handler_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcEventHandler, g_object_unref)
VALA_EXTERN GType dc_rpc_client_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcRpcClient, g_object_unref)
VALA_EXTERN DcEventHandler* dc_event_handler_new (DcRpcClient* rpc);
VALA_EXTERN DcEventHandler* dc_event_handler_construct (GType object_type,
                                            DcRpcClient* rpc);
VALA_EXTERN void dc_event_handler_set_app (DcEventHandler* self,
                               GApplication* a);
static void dc_event_handler_start_data_free (gpointer _data);
VALA_EXTERN void dc_event_handler_start (DcEventHandler* self,
                             GAsyncReadyCallback _callback_,
                             gpointer _user_data_);
VALA_EXTERN void dc_event_handler_start_finish (DcEventHandler* self,
                                    GAsyncResult* _res_);
static gboolean dc_event_handler_start_co (DcEventHandlerStartData* _data_);
VALA_EXTERN gboolean dc_rpc_client_get_is_connected (DcRpcClient* self);
VALA_EXTERN void dc_rpc_client_get_next_event (DcRpcClient* self,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_);
VALA_EXTERN JsonObject* dc_rpc_client_get_next_event_finish (DcRpcClient* self,
                                                 GAsyncResult* _res_,
                                                 GError** error);
static void dc_event_handler_start_ready (GObject* source_object,
                                   GAsyncResult* _res_,
                                   gpointer _user_data_);
VALA_EXTERN gint dc_rpc_client_get_account_id (DcRpcClient* self);
static void dc_event_handler_dispatch_background (DcEventHandler* self,
                                           gint acct_id,
                                           const gchar* kind,
                                           JsonObject* event);
static void dc_event_handler_dispatch (DcEventHandler* self,
                                const gchar* kind,
                                JsonObject* event);
static void dc_event_handler_nap (DcEventHandler* self,
                           guint ms,
                           GAsyncReadyCallback _callback_,
                           gpointer _user_data_);
static void dc_event_handler_nap_finish (DcEventHandler* self,
                                  GAsyncResult* _res_);
VALA_EXTERN void dc_event_handler_schedule_chats_reload (DcEventHandler* self);
static gboolean __lambda41_ (DcEventHandler* self);
static gboolean ___lambda41__gsource_func (gpointer self);
VALA_EXTERN void dc_event_handler_schedule_messages_reload (DcEventHandler* self);
VALA_EXTERN gint dc_event_handler_get_active_chat_id (DcEventHandler* self);
static gboolean __lambda40_ (DcEventHandler* self);
static gboolean ___lambda40__gsource_func (gpointer self);
static void dc_event_handler_send_notification_data_free (gpointer _data);
VALA_EXTERN void dc_event_handler_send_notification (DcEventHandler* self,
                                         gint acct_id,
                                         gint chat_id,
                                         gint msg_id,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_);
VALA_EXTERN void dc_event_handler_send_notification_finish (DcEventHandler* self,
                                                GAsyncResult* _res_);
static gboolean dc_event_handler_send_notification_co (DcEventHandlerSendNotificationData* _data_);
VALA_EXTERN GType dc_message_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcMessage, g_object_unref)
VALA_EXTERN void dc_rpc_client_fetch_message_for (DcRpcClient* self,
                                      gint acct_id,
                                      gint msg_id,
                                      const gchar* self_addr,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_);
VALA_EXTERN DcMessage* dc_rpc_client_fetch_message_for_finish (DcRpcClient* self,
                                                   GAsyncResult* _res_,
                                                   GError** error);
static void dc_event_handler_send_notification_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_);
VALA_EXTERN gboolean dc_message_get_is_outgoing (DcMessage* self);
VALA_EXTERN gboolean dc_message_get_is_info (DcMessage* self);
VALA_EXTERN const gchar* dc_message_get_sender_name (DcMessage* self);
VALA_EXTERN const gchar* dc_message_get_sender_address (DcMessage* self);
VALA_EXTERN void dc_rpc_client_get_full_chat_by_id_for (DcRpcClient* self,
                                            gint acct_id,
                                            gint chat_id,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_);
VALA_EXTERN JsonObject* dc_rpc_client_get_full_chat_by_id_for_finish (DcRpcClient* self,
                                                          GAsyncResult* _res_,
                                                          GError** error);
VALA_EXTERN void dc_rpc_client_get_config (DcRpcClient* self,
                               const gchar* key,
                               gint acct_id,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_);
VALA_EXTERN gchar* dc_rpc_client_get_config_finish (DcRpcClient* self,
                                        GAsyncResult* _res_,
                                        GError** error);
VALA_EXTERN const gchar* dc_message_get_text (DcMessage* self);
VALA_EXTERN const gchar* dc_message_get_file_name (DcMessage* self);
static void dc_event_handler_nap_data_free (gpointer _data);
static gboolean dc_event_handler_nap_co (DcEventHandlerNapData* _data_);
static gboolean _dc_event_handler_nap_co_gsource_func (gpointer self);
VALA_EXTERN void dc_event_handler_set_active_chat_id (DcEventHandler* self,
                                          gint value);
VALA_EXTERN gboolean dc_event_handler_get_is_listening (DcEventHandler* self);
static void g_cclosure_user_marshal_VOID__INT_INT_INT (GClosure * closure,
                                                GValue * return_value,
                                                guint n_param_values,
                                                const GValue * param_values,
                                                gpointer invocation_hint,
                                                gpointer marshal_data);
static void g_cclosure_user_marshal_VOID__INT_INT (GClosure * closure,
                                            GValue * return_value,
                                            guint n_param_values,
                                            const GValue * param_values,
                                            gpointer invocation_hint,
                                            gpointer marshal_data);
static void g_cclosure_user_marshal_VOID__INT_INT_STRING (GClosure * closure,
                                                   GValue * return_value,
                                                   guint n_param_values,
                                                   const GValue * param_values,
                                                   gpointer invocation_hint,
                                                   gpointer marshal_data);
static void dc_event_handler_finalize (GObject * obj);
static GType dc_event_handler_get_type_once (void);
static void _vala_dc_event_handler_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec);
static void _vala_dc_event_handler_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dc_event_handler_get_instance_private (DcEventHandler* self)
{
	return G_STRUCT_MEMBER_P (self, DcEventHandler_private_offset);
}

DcEventHandler*
dc_event_handler_construct (GType object_type,
                            DcRpcClient* rpc)
{
	DcEventHandler * self = NULL;
	g_return_val_if_fail (rpc != NULL, NULL);
	self = (DcEventHandler*) g_object_new (object_type, NULL);
	self->priv->rpc = rpc;
	return self;
}

DcEventHandler*
dc_event_handler_new (DcRpcClient* rpc)
{
	return dc_event_handler_construct (DC_TYPE_EVENT_HANDLER, rpc);
}

void
dc_event_handler_set_app (DcEventHandler* self,
                          GApplication* a)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (a != NULL);
	self->priv->app = a;
}

static void
dc_event_handler_start_data_free (gpointer _data)
{
	DcEventHandlerStartData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (DcEventHandlerStartData, _data_);
}

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

void
dc_event_handler_start (DcEventHandler* self,
                        GAsyncReadyCallback _callback_,
                        gpointer _user_data_)
{
	DcEventHandlerStartData* _data_;
	DcEventHandler* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcEventHandlerStartData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_event_handler_start_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	dc_event_handler_start_co (_data_);
}

void
dc_event_handler_start_finish (DcEventHandler* self,
                               GAsyncResult* _res_)
{
	DcEventHandlerStartData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dc_event_handler_start_ready (GObject* source_object,
                              GAsyncResult* _res_,
                              gpointer _user_data_)
{
	DcEventHandlerStartData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_event_handler_start_co (_data_);
}

static gpointer
_json_object_ref0 (gpointer self)
{
	return self ? json_object_ref (self) : NULL;
}

static gboolean
dc_event_handler_start_co (DcEventHandlerStartData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->self->priv->_listening) {
		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_->self->priv->_listening = TRUE;
	while (TRUE) {
		_data_->_tmp0_ = _data_->self->priv->rpc;
		_data_->_tmp1_ = dc_rpc_client_get_is_connected (_data_->_tmp0_);
		_data_->_tmp2_ = _data_->_tmp1_;
		if (!_data_->_tmp2_) {
			break;
		}
		{
			_data_->_tmp3_ = _data_->self->priv->rpc;
			_data_->_state_ = 1;
			dc_rpc_client_get_next_event (_data_->_tmp3_, dc_event_handler_start_ready, _data_);
			return FALSE;
			_state_1:
			_data_->_tmp4_ = dc_rpc_client_get_next_event_finish (_data_->_tmp3_, _data_->_res_, &_data_->_inner_error0_);
			_data_->ev = _data_->_tmp4_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_data_->_tmp5_ = _data_->ev;
			if (_data_->_tmp5_ == NULL) {
				_json_object_unref0 (_data_->ev);
				continue;
			}
			_data_->_tmp6_ = _data_->ev;
			_data_->ctx = (gint) json_object_get_int_member (_data_->_tmp6_, "contextId");
			_data_->_tmp7_ = _data_->ev;
			_data_->_tmp8_ = json_object_get_object_member (_data_->_tmp7_, "event");
			_data_->_tmp9_ = _json_object_ref0 (_data_->_tmp8_);
			_data_->event = _data_->_tmp9_;
			_data_->_tmp10_ = _data_->event;
			if (_data_->_tmp10_ == NULL) {
				_json_object_unref0 (_data_->event);
				_json_object_unref0 (_data_->ev);
				continue;
			}
			_data_->_tmp11_ = _data_->event;
			_data_->_tmp12_ = json_object_get_string_member (_data_->_tmp11_, "kind");
			_data_->_tmp13_ = g_strdup (_data_->_tmp12_);
			_data_->kind = _data_->_tmp13_;
			_data_->_tmp14_ = _data_->kind;
			if (g_strcmp0 (_data_->_tmp14_, "ImexProgress") == 0) {
				_data_->_tmp15_ = _data_->event;
				_data_->progress = (gint) json_object_get_int_member (_data_->_tmp15_, "progress");
				g_signal_emit (_data_->self, dc_event_handler_signals[DC_EVENT_HANDLER_IMEX_PROGRESS_SIGNAL], 0, _data_->ctx, _data_->progress);
				_g_free0 (_data_->kind);
				_json_object_unref0 (_data_->event);
				_json_object_unref0 (_data_->ev);
				continue;
			}
			_data_->_tmp16_ = _data_->kind;
			if (g_strcmp0 (_data_->_tmp16_, "ConfigureProgress") == 0) {
				_data_->_tmp17_ = _data_->event;
				_data_->_vala1_progress = (gint) json_object_get_int_member (_data_->_tmp17_, "progress");
				_data_->comment = NULL;
				_data_->_tmp19_ = _data_->event;
				if (json_object_has_member (_data_->_tmp19_, "comment")) {
					_data_->_tmp20_ = _data_->event;
					_data_->_tmp21_ = json_object_get_member (_data_->_tmp20_, "comment");
					_data_->_tmp18_ = !json_node_is_null (_data_->_tmp21_);
				} else {
					_data_->_tmp18_ = FALSE;
				}
				if (_data_->_tmp18_) {
					_data_->_tmp22_ = _data_->event;
					_data_->_tmp23_ = json_object_get_string_member (_data_->_tmp22_, "comment");
					_data_->_tmp24_ = g_strdup (_data_->_tmp23_);
					_g_free0 (_data_->comment);
					_data_->comment = _data_->_tmp24_;
				}
				_data_->_tmp25_ = _data_->comment;
				g_signal_emit (_data_->self, dc_event_handler_signals[DC_EVENT_HANDLER_CONFIGURE_PROGRESS_SIGNAL], 0, _data_->ctx, _data_->_vala1_progress, _data_->_tmp25_);
				_g_free0 (_data_->comment);
				_g_free0 (_data_->kind);
				_json_object_unref0 (_data_->event);
				_json_object_unref0 (_data_->ev);
				continue;
			}
			_data_->_tmp26_ = _data_->self->priv->rpc;
			_data_->_tmp27_ = dc_rpc_client_get_account_id (_data_->_tmp26_);
			_data_->_tmp28_ = _data_->_tmp27_;
			if (_data_->ctx != _data_->_tmp28_) {
				_data_->_tmp29_ = _data_->kind;
				_data_->_tmp30_ = _data_->event;
				dc_event_handler_dispatch_background (_data_->self, _data_->ctx, _data_->_tmp29_, _data_->_tmp30_);
				_g_free0 (_data_->kind);
				_json_object_unref0 (_data_->event);
				_json_object_unref0 (_data_->ev);
				continue;
			}
			_data_->_tmp31_ = _data_->kind;
			_data_->_tmp32_ = _data_->event;
			dc_event_handler_dispatch (_data_->self, _data_->_tmp31_, _data_->_tmp32_);
			_g_free0 (_data_->kind);
			_json_object_unref0 (_data_->event);
			_json_object_unref0 (_data_->ev);
		}
		goto __finally0;
		__catch0_g_error:
		{
			_data_->e = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp33_ = _data_->self->priv->rpc;
			_data_->_tmp34_ = dc_rpc_client_get_is_connected (_data_->_tmp33_);
			_data_->_tmp35_ = _data_->_tmp34_;
			if (_data_->_tmp35_) {
				_data_->_tmp36_ = _data_->e;
				_data_->_tmp37_ = _data_->_tmp36_->message;
				g_warning ("event_handler.vala:70: Event loop error: %s", _data_->_tmp37_);
				_data_->_state_ = 2;
				dc_event_handler_nap (_data_->self, (guint) 1000, dc_event_handler_start_ready, _data_);
				return FALSE;
				_state_2:
				dc_event_handler_nap_finish (_data_->self, _data_->_res_);
			}
			_g_error_free0 (_data_->e);
		}
		__finally0:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->self->priv->_listening = FALSE;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gboolean
__lambda41_ (DcEventHandler* self)
{
	gboolean result;
	self->priv->chats_reload_timer = (guint) 0;
	g_signal_emit (self, dc_event_handler_signals[DC_EVENT_HANDLER_CHATS_RELOAD_FIRED_SIGNAL], 0);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda41__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda41_ ((DcEventHandler*) self);
	return result;
}

void
dc_event_handler_schedule_chats_reload (DcEventHandler* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->chats_reload_timer > ((guint) 0)) {
		return;
	}
	self->priv->chats_reload_timer = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 150, ___lambda41__gsource_func, g_object_ref (self), g_object_unref);
}

static gboolean
__lambda40_ (DcEventHandler* self)
{
	gboolean result;
	self->priv->messages_reload_timer = (guint) 0;
	g_signal_emit (self, dc_event_handler_signals[DC_EVENT_HANDLER_MESSAGES_RELOAD_FIRED_SIGNAL], 0);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda40__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda40_ ((DcEventHandler*) self);
	return result;
}

void
dc_event_handler_schedule_messages_reload (DcEventHandler* self)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	if (self->priv->messages_reload_timer > ((guint) 0)) {
		_tmp0_ = TRUE;
	} else {
		gint _tmp1_;
		_tmp1_ = self->priv->_active_chat_id;
		_tmp0_ = _tmp1_ <= 0;
	}
	if (_tmp0_) {
		return;
	}
	self->priv->messages_reload_timer = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 150, ___lambda40__gsource_func, g_object_ref (self), g_object_unref);
}

static void
dc_event_handler_dispatch (DcEventHandler* self,
                           const gchar* kind,
                           JsonObject* event)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	static GQuark _tmp1_label3 = 0;
	static GQuark _tmp1_label4 = 0;
	static GQuark _tmp1_label5 = 0;
	static GQuark _tmp1_label6 = 0;
	static GQuark _tmp1_label7 = 0;
	static GQuark _tmp1_label8 = 0;
	static GQuark _tmp1_label9 = 0;
	static GQuark _tmp1_label10 = 0;
	static GQuark _tmp1_label11 = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (kind != NULL);
	g_return_if_fail (event != NULL);
	_tmp0_ = kind;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("IncomingMsg")))) {
		switch (0) {
			default:
			{
				gint chat_id = 0;
				gint msg_id = 0;
				DcRpcClient* _tmp3_;
				gint _tmp4_;
				gint _tmp5_;
				chat_id = (gint) json_object_get_int_member (event, "chatId");
				msg_id = (gint) json_object_get_int_member (event, "msgId");
				_tmp3_ = self->priv->rpc;
				_tmp4_ = dc_rpc_client_get_account_id (_tmp3_);
				_tmp5_ = _tmp4_;
				g_signal_emit (self, dc_event_handler_signals[DC_EVENT_HANDLER_INCOMING_MSG_RECEIVED_SIGNAL], 0, _tmp5_, chat_id, msg_id);
				break;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("MsgsChanged")))) {
		switch (0) {
			default:
			{
				gint changed_chat = 0;
				gboolean _tmp6_ = FALSE;
				changed_chat = (gint) json_object_get_int_member (event, "chatId");
				if (changed_chat == 0) {
					_tmp6_ = TRUE;
				} else {
					gint _tmp7_;
					_tmp7_ = self->priv->_active_chat_id;
					_tmp6_ = changed_chat == _tmp7_;
				}
				if (_tmp6_) {
					dc_event_handler_schedule_messages_reload (self);
				}
				break;
			}
		}
	} else if (((((_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("MsgDelivered")))) || (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string ("MsgRead"))))) || (_tmp2_ == ((0 != _tmp1_label4) ? _tmp1_label4 : (_tmp1_label4 = g_quark_from_static_string ("MsgFailed"))))) || (_tmp2_ == ((0 != _tmp1_label5) ? _tmp1_label5 : (_tmp1_label5 = g_quark_from_static_string ("MsgDeleted"))))) || (_tmp2_ == ((0 != _tmp1_label6) ? _tmp1_label6 : (_tmp1_label6 = g_quark_from_static_string ("ReactionsChanged"))))) {
		switch (0) {
			default:
			{
				gint msg_chat = 0;
				gint _tmp8_;
				msg_chat = (gint) json_object_get_int_member (event, "chatId");
				_tmp8_ = self->priv->_active_chat_id;
				if (msg_chat == _tmp8_) {
					dc_event_handler_schedule_messages_reload (self);
				}
				break;
			}
		}
	} else if (((((_tmp2_ == ((0 != _tmp1_label7) ? _tmp1_label7 : (_tmp1_label7 = g_quark_from_static_string ("ChatlistChanged")))) || (_tmp2_ == ((0 != _tmp1_label8) ? _tmp1_label8 : (_tmp1_label8 = g_quark_from_static_string ("ChatlistItemChanged"))))) || (_tmp2_ == ((0 != _tmp1_label9) ? _tmp1_label9 : (_tmp1_label9 = g_quark_from_static_string ("MsgsNoticed"))))) || (_tmp2_ == ((0 != _tmp1_label10) ? _tmp1_label10 : (_tmp1_label10 = g_quark_from_static_string ("ChatModified"))))) || (_tmp2_ == ((0 != _tmp1_label11) ? _tmp1_label11 : (_tmp1_label11 = g_quark_from_static_string ("ChatDeleted"))))) {
		switch (0) {
			default:
			{
				dc_event_handler_schedule_chats_reload (self);
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				break;
			}
		}
	}
}

static void
dc_event_handler_dispatch_background (DcEventHandler* self,
                                      gint acct_id,
                                      const gchar* kind,
                                      JsonObject* event)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	static GQuark _tmp1_label3 = 0;
	static GQuark _tmp1_label4 = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (kind != NULL);
	g_return_if_fail (event != NULL);
	_tmp0_ = kind;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("IncomingMsg")))) {
		switch (0) {
			default:
			{
				gint chat_id = 0;
				gint msg_id = 0;
				chat_id = (gint) json_object_get_int_member (event, "chatId");
				msg_id = (gint) json_object_get_int_member (event, "msgId");
				g_signal_emit (self, dc_event_handler_signals[DC_EVENT_HANDLER_INCOMING_MSG_RECEIVED_SIGNAL], 0, acct_id, chat_id, msg_id);
				break;
			}
		}
	} else if ((((_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("ChatlistChanged")))) || (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("ChatlistItemChanged"))))) || (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string ("MsgsNoticed"))))) || (_tmp2_ == ((0 != _tmp1_label4) ? _tmp1_label4 : (_tmp1_label4 = g_quark_from_static_string ("ChatModified"))))) {
		switch (0) {
			default:
			{
				g_signal_emit (self, dc_event_handler_signals[DC_EVENT_HANDLER_ACCOUNT_UNREAD_CHANGED_SIGNAL], 0, acct_id);
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				break;
			}
		}
	}
}

static void
dc_event_handler_send_notification_data_free (gpointer _data)
{
	DcEventHandlerSendNotificationData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (DcEventHandlerSendNotificationData, _data_);
}

void
dc_event_handler_send_notification (DcEventHandler* self,
                                    gint acct_id,
                                    gint chat_id,
                                    gint msg_id,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_)
{
	DcEventHandlerSendNotificationData* _data_;
	DcEventHandler* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcEventHandlerSendNotificationData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_event_handler_send_notification_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->acct_id = acct_id;
	_data_->chat_id = chat_id;
	_data_->msg_id = msg_id;
	dc_event_handler_send_notification_co (_data_);
}

void
dc_event_handler_send_notification_finish (DcEventHandler* self,
                                           GAsyncResult* _res_)
{
	DcEventHandlerSendNotificationData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dc_event_handler_send_notification_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_)
{
	DcEventHandlerSendNotificationData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_event_handler_send_notification_co (_data_);
}

static gboolean
dc_event_handler_send_notification_co (DcEventHandlerSendNotificationData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->app;
	if (_data_->_tmp0_ == 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;
	}
	{
		_data_->_tmp1_ = _data_->self->priv->rpc;
		_data_->_state_ = 1;
		dc_rpc_client_fetch_message_for (_data_->_tmp1_, _data_->acct_id, _data_->msg_id, NULL, dc_event_handler_send_notification_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp2_ = dc_rpc_client_fetch_message_for_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error0_);
		_data_->msg = _data_->_tmp2_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp3_ = _data_->msg;
		if (_data_->_tmp3_ == NULL) {
			_g_object_unref0 (_data_->msg);
			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_->_tmp5_ = _data_->msg;
		_data_->_tmp6_ = dc_message_get_is_outgoing (_data_->_tmp5_);
		_data_->_tmp7_ = _data_->_tmp6_;
		if (_data_->_tmp7_) {
			_data_->_tmp4_ = TRUE;
		} else {
			_data_->_tmp8_ = _data_->msg;
			_data_->_tmp9_ = dc_message_get_is_info (_data_->_tmp8_);
			_data_->_tmp10_ = _data_->_tmp9_;
			_data_->_tmp4_ = _data_->_tmp10_;
		}
		if (_data_->_tmp4_) {
			_g_object_unref0 (_data_->msg);
			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_->_tmp12_ = _data_->msg;
		_data_->_tmp13_ = dc_message_get_sender_name (_data_->_tmp12_);
		_data_->_tmp14_ = _data_->_tmp13_;
		_data_->_tmp11_ = _data_->_tmp14_;
		if (_data_->_tmp11_ == NULL) {
			_data_->_tmp16_ = _data_->msg;
			_data_->_tmp17_ = dc_message_get_sender_address (_data_->_tmp16_);
			_data_->_tmp18_ = _data_->_tmp17_;
			_data_->_tmp15_ = _data_->_tmp18_;
			if (_data_->_tmp15_ == NULL) {
				_data_->_tmp15_ = "New message";
			}
			_data_->_tmp11_ = _data_->_tmp15_;
		}
		_data_->_tmp19_ = g_strdup (_data_->_tmp11_);
		_data_->title = _data_->_tmp19_;
		{
			_data_->_tmp20_ = _data_->self->priv->rpc;
			_data_->_state_ = 2;
			dc_rpc_client_get_full_chat_by_id_for (_data_->_tmp20_, _data_->acct_id, _data_->chat_id, dc_event_handler_send_notification_ready, _data_);
			return FALSE;
			_state_2:
			_data_->_tmp21_ = dc_rpc_client_get_full_chat_by_id_for_finish (_data_->_tmp20_, _data_->_res_, &_data_->_inner_error0_);
			_data_->chat_obj = _data_->_tmp21_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch1_g_error;
			}
			_data_->_tmp23_ = _data_->chat_obj;
			if (_data_->_tmp23_ != NULL) {
				_data_->_tmp24_ = _data_->chat_obj;
				_data_->_tmp22_ = json_object_has_member (_data_->_tmp24_, "name");
			} else {
				_data_->_tmp22_ = FALSE;
			}
			if (_data_->_tmp22_) {
				_data_->_tmp25_ = _data_->chat_obj;
				_data_->_tmp26_ = json_object_get_string_member (_data_->_tmp25_, "name");
				_data_->_tmp27_ = g_strdup (_data_->_tmp26_);
				_data_->chat_name = _data_->_tmp27_;
				_data_->_tmp30_ = _data_->chat_name;
				if (_data_->_tmp30_ != NULL) {
					_data_->_tmp31_ = _data_->chat_name;
					_data_->_tmp32_ = strlen (_data_->_tmp31_);
					_data_->_tmp33_ = _data_->_tmp32_;
					_data_->_tmp29_ = _data_->_tmp33_ > 0;
				} else {
					_data_->_tmp29_ = FALSE;
				}
				if (_data_->_tmp29_) {
					_data_->_tmp34_ = _data_->chat_name;
					_data_->_tmp35_ = _data_->title;
					_data_->_tmp28_ = g_strcmp0 (_data_->_tmp34_, _data_->_tmp35_) != 0;
				} else {
					_data_->_tmp28_ = FALSE;
				}
				if (_data_->_tmp28_) {
					_data_->_tmp36_ = _data_->title;
					_data_->_tmp37_ = _data_->chat_name;
					_data_->_tmp38_ = g_strdup_printf ("%s (%s)", _data_->_tmp36_, _data_->_tmp37_);
					_g_free0 (_data_->title);
					_data_->title = _data_->_tmp38_;
				}
				_g_free0 (_data_->chat_name);
			}
			_json_object_unref0 (_data_->chat_obj);
		}
		goto __finally1;
		__catch1_g_error:
		{
			g_clear_error (&_data_->_inner_error0_);
		}
		__finally1:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_free0 (_data_->title);
			_g_object_unref0 (_data_->msg);
			goto __catch0_g_error;
		}
		_data_->_tmp39_ = _data_->self->priv->rpc;
		_data_->_tmp40_ = dc_rpc_client_get_account_id (_data_->_tmp39_);
		_data_->_tmp41_ = _data_->_tmp40_;
		if (_data_->acct_id != _data_->_tmp41_) {
			{
				_data_->_tmp42_ = _data_->self->priv->rpc;
				_data_->_state_ = 3;
				dc_rpc_client_get_config (_data_->_tmp42_, "displayname", _data_->acct_id, dc_event_handler_send_notification_ready, _data_);
				return FALSE;
				_state_3:
				_data_->_tmp43_ = dc_rpc_client_get_config_finish (_data_->_tmp42_, _data_->_res_, &_data_->_inner_error0_);
				_data_->acct_name = _data_->_tmp43_;
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					goto __catch2_g_error;
				}
				_data_->_tmp45_ = _data_->acct_name;
				if (_data_->_tmp45_ == NULL) {
					_data_->_tmp44_ = TRUE;
				} else {
					_data_->_tmp46_ = _data_->acct_name;
					_data_->_tmp47_ = strlen (_data_->_tmp46_);
					_data_->_tmp48_ = _data_->_tmp47_;
					_data_->_tmp44_ = _data_->_tmp48_ == 0;
				}
				if (_data_->_tmp44_) {
					_data_->_tmp50_ = _data_->self->priv->rpc;
					_data_->_state_ = 4;
					dc_rpc_client_get_config (_data_->_tmp50_, "addr", _data_->acct_id, dc_event_handler_send_notification_ready, _data_);
					return FALSE;
					_state_4:
					_data_->_tmp51_ = dc_rpc_client_get_config_finish (_data_->_tmp50_, _data_->_res_, &_data_->_inner_error0_);
					_data_->_tmp49_ = _data_->_tmp51_;
					if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
						_g_free0 (_data_->acct_name);
						goto __catch2_g_error;
					}
					_data_->_tmp52_ = _data_->_tmp49_;
					_data_->_tmp49_ = NULL;
					_g_free0 (_data_->acct_name);
					_data_->acct_name = _data_->_tmp52_;
					_g_free0 (_data_->_tmp49_);
				}
				_data_->_tmp54_ = _data_->acct_name;
				if (_data_->_tmp54_ != NULL) {
					_data_->_tmp55_ = _data_->acct_name;
					_data_->_tmp56_ = strlen (_data_->_tmp55_);
					_data_->_tmp57_ = _data_->_tmp56_;
					_data_->_tmp53_ = _data_->_tmp57_ > 0;
				} else {
					_data_->_tmp53_ = FALSE;
				}
				if (_data_->_tmp53_) {
					_data_->_tmp58_ = _data_->acct_name;
					_data_->_tmp59_ = _data_->title;
					_data_->_tmp60_ = g_strdup_printf ("[%s] %s", _data_->_tmp58_, _data_->_tmp59_);
					_g_free0 (_data_->title);
					_data_->title = _data_->_tmp60_;
				}
				_g_free0 (_data_->acct_name);
			}
			goto __finally2;
			__catch2_g_error:
			{
				g_clear_error (&_data_->_inner_error0_);
			}
			__finally2:
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_free0 (_data_->title);
				_g_object_unref0 (_data_->msg);
				goto __catch0_g_error;
			}
		}
		_data_->_tmp63_ = _data_->msg;
		_data_->_tmp64_ = dc_message_get_text (_data_->_tmp63_);
		_data_->_tmp65_ = _data_->_tmp64_;
		if (_data_->_tmp65_ != NULL) {
			_data_->_tmp66_ = _data_->msg;
			_data_->_tmp67_ = dc_message_get_text (_data_->_tmp66_);
			_data_->_tmp68_ = _data_->_tmp67_;
			_data_->_tmp69_ = strlen (_data_->_tmp68_);
			_data_->_tmp70_ = _data_->_tmp69_;
			_data_->_tmp62_ = _data_->_tmp70_ > 0;
		} else {
			_data_->_tmp62_ = FALSE;
		}
		if (_data_->_tmp62_) {
			_data_->_tmp71_ = _data_->msg;
			_data_->_tmp72_ = dc_message_get_text (_data_->_tmp71_);
			_data_->_tmp73_ = _data_->_tmp72_;
			_data_->_tmp61_ = _data_->_tmp73_;
		} else {
			_data_->_tmp76_ = _data_->msg;
			_data_->_tmp77_ = dc_message_get_file_name (_data_->_tmp76_);
			_data_->_tmp78_ = _data_->_tmp77_;
			if (_data_->_tmp78_ != NULL) {
				_data_->_tmp79_ = _data_->msg;
				_data_->_tmp80_ = dc_message_get_file_name (_data_->_tmp79_);
				_data_->_tmp81_ = _data_->_tmp80_;
				_data_->_tmp82_ = strlen (_data_->_tmp81_);
				_data_->_tmp83_ = _data_->_tmp82_;
				_data_->_tmp75_ = _data_->_tmp83_ > 0;
			} else {
				_data_->_tmp75_ = FALSE;
			}
			if (_data_->_tmp75_) {
				_data_->_tmp84_ = _data_->msg;
				_data_->_tmp85_ = dc_message_get_file_name (_data_->_tmp84_);
				_data_->_tmp86_ = _data_->_tmp85_;
				_data_->_tmp74_ = _data_->_tmp86_;
			} else {
				_data_->_tmp74_ = "New message";
			}
			_data_->_tmp61_ = _data_->_tmp74_;
		}
		_data_->_tmp87_ = g_strdup (_data_->_tmp61_);
		_data_->body = _data_->_tmp87_;
		_data_->_tmp88_ = _data_->title;
		_data_->_tmp89_ = g_notification_new (_data_->_tmp88_);
		_data_->n = _data_->_tmp89_;
		_data_->_tmp90_ = _data_->n;
		_data_->_tmp91_ = _data_->body;
		g_notification_set_body (_data_->_tmp90_, _data_->_tmp91_);
		_data_->_tmp92_ = _data_->n;
		g_notification_set_priority (_data_->_tmp92_, G_NOTIFICATION_PRIORITY_NORMAL);
		_data_->_tmp93_ = _data_->n;
		_data_->_tmp94_ = g_variant_new ("(ii)", _data_->acct_id, _data_->chat_id, NULL);
		g_variant_ref_sink (_data_->_tmp94_);
		_data_->_tmp95_ = _data_->_tmp94_;
		g_notification_set_default_action_and_target_value (_data_->_tmp93_, "app.open-chat", _data_->_tmp95_);
		_g_variant_unref0 (_data_->_tmp95_);
		_data_->_tmp96_ = _data_->self->priv->app;
		_data_->_tmp97_ = g_strdup_printf ("dc-msg-%d-%d", _data_->acct_id, _data_->msg_id);
		_data_->_tmp98_ = _data_->_tmp97_;
		_data_->_tmp99_ = _data_->n;
		g_application_send_notification (_data_->_tmp96_, _data_->_tmp98_, _data_->_tmp99_);
		_g_free0 (_data_->_tmp98_);
		_g_object_unref0 (_data_->n);
		_g_free0 (_data_->body);
		_g_free0 (_data_->title);
		_g_object_unref0 (_data_->msg);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp100_ = _data_->e;
		_data_->_tmp101_ = _data_->_tmp100_->message;
		g_warning ("event_handler.vala:206: Failed to send notification: %s", _data_->_tmp101_);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	g_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
dc_event_handler_nap_data_free (gpointer _data)
{
	DcEventHandlerNapData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (DcEventHandlerNapData, _data_);
}

static void
dc_event_handler_nap (DcEventHandler* self,
                      guint ms,
                      GAsyncReadyCallback _callback_,
                      gpointer _user_data_)
{
	DcEventHandlerNapData* _data_;
	DcEventHandler* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcEventHandlerNapData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_event_handler_nap_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->ms = ms;
	dc_event_handler_nap_co (_data_);
}

static void
dc_event_handler_nap_finish (DcEventHandler* self,
                             GAsyncResult* _res_)
{
	DcEventHandlerNapData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static gboolean
_dc_event_handler_nap_co_gsource_func (gpointer self)
{
	gboolean result;
	result = dc_event_handler_nap_co (self);
	return result;
}

static gboolean
dc_event_handler_nap_co (DcEventHandlerNapData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	g_timeout_add_full (G_PRIORITY_DEFAULT, _data_->ms, _dc_event_handler_nap_co_gsource_func, _data_, NULL);
	_data_->_state_ = 1;
	return FALSE;
	_state_1:
	;
	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;
}

gint
dc_event_handler_get_active_chat_id (DcEventHandler* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = self->priv->_active_chat_id;
	return result;
}

void
dc_event_handler_set_active_chat_id (DcEventHandler* self,
                                     gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = dc_event_handler_get_active_chat_id (self);
	if (old_value != value) {
		self->priv->_active_chat_id = value;
		g_object_notify_by_pspec ((GObject *) self, dc_event_handler_properties[DC_EVENT_HANDLER_ACTIVE_CHAT_ID_PROPERTY]);
	}
}

gboolean
dc_event_handler_get_is_listening (DcEventHandler* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_listening;
	return result;
}

static void
g_cclosure_user_marshal_VOID__INT_INT_INT (GClosure * closure,
                                           GValue * return_value,
                                           guint n_param_values,
                                           const GValue * param_values,
                                           gpointer invocation_hint,
                                           gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__INT_INT_INT) (gpointer data1, gint arg_1, gint arg_2, gint arg_3, gpointer data2);
	register GMarshalFunc_VOID__INT_INT_INT callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 4);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__INT_INT_INT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_int (param_values + 1), g_value_get_int (param_values + 2), g_value_get_int (param_values + 3), data2);
}

static void
g_cclosure_user_marshal_VOID__INT_INT (GClosure * closure,
                                       GValue * return_value,
                                       guint n_param_values,
                                       const GValue * param_values,
                                       gpointer invocation_hint,
                                       gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__INT_INT) (gpointer data1, gint arg_1, gint arg_2, gpointer data2);
	register GMarshalFunc_VOID__INT_INT callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__INT_INT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_int (param_values + 1), g_value_get_int (param_values + 2), data2);
}

static void
g_cclosure_user_marshal_VOID__INT_INT_STRING (GClosure * closure,
                                              GValue * return_value,
                                              guint n_param_values,
                                              const GValue * param_values,
                                              gpointer invocation_hint,
                                              gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__INT_INT_STRING) (gpointer data1, gint arg_1, gint arg_2, const char* arg_3, gpointer data2);
	register GMarshalFunc_VOID__INT_INT_STRING callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 4);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__INT_INT_STRING) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_int (param_values + 1), g_value_get_int (param_values + 2), g_value_get_string (param_values + 3), data2);
}

static void
dc_event_handler_class_init (DcEventHandlerClass * klass,
                             gpointer klass_data)
{
	dc_event_handler_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DcEventHandler_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dc_event_handler_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_dc_event_handler_set_property;
	G_OBJECT_CLASS (klass)->finalize = dc_event_handler_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DC_EVENT_HANDLER_ACTIVE_CHAT_ID_PROPERTY, dc_event_handler_properties[DC_EVENT_HANDLER_ACTIVE_CHAT_ID_PROPERTY] = g_param_spec_int ("active-chat-id", "active-chat-id", "active-chat-id", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DC_EVENT_HANDLER_IS_LISTENING_PROPERTY, dc_event_handler_properties[DC_EVENT_HANDLER_IS_LISTENING_PROPERTY] = g_param_spec_boolean ("is-listening", "is-listening", "is-listening", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	dc_event_handler_signals[DC_EVENT_HANDLER_CHATS_RELOAD_FIRED_SIGNAL] = g_signal_new ("chats-reload-fired", DC_TYPE_EVENT_HANDLER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	dc_event_handler_signals[DC_EVENT_HANDLER_MESSAGES_RELOAD_FIRED_SIGNAL] = g_signal_new ("messages-reload-fired", DC_TYPE_EVENT_HANDLER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	dc_event_handler_signals[DC_EVENT_HANDLER_INCOMING_MSG_RECEIVED_SIGNAL] = g_signal_new ("incoming-msg-received", DC_TYPE_EVENT_HANDLER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT_INT_INT, G_TYPE_NONE, 3, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT);
	dc_event_handler_signals[DC_EVENT_HANDLER_ACCOUNT_UNREAD_CHANGED_SIGNAL] = g_signal_new ("account-unread-changed", DC_TYPE_EVENT_HANDLER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
	dc_event_handler_signals[DC_EVENT_HANDLER_IMEX_PROGRESS_SIGNAL] = g_signal_new ("imex-progress", DC_TYPE_EVENT_HANDLER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT_INT, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
	dc_event_handler_signals[DC_EVENT_HANDLER_CONFIGURE_PROGRESS_SIGNAL] = g_signal_new ("configure-progress", DC_TYPE_EVENT_HANDLER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT_INT_STRING, G_TYPE_NONE, 3, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING);
}

static void
dc_event_handler_instance_init (DcEventHandler * self,
                                gpointer klass)
{
	self->priv = dc_event_handler_get_instance_private (self);
	self->priv->app = NULL;
	self->priv->_listening = FALSE;
	self->priv->chats_reload_timer = (guint) 0;
	self->priv->messages_reload_timer = (guint) 0;
	self->priv->_active_chat_id = 0;
}

static void
dc_event_handler_finalize (GObject * obj)
{
	DcEventHandler * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_EVENT_HANDLER, DcEventHandler);
	G_OBJECT_CLASS (dc_event_handler_parent_class)->finalize (obj);
}

static GType
dc_event_handler_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcEventHandlerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_event_handler_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcEventHandler), 0, (GInstanceInitFunc) dc_event_handler_instance_init, NULL };
	GType dc_event_handler_type_id;
	dc_event_handler_type_id = g_type_register_static (G_TYPE_OBJECT, "DcEventHandler", &g_define_type_info, 0);
	DcEventHandler_private_offset = g_type_add_instance_private (dc_event_handler_type_id, sizeof (DcEventHandlerPrivate));
	return dc_event_handler_type_id;
}

GType
dc_event_handler_get_type (void)
{
	static volatile gsize dc_event_handler_type_id__once = 0;
	if (g_once_init_enter (&dc_event_handler_type_id__once)) {
		GType dc_event_handler_type_id;
		dc_event_handler_type_id = dc_event_handler_get_type_once ();
		g_once_init_leave (&dc_event_handler_type_id__once, dc_event_handler_type_id);
	}
	return dc_event_handler_type_id__once;
}

static void
_vala_dc_event_handler_get_property (GObject * object,
                                     guint property_id,
                                     GValue * value,
                                     GParamSpec * pspec)
{
	DcEventHandler * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DC_TYPE_EVENT_HANDLER, DcEventHandler);
	switch (property_id) {
		case DC_EVENT_HANDLER_ACTIVE_CHAT_ID_PROPERTY:
		g_value_set_int (value, dc_event_handler_get_active_chat_id (self));
		break;
		case DC_EVENT_HANDLER_IS_LISTENING_PROPERTY:
		g_value_set_boolean (value, dc_event_handler_get_is_listening (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_dc_event_handler_set_property (GObject * object,
                                     guint property_id,
                                     const GValue * value,
                                     GParamSpec * pspec)
{
	DcEventHandler * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DC_TYPE_EVENT_HANDLER, DcEventHandler);
	switch (property_id) {
		case DC_EVENT_HANDLER_ACTIVE_CHAT_ID_PROPERTY:
		dc_event_handler_set_active_chat_id (self, g_value_get_int (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

