/* 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 <stdlib.h>
#include <string.h>
#include <glib.h>
#include <json-glib/json-glib.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_DESKTOP_NOTIFICATION_SERVER (dc_desktop_notification_server_get_type ())
#define DC_DESKTOP_NOTIFICATION_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_DESKTOP_NOTIFICATION_SERVER, DcDesktopNotificationServer))
#define DC_IS_DESKTOP_NOTIFICATION_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_DESKTOP_NOTIFICATION_SERVER))
#define DC_DESKTOP_NOTIFICATION_SERVER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), DC_TYPE_DESKTOP_NOTIFICATION_SERVER, DcDesktopNotificationServerIface))

typedef struct _DcDesktopNotificationServer DcDesktopNotificationServer;
typedef struct _DcDesktopNotificationServerIface DcDesktopNotificationServerIface;

#define DC_TYPE_DESKTOP_NOTIFICATION_SERVER_PROXY (dc_desktop_notification_server_proxy_get_type ())
typedef GDBusProxy DcDesktopNotificationServerProxy;
typedef GDBusProxyClass DcDesktopNotificationServerProxyClass;

#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 _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define __vala_JsonNode_free0(var) ((var == NULL) ? NULL : (var = (_vala_JsonNode_free (var), NULL)))
#define _json_array_unref0(var) ((var == NULL) ? NULL : (var = (json_array_unref (var), NULL)))
typedef struct _DcEventHandlerReconcileDesktopNotificationsData DcEventHandlerReconcileDesktopNotificationsData;
typedef struct _DcEventHandlerReconcileAccountNotificationsData DcEventHandlerReconcileAccountNotificationsData;
typedef struct _DcEventHandlerWithdrawLegacyNotificationsForChatData DcEventHandlerWithdrawLegacyNotificationsForChatData;
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_INCOMING_REACTION_RECEIVED_SIGNAL,
	DC_EVENT_HANDLER_CHAT_MESSAGES_CHANGED_SIGNAL,
	DC_EVENT_HANDLER_ACCOUNT_UNREAD_CHANGED_SIGNAL,
	DC_EVENT_HANDLER_CONTACTS_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 _DcDesktopNotificationServerIface {
	GTypeInterface parent_iface;
	gchar** (*get_capabilities) (DcDesktopNotificationServer* self, gint* result_length1, GError** error);
};

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 notification_actions_supported;
	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_;
	const gchar* _tmp26_;
	DcRpcClient* _tmp27_;
	gint _tmp28_;
	gint _tmp29_;
	const gchar* _tmp30_;
	JsonObject* _tmp31_;
	JsonObject* _tmp32_;
	const gchar* _tmp33_;
	JsonObject* _tmp34_;
	JsonObject* _tmp35_;
	JsonObject* _tmp36_;
	JsonObject* _tmp37_;
	const gchar* _tmp38_;
	const gchar* _tmp39_;
	JsonObject* _tmp40_;
	DcRpcClient* _tmp41_;
	gint _tmp42_;
	gint _tmp43_;
	DcRpcClient* _tmp44_;
	gint _tmp45_;
	gint _tmp46_;
	const gchar* _tmp47_;
	const gchar* _tmp48_;
	JsonObject* _tmp49_;
	GError* e;
	DcRpcClient* _tmp50_;
	gboolean _tmp51_;
	gboolean _tmp52_;
	GError* _tmp53_;
	const gchar* _tmp54_;
	GError* _inner_error0_;
};

struct _DcEventHandlerReconcileDesktopNotificationsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcEventHandler* self;
	gboolean _tmp0_;
	GApplication* _tmp1_;
	DcRpcClient* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	JsonNode* accounts_node;
	DcRpcClient* _tmp5_;
	JsonNode* _tmp6_;
	JsonNode* _tmp7_;
	JsonArray* accounts;
	JsonNode* _tmp8_;
	JsonArray* _tmp9_;
	JsonArray* _tmp10_;
	guint i;
	gboolean _tmp11_;
	guint _tmp12_;
	JsonArray* _tmp13_;
	gint acct_id;
	JsonArray* _tmp14_;
	JsonObject* _tmp15_;
	GError* e;
	GError* _tmp16_;
	const gchar* _tmp17_;
	GError* _inner_error0_;
};

struct _DcEventHandlerReconcileAccountNotificationsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcEventHandler* self;
	gint acct_id;
	gchar* _tmp0_;
	gchar* _tmp1_;
	JsonArray* entries;
	DcRpcClient* _tmp2_;
	JsonArray* _tmp3_;
	JsonArray* _tmp4_;
	guint i;
	gboolean _tmp5_;
	guint _tmp6_;
	JsonArray* _tmp7_;
	gint chat_id;
	JsonArray* _tmp8_;
	GError* _inner_error0_;
};

struct _DcEventHandlerWithdrawLegacyNotificationsForChatData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcEventHandler* self;
	gint acct_id;
	gint chat_id;
	JsonArray* msg_ids;
	DcRpcClient* _tmp0_;
	JsonArray* _tmp1_;
	guint i;
	gboolean _tmp2_;
	guint _tmp3_;
	gint msg_id;
	gchar* _tmp4_;
	gchar* _tmp5_;
	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_desktop_notification_server_proxy_get_type (void) G_GNUC_CONST ;
VALA_EXTERN guint dc_desktop_notification_server_register_object (void* object,
                                                      GDBusConnection* connection,
                                                      const gchar* path,
                                                      GError** error);
VALA_EXTERN GType dc_desktop_notification_server_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcDesktopNotificationServer, g_object_unref)
VALA_EXTERN gchar** dc_desktop_notification_server_get_capabilities (DcDesktopNotificationServer* self,
                                                         gint* result_length1,
                                                         GError** error);
static GType dc_desktop_notification_server_get_type_once (void);
static void dc_desktop_notification_server_proxy_g_signal (GDBusProxy* proxy,
                                                    const gchar* sender_name,
                                                    const gchar* signal_name,
                                                    GVariant* parameters);
static gchar** dc_desktop_notification_server_proxy_get_capabilities (DcDesktopNotificationServer* self,
                                                               gint* result_length1,
                                                               GError** error);
static void dc_desktop_notification_server_proxy_dc_desktop_notification_server_interface_init (DcDesktopNotificationServerIface* iface);
static void _dbus_dc_desktop_notification_server_get_capabilities (DcDesktopNotificationServer* self,
                                                            GVariant* _parameters_,
                                                            GDBusMethodInvocation* invocation);
static void dc_desktop_notification_server_dbus_interface_method_call (GDBusConnection* connection,
                                                                const gchar* sender,
                                                                const gchar* object_path,
                                                                const gchar* interface_name,
                                                                const gchar* method_name,
                                                                GVariant* parameters,
                                                                GDBusMethodInvocation* invocation,
                                                                gpointer user_data);
static GVariant* dc_desktop_notification_server_dbus_interface_get_property (GDBusConnection* connection,
                                                                      const gchar* sender,
                                                                      const gchar* object_path,
                                                                      const gchar* interface_name,
                                                                      const gchar* property_name,
                                                                      GError** error,
                                                                      gpointer user_data);
static gboolean dc_desktop_notification_server_dbus_interface_set_property (GDBusConnection* connection,
                                                                     const gchar* sender,
                                                                     const gchar* object_path,
                                                                     const gchar* interface_name,
                                                                     const gchar* property_name,
                                                                     GVariant* value,
                                                                     GError** error,
                                                                     gpointer user_data);
static void _dc_desktop_notification_server_unregister_object (gpointer user_data);
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);
VALA_EXTERN void dc_event_handler_schedule_messages_reload (DcEventHandler* self);
VALA_EXTERN void dc_event_handler_schedule_chats_reload (DcEventHandler* self);
VALA_EXTERN void dc_event_handler_clear_notifications_for_chat (DcEventHandler* self,
                                                    gint acct_id,
                                                    gint chat_id);
static void dc_event_handler_dispatch_background (DcEventHandler* self,
                                           gint acct_id,
                                           const gchar* kind);
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_);
static gboolean __lambda75_ (DcEventHandler* self);
static gboolean ___lambda75__gsource_func (gpointer self);
VALA_EXTERN gint dc_event_handler_get_active_chat_id (DcEventHandler* self);
static gboolean __lambda74_ (DcEventHandler* self);
static gboolean ___lambda74__gsource_func (gpointer self);
static gint dc_event_handler_event_chat_id (JsonObject* event);
VALA_EXTERN void dc_webxdc_status_update (gint msg_id);
VALA_EXTERN void dc_webxdc_instance_deleted (gint msg_id);
VALA_EXTERN void dc_event_handler_send_chat_notification (DcEventHandler* self,
                                              gint acct_id,
                                              gint chat_id,
                                              const gchar* title,
                                              const gchar* body);
static void dc_event_handler_set_open_chat_action (DcEventHandler* self,
                                            GNotification* notification,
                                            gint acct_id,
                                            gint chat_id);
static gchar* dc_event_handler_notification_id (gint acct_id,
                                         gint chat_id);
static void dc_event_handler_withdraw_notification_id (DcEventHandler* self,
                                                const gchar* id);
static gchar* dc_event_handler_mention_notification_id (gint acct_id,
                                                 gint chat_id);
VALA_EXTERN void dc_event_handler_send_mention_notification (DcEventHandler* self,
                                                 gint acct_id,
                                                 gint chat_id,
                                                 const gchar* title,
                                                 const gchar* body);
static gboolean dc_event_handler_server_supports_actions (DcEventHandler* self);
static void dc_event_handler_reconcile_desktop_notifications_data_free (gpointer _data);
VALA_EXTERN void dc_event_handler_reconcile_desktop_notifications (DcEventHandler* self,
                                                       GAsyncReadyCallback _callback_,
                                                       gpointer _user_data_);
VALA_EXTERN void dc_event_handler_reconcile_desktop_notifications_finish (DcEventHandler* self,
                                                              GAsyncResult* _res_);
static gboolean dc_event_handler_reconcile_desktop_notifications_co (DcEventHandlerReconcileDesktopNotificationsData* _data_);
VALA_EXTERN void dc_rpc_client_get_all_accounts (DcRpcClient* self,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_);
VALA_EXTERN JsonNode* dc_rpc_client_get_all_accounts_finish (DcRpcClient* self,
                                                 GAsyncResult* _res_,
                                                 GError** error);
static void dc_event_handler_reconcile_desktop_notifications_ready (GObject* source_object,
                                                             GAsyncResult* _res_,
                                                             gpointer _user_data_);
static void _vala_JsonNode_free (JsonNode* self);
static void dc_event_handler_reconcile_account_notifications (DcEventHandler* self,
                                                       gint acct_id,
                                                       GAsyncReadyCallback _callback_,
                                                       gpointer _user_data_);
static void dc_event_handler_reconcile_account_notifications_finish (DcEventHandler* self,
                                                              GAsyncResult* _res_,
                                                              GError** error);
static gchar* dc_event_handler_legacy_notification_id (gint acct_id,
                                                gint msg_id);
static void dc_event_handler_reconcile_account_notifications_data_free (gpointer _data);
static gboolean dc_event_handler_reconcile_account_notifications_co (DcEventHandlerReconcileAccountNotificationsData* _data_);
VALA_EXTERN void dc_rpc_client_get_chatlist_entries_for (DcRpcClient* self,
                                             gint acct_id,
                                             const gchar* query,
                                             gint list_flags,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
VALA_EXTERN JsonArray* dc_rpc_client_get_chatlist_entries_for_finish (DcRpcClient* self,
                                                          GAsyncResult* _res_,
                                                          GError** error);
static void dc_event_handler_reconcile_account_notifications_ready (GObject* source_object,
                                                             GAsyncResult* _res_,
                                                             gpointer _user_data_);
static void dc_event_handler_withdraw_legacy_notifications_for_chat (DcEventHandler* self,
                                                              gint acct_id,
                                                              gint chat_id,
                                                              GAsyncReadyCallback _callback_,
                                                              gpointer _user_data_);
static void dc_event_handler_withdraw_legacy_notifications_for_chat_finish (DcEventHandler* self,
                                                                     GAsyncResult* _res_,
                                                                     GError** error);
static void dc_event_handler_withdraw_legacy_notifications_for_chat_data_free (gpointer _data);
static gboolean dc_event_handler_withdraw_legacy_notifications_for_chat_co (DcEventHandlerWithdrawLegacyNotificationsForChatData* _data_);
VALA_EXTERN void dc_rpc_client_get_message_ids_for (DcRpcClient* self,
                                        gint acct_id,
                                        gint chat_id,
                                        gboolean info_only,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_);
VALA_EXTERN JsonArray* dc_rpc_client_get_message_ids_for_finish (DcRpcClient* self,
                                                     GAsyncResult* _res_,
                                                     GError** error);
static void dc_event_handler_withdraw_legacy_notifications_for_chat_ready (GObject* source_object,
                                                                    GAsyncResult* _res_,
                                                                    gpointer _user_data_);
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_INT_INT_STRING (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 void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static const GDBusArgInfo _dc_desktop_notification_server_dbus_arg_info_get_capabilities_result = {-1, "result", "as", NULL};
static const GDBusArgInfo * const _dc_desktop_notification_server_dbus_arg_info_get_capabilities_in[] = {NULL};
static const GDBusArgInfo * const _dc_desktop_notification_server_dbus_arg_info_get_capabilities_out[] = {&_dc_desktop_notification_server_dbus_arg_info_get_capabilities_result, NULL};
static const GDBusMethodInfo _dc_desktop_notification_server_dbus_method_info_get_capabilities = {-1, "GetCapabilities", (GDBusArgInfo **) (&_dc_desktop_notification_server_dbus_arg_info_get_capabilities_in), (GDBusArgInfo **) (&_dc_desktop_notification_server_dbus_arg_info_get_capabilities_out), NULL};
static const GDBusMethodInfo * const _dc_desktop_notification_server_dbus_method_info[] = {&_dc_desktop_notification_server_dbus_method_info_get_capabilities, NULL};
static const GDBusSignalInfo * const _dc_desktop_notification_server_dbus_signal_info[] = {NULL};
static const GDBusPropertyInfo * const _dc_desktop_notification_server_dbus_property_info[] = {NULL};
static const GDBusInterfaceInfo _dc_desktop_notification_server_dbus_interface_info = {-1, "org.freedesktop.Notifications", (GDBusMethodInfo **) (&_dc_desktop_notification_server_dbus_method_info), (GDBusSignalInfo **) (&_dc_desktop_notification_server_dbus_signal_info), (GDBusPropertyInfo **) (&_dc_desktop_notification_server_dbus_property_info), NULL};
static const GDBusInterfaceVTable _dc_desktop_notification_server_dbus_interface_vtable = {dc_desktop_notification_server_dbus_interface_method_call, dc_desktop_notification_server_dbus_interface_get_property, dc_desktop_notification_server_dbus_interface_set_property};

gchar**
dc_desktop_notification_server_get_capabilities (DcDesktopNotificationServer* self,
                                                 gint* result_length1,
                                                 GError** error)
{
	DcDesktopNotificationServerIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = DC_DESKTOP_NOTIFICATION_SERVER_GET_INTERFACE (self);
	if (_iface_->get_capabilities) {
		return _iface_->get_capabilities (self, result_length1, error);
	}
	return NULL;
}

static void
dc_desktop_notification_server_default_init (DcDesktopNotificationServerIface * iface,
                                             gpointer iface_data)
{
}

static GType
dc_desktop_notification_server_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcDesktopNotificationServerIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_desktop_notification_server_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType dc_desktop_notification_server_type_id;
	dc_desktop_notification_server_type_id = g_type_register_static (G_TYPE_INTERFACE, "DcDesktopNotificationServer", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (dc_desktop_notification_server_type_id, G_TYPE_OBJECT);
	g_type_set_qdata (dc_desktop_notification_server_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) dc_desktop_notification_server_proxy_get_type);
	g_type_set_qdata (dc_desktop_notification_server_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.freedesktop.Notifications");
	g_type_set_qdata (dc_desktop_notification_server_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_dc_desktop_notification_server_dbus_interface_info));
	g_type_set_qdata (dc_desktop_notification_server_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) dc_desktop_notification_server_register_object);
	return dc_desktop_notification_server_type_id;
}

GType
dc_desktop_notification_server_get_type (void)
{
	static volatile gsize dc_desktop_notification_server_type_id__once = 0;
	if (g_once_init_enter (&dc_desktop_notification_server_type_id__once)) {
		GType dc_desktop_notification_server_type_id;
		dc_desktop_notification_server_type_id = dc_desktop_notification_server_get_type_once ();
		g_once_init_leave (&dc_desktop_notification_server_type_id__once, dc_desktop_notification_server_type_id);
	}
	return dc_desktop_notification_server_type_id__once;
}

G_DEFINE_TYPE_EXTENDED (DcDesktopNotificationServerProxy, dc_desktop_notification_server_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (DC_TYPE_DESKTOP_NOTIFICATION_SERVER, dc_desktop_notification_server_proxy_dc_desktop_notification_server_interface_init) )
static void
dc_desktop_notification_server_proxy_class_init (DcDesktopNotificationServerProxyClass* klass)
{
	G_DBUS_PROXY_CLASS (klass)->g_signal = dc_desktop_notification_server_proxy_g_signal;
}

static void
dc_desktop_notification_server_proxy_g_signal (GDBusProxy* proxy,
                                               const gchar* sender_name,
                                               const gchar* signal_name,
                                               GVariant* parameters)
{
}

static void
dc_desktop_notification_server_proxy_init (DcDesktopNotificationServerProxy* self)
{
	g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_dc_desktop_notification_server_dbus_interface_info));
}

static gchar**
dc_desktop_notification_server_proxy_get_capabilities (DcDesktopNotificationServer* self,
                                                       gint* result_length1,
                                                       GError** error)
{
	GDBusMessage *_message;
	GVariant *_arguments;
	GVariantBuilder _arguments_builder;
	GDBusMessage *_reply_message;
	GVariant *_reply;
	GVariantIter _reply_iter;
	gchar** _result = NULL;
	gint _result_length1;
	GVariant* _tmp0_;
	gchar** _tmp1_;
	gint _tmp1__length;
	gint _tmp1__size;
	gint _tmp1__length1;
	GVariantIter _tmp2_;
	GVariant* _tmp3_;
	_message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.freedesktop.Notifications", "GetCapabilities");
	g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE);
	_arguments = g_variant_builder_end (&_arguments_builder);
	g_dbus_message_set_body (_message, _arguments);
	_reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error);
	g_object_unref (_message);
	if (!_reply_message) {
		return NULL;
	}
	if (g_dbus_message_to_gerror (_reply_message, error)) {
		g_object_unref (_reply_message);
		return NULL;
	}
	_reply = g_dbus_message_get_body (_reply_message);
	g_variant_iter_init (&_reply_iter, _reply);
	_result_length1 = 0;
	_tmp0_ = g_variant_iter_next_value (&_reply_iter);
	_tmp1_ = g_new (gchar*, 5);
	_tmp1__length = 0;
	_tmp1__size = 4;
	_tmp1__length1 = 0;
	g_variant_iter_init (&_tmp2_, _tmp0_);
	for (; (_tmp3_ = g_variant_iter_next_value (&_tmp2_)) != NULL; _tmp1__length1++) {
		if (_tmp1__size == _tmp1__length) {
			_tmp1__size = 2 * _tmp1__size;
			_tmp1_ = g_renew (gchar*, _tmp1_, _tmp1__size + 1);
		}
		_tmp1_[_tmp1__length++] = g_variant_dup_string (_tmp3_, NULL);
		g_variant_unref (_tmp3_);
	}
	_result_length1 = _tmp1__length1;
	_tmp1_[_tmp1__length] = NULL;
	_result = _tmp1_;
	g_variant_unref (_tmp0_);
	*result_length1 = _result_length1;
	g_object_unref (_reply_message);
	return _result;
}

static void
dc_desktop_notification_server_proxy_dc_desktop_notification_server_interface_init (DcDesktopNotificationServerIface* iface)
{
	iface->get_capabilities = dc_desktop_notification_server_proxy_get_capabilities;
}

static void
_dbus_dc_desktop_notification_server_get_capabilities (DcDesktopNotificationServer* self,
                                                       GVariant* _parameters_,
                                                       GDBusMethodInvocation* invocation)
{
	GError* error = NULL;
	GVariantIter _arguments_iter;
	GDBusMessage* _reply_message = NULL;
	GVariant* _reply;
	GVariantBuilder _reply_builder;
	gchar** result;
	gint result_length1 = 0;
	gchar** _tmp4_;
	GVariantBuilder _tmp5_;
	gint _tmp6_;
	g_variant_iter_init (&_arguments_iter, _parameters_);
	result = dc_desktop_notification_server_get_capabilities (self, &result_length1, &error);
	if (error) {
		g_dbus_method_invocation_take_error (invocation, error);
		return;
	}
	_reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation));
	g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE);
	_tmp4_ = result;
	g_variant_builder_init (&_tmp5_, G_VARIANT_TYPE ("as"));
	for (_tmp6_ = 0; _tmp6_ < result_length1; _tmp6_++) {
		g_variant_builder_add_value (&_tmp5_, g_variant_new_string (*_tmp4_));
		_tmp4_++;
	}
	g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp5_));
	result = (_vala_array_free (result, result_length1, (GDestroyNotify) g_free), NULL);
	_reply = g_variant_builder_end (&_reply_builder);
	g_dbus_message_set_body (_reply_message, _reply);
	g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
	g_object_unref (invocation);
	g_object_unref (_reply_message);
}

static void
dc_desktop_notification_server_dbus_interface_method_call (GDBusConnection* connection,
                                                           const gchar* sender,
                                                           const gchar* object_path,
                                                           const gchar* interface_name,
                                                           const gchar* method_name,
                                                           GVariant* parameters,
                                                           GDBusMethodInvocation* invocation,
                                                           gpointer user_data)
{
	gpointer* data;
	gpointer object;
	data = user_data;
	object = data[0];
	if (strcmp (method_name, "GetCapabilities") == 0) {
		_dbus_dc_desktop_notification_server_get_capabilities (object, parameters, invocation);
	} else {
		g_object_unref (invocation);
	}
}

static GVariant*
dc_desktop_notification_server_dbus_interface_get_property (GDBusConnection* connection,
                                                            const gchar* sender,
                                                            const gchar* object_path,
                                                            const gchar* interface_name,
                                                            const gchar* property_name,
                                                            GError** error,
                                                            gpointer user_data)
{
	return NULL;
}

static gboolean
dc_desktop_notification_server_dbus_interface_set_property (GDBusConnection* connection,
                                                            const gchar* sender,
                                                            const gchar* object_path,
                                                            const gchar* interface_name,
                                                            const gchar* property_name,
                                                            GVariant* value,
                                                            GError** error,
                                                            gpointer user_data)
{
	return FALSE;
}

guint
dc_desktop_notification_server_register_object (gpointer object,
                                                GDBusConnection* connection,
                                                const gchar* path,
                                                GError** error)
{
	guint result;
	gpointer *data;
	data = g_new (gpointer, 3);
	data[0] = g_object_ref (object);
	data[1] = g_object_ref (connection);
	data[2] = g_strdup (path);
	result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_dc_desktop_notification_server_dbus_interface_info), &_dc_desktop_notification_server_dbus_interface_vtable, data, _dc_desktop_notification_server_unregister_object, error);
	if (!result) {
		return 0;
	}
	return result;
}

static void
_dc_desktop_notification_server_unregister_object (gpointer user_data)
{
	gpointer* data;
	data = user_data;
	g_object_unref (data[0]);
	g_object_unref (data[1]);
	g_free (data[2]);
	g_free (data);
}

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_->kind;
			if (g_strcmp0 (_data_->_tmp26_, "IncomingMsgBunch") == 0) {
				_data_->_tmp27_ = _data_->self->priv->rpc;
				_data_->_tmp28_ = dc_rpc_client_get_account_id (_data_->_tmp27_);
				_data_->_tmp29_ = _data_->_tmp28_;
				if (_data_->ctx == _data_->_tmp29_) {
					g_signal_emit (_data_->self, dc_event_handler_signals[DC_EVENT_HANDLER_CHAT_MESSAGES_CHANGED_SIGNAL], 0, _data_->ctx, 0);
					dc_event_handler_schedule_messages_reload (_data_->self);
					dc_event_handler_schedule_chats_reload (_data_->self);
				}
				g_signal_emit (_data_->self, dc_event_handler_signals[DC_EVENT_HANDLER_ACCOUNT_UNREAD_CHANGED_SIGNAL], 0, _data_->ctx);
				_g_free0 (_data_->kind);
				_json_object_unref0 (_data_->event);
				_json_object_unref0 (_data_->ev);
				continue;
			}
			_data_->_tmp30_ = _data_->kind;
			if (g_strcmp0 (_data_->_tmp30_, "IncomingMsg") == 0) {
				_data_->_tmp31_ = _data_->event;
				_data_->_tmp32_ = _data_->event;
				g_signal_emit (_data_->self, dc_event_handler_signals[DC_EVENT_HANDLER_INCOMING_MSG_RECEIVED_SIGNAL], 0, _data_->ctx, (gint) json_object_get_int_member (_data_->_tmp31_, "chatId"), (gint) json_object_get_int_member (_data_->_tmp32_, "msgId"));
				g_signal_emit (_data_->self, dc_event_handler_signals[DC_EVENT_HANDLER_ACCOUNT_UNREAD_CHANGED_SIGNAL], 0, _data_->ctx);
				_g_free0 (_data_->kind);
				_json_object_unref0 (_data_->event);
				_json_object_unref0 (_data_->ev);
				continue;
			}
			_data_->_tmp33_ = _data_->kind;
			if (g_strcmp0 (_data_->_tmp33_, "IncomingReaction") == 0) {
				_data_->_tmp34_ = _data_->event;
				_data_->_tmp35_ = _data_->event;
				_data_->_tmp36_ = _data_->event;
				_data_->_tmp37_ = _data_->event;
				_data_->_tmp38_ = json_object_get_string_member (_data_->_tmp37_, "reaction");
				g_signal_emit (_data_->self, dc_event_handler_signals[DC_EVENT_HANDLER_INCOMING_REACTION_RECEIVED_SIGNAL], 0, _data_->ctx, (gint) json_object_get_int_member (_data_->_tmp34_, "chatId"), (gint) json_object_get_int_member (_data_->_tmp35_, "msgId"), (gint) json_object_get_int_member (_data_->_tmp36_, "contactId"), _data_->_tmp38_);
				_g_free0 (_data_->kind);
				_json_object_unref0 (_data_->event);
				_json_object_unref0 (_data_->ev);
				continue;
			}
			_data_->_tmp39_ = _data_->kind;
			if (g_strcmp0 (_data_->_tmp39_, "MsgsNoticed") == 0) {
				_data_->_tmp40_ = _data_->event;
				dc_event_handler_clear_notifications_for_chat (_data_->self, _data_->ctx, (gint) json_object_get_int_member (_data_->_tmp40_, "chatId"));
				g_signal_emit (_data_->self, dc_event_handler_signals[DC_EVENT_HANDLER_ACCOUNT_UNREAD_CHANGED_SIGNAL], 0, _data_->ctx);
				_data_->_tmp41_ = _data_->self->priv->rpc;
				_data_->_tmp42_ = dc_rpc_client_get_account_id (_data_->_tmp41_);
				_data_->_tmp43_ = _data_->_tmp42_;
				if (_data_->ctx == _data_->_tmp43_) {
					dc_event_handler_schedule_chats_reload (_data_->self);
				}
				_g_free0 (_data_->kind);
				_json_object_unref0 (_data_->event);
				_json_object_unref0 (_data_->ev);
				continue;
			}
			_data_->_tmp44_ = _data_->self->priv->rpc;
			_data_->_tmp45_ = dc_rpc_client_get_account_id (_data_->_tmp44_);
			_data_->_tmp46_ = _data_->_tmp45_;
			if (_data_->ctx != _data_->_tmp46_) {
				_data_->_tmp47_ = _data_->kind;
				dc_event_handler_dispatch_background (_data_->self, _data_->ctx, _data_->_tmp47_);
				_g_free0 (_data_->kind);
				_json_object_unref0 (_data_->event);
				_json_object_unref0 (_data_->ev);
				continue;
			}
			_data_->_tmp48_ = _data_->kind;
			_data_->_tmp49_ = _data_->event;
			dc_event_handler_dispatch (_data_->self, _data_->_tmp48_, _data_->_tmp49_);
			_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_->_tmp50_ = _data_->self->priv->rpc;
			_data_->_tmp51_ = dc_rpc_client_get_is_connected (_data_->_tmp50_);
			_data_->_tmp52_ = _data_->_tmp51_;
			if (_data_->_tmp52_) {
				_data_->_tmp53_ = _data_->e;
				_data_->_tmp54_ = _data_->_tmp53_->message;
				g_warning ("event_handler.vala:117: Event loop error: %s", _data_->_tmp54_);
				_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
__lambda75_ (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
___lambda75__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda75_ ((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, ___lambda75__gsource_func, g_object_ref (self), g_object_unref);
}

static gboolean
__lambda74_ (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
___lambda74__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda74_ ((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, ___lambda74__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;
	static GQuark _tmp1_label12 = 0;
	static GQuark _tmp1_label13 = 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 ("MsgsChanged")))) {
		switch (0) {
			default:
			{
				gint changed_chat = 0;
				DcRpcClient* _tmp3_;
				gint _tmp4_;
				gint _tmp5_;
				gboolean _tmp6_ = FALSE;
				DcRpcClient* _tmp8_;
				gint _tmp9_;
				gint _tmp10_;
				changed_chat = (gint) json_object_get_int_member (event, "chatId");
				_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_CHAT_MESSAGES_CHANGED_SIGNAL], 0, _tmp5_, changed_chat);
				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);
				}
				_tmp8_ = self->priv->rpc;
				_tmp9_ = dc_rpc_client_get_account_id (_tmp8_);
				_tmp10_ = _tmp9_;
				g_signal_emit (self, dc_event_handler_signals[DC_EVENT_HANDLER_ACCOUNT_UNREAD_CHANGED_SIGNAL], 0, _tmp10_);
				break;
			}
		}
	} else if ((((((_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("MsgDelivered")))) || (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("MsgRead"))))) || (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string ("MsgReadCountChanged"))))) || (_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;
				DcRpcClient* _tmp11_;
				gint _tmp12_;
				gint _tmp13_;
				gint _tmp14_;
				msg_chat = (gint) json_object_get_int_member (event, "chatId");
				_tmp11_ = self->priv->rpc;
				_tmp12_ = dc_rpc_client_get_account_id (_tmp11_);
				_tmp13_ = _tmp12_;
				g_signal_emit (self, dc_event_handler_signals[DC_EVENT_HANDLER_CHAT_MESSAGES_CHANGED_SIGNAL], 0, _tmp13_, msg_chat);
				_tmp14_ = self->priv->_active_chat_id;
				if (msg_chat == _tmp14_) {
					dc_event_handler_schedule_messages_reload (self);
				}
				if (g_strcmp0 (kind, "MsgDeleted") == 0) {
					DcRpcClient* _tmp15_;
					gint _tmp16_;
					gint _tmp17_;
					_tmp15_ = self->priv->rpc;
					_tmp16_ = dc_rpc_client_get_account_id (_tmp15_);
					_tmp17_ = _tmp16_;
					g_signal_emit (self, dc_event_handler_signals[DC_EVENT_HANDLER_ACCOUNT_UNREAD_CHANGED_SIGNAL], 0, _tmp17_);
				}
				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"))))) {
		switch (0) {
			default:
			{
				gint list_chat = 0;
				DcRpcClient* _tmp21_;
				gint _tmp22_;
				gint _tmp23_;
				list_chat = dc_event_handler_event_chat_id (event);
				if (list_chat > 0) {
					DcRpcClient* _tmp18_;
					gint _tmp19_;
					gint _tmp20_;
					_tmp18_ = self->priv->rpc;
					_tmp19_ = dc_rpc_client_get_account_id (_tmp18_);
					_tmp20_ = _tmp19_;
					g_signal_emit (self, dc_event_handler_signals[DC_EVENT_HANDLER_CHAT_MESSAGES_CHANGED_SIGNAL], 0, _tmp20_, list_chat);
				}
				dc_event_handler_schedule_chats_reload (self);
				_tmp21_ = self->priv->rpc;
				_tmp22_ = dc_rpc_client_get_account_id (_tmp21_);
				_tmp23_ = _tmp22_;
				g_signal_emit (self, dc_event_handler_signals[DC_EVENT_HANDLER_ACCOUNT_UNREAD_CHANGED_SIGNAL], 0, _tmp23_);
				break;
			}
		}
	} else if ((_tmp2_ == ((0 != _tmp1_label9) ? _tmp1_label9 : (_tmp1_label9 = g_quark_from_static_string ("ChatModified")))) || (_tmp2_ == ((0 != _tmp1_label10) ? _tmp1_label10 : (_tmp1_label10 = g_quark_from_static_string ("ChatDeleted"))))) {
		switch (0) {
			default:
			{
				DcRpcClient* _tmp24_;
				gint _tmp25_;
				gint _tmp26_;
				dc_event_handler_schedule_chats_reload (self);
				_tmp24_ = self->priv->rpc;
				_tmp25_ = dc_rpc_client_get_account_id (_tmp24_);
				_tmp26_ = _tmp25_;
				g_signal_emit (self, dc_event_handler_signals[DC_EVENT_HANDLER_ACCOUNT_UNREAD_CHANGED_SIGNAL], 0, _tmp26_);
				break;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label11) ? _tmp1_label11 : (_tmp1_label11 = g_quark_from_static_string ("ContactsChanged")))) {
		switch (0) {
			default:
			{
				DcRpcClient* _tmp27_;
				gint _tmp28_;
				gint _tmp29_;
				_tmp27_ = self->priv->rpc;
				_tmp28_ = dc_rpc_client_get_account_id (_tmp27_);
				_tmp29_ = _tmp28_;
				g_signal_emit (self, dc_event_handler_signals[DC_EVENT_HANDLER_CONTACTS_CHANGED_SIGNAL], 0, _tmp29_);
				dc_event_handler_schedule_messages_reload (self);
				dc_event_handler_schedule_chats_reload (self);
				break;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label12) ? _tmp1_label12 : (_tmp1_label12 = g_quark_from_static_string ("WebxdcStatusUpdate")))) {
		switch (0) {
			default:
			{
				dc_webxdc_status_update ((gint) json_object_get_int_member (event, "msgId"));
				break;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label13) ? _tmp1_label13 : (_tmp1_label13 = g_quark_from_static_string ("WebxdcInstanceDeleted")))) {
		switch (0) {
			default:
			{
				dc_webxdc_instance_deleted ((gint) json_object_get_int_member (event, "msgId"));
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				break;
			}
		}
	}
}

static gint
dc_event_handler_event_chat_id (JsonObject* event)
{
	gboolean _tmp0_ = FALSE;
	gint result;
	g_return_val_if_fail (event != NULL, -1);
	if (!json_object_has_member (event, "chatId")) {
		_tmp0_ = TRUE;
	} else {
		JsonNode* _tmp1_;
		_tmp1_ = json_object_get_member (event, "chatId");
		_tmp0_ = json_node_is_null (_tmp1_);
	}
	if (_tmp0_) {
		result = 0;
		return result;
	}
	result = (gint) json_object_get_int_member (event, "chatId");
	return result;
}

static void
dc_event_handler_dispatch_background (DcEventHandler* self,
                                      gint acct_id,
                                      const gchar* kind)
{
	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;
	g_return_if_fail (self != NULL);
	g_return_if_fail (kind != 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 ("MsgsChanged")))) || (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("MsgDeleted"))))) || (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("ChatlistChanged"))))) || (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string ("ChatlistItemChanged"))))) || (_tmp2_ == ((0 != _tmp1_label4) ? _tmp1_label4 : (_tmp1_label4 = g_quark_from_static_string ("ChatModified"))))) || (_tmp2_ == ((0 != _tmp1_label5) ? _tmp1_label5 : (_tmp1_label5 = g_quark_from_static_string ("ChatDeleted"))))) {
		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;
			}
		}
	}
}

void
dc_event_handler_send_chat_notification (DcEventHandler* self,
                                         gint acct_id,
                                         gint chat_id,
                                         const gchar* title,
                                         const gchar* body)
{
	gboolean _tmp0_ = FALSE;
	GApplication* _tmp1_;
	GNotification* n = NULL;
	GNotification* _tmp2_;
	GNotification* _tmp3_;
	GNotification* _tmp4_;
	GNotification* _tmp5_;
	GApplication* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	GNotification* _tmp9_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (title != NULL);
	g_return_if_fail (body != NULL);
	_tmp1_ = self->priv->app;
	if (_tmp1_ == NULL) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = acct_id <= 0;
	}
	if (_tmp0_) {
		return;
	}
	_tmp2_ = g_notification_new (title);
	n = _tmp2_;
	_tmp3_ = n;
	g_notification_set_body (_tmp3_, body);
	_tmp4_ = n;
	g_notification_set_priority (_tmp4_, G_NOTIFICATION_PRIORITY_NORMAL);
	_tmp5_ = n;
	dc_event_handler_set_open_chat_action (self, _tmp5_, acct_id, chat_id);
	_tmp6_ = self->priv->app;
	_tmp7_ = dc_event_handler_notification_id (acct_id, chat_id);
	_tmp8_ = _tmp7_;
	_tmp9_ = n;
	g_application_send_notification (_tmp6_, _tmp8_, _tmp9_);
	_g_free0 (_tmp8_);
	_g_object_unref0 (n);
}

void
dc_event_handler_clear_notifications_for_chat (DcEventHandler* self,
                                               gint acct_id,
                                               gint chat_id)
{
	gboolean _tmp0_ = FALSE;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	g_return_if_fail (self != NULL);
	if (acct_id <= 0) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = chat_id <= 0;
	}
	if (_tmp0_) {
		return;
	}
	_tmp1_ = dc_event_handler_notification_id (acct_id, chat_id);
	_tmp2_ = _tmp1_;
	dc_event_handler_withdraw_notification_id (self, _tmp2_);
	_g_free0 (_tmp2_);
	_tmp3_ = dc_event_handler_mention_notification_id (acct_id, chat_id);
	_tmp4_ = _tmp3_;
	dc_event_handler_withdraw_notification_id (self, _tmp4_);
	_g_free0 (_tmp4_);
	_tmp5_ = dc_event_handler_notification_id (acct_id, 0);
	_tmp6_ = _tmp5_;
	dc_event_handler_withdraw_notification_id (self, _tmp6_);
	_g_free0 (_tmp6_);
}

void
dc_event_handler_send_mention_notification (DcEventHandler* self,
                                            gint acct_id,
                                            gint chat_id,
                                            const gchar* title,
                                            const gchar* body)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GApplication* _tmp2_;
	GNotification* n = NULL;
	GNotification* _tmp3_;
	GNotification* _tmp4_;
	GNotification* _tmp5_;
	GNotification* _tmp6_;
	GApplication* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	GNotification* _tmp10_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (title != NULL);
	g_return_if_fail (body != NULL);
	_tmp2_ = self->priv->app;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = acct_id <= 0;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = chat_id <= 0;
	}
	if (_tmp0_) {
		return;
	}
	_tmp3_ = g_notification_new (title);
	n = _tmp3_;
	_tmp4_ = n;
	g_notification_set_body (_tmp4_, body);
	_tmp5_ = n;
	g_notification_set_priority (_tmp5_, G_NOTIFICATION_PRIORITY_HIGH);
	_tmp6_ = n;
	dc_event_handler_set_open_chat_action (self, _tmp6_, acct_id, chat_id);
	_tmp7_ = self->priv->app;
	_tmp8_ = dc_event_handler_mention_notification_id (acct_id, chat_id);
	_tmp9_ = _tmp8_;
	_tmp10_ = n;
	g_application_send_notification (_tmp7_, _tmp9_, _tmp10_);
	_g_free0 (_tmp9_);
	_g_object_unref0 (n);
}

static void
dc_event_handler_set_open_chat_action (DcEventHandler* self,
                                       GNotification* notification,
                                       gint acct_id,
                                       gint chat_id)
{
	GVariant* _tmp0_;
	GVariant* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (notification != NULL);
	if (!dc_event_handler_server_supports_actions (self)) {
		return;
	}
	_tmp0_ = g_variant_new ("(ii)", acct_id, chat_id, NULL);
	g_variant_ref_sink (_tmp0_);
	_tmp1_ = _tmp0_;
	g_notification_set_default_action_and_target_value (notification, "app.open-chat", _tmp1_);
	_g_variant_unref0 (_tmp1_);
}

static gboolean
dc_event_handler_server_supports_actions (DcEventHandler* self)
{
	gboolean supported = FALSE;
	gint _tmp10_ = 0;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (self->priv->notification_actions_supported >= 0) {
		result = self->priv->notification_actions_supported == 1;
		return result;
	}
	supported = TRUE;
	{
		DcDesktopNotificationServer* server = NULL;
		DcDesktopNotificationServer* _tmp0_;
		gchar** _tmp1_ = NULL;
		DcDesktopNotificationServer* _tmp2_;
		gint _tmp3_ = 0;
		gchar** _tmp4_;
		gint _tmp1__length1;
		gint __tmp1__size_;
		_tmp0_ = (DcDesktopNotificationServer*) g_initable_new (DC_TYPE_DESKTOP_NOTIFICATION_SERVER_PROXY, NULL, &_inner_error0_, "g-flags", 0, "g-name", "org.freedesktop.Notifications", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/freedesktop/Notifications", "g-interface-name", "org.freedesktop.Notifications", NULL);
		server = (DcDesktopNotificationServer*) _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		supported = FALSE;
		_tmp2_ = server;
		_tmp4_ = dc_desktop_notification_server_get_capabilities (_tmp2_, &_tmp3_, &_inner_error0_);
		_tmp1_ = _tmp4_;
		_tmp1__length1 = _tmp3_;
		__tmp1__size_ = _tmp1__length1;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (server);
			goto __catch0_g_error;
		}
		{
			gchar** capability_collection = NULL;
			gint capability_collection_length1 = 0;
			gint _capability_collection_size_ = 0;
			gint capability_it = 0;
			capability_collection = _tmp1_;
			capability_collection_length1 = _tmp1__length1;
			for (capability_it = 0; capability_it < capability_collection_length1; capability_it = capability_it + 1) {
				gchar* _tmp5_;
				gchar* capability = NULL;
				_tmp5_ = g_strdup (capability_collection[capability_it]);
				capability = _tmp5_;
				{
					const gchar* _tmp6_;
					_tmp6_ = capability;
					if (g_strcmp0 (_tmp6_, "actions") == 0) {
						supported = TRUE;
						_g_free0 (capability);
						break;
					}
					_g_free0 (capability);
				}
			}
		}
		_tmp1_ = (_vala_array_free (_tmp1_, _tmp1__length1, (GDestroyNotify) g_free), NULL);
		_g_object_unref0 (server);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp7_;
		const gchar* _tmp8_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp7_ = e;
		_tmp8_ = _tmp7_->message;
		g_debug ("event_handler.vala:299: Could not query notification capabilities: %s", _tmp8_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp9_ = FALSE;
		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 _tmp9_;
	}
	if (supported) {
		_tmp10_ = 1;
	} else {
		_tmp10_ = 0;
	}
	self->priv->notification_actions_supported = _tmp10_;
	result = supported;
	return result;
}

static gchar*
dc_event_handler_mention_notification_id (gint acct_id,
                                          gint chat_id)
{
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = g_strdup_printf ("dc-mention-%d-%d", acct_id, chat_id);
	result = _tmp0_;
	return result;
}

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

void
dc_event_handler_reconcile_desktop_notifications (DcEventHandler* self,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_)
{
	DcEventHandlerReconcileDesktopNotificationsData* _data_;
	DcEventHandler* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcEventHandlerReconcileDesktopNotificationsData);
	_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_reconcile_desktop_notifications_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	dc_event_handler_reconcile_desktop_notifications_co (_data_);
}

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

static void
dc_event_handler_reconcile_desktop_notifications_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_)
{
	DcEventHandlerReconcileDesktopNotificationsData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_event_handler_reconcile_desktop_notifications_co (_data_);
}

static void
_vala_JsonNode_free (JsonNode* self)
{
	g_boxed_free (json_node_get_type (), self);
}

static gpointer
_json_array_ref0 (gpointer self)
{
	return self ? json_array_ref (self) : NULL;
}

static gboolean
dc_event_handler_reconcile_desktop_notifications_co (DcEventHandlerReconcileDesktopNotificationsData* _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:
	_data_->_tmp1_ = _data_->self->priv->app;
	if (_data_->_tmp1_ == NULL) {
		_data_->_tmp0_ = TRUE;
	} else {
		_data_->_tmp2_ = _data_->self->priv->rpc;
		_data_->_tmp3_ = dc_rpc_client_get_is_connected (_data_->_tmp2_);
		_data_->_tmp4_ = _data_->_tmp3_;
		_data_->_tmp0_ = !_data_->_tmp4_;
	}
	if (_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_->_tmp5_ = _data_->self->priv->rpc;
		_data_->_state_ = 1;
		dc_rpc_client_get_all_accounts (_data_->_tmp5_, dc_event_handler_reconcile_desktop_notifications_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp6_ = dc_rpc_client_get_all_accounts_finish (_data_->_tmp5_, _data_->_res_, &_data_->_inner_error0_);
		_data_->accounts_node = _data_->_tmp6_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp7_ = _data_->accounts_node;
		if (_data_->_tmp7_ == NULL) {
			__vala_JsonNode_free0 (_data_->accounts_node);
			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_->_tmp8_ = _data_->accounts_node;
		_data_->_tmp9_ = json_node_get_array (_data_->_tmp8_);
		_data_->_tmp10_ = _json_array_ref0 (_data_->_tmp9_);
		_data_->accounts = _data_->_tmp10_;
		{
			_data_->i = (guint) 0;
			{
				_data_->_tmp11_ = TRUE;
				while (TRUE) {
					if (!_data_->_tmp11_) {
						_data_->_tmp12_ = _data_->i;
						_data_->i = _data_->_tmp12_ + 1;
					}
					_data_->_tmp11_ = FALSE;
					_data_->_tmp13_ = _data_->accounts;
					if (!(_data_->i < json_array_get_length (_data_->_tmp13_))) {
						break;
					}
					_data_->_tmp14_ = _data_->accounts;
					_data_->_tmp15_ = json_array_get_object_element (_data_->_tmp14_, _data_->i);
					_data_->acct_id = (gint) json_object_get_int_member (_data_->_tmp15_, "id");
					if (_data_->acct_id <= 0) {
						continue;
					}
					{
						_data_->_state_ = 2;
						dc_event_handler_reconcile_account_notifications (_data_->self, _data_->acct_id, dc_event_handler_reconcile_desktop_notifications_ready, _data_);
						return FALSE;
						_state_2:
						dc_event_handler_reconcile_account_notifications_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
						if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
							goto __catch1_g_error;
						}
					}
					goto __finally1;
					__catch1_g_error:
					{
						g_clear_error (&_data_->_inner_error0_);
					}
					__finally1:
					if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
						_json_array_unref0 (_data_->accounts);
						__vala_JsonNode_free0 (_data_->accounts_node);
						goto __catch0_g_error;
					}
				}
			}
		}
		_json_array_unref0 (_data_->accounts);
		__vala_JsonNode_free0 (_data_->accounts_node);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp16_ = _data_->e;
		_data_->_tmp17_ = _data_->_tmp16_->message;
		g_warning ("event_handler.vala:323: Failed to reconcile desktop notifications: %s", _data_->_tmp17_);
		_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 gchar*
dc_event_handler_notification_id (gint acct_id,
                                  gint chat_id)
{
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = g_strdup_printf ("dc-chat-%d-%d", acct_id, chat_id);
	result = _tmp0_;
	return result;
}

static gchar*
dc_event_handler_legacy_notification_id (gint acct_id,
                                         gint msg_id)
{
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = g_strdup_printf ("dc-msg-%d-%d", acct_id, msg_id);
	result = _tmp0_;
	return result;
}

static void
dc_event_handler_withdraw_notification_id (DcEventHandler* self,
                                           const gchar* id)
{
	gboolean _tmp0_ = FALSE;
	GApplication* _tmp1_;
	GApplication* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (id != NULL);
	_tmp1_ = self->priv->app;
	if (_tmp1_ == NULL) {
		_tmp0_ = TRUE;
	} else {
		gint _tmp2_;
		gint _tmp3_;
		_tmp2_ = strlen (id);
		_tmp3_ = _tmp2_;
		_tmp0_ = _tmp3_ == 0;
	}
	if (_tmp0_) {
		return;
	}
	_tmp4_ = self->priv->app;
	g_application_withdraw_notification (_tmp4_, id);
}

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

static void
dc_event_handler_reconcile_account_notifications (DcEventHandler* self,
                                                  gint acct_id,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_)
{
	DcEventHandlerReconcileAccountNotificationsData* _data_;
	DcEventHandler* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcEventHandlerReconcileAccountNotificationsData);
	_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_reconcile_account_notifications_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->acct_id = acct_id;
	dc_event_handler_reconcile_account_notifications_co (_data_);
}

static void
dc_event_handler_reconcile_account_notifications_finish (DcEventHandler* self,
                                                         GAsyncResult* _res_,
                                                         GError** error)
{
	DcEventHandlerReconcileAccountNotificationsData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
dc_event_handler_reconcile_account_notifications_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_)
{
	DcEventHandlerReconcileAccountNotificationsData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_event_handler_reconcile_account_notifications_co (_data_);
}

static gboolean
dc_event_handler_reconcile_account_notifications_co (DcEventHandlerReconcileAccountNotificationsData* _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:
	_data_->_tmp0_ = dc_event_handler_notification_id (_data_->acct_id, 0);
	_data_->_tmp1_ = _data_->_tmp0_;
	dc_event_handler_withdraw_notification_id (_data_->self, _data_->_tmp1_);
	_g_free0 (_data_->_tmp1_);
	_data_->_tmp2_ = _data_->self->priv->rpc;
	_data_->_state_ = 1;
	dc_rpc_client_get_chatlist_entries_for (_data_->_tmp2_, _data_->acct_id, NULL, -1, dc_event_handler_reconcile_account_notifications_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp3_ = dc_rpc_client_get_chatlist_entries_for_finish (_data_->_tmp2_, _data_->_res_, &_data_->_inner_error0_);
	_data_->entries = _data_->_tmp3_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp4_ = _data_->entries;
	if (_data_->_tmp4_ == NULL) {
		_json_array_unref0 (_data_->entries);
		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_->i = (guint) 0;
		{
			_data_->_tmp5_ = TRUE;
			while (TRUE) {
				if (!_data_->_tmp5_) {
					_data_->_tmp6_ = _data_->i;
					_data_->i = _data_->_tmp6_ + 1;
				}
				_data_->_tmp5_ = FALSE;
				_data_->_tmp7_ = _data_->entries;
				if (!(_data_->i < json_array_get_length (_data_->_tmp7_))) {
					break;
				}
				_data_->_tmp8_ = _data_->entries;
				_data_->chat_id = (gint) json_array_get_int_element (_data_->_tmp8_, _data_->i);
				dc_event_handler_clear_notifications_for_chat (_data_->self, _data_->acct_id, _data_->chat_id);
				_data_->_state_ = 2;
				dc_event_handler_withdraw_legacy_notifications_for_chat (_data_->self, _data_->acct_id, _data_->chat_id, dc_event_handler_reconcile_account_notifications_ready, _data_);
				return FALSE;
				_state_2:
				dc_event_handler_withdraw_legacy_notifications_for_chat_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
					_json_array_unref0 (_data_->entries);
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
			}
		}
	}
	_json_array_unref0 (_data_->entries);
	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_withdraw_legacy_notifications_for_chat_data_free (gpointer _data)
{
	DcEventHandlerWithdrawLegacyNotificationsForChatData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (DcEventHandlerWithdrawLegacyNotificationsForChatData, _data_);
}

static void
dc_event_handler_withdraw_legacy_notifications_for_chat (DcEventHandler* self,
                                                         gint acct_id,
                                                         gint chat_id,
                                                         GAsyncReadyCallback _callback_,
                                                         gpointer _user_data_)
{
	DcEventHandlerWithdrawLegacyNotificationsForChatData* _data_;
	DcEventHandler* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcEventHandlerWithdrawLegacyNotificationsForChatData);
	_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_withdraw_legacy_notifications_for_chat_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->acct_id = acct_id;
	_data_->chat_id = chat_id;
	dc_event_handler_withdraw_legacy_notifications_for_chat_co (_data_);
}

static void
dc_event_handler_withdraw_legacy_notifications_for_chat_finish (DcEventHandler* self,
                                                                GAsyncResult* _res_,
                                                                GError** error)
{
	DcEventHandlerWithdrawLegacyNotificationsForChatData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
dc_event_handler_withdraw_legacy_notifications_for_chat_ready (GObject* source_object,
                                                               GAsyncResult* _res_,
                                                               gpointer _user_data_)
{
	DcEventHandlerWithdrawLegacyNotificationsForChatData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_event_handler_withdraw_legacy_notifications_for_chat_co (_data_);
}

static gboolean
dc_event_handler_withdraw_legacy_notifications_for_chat_co (DcEventHandlerWithdrawLegacyNotificationsForChatData* _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->rpc;
	_data_->_state_ = 1;
	dc_rpc_client_get_message_ids_for (_data_->_tmp0_, _data_->acct_id, _data_->chat_id, FALSE, dc_event_handler_withdraw_legacy_notifications_for_chat_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp1_ = dc_rpc_client_get_message_ids_for_finish (_data_->_tmp0_, _data_->_res_, &_data_->_inner_error0_);
	_data_->msg_ids = _data_->_tmp1_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (_data_->msg_ids == NULL) {
		_json_array_unref0 (_data_->msg_ids);
		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_->i = (guint) 0;
		{
			_data_->_tmp2_ = TRUE;
			while (TRUE) {
				if (!_data_->_tmp2_) {
					_data_->_tmp3_ = _data_->i;
					_data_->i = _data_->_tmp3_ + 1;
				}
				_data_->_tmp2_ = FALSE;
				if (!(_data_->i < json_array_get_length (_data_->msg_ids))) {
					break;
				}
				_data_->msg_id = (gint) json_array_get_int_element (_data_->msg_ids, _data_->i);
				if (_data_->msg_id <= 0) {
					continue;
				}
				_data_->_tmp4_ = dc_event_handler_legacy_notification_id (_data_->acct_id, _data_->msg_id);
				_data_->_tmp5_ = _data_->_tmp4_;
				dc_event_handler_withdraw_notification_id (_data_->self, _data_->_tmp5_);
				_g_free0 (_data_->_tmp5_);
			}
		}
	}
	_json_array_unref0 (_data_->msg_ids);
	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_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_INT_INT_STRING) (gpointer data1, gint arg_1, gint arg_2, gint arg_3, gint arg_4, const char* arg_5, gpointer data2);
	register GMarshalFunc_VOID__INT_INT_INT_INT_STRING callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 6);
	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_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_int (param_values + 3), g_value_get_int (param_values + 4), g_value_get_string (param_values + 5), 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_INCOMING_REACTION_RECEIVED_SIGNAL] = g_signal_new ("incoming-reaction-received", DC_TYPE_EVENT_HANDLER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT_INT_INT_INT_STRING, G_TYPE_NONE, 5, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING);
	dc_event_handler_signals[DC_EVENT_HANDLER_CHAT_MESSAGES_CHANGED_SIGNAL] = g_signal_new ("chat-messages-changed", 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_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_CONTACTS_CHANGED_SIGNAL] = g_signal_new ("contacts-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->notification_actions_supported = -1;
	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 void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

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

