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

#include <adwaita.h>
#include <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <json-glib/json-glib.h>

#define DC_RPC_CLIENT_GCL_NO_SPECIALS 0x02
#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_CONTACT_PICKER_DIALOG (dc_contact_picker_dialog_get_type ())
#define DC_CONTACT_PICKER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_CONTACT_PICKER_DIALOG, DcContactPickerDialog))
#define DC_CONTACT_PICKER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_CONTACT_PICKER_DIALOG, DcContactPickerDialogClass))
#define DC_IS_CONTACT_PICKER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_CONTACT_PICKER_DIALOG))
#define DC_IS_CONTACT_PICKER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_CONTACT_PICKER_DIALOG))
#define DC_CONTACT_PICKER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_CONTACT_PICKER_DIALOG, DcContactPickerDialogClass))

typedef struct _DcContactPickerDialog DcContactPickerDialog;
typedef struct _DcContactPickerDialogClass DcContactPickerDialogClass;
typedef struct _DcContactPickerDialogPrivate DcContactPickerDialogPrivate;

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

#define DC_TYPE_CONTACT (dc_contact_get_type ())
#define DC_CONTACT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_CONTACT, DcContact))
#define DC_CONTACT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_CONTACT, DcContactClass))
#define DC_IS_CONTACT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_CONTACT))
#define DC_IS_CONTACT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_CONTACT))
#define DC_CONTACT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_CONTACT, DcContactClass))

typedef struct _DcContact DcContact;
typedef struct _DcContactClass DcContactClass;

#define DC_TYPE_CHAT_ENTRY (dc_chat_entry_get_type ())
#define DC_CHAT_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_CHAT_ENTRY, DcChatEntry))
#define DC_CHAT_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_CHAT_ENTRY, DcChatEntryClass))
#define DC_IS_CHAT_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_CHAT_ENTRY))
#define DC_IS_CHAT_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_CHAT_ENTRY))
#define DC_CHAT_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_CHAT_ENTRY, DcChatEntryClass))

typedef struct _DcChatEntry DcChatEntry;
typedef struct _DcChatEntryClass DcChatEntryClass;
enum  {
	DC_CONTACT_PICKER_DIALOG_0_PROPERTY,
	DC_CONTACT_PICKER_DIALOG_SELECTED_ACCOUNT_ID_PROPERTY,
	DC_CONTACT_PICKER_DIALOG_NUM_PROPERTIES
};
static GParamSpec* dc_contact_picker_dialog_properties[DC_CONTACT_PICKER_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_ptr_array_unref0(var) ((var == NULL) ? NULL : (var = (g_ptr_array_unref (var), NULL)))
#define _json_object_unref0(var) ((var == NULL) ? NULL : (var = (json_object_unref (var), NULL)))
#define _json_array_unref0(var) ((var == NULL) ? NULL : (var = (json_array_unref (var), NULL)))
#define __vala_JsonNode_free0(var) ((var == NULL) ? NULL : (var = (_vala_JsonNode_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _DcContactPickerDialogLoadAccountsData DcContactPickerDialogLoadAccountsData;
typedef struct _DcContactPickerDialogLoadChatsForAccountData DcContactPickerDialogLoadChatsForAccountData;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _DcContactPickerDialogLoadContactsData DcContactPickerDialogLoadContactsData;
enum  {
	DC_CONTACT_PICKER_DIALOG_CONTACT_PICKED_SIGNAL,
	DC_CONTACT_PICKER_DIALOG_CHAT_PICKED_SIGNAL,
	DC_CONTACT_PICKER_DIALOG_NUM_SIGNALS
};
static guint dc_contact_picker_dialog_signals[DC_CONTACT_PICKER_DIALOG_NUM_SIGNALS] = {0};

struct _DcContactPickerDialog {
	AdwDialog parent_instance;
	DcContactPickerDialogPrivate * priv;
};

struct _DcContactPickerDialogClass {
	AdwDialogClass parent_class;
};

struct _DcContactPickerDialogPrivate {
	gint _selected_account_id;
	DcRpcClient* rpc;
	GListStore* chat_store;
	GtkSearchEntry* search_entry;
	GtkListBox* chat_listbox;
	GtkListBox* contact_listbox;
	GtkLabel* chats_header;
	GtkLabel* contacts_header;
	GtkButton* use_email_btn;
	GPtrArray* all_contacts;
	gboolean account_selector_enabled;
	GtkDropDown* account_dropdown;
	gint* account_ids;
	gint account_ids_length1;
	gint _account_ids_size_;
	GPtrArray* loaded_chats;
	guint chat_load_gen;
	guint contact_load_gen;
};

struct _DcContactPickerDialogLoadAccountsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcContactPickerDialog* self;
	GtkDropDown* _tmp0_;
	GtkStringList* model;
	GtkDropDown* _tmp1_;
	GListModel* _tmp2_;
	GListModel* _tmp3_;
	GtkStringList* _tmp4_;
	gint* ids;
	gint* _tmp5_;
	gint ids_length1;
	gint _ids_size_;
	gint selected_idx;
	JsonNode* accounts_node;
	DcRpcClient* _tmp6_;
	JsonNode* _tmp7_;
	gboolean _tmp8_;
	JsonNode* _tmp9_;
	JsonNode* _tmp10_;
	JsonArray* accounts;
	JsonNode* _tmp11_;
	JsonArray* _tmp12_;
	JsonArray* _tmp13_;
	guint i;
	gboolean _tmp14_;
	guint _tmp15_;
	JsonArray* _tmp16_;
	JsonObject* acct;
	JsonArray* _tmp17_;
	JsonObject* _tmp18_;
	JsonObject* _tmp19_;
	JsonObject* _tmp20_;
	gint id;
	JsonObject* _tmp21_;
	gboolean _tmp22_;
	gboolean _tmp23_;
	DcRpcClient* _tmp24_;
	gchar* name;
	DcRpcClient* _tmp25_;
	gchar* _tmp26_;
	gchar* addr;
	DcRpcClient* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_;
	gboolean _tmp30_;
	const gchar* _tmp31_;
	const gchar* _tmp32_;
	gint _tmp33_;
	gint _tmp34_;
	const gchar* _tmp35_;
	gchar* _tmp36_;
	gchar* _tmp37_;
	const gchar* _tmp38_;
	gchar* _tmp39_;
	gchar* _tmp40_;
	gchar* _tmp41_;
	gchar* label;
	gchar* _tmp42_;
	gboolean _tmp43_;
	gboolean _tmp44_;
	gboolean _tmp45_;
	const gchar* _tmp46_;
	const gchar* _tmp47_;
	gint _tmp48_;
	gint _tmp49_;
	const gchar* _tmp50_;
	const gchar* _tmp51_;
	gint _tmp52_;
	gint _tmp53_;
	const gchar* _tmp54_;
	const gchar* _tmp55_;
	gchar* _tmp56_;
	gint _tmp57_;
	gint* _tmp58_;
	gint _tmp58__length1;
	GtkStringList* _tmp59_;
	const gchar* _tmp60_;
	gint* _tmp61_;
	gint _tmp61__length1;
	gint* _tmp62_;
	gint _tmp62__length1;
	gint* _tmp63_;
	gint _tmp63__length1;
	GtkDropDown* _tmp64_;
	GError* _inner_error0_;
};

struct _DcContactPickerDialogLoadChatsForAccountData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcContactPickerDialog* self;
	gint acct_id;
	guint gen;
	guint _tmp0_;
	GPtrArray* chats;
	GPtrArray* _tmp1_;
	JsonArray* entries;
	DcRpcClient* _tmp2_;
	JsonArray* _tmp3_;
	JsonArray* _tmp4_;
	JsonObject* items;
	DcRpcClient* _tmp5_;
	JsonArray* _tmp6_;
	JsonObject* _tmp7_;
	guint i;
	gboolean _tmp8_;
	guint _tmp9_;
	JsonArray* _tmp10_;
	gint chat_id;
	JsonArray* _tmp11_;
	gchar* id_str;
	gchar* _tmp12_;
	gboolean _tmp13_;
	JsonObject* _tmp14_;
	JsonObject* _tmp15_;
	const gchar* _tmp16_;
	JsonObject* item;
	JsonObject* _tmp17_;
	const gchar* _tmp18_;
	JsonObject* _tmp19_;
	JsonObject* _tmp20_;
	GPtrArray* _tmp21_;
	JsonObject* _tmp22_;
	DcChatEntry* _tmp23_;
	GPtrArray* _tmp24_;
	GPtrArray* _tmp25_;
	GtkSearchEntry* _tmp26_;
	const gchar* _tmp27_;
	const gchar* _tmp28_;
	gchar* _tmp29_;
	gchar* _tmp30_;
	GError* _inner_error0_;
};

struct _DcContactPickerDialogLoadContactsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcContactPickerDialog* self;
	guint gen;
	guint _tmp0_;
	gint acct_id;
	gint _tmp1_;
	GPtrArray* collected;
	GPtrArray* _tmp2_;
	JsonArray* ids;
	DcRpcClient* _tmp3_;
	JsonArray* _tmp4_;
	JsonArray* _tmp5_;
	guint i;
	gboolean _tmp6_;
	guint _tmp7_;
	JsonArray* _tmp8_;
	gint cid;
	JsonArray* _tmp9_;
	JsonObject* obj;
	DcRpcClient* _tmp10_;
	JsonObject* _tmp11_;
	JsonObject* _tmp12_;
	DcContact* ci;
	JsonObject* _tmp13_;
	DcContact* _tmp14_;
	DcContact* _tmp15_;
	const gchar* _tmp16_;
	const gchar* _tmp17_;
	gint _tmp18_;
	gint _tmp19_;
	GPtrArray* _tmp20_;
	DcContact* _tmp21_;
	DcContact* _tmp22_;
	GPtrArray* _tmp23_;
	GPtrArray* _tmp24_;
	GtkSearchEntry* _tmp25_;
	const gchar* _tmp26_;
	const gchar* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_;
	GError* e;
	GtkLabel* lbl;
	GError* _tmp30_;
	const gchar* _tmp31_;
	gchar* _tmp32_;
	gchar* _tmp33_;
	GtkLabel* _tmp34_;
	GtkLabel* _tmp35_;
	GtkLabel* _tmp36_;
	GtkLabel* _tmp37_;
	GtkListBox* _tmp38_;
	GtkLabel* _tmp39_;
	GError* _inner_error0_;
};

static gint DcContactPickerDialog_private_offset;
static gpointer dc_contact_picker_dialog_parent_class = NULL;

VALA_EXTERN GType dc_contact_picker_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcContactPickerDialog, 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 GType dc_contact_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcContact, g_object_unref)
VALA_EXTERN GType dc_chat_entry_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcChatEntry, g_object_unref)
static void _g_object_unref0_ (gpointer var);
VALA_EXTERN DcContactPickerDialog* dc_contact_picker_dialog_new (DcRpcClient* rpc,
                                                     GListStore* chat_store,
                                                     const gchar* title,
                                                     gboolean enable_account_selector);
VALA_EXTERN DcContactPickerDialog* dc_contact_picker_dialog_construct (GType object_type,
                                                           DcRpcClient* rpc,
                                                           GListStore* chat_store,
                                                           const gchar* title,
                                                           gboolean enable_account_selector);
VALA_EXTERN gint dc_rpc_client_get_account_id (DcRpcClient* self);
static void dc_contact_picker_dialog_set_selected_account_id (DcContactPickerDialog* self,
                                                       gint value);
static void dc_contact_picker_dialog_on_account_changed (DcContactPickerDialog* self);
static void _dc_contact_picker_dialog_on_account_changed_g_object_notify (GObject* _sender,
                                                                   GParamSpec* pspec,
                                                                   gpointer self);
static void dc_contact_picker_dialog_on_search_changed (DcContactPickerDialog* self);
static void _dc_contact_picker_dialog_on_search_changed_gtk_search_entry_search_changed (GtkSearchEntry* _sender,
                                                                                  gpointer self);
static void dc_contact_picker_dialog_on_activate_search (DcContactPickerDialog* self);
static void _dc_contact_picker_dialog_on_activate_search_gtk_search_entry_activate (GtkSearchEntry* _sender,
                                                                             gpointer self);
static void dc_contact_picker_dialog_on_use_email (DcContactPickerDialog* self);
static void _dc_contact_picker_dialog_on_use_email_gtk_button_clicked (GtkButton* _sender,
                                                                gpointer self);
static void dc_contact_picker_dialog_on_chat_row_activated (DcContactPickerDialog* self,
                                                     GtkListBoxRow* row);
static void _dc_contact_picker_dialog_on_chat_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                                 GtkListBoxRow* row,
                                                                                 gpointer self);
static void dc_contact_picker_dialog_on_contact_row_activated (DcContactPickerDialog* self,
                                                        GtkListBoxRow* row);
static void _dc_contact_picker_dialog_on_contact_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                                    GtkListBoxRow* row,
                                                                                    gpointer self);
VALA_EXTERN void dc_install_escape_close (AdwDialog* dialog);
static void dc_contact_picker_dialog_load_contacts (DcContactPickerDialog* self,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
static void dc_contact_picker_dialog_load_contacts_finish (DcContactPickerDialog* self,
                                                    GAsyncResult* _res_);
static void dc_contact_picker_dialog_load_accounts (DcContactPickerDialog* self,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
static void dc_contact_picker_dialog_load_accounts_finish (DcContactPickerDialog* self,
                                                    GAsyncResult* _res_);
static void dc_contact_picker_dialog_load_chats_for_account (DcContactPickerDialog* self,
                                                      gint acct_id,
                                                      GAsyncReadyCallback _callback_,
                                                      gpointer _user_data_);
static void dc_contact_picker_dialog_load_chats_for_account_finish (DcContactPickerDialog* self,
                                                             GAsyncResult* _res_);
VALA_EXTERN gint dc_contact_picker_dialog_get_selected_account_id (DcContactPickerDialog* self);
static void dc_contact_picker_dialog_rebuild_chat_list (DcContactPickerDialog* self,
                                                 const gchar* query);
static void dc_contact_picker_dialog_load_accounts_data_free (gpointer _data);
static gboolean dc_contact_picker_dialog_load_accounts_co (DcContactPickerDialogLoadAccountsData* _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_contact_picker_dialog_load_accounts_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_);
VALA_EXTERN void dc_rpc_client_is_configured (DcRpcClient* self,
                                  gint acct_id,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_);
VALA_EXTERN gboolean dc_rpc_client_is_configured_finish (DcRpcClient* self,
                                             GAsyncResult* _res_,
                                             GError** error);
static void _vala_JsonNode_free (JsonNode* self);
VALA_EXTERN void dc_rpc_client_get_config (DcRpcClient* self,
                               const gchar* key,
                               gint acct_id,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_);
VALA_EXTERN gchar* dc_rpc_client_get_config_finish (DcRpcClient* self,
                                        GAsyncResult* _res_,
                                        GError** error);
static void _vala_array_add59 (gint* * array,
                        gint* length,
                        gint* size,
                        gint value);
static gint* _vala_array_dup25 (gint* self,
                         gssize length);
static void dc_contact_picker_dialog_load_chats_for_account_data_free (gpointer _data);
static gboolean dc_contact_picker_dialog_load_chats_for_account_co (DcContactPickerDialogLoadChatsForAccountData* _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_contact_picker_dialog_load_chats_for_account_ready (GObject* source_object,
                                                            GAsyncResult* _res_,
                                                            gpointer _user_data_);
VALA_EXTERN void dc_rpc_client_get_chatlist_items_by_entries_for (DcRpcClient* self,
                                                      gint acct_id,
                                                      JsonArray* entries,
                                                      GAsyncReadyCallback _callback_,
                                                      gpointer _user_data_);
VALA_EXTERN JsonObject* dc_rpc_client_get_chatlist_items_by_entries_for_finish (DcRpcClient* self,
                                                                    GAsyncResult* _res_,
                                                                    GError** error);
VALA_EXTERN DcChatEntry* dc_rpc_parsers_parse_chat_item (gint chat_id,
                                             JsonObject* obj);
static void dc_contact_picker_dialog_load_contacts_data_free (gpointer _data);
static gboolean dc_contact_picker_dialog_load_contacts_co (DcContactPickerDialogLoadContactsData* _data_);
VALA_EXTERN void dc_rpc_client_get_contact_ids_for (DcRpcClient* self,
                                        gint acct_id,
                                        const gchar* query,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_);
VALA_EXTERN JsonArray* dc_rpc_client_get_contact_ids_for_finish (DcRpcClient* self,
                                                     GAsyncResult* _res_,
                                                     GError** error);
static void dc_contact_picker_dialog_load_contacts_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_);
VALA_EXTERN void dc_rpc_client_get_contact_for (DcRpcClient* self,
                                    gint acct_id,
                                    gint contact_id,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_);
VALA_EXTERN JsonObject* dc_rpc_client_get_contact_for_finish (DcRpcClient* self,
                                                  GAsyncResult* _res_,
                                                  GError** error);
VALA_EXTERN DcContact* dc_rpc_parsers_parse_contact (gint contact_id,
                                         JsonObject* obj);
VALA_EXTERN const gchar* dc_contact_get_address (DcContact* self);
static void dc_contact_picker_dialog_rebuild_contact_list (DcContactPickerDialog* self,
                                                    const gchar* query);
VALA_EXTERN void dc_clear_listbox (GtkListBox* lb);
VALA_EXTERN const gchar* dc_contact_get_display_name (DcContact* self);
static AdwActionRow* dc_contact_picker_dialog_build_contact_row (DcContactPickerDialog* self,
                                                          DcContact* ci);
VALA_EXTERN const gchar* dc_chat_entry_get_name (DcChatEntry* self);
VALA_EXTERN AdwActionRow* dc_chat_pick_row (DcChatEntry* chat);
VALA_EXTERN AdwActionRow* dc_contact_row (DcContact* c,
                              gboolean activatable,
                              gboolean show_presence);
VALA_EXTERN gint dc_contact_get_id (DcContact* self);
static void g_cclosure_user_marshal_VOID__INT_STRING (GClosure * closure,
                                               GValue * return_value,
                                               guint n_param_values,
                                               const GValue * param_values,
                                               gpointer invocation_hint,
                                               gpointer marshal_data);
static void dc_contact_picker_dialog_finalize (GObject * obj);
static GType dc_contact_picker_dialog_get_type_once (void);
static void _vala_dc_contact_picker_dialog_get_property (GObject * object,
                                                  guint property_id,
                                                  GValue * value,
                                                  GParamSpec * pspec);
static void _vala_dc_contact_picker_dialog_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 gssize _vala_array_length (gpointer array);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dc_contact_picker_dialog_get_instance_private (DcContactPickerDialog* self)
{
	return G_STRUCT_MEMBER_P (self, DcContactPickerDialog_private_offset);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

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

static void
_dc_contact_picker_dialog_on_account_changed_g_object_notify (GObject* _sender,
                                                              GParamSpec* pspec,
                                                              gpointer self)
{
	dc_contact_picker_dialog_on_account_changed ((DcContactPickerDialog*) self);
}

static void
_dc_contact_picker_dialog_on_search_changed_gtk_search_entry_search_changed (GtkSearchEntry* _sender,
                                                                             gpointer self)
{
	dc_contact_picker_dialog_on_search_changed ((DcContactPickerDialog*) self);
}

static void
_dc_contact_picker_dialog_on_activate_search_gtk_search_entry_activate (GtkSearchEntry* _sender,
                                                                        gpointer self)
{
	dc_contact_picker_dialog_on_activate_search ((DcContactPickerDialog*) self);
}

static void
_dc_contact_picker_dialog_on_use_email_gtk_button_clicked (GtkButton* _sender,
                                                           gpointer self)
{
	dc_contact_picker_dialog_on_use_email ((DcContactPickerDialog*) self);
}

static void
_dc_contact_picker_dialog_on_chat_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                            GtkListBoxRow* row,
                                                                            gpointer self)
{
	dc_contact_picker_dialog_on_chat_row_activated ((DcContactPickerDialog*) self, row);
}

static void
_dc_contact_picker_dialog_on_contact_row_activated_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                               GtkListBoxRow* row,
                                                                               gpointer self)
{
	dc_contact_picker_dialog_on_contact_row_activated ((DcContactPickerDialog*) self, row);
}

DcContactPickerDialog*
dc_contact_picker_dialog_construct (GType object_type,
                                    DcRpcClient* rpc,
                                    GListStore* chat_store,
                                    const gchar* title,
                                    gboolean enable_account_selector)
{
	DcContactPickerDialog * self = NULL;
	DcRpcClient* _tmp0_;
	GListStore* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	const gchar* _tmp4_ = NULL;
	GtkBox* box = NULL;
	GtkBox* _tmp6_;
	AdwHeaderBar* header = NULL;
	AdwHeaderBar* _tmp7_;
	AdwHeaderBar* _tmp8_;
	GtkBox* _tmp9_;
	AdwHeaderBar* _tmp10_;
	GtkBox* content = NULL;
	GtkBox* _tmp11_;
	GtkBox* _tmp12_;
	GtkBox* _tmp13_;
	GtkBox* _tmp14_;
	GtkBox* _tmp15_;
	GtkSearchEntry* _tmp23_;
	const gchar* _tmp24_ = NULL;
	GtkSearchEntry* _tmp25_;
	GtkSearchEntry* _tmp26_;
	GtkSearchEntry* _tmp27_;
	GtkSearchEntry* _tmp28_;
	GtkBox* _tmp29_;
	GtkSearchEntry* _tmp30_;
	GtkButton* _tmp31_;
	GtkButton* _tmp32_;
	GtkButton* _tmp33_;
	GtkButton* _tmp34_;
	GtkBox* _tmp35_;
	GtkButton* _tmp36_;
	GtkScrolledWindow* scroll = NULL;
	GtkScrolledWindow* _tmp37_;
	GtkScrolledWindow* _tmp38_;
	GtkScrolledWindow* _tmp39_;
	GtkBox* list_box = NULL;
	GtkBox* _tmp40_;
	GtkLabel* _tmp41_;
	GtkLabel* _tmp42_;
	GtkLabel* _tmp43_;
	GtkLabel* _tmp44_;
	GtkLabel* _tmp45_;
	GtkBox* _tmp46_;
	GtkLabel* _tmp47_;
	GtkListBox* _tmp48_;
	GtkListBox* _tmp49_;
	GtkListBox* _tmp50_;
	GtkListBox* _tmp51_;
	GtkListBox* _tmp52_;
	GtkBox* _tmp53_;
	GtkListBox* _tmp54_;
	GtkLabel* _tmp55_;
	GtkLabel* _tmp56_;
	GtkLabel* _tmp57_;
	GtkLabel* _tmp58_;
	GtkLabel* _tmp59_;
	GtkBox* _tmp60_;
	GtkLabel* _tmp61_;
	GtkListBox* _tmp62_;
	GtkListBox* _tmp63_;
	GtkListBox* _tmp64_;
	GtkListBox* _tmp65_;
	GtkBox* _tmp66_;
	GtkListBox* _tmp67_;
	GtkScrolledWindow* _tmp68_;
	GtkBox* _tmp69_;
	GtkBox* _tmp70_;
	GtkScrolledWindow* _tmp71_;
	GtkBox* _tmp72_;
	GtkBox* _tmp73_;
	GtkBox* _tmp74_;
	g_return_val_if_fail (rpc != NULL, NULL);
	self = (DcContactPickerDialog*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (rpc);
	_g_object_unref0 (self->priv->rpc);
	self->priv->rpc = _tmp0_;
	_tmp1_ = _g_object_ref0 (chat_store);
	_g_object_unref0 (self->priv->chat_store);
	self->priv->chat_store = _tmp1_;
	self->priv->account_selector_enabled = enable_account_selector;
	_tmp2_ = dc_rpc_client_get_account_id (rpc);
	_tmp3_ = _tmp2_;
	dc_contact_picker_dialog_set_selected_account_id (self, _tmp3_);
	_tmp4_ = title;
	if (_tmp4_ == NULL) {
		const gchar* _tmp5_ = NULL;
		if (chat_store != NULL) {
			_tmp5_ = "Select Destination";
		} else {
			_tmp5_ = "Select Contact";
		}
		_tmp4_ = _tmp5_;
	}
	adw_dialog_set_title ((AdwDialog*) self, _tmp4_);
	adw_dialog_set_content_width ((AdwDialog*) self, 360);
	adw_dialog_set_content_height ((AdwDialog*) self, 500);
	_tmp6_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp6_);
	box = _tmp6_;
	_tmp7_ = (AdwHeaderBar*) adw_header_bar_new ();
	g_object_ref_sink (_tmp7_);
	header = _tmp7_;
	_tmp8_ = header;
	adw_header_bar_set_show_end_title_buttons (_tmp8_, TRUE);
	_tmp9_ = box;
	_tmp10_ = header;
	gtk_box_append (_tmp9_, (GtkWidget*) _tmp10_);
	_tmp11_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
	g_object_ref_sink (_tmp11_);
	content = _tmp11_;
	_tmp12_ = content;
	gtk_widget_set_margin_start ((GtkWidget*) _tmp12_, 12);
	_tmp13_ = content;
	gtk_widget_set_margin_end ((GtkWidget*) _tmp13_, 12);
	_tmp14_ = content;
	gtk_widget_set_margin_top ((GtkWidget*) _tmp14_, 8);
	_tmp15_ = content;
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp15_, 12);
	if (self->priv->account_selector_enabled) {
		GtkStringList* _tmp16_;
		GtkDropDown* _tmp17_;
		GtkDropDown* _tmp18_;
		GtkDropDown* _tmp19_;
		GtkDropDown* _tmp20_;
		GtkBox* _tmp21_;
		GtkDropDown* _tmp22_;
		_tmp16_ = gtk_string_list_new (NULL);
		_tmp17_ = (GtkDropDown*) gtk_drop_down_new ((GListModel*) _tmp16_, NULL);
		g_object_ref_sink (_tmp17_);
		_g_object_unref0 (self->priv->account_dropdown);
		self->priv->account_dropdown = _tmp17_;
		_tmp18_ = self->priv->account_dropdown;
		gtk_widget_set_hexpand ((GtkWidget*) _tmp18_, TRUE);
		_tmp19_ = self->priv->account_dropdown;
		gtk_widget_set_tooltip_text ((GtkWidget*) _tmp19_, "Destination account");
		_tmp20_ = self->priv->account_dropdown;
		g_signal_connect_object ((GObject*) _tmp20_, "notify::selected", (GCallback) _dc_contact_picker_dialog_on_account_changed_g_object_notify, self, 0);
		_tmp21_ = content;
		_tmp22_ = self->priv->account_dropdown;
		gtk_box_append (_tmp21_, (GtkWidget*) _tmp22_);
	}
	_tmp23_ = (GtkSearchEntry*) gtk_search_entry_new ();
	g_object_ref_sink (_tmp23_);
	_g_object_unref0 (self->priv->search_entry);
	self->priv->search_entry = _tmp23_;
	if (chat_store != NULL) {
		_tmp24_ = "Search chats, contacts or enter email\u2026";
	} else {
		_tmp24_ = "Search or enter email\u2026";
	}
	_tmp25_ = self->priv->search_entry;
	g_object_set (_tmp25_, "placeholder-text", _tmp24_, NULL);
	_tmp26_ = self->priv->search_entry;
	gtk_widget_set_hexpand ((GtkWidget*) _tmp26_, TRUE);
	_tmp27_ = self->priv->search_entry;
	g_signal_connect_object (_tmp27_, "search-changed", (GCallback) _dc_contact_picker_dialog_on_search_changed_gtk_search_entry_search_changed, self, 0);
	_tmp28_ = self->priv->search_entry;
	g_signal_connect_object (_tmp28_, "activate", (GCallback) _dc_contact_picker_dialog_on_activate_search_gtk_search_entry_activate, self, 0);
	_tmp29_ = content;
	_tmp30_ = self->priv->search_entry;
	gtk_box_append (_tmp29_, (GtkWidget*) _tmp30_);
	_tmp31_ = (GtkButton*) gtk_button_new ();
	g_object_ref_sink (_tmp31_);
	_g_object_unref0 (self->priv->use_email_btn);
	self->priv->use_email_btn = _tmp31_;
	_tmp32_ = self->priv->use_email_btn;
	gtk_widget_add_css_class ((GtkWidget*) _tmp32_, "suggested-action");
	_tmp33_ = self->priv->use_email_btn;
	gtk_widget_set_visible ((GtkWidget*) _tmp33_, FALSE);
	_tmp34_ = self->priv->use_email_btn;
	g_signal_connect_object (_tmp34_, "clicked", (GCallback) _dc_contact_picker_dialog_on_use_email_gtk_button_clicked, self, 0);
	_tmp35_ = content;
	_tmp36_ = self->priv->use_email_btn;
	gtk_box_append (_tmp35_, (GtkWidget*) _tmp36_);
	_tmp37_ = (GtkScrolledWindow*) gtk_scrolled_window_new ();
	g_object_ref_sink (_tmp37_);
	scroll = _tmp37_;
	_tmp38_ = scroll;
	gtk_widget_set_vexpand ((GtkWidget*) _tmp38_, TRUE);
	_tmp39_ = scroll;
	g_object_set (_tmp39_, "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
	_tmp40_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
	g_object_ref_sink (_tmp40_);
	list_box = _tmp40_;
	_tmp41_ = (GtkLabel*) gtk_label_new ("Chats");
	g_object_ref_sink (_tmp41_);
	_g_object_unref0 (self->priv->chats_header);
	self->priv->chats_header = _tmp41_;
	_tmp42_ = self->priv->chats_header;
	gtk_widget_add_css_class ((GtkWidget*) _tmp42_, "heading");
	_tmp43_ = self->priv->chats_header;
	gtk_widget_add_css_class ((GtkWidget*) _tmp43_, "dim-label");
	_tmp44_ = self->priv->chats_header;
	gtk_widget_set_halign ((GtkWidget*) _tmp44_, GTK_ALIGN_START);
	_tmp45_ = self->priv->chats_header;
	gtk_widget_set_visible ((GtkWidget*) _tmp45_, FALSE);
	_tmp46_ = list_box;
	_tmp47_ = self->priv->chats_header;
	gtk_box_append (_tmp46_, (GtkWidget*) _tmp47_);
	_tmp48_ = (GtkListBox*) gtk_list_box_new ();
	g_object_ref_sink (_tmp48_);
	_g_object_unref0 (self->priv->chat_listbox);
	self->priv->chat_listbox = _tmp48_;
	_tmp49_ = self->priv->chat_listbox;
	gtk_list_box_set_selection_mode (_tmp49_, GTK_SELECTION_NONE);
	_tmp50_ = self->priv->chat_listbox;
	gtk_widget_add_css_class ((GtkWidget*) _tmp50_, "boxed-list");
	_tmp51_ = self->priv->chat_listbox;
	g_signal_connect_object (_tmp51_, "row-activated", (GCallback) _dc_contact_picker_dialog_on_chat_row_activated_gtk_list_box_row_activated, self, 0);
	_tmp52_ = self->priv->chat_listbox;
	gtk_widget_set_visible ((GtkWidget*) _tmp52_, FALSE);
	_tmp53_ = list_box;
	_tmp54_ = self->priv->chat_listbox;
	gtk_box_append (_tmp53_, (GtkWidget*) _tmp54_);
	_tmp55_ = (GtkLabel*) gtk_label_new ("Contacts");
	g_object_ref_sink (_tmp55_);
	_g_object_unref0 (self->priv->contacts_header);
	self->priv->contacts_header = _tmp55_;
	_tmp56_ = self->priv->contacts_header;
	gtk_widget_add_css_class ((GtkWidget*) _tmp56_, "heading");
	_tmp57_ = self->priv->contacts_header;
	gtk_widget_add_css_class ((GtkWidget*) _tmp57_, "dim-label");
	_tmp58_ = self->priv->contacts_header;
	gtk_widget_set_halign ((GtkWidget*) _tmp58_, GTK_ALIGN_START);
	_tmp59_ = self->priv->contacts_header;
	gtk_widget_set_visible ((GtkWidget*) _tmp59_, chat_store != NULL);
	_tmp60_ = list_box;
	_tmp61_ = self->priv->contacts_header;
	gtk_box_append (_tmp60_, (GtkWidget*) _tmp61_);
	_tmp62_ = (GtkListBox*) gtk_list_box_new ();
	g_object_ref_sink (_tmp62_);
	_g_object_unref0 (self->priv->contact_listbox);
	self->priv->contact_listbox = _tmp62_;
	_tmp63_ = self->priv->contact_listbox;
	gtk_list_box_set_selection_mode (_tmp63_, GTK_SELECTION_NONE);
	_tmp64_ = self->priv->contact_listbox;
	gtk_widget_add_css_class ((GtkWidget*) _tmp64_, "boxed-list");
	_tmp65_ = self->priv->contact_listbox;
	g_signal_connect_object (_tmp65_, "row-activated", (GCallback) _dc_contact_picker_dialog_on_contact_row_activated_gtk_list_box_row_activated, self, 0);
	_tmp66_ = list_box;
	_tmp67_ = self->priv->contact_listbox;
	gtk_box_append (_tmp66_, (GtkWidget*) _tmp67_);
	_tmp68_ = scroll;
	_tmp69_ = list_box;
	gtk_scrolled_window_set_child (_tmp68_, (GtkWidget*) _tmp69_);
	_tmp70_ = content;
	_tmp71_ = scroll;
	gtk_box_append (_tmp70_, (GtkWidget*) _tmp71_);
	_tmp72_ = box;
	_tmp73_ = content;
	gtk_box_append (_tmp72_, (GtkWidget*) _tmp73_);
	_tmp74_ = box;
	adw_dialog_set_child ((AdwDialog*) self, (GtkWidget*) _tmp74_);
	dc_install_escape_close ((AdwDialog*) self);
	dc_contact_picker_dialog_load_contacts (self, NULL, NULL);
	if (self->priv->account_selector_enabled) {
		gint _tmp75_;
		dc_contact_picker_dialog_load_accounts (self, NULL, NULL);
		_tmp75_ = self->priv->_selected_account_id;
		dc_contact_picker_dialog_load_chats_for_account (self, _tmp75_, NULL, NULL);
	} else {
		if (chat_store != NULL) {
			dc_contact_picker_dialog_rebuild_chat_list (self, "");
		}
	}
	_g_object_unref0 (list_box);
	_g_object_unref0 (scroll);
	_g_object_unref0 (content);
	_g_object_unref0 (header);
	_g_object_unref0 (box);
	return self;
}

DcContactPickerDialog*
dc_contact_picker_dialog_new (DcRpcClient* rpc,
                              GListStore* chat_store,
                              const gchar* title,
                              gboolean enable_account_selector)
{
	return dc_contact_picker_dialog_construct (DC_TYPE_CONTACT_PICKER_DIALOG, rpc, chat_store, title, enable_account_selector);
}

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

static void
dc_contact_picker_dialog_load_accounts (DcContactPickerDialog* self,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	DcContactPickerDialogLoadAccountsData* _data_;
	DcContactPickerDialog* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcContactPickerDialogLoadAccountsData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_contact_picker_dialog_load_accounts_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	dc_contact_picker_dialog_load_accounts_co (_data_);
}

static void
dc_contact_picker_dialog_load_accounts_finish (DcContactPickerDialog* self,
                                               GAsyncResult* _res_)
{
	DcContactPickerDialogLoadAccountsData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dc_contact_picker_dialog_load_accounts_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_)
{
	DcContactPickerDialogLoadAccountsData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_contact_picker_dialog_load_accounts_co (_data_);
}

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

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

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

static void
_vala_array_add59 (gint* * array,
                   gint* length,
                   gint* size,
                   gint value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gint, *array, *size);
	}
	(*array)[(*length)++] = value;
}

static gint*
_vala_array_dup25 (gint* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (gint));
	}
	return NULL;
}

static gboolean
dc_contact_picker_dialog_load_accounts_co (DcContactPickerDialogLoadAccountsData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->account_dropdown;
	if (_data_->_tmp0_ == NULL) {
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = _data_->self->priv->account_dropdown;
	_data_->_tmp2_ = gtk_drop_down_get_model (_data_->_tmp1_);
	_data_->_tmp3_ = _data_->_tmp2_;
	_data_->_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp3_, gtk_string_list_get_type (), GtkStringList));
	_data_->model = _data_->_tmp4_;
	_data_->_tmp5_ = g_new0 (gint, 0);
	_data_->ids = _data_->_tmp5_;
	_data_->ids_length1 = 0;
	_data_->_ids_size_ = _data_->ids_length1;
	_data_->selected_idx = 0;
	{
		_data_->_tmp6_ = _data_->self->priv->rpc;
		_data_->_state_ = 1;
		dc_rpc_client_get_all_accounts (_data_->_tmp6_, dc_contact_picker_dialog_load_accounts_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp7_ = dc_rpc_client_get_all_accounts_finish (_data_->_tmp6_, _data_->_res_, &_data_->_inner_error0_);
		_data_->accounts_node = _data_->_tmp7_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp9_ = _data_->accounts_node;
		if (_data_->_tmp9_ != NULL) {
			_data_->_tmp10_ = _data_->accounts_node;
			_data_->_tmp8_ = json_node_get_node_type (_data_->_tmp10_) == JSON_NODE_ARRAY;
		} else {
			_data_->_tmp8_ = FALSE;
		}
		if (_data_->_tmp8_) {
			_data_->_tmp11_ = _data_->accounts_node;
			_data_->_tmp12_ = json_node_get_array (_data_->_tmp11_);
			_data_->_tmp13_ = _json_array_ref0 (_data_->_tmp12_);
			_data_->accounts = _data_->_tmp13_;
			{
				_data_->i = (guint) 0;
				{
					_data_->_tmp14_ = TRUE;
					while (TRUE) {
						if (!_data_->_tmp14_) {
							_data_->_tmp15_ = _data_->i;
							_data_->i = _data_->_tmp15_ + 1;
						}
						_data_->_tmp14_ = FALSE;
						_data_->_tmp16_ = _data_->accounts;
						if (!(_data_->i < json_array_get_length (_data_->_tmp16_))) {
							break;
						}
						_data_->_tmp17_ = _data_->accounts;
						_data_->_tmp18_ = json_array_get_object_element (_data_->_tmp17_, _data_->i);
						_data_->_tmp19_ = _json_object_ref0 (_data_->_tmp18_);
						_data_->acct = _data_->_tmp19_;
						_data_->_tmp20_ = _data_->acct;
						if (_data_->_tmp20_ == NULL) {
							_json_object_unref0 (_data_->acct);
							continue;
						}
						_data_->_tmp21_ = _data_->acct;
						_data_->id = (gint) json_object_get_int_member (_data_->_tmp21_, "id");
						if (_data_->id <= 0) {
							_data_->_tmp22_ = TRUE;
						} else {
							_data_->_tmp24_ = _data_->self->priv->rpc;
							_data_->_state_ = 2;
							dc_rpc_client_is_configured (_data_->_tmp24_, _data_->id, dc_contact_picker_dialog_load_accounts_ready, _data_);
							return FALSE;
							_state_2:
							_data_->_tmp23_ = dc_rpc_client_is_configured_finish (_data_->_tmp24_, _data_->_res_, &_data_->_inner_error0_);
							if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
								_json_object_unref0 (_data_->acct);
								_json_array_unref0 (_data_->accounts);
								__vala_JsonNode_free0 (_data_->accounts_node);
								goto __catch0_g_error;
							}
							_data_->_tmp22_ = !_data_->_tmp23_;
						}
						if (_data_->_tmp22_) {
							_json_object_unref0 (_data_->acct);
							continue;
						}
						_data_->_tmp25_ = _data_->self->priv->rpc;
						_data_->_state_ = 3;
						dc_rpc_client_get_config (_data_->_tmp25_, "displayname", _data_->id, dc_contact_picker_dialog_load_accounts_ready, _data_);
						return FALSE;
						_state_3:
						_data_->_tmp26_ = dc_rpc_client_get_config_finish (_data_->_tmp25_, _data_->_res_, &_data_->_inner_error0_);
						_data_->name = _data_->_tmp26_;
						if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
							_json_object_unref0 (_data_->acct);
							_json_array_unref0 (_data_->accounts);
							__vala_JsonNode_free0 (_data_->accounts_node);
							goto __catch0_g_error;
						}
						_data_->_tmp27_ = _data_->self->priv->rpc;
						_data_->_state_ = 4;
						dc_rpc_client_get_config (_data_->_tmp27_, "addr", _data_->id, dc_contact_picker_dialog_load_accounts_ready, _data_);
						return FALSE;
						_state_4:
						_data_->_tmp28_ = dc_rpc_client_get_config_finish (_data_->_tmp27_, _data_->_res_, &_data_->_inner_error0_);
						_data_->addr = _data_->_tmp28_;
						if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
							_g_free0 (_data_->name);
							_json_object_unref0 (_data_->acct);
							_json_array_unref0 (_data_->accounts);
							__vala_JsonNode_free0 (_data_->accounts_node);
							goto __catch0_g_error;
						}
						_data_->_tmp31_ = _data_->name;
						if (_data_->_tmp31_ != NULL) {
							_data_->_tmp32_ = _data_->name;
							_data_->_tmp33_ = strlen (_data_->_tmp32_);
							_data_->_tmp34_ = _data_->_tmp33_;
							_data_->_tmp30_ = _data_->_tmp34_ > 0;
						} else {
							_data_->_tmp30_ = FALSE;
						}
						if (_data_->_tmp30_) {
							_data_->_tmp35_ = _data_->name;
							_data_->_tmp36_ = g_strdup (_data_->_tmp35_);
							_g_free0 (_data_->_tmp29_);
							_data_->_tmp29_ = _data_->_tmp36_;
						} else {
							_data_->_tmp38_ = _data_->addr;
							_data_->_tmp39_ = g_strdup (_data_->_tmp38_);
							_data_->_tmp37_ = _data_->_tmp39_;
							if (_data_->_tmp37_ == NULL) {
								_data_->_tmp40_ = g_strdup_printf ("Account #%d", _data_->id);
								_g_free0 (_data_->_tmp37_);
								_data_->_tmp37_ = _data_->_tmp40_;
							}
							_data_->_tmp41_ = _data_->_tmp37_;
							_data_->_tmp37_ = NULL;
							_g_free0 (_data_->_tmp29_);
							_data_->_tmp29_ = _data_->_tmp41_;
							_g_free0 (_data_->_tmp37_);
						}
						_data_->_tmp42_ = _data_->_tmp29_;
						_data_->_tmp29_ = NULL;
						_data_->label = _data_->_tmp42_;
						_data_->_tmp46_ = _data_->name;
						if (_data_->_tmp46_ != NULL) {
							_data_->_tmp47_ = _data_->name;
							_data_->_tmp48_ = strlen (_data_->_tmp47_);
							_data_->_tmp49_ = _data_->_tmp48_;
							_data_->_tmp45_ = _data_->_tmp49_ > 0;
						} else {
							_data_->_tmp45_ = FALSE;
						}
						if (_data_->_tmp45_) {
							_data_->_tmp50_ = _data_->addr;
							_data_->_tmp44_ = _data_->_tmp50_ != NULL;
						} else {
							_data_->_tmp44_ = FALSE;
						}
						if (_data_->_tmp44_) {
							_data_->_tmp51_ = _data_->addr;
							_data_->_tmp52_ = strlen (_data_->_tmp51_);
							_data_->_tmp53_ = _data_->_tmp52_;
							_data_->_tmp43_ = _data_->_tmp53_ > 0;
						} else {
							_data_->_tmp43_ = FALSE;
						}
						if (_data_->_tmp43_) {
							_data_->_tmp54_ = _data_->name;
							_data_->_tmp55_ = _data_->addr;
							_data_->_tmp56_ = g_strdup_printf ("%s (%s)", _data_->_tmp54_, _data_->_tmp55_);
							_g_free0 (_data_->label);
							_data_->label = _data_->_tmp56_;
						}
						_data_->_tmp57_ = _data_->self->priv->_selected_account_id;
						if (_data_->id == _data_->_tmp57_) {
							_data_->_tmp58_ = _data_->ids;
							_data_->_tmp58__length1 = _data_->ids_length1;
							_data_->selected_idx = _data_->_tmp58__length1;
						}
						_vala_array_add59 (&_data_->ids, &_data_->ids_length1, &_data_->_ids_size_, _data_->id);
						_data_->_tmp59_ = _data_->model;
						_data_->_tmp60_ = _data_->label;
						gtk_string_list_append (_data_->_tmp59_, _data_->_tmp60_);
						_g_free0 (_data_->label);
						_g_free0 (_data_->_tmp29_);
						_g_free0 (_data_->addr);
						_g_free0 (_data_->name);
						_json_object_unref0 (_data_->acct);
					}
				}
			}
			_json_array_unref0 (_data_->accounts);
		}
		__vala_JsonNode_free0 (_data_->accounts_node);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_data_->_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_data_->ids = (g_free (_data_->ids), NULL);
		_g_object_unref0 (_data_->model);
		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_->_tmp61_ = _data_->ids;
	_data_->_tmp61__length1 = _data_->ids_length1;
	_data_->_tmp62_ = (_data_->_tmp61_ != NULL) ? _vala_array_dup25 (_data_->_tmp61_, _data_->_tmp61__length1) : _data_->_tmp61_;
	_data_->_tmp62__length1 = _data_->_tmp61__length1;
	_data_->self->priv->account_ids = (g_free (_data_->self->priv->account_ids), NULL);
	_data_->self->priv->account_ids = _data_->_tmp62_;
	_data_->self->priv->account_ids_length1 = _data_->_tmp62__length1;
	_data_->self->priv->_account_ids_size_ = _data_->self->priv->account_ids_length1;
	_data_->_tmp63_ = _data_->ids;
	_data_->_tmp63__length1 = _data_->ids_length1;
	if (_data_->_tmp63__length1 > 0) {
		_data_->_tmp64_ = _data_->self->priv->account_dropdown;
		gtk_drop_down_set_selected (_data_->_tmp64_, (guint) _data_->selected_idx);
	}
	_data_->ids = (g_free (_data_->ids), NULL);
	_g_object_unref0 (_data_->model);
	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_contact_picker_dialog_on_account_changed (DcContactPickerDialog* self)
{
	GtkDropDown* _tmp0_;
	gint idx = 0;
	GtkDropDown* _tmp1_;
	guint _tmp2_;
	guint _tmp3_;
	gboolean _tmp4_ = FALSE;
	gint id = 0;
	gint* _tmp6_;
	gint _tmp6__length1;
	gint _tmp7_;
	gint _tmp8_;
	GtkSearchEntry* _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->account_dropdown;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->account_dropdown;
	_tmp2_ = gtk_drop_down_get_selected (_tmp1_);
	_tmp3_ = _tmp2_;
	idx = (gint) _tmp3_;
	if (idx < 0) {
		_tmp4_ = TRUE;
	} else {
		gint* _tmp5_;
		gint _tmp5__length1;
		_tmp5_ = self->priv->account_ids;
		_tmp5__length1 = self->priv->account_ids_length1;
		_tmp4_ = idx >= _tmp5__length1;
	}
	if (_tmp4_) {
		return;
	}
	_tmp6_ = self->priv->account_ids;
	_tmp6__length1 = self->priv->account_ids_length1;
	_tmp7_ = _tmp6_[idx];
	id = _tmp7_;
	_tmp8_ = self->priv->_selected_account_id;
	if (id == _tmp8_) {
		return;
	}
	dc_contact_picker_dialog_set_selected_account_id (self, id);
	_tmp9_ = self->priv->search_entry;
	gtk_editable_set_text ((GtkEditable*) _tmp9_, "");
	dc_contact_picker_dialog_load_contacts (self, NULL, NULL);
	dc_contact_picker_dialog_load_chats_for_account (self, id, NULL, NULL);
}

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

static void
dc_contact_picker_dialog_load_chats_for_account (DcContactPickerDialog* self,
                                                 gint acct_id,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_)
{
	DcContactPickerDialogLoadChatsForAccountData* _data_;
	DcContactPickerDialog* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcContactPickerDialogLoadChatsForAccountData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_contact_picker_dialog_load_chats_for_account_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->acct_id = acct_id;
	dc_contact_picker_dialog_load_chats_for_account_co (_data_);
}

static void
dc_contact_picker_dialog_load_chats_for_account_finish (DcContactPickerDialog* self,
                                                        GAsyncResult* _res_)
{
	DcContactPickerDialogLoadChatsForAccountData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dc_contact_picker_dialog_load_chats_for_account_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_)
{
	DcContactPickerDialogLoadChatsForAccountData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_contact_picker_dialog_load_chats_for_account_co (_data_);
}

static gpointer
_g_ptr_array_ref0 (gpointer self)
{
	return self ? g_ptr_array_ref (self) : NULL;
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

static gboolean
dc_contact_picker_dialog_load_chats_for_account_co (DcContactPickerDialogLoadChatsForAccountData* _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_->self->priv->chat_load_gen = _data_->self->priv->chat_load_gen + 1;
	_data_->_tmp0_ = _data_->self->priv->chat_load_gen;
	_data_->gen = _data_->_tmp0_;
	_data_->_tmp1_ = g_ptr_array_new_full ((guint) 0, _g_object_unref0_);
	_data_->chats = _data_->_tmp1_;
	{
		_data_->_tmp2_ = _data_->self->priv->rpc;
		_data_->_state_ = 1;
		dc_rpc_client_get_chatlist_entries_for (_data_->_tmp2_, _data_->acct_id, NULL, DC_RPC_CLIENT_GCL_NO_SPECIALS, dc_contact_picker_dialog_load_chats_for_account_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)) {
			goto __catch0_g_error;
		}
		_data_->_tmp4_ = _data_->entries;
		if (_data_->_tmp4_ != NULL) {
			_data_->_tmp5_ = _data_->self->priv->rpc;
			_data_->_tmp6_ = _data_->entries;
			_data_->_state_ = 2;
			dc_rpc_client_get_chatlist_items_by_entries_for (_data_->_tmp5_, _data_->acct_id, _data_->_tmp6_, dc_contact_picker_dialog_load_chats_for_account_ready, _data_);
			return FALSE;
			_state_2:
			_data_->_tmp7_ = dc_rpc_client_get_chatlist_items_by_entries_for_finish (_data_->_tmp5_, _data_->_res_, &_data_->_inner_error0_);
			_data_->items = _data_->_tmp7_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_json_array_unref0 (_data_->entries);
				goto __catch0_g_error;
			}
			{
				_data_->i = (guint) 0;
				{
					_data_->_tmp8_ = TRUE;
					while (TRUE) {
						if (!_data_->_tmp8_) {
							_data_->_tmp9_ = _data_->i;
							_data_->i = _data_->_tmp9_ + 1;
						}
						_data_->_tmp8_ = FALSE;
						_data_->_tmp10_ = _data_->entries;
						if (!(_data_->i < json_array_get_length (_data_->_tmp10_))) {
							break;
						}
						_data_->_tmp11_ = _data_->entries;
						_data_->chat_id = (gint) json_array_get_int_element (_data_->_tmp11_, _data_->i);
						_data_->_tmp12_ = g_strdup_printf ("%i", _data_->chat_id);
						_data_->id_str = _data_->_tmp12_;
						_data_->_tmp14_ = _data_->items;
						if (_data_->_tmp14_ != NULL) {
							_data_->_tmp15_ = _data_->items;
							_data_->_tmp16_ = _data_->id_str;
							_data_->_tmp13_ = json_object_has_member (_data_->_tmp15_, _data_->_tmp16_);
						} else {
							_data_->_tmp13_ = FALSE;
						}
						if (_data_->_tmp13_) {
							_data_->_tmp17_ = _data_->items;
							_data_->_tmp18_ = _data_->id_str;
							_data_->_tmp19_ = json_object_get_object_member (_data_->_tmp17_, _data_->_tmp18_);
							_data_->_tmp20_ = _json_object_ref0 (_data_->_tmp19_);
							_data_->item = _data_->_tmp20_;
							_data_->_tmp21_ = _data_->chats;
							_data_->_tmp22_ = _data_->item;
							_data_->_tmp23_ = dc_rpc_parsers_parse_chat_item (_data_->chat_id, _data_->_tmp22_);
							g_ptr_array_add (_data_->_tmp21_, _data_->_tmp23_);
							_json_object_unref0 (_data_->item);
						}
						_g_free0 (_data_->id_str);
					}
				}
			}
			_json_object_unref0 (_data_->items);
		}
		_json_array_unref0 (_data_->entries);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_data_->_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_ptr_array_unref0 (_data_->chats);
		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;
	}
	if (_data_->gen != _data_->self->priv->chat_load_gen) {
		_g_ptr_array_unref0 (_data_->chats);
		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_->_tmp24_ = _data_->chats;
	_data_->_tmp25_ = _g_ptr_array_ref0 (_data_->_tmp24_);
	_g_ptr_array_unref0 (_data_->self->priv->loaded_chats);
	_data_->self->priv->loaded_chats = _data_->_tmp25_;
	_data_->_tmp26_ = _data_->self->priv->search_entry;
	_data_->_tmp27_ = gtk_editable_get_text ((GtkEditable*) _data_->_tmp26_);
	_data_->_tmp28_ = _data_->_tmp27_;
	_data_->_tmp29_ = string_strip (_data_->_tmp28_);
	_data_->_tmp30_ = _data_->_tmp29_;
	dc_contact_picker_dialog_rebuild_chat_list (_data_->self, _data_->_tmp30_);
	_g_free0 (_data_->_tmp30_);
	_g_ptr_array_unref0 (_data_->chats);
	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_contact_picker_dialog_load_contacts_data_free (gpointer _data)
{
	DcContactPickerDialogLoadContactsData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (DcContactPickerDialogLoadContactsData, _data_);
}

static void
dc_contact_picker_dialog_load_contacts (DcContactPickerDialog* self,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	DcContactPickerDialogLoadContactsData* _data_;
	DcContactPickerDialog* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcContactPickerDialogLoadContactsData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_contact_picker_dialog_load_contacts_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	dc_contact_picker_dialog_load_contacts_co (_data_);
}

static void
dc_contact_picker_dialog_load_contacts_finish (DcContactPickerDialog* self,
                                               GAsyncResult* _res_)
{
	DcContactPickerDialogLoadContactsData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dc_contact_picker_dialog_load_contacts_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_)
{
	DcContactPickerDialogLoadContactsData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_contact_picker_dialog_load_contacts_co (_data_);
}

static gboolean
dc_contact_picker_dialog_load_contacts_co (DcContactPickerDialogLoadContactsData* _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_->self->priv->contact_load_gen = _data_->self->priv->contact_load_gen + 1;
	_data_->_tmp0_ = _data_->self->priv->contact_load_gen;
	_data_->gen = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->self->priv->_selected_account_id;
	_data_->acct_id = _data_->_tmp1_;
	_data_->_tmp2_ = g_ptr_array_new_full ((guint) 0, _g_object_unref0_);
	_data_->collected = _data_->_tmp2_;
	{
		_data_->_tmp3_ = _data_->self->priv->rpc;
		_data_->_state_ = 1;
		dc_rpc_client_get_contact_ids_for (_data_->_tmp3_, _data_->acct_id, NULL, dc_contact_picker_dialog_load_contacts_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp4_ = dc_rpc_client_get_contact_ids_for_finish (_data_->_tmp3_, _data_->_res_, &_data_->_inner_error0_);
		_data_->ids = _data_->_tmp4_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp5_ = _data_->ids;
		if (_data_->_tmp5_ == NULL) {
			_json_array_unref0 (_data_->ids);
			_g_ptr_array_unref0 (_data_->collected);
			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_->_tmp6_ = TRUE;
				while (TRUE) {
					if (!_data_->_tmp6_) {
						_data_->_tmp7_ = _data_->i;
						_data_->i = _data_->_tmp7_ + 1;
					}
					_data_->_tmp6_ = FALSE;
					_data_->_tmp8_ = _data_->ids;
					if (!(_data_->i < json_array_get_length (_data_->_tmp8_))) {
						break;
					}
					_data_->_tmp9_ = _data_->ids;
					_data_->cid = (gint) json_array_get_int_element (_data_->_tmp9_, _data_->i);
					if (_data_->cid <= 1) {
						continue;
					}
					_data_->_tmp10_ = _data_->self->priv->rpc;
					_data_->_state_ = 2;
					dc_rpc_client_get_contact_for (_data_->_tmp10_, _data_->acct_id, _data_->cid, dc_contact_picker_dialog_load_contacts_ready, _data_);
					return FALSE;
					_state_2:
					_data_->_tmp11_ = dc_rpc_client_get_contact_for_finish (_data_->_tmp10_, _data_->_res_, &_data_->_inner_error0_);
					_data_->obj = _data_->_tmp11_;
					if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
						_json_array_unref0 (_data_->ids);
						goto __catch0_g_error;
					}
					_data_->_tmp12_ = _data_->obj;
					if (_data_->_tmp12_ == NULL) {
						_json_object_unref0 (_data_->obj);
						continue;
					}
					_data_->_tmp13_ = _data_->obj;
					_data_->_tmp14_ = dc_rpc_parsers_parse_contact (_data_->cid, _data_->_tmp13_);
					_data_->ci = _data_->_tmp14_;
					_data_->_tmp15_ = _data_->ci;
					_data_->_tmp16_ = dc_contact_get_address (_data_->_tmp15_);
					_data_->_tmp17_ = _data_->_tmp16_;
					_data_->_tmp18_ = strlen (_data_->_tmp17_);
					_data_->_tmp19_ = _data_->_tmp18_;
					if (_data_->_tmp19_ == 0) {
						_g_object_unref0 (_data_->ci);
						_json_object_unref0 (_data_->obj);
						continue;
					}
					_data_->_tmp20_ = _data_->collected;
					_data_->_tmp21_ = _data_->ci;
					_data_->_tmp22_ = _g_object_ref0 (_data_->_tmp21_);
					g_ptr_array_add (_data_->_tmp20_, _data_->_tmp22_);
					_g_object_unref0 (_data_->ci);
					_json_object_unref0 (_data_->obj);
				}
			}
		}
		if (_data_->gen != _data_->self->priv->contact_load_gen) {
			_json_array_unref0 (_data_->ids);
			_g_ptr_array_unref0 (_data_->collected);
			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_->_tmp23_ = _data_->collected;
		_data_->_tmp24_ = _g_ptr_array_ref0 (_data_->_tmp23_);
		_g_ptr_array_unref0 (_data_->self->priv->all_contacts);
		_data_->self->priv->all_contacts = _data_->_tmp24_;
		_data_->_tmp25_ = _data_->self->priv->search_entry;
		_data_->_tmp26_ = gtk_editable_get_text ((GtkEditable*) _data_->_tmp25_);
		_data_->_tmp27_ = _data_->_tmp26_;
		_data_->_tmp28_ = string_strip (_data_->_tmp27_);
		_data_->_tmp29_ = _data_->_tmp28_;
		dc_contact_picker_dialog_rebuild_contact_list (_data_->self, _data_->_tmp29_);
		_g_free0 (_data_->_tmp29_);
		_json_array_unref0 (_data_->ids);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp30_ = _data_->e;
		_data_->_tmp31_ = _data_->_tmp30_->message;
		_data_->_tmp32_ = g_strconcat ("Failed to load contacts: ", _data_->_tmp31_, NULL);
		_data_->_tmp33_ = _data_->_tmp32_;
		_data_->_tmp34_ = (GtkLabel*) gtk_label_new (_data_->_tmp33_);
		g_object_ref_sink (_data_->_tmp34_);
		_data_->_tmp35_ = _data_->_tmp34_;
		_g_free0 (_data_->_tmp33_);
		_data_->lbl = _data_->_tmp35_;
		_data_->_tmp36_ = _data_->lbl;
		gtk_widget_add_css_class ((GtkWidget*) _data_->_tmp36_, "dim-label");
		_data_->_tmp37_ = _data_->lbl;
		gtk_label_set_wrap (_data_->_tmp37_, TRUE);
		_data_->_tmp38_ = _data_->self->priv->contact_listbox;
		_data_->_tmp39_ = _data_->lbl;
		gtk_list_box_append (_data_->_tmp38_, (GtkWidget*) _data_->_tmp39_);
		_g_object_unref0 (_data_->lbl);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_ptr_array_unref0 (_data_->collected);
		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_ptr_array_unref0 (_data_->collected);
	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 gint
vala_g_ptr_array_get_length (GPtrArray* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = (gint) self->len;
	return result;
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

static void
dc_contact_picker_dialog_rebuild_contact_list (DcContactPickerDialog* self,
                                               const gchar* query)
{
	GtkListBox* _tmp0_;
	gchar* q = NULL;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (query != NULL);
	_tmp0_ = self->priv->contact_listbox;
	dc_clear_listbox (_tmp0_);
	_tmp1_ = string_strip (query);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_utf8_strdown (_tmp2_, (gssize) -1);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	q = _tmp4_;
	{
		guint i = 0U;
		i = (guint) 0;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				GPtrArray* _tmp7_;
				gint _tmp8_;
				gint _tmp9_;
				DcContact* ci = NULL;
				GPtrArray* _tmp10_;
				gconstpointer _tmp11_;
				DcContact* _tmp12_;
				const gchar* _tmp13_;
				gint _tmp14_;
				gint _tmp15_;
				AdwActionRow* r = NULL;
				DcContact* _tmp30_;
				AdwActionRow* _tmp31_;
				GtkListBox* _tmp32_;
				AdwActionRow* _tmp33_;
				if (!_tmp5_) {
					guint _tmp6_;
					_tmp6_ = i;
					i = _tmp6_ + 1;
				}
				_tmp5_ = FALSE;
				_tmp7_ = self->priv->all_contacts;
				_tmp8_ = vala_g_ptr_array_get_length (_tmp7_);
				_tmp9_ = _tmp8_;
				if (!(i < ((guint) _tmp9_))) {
					break;
				}
				_tmp10_ = self->priv->all_contacts;
				_tmp11_ = g_ptr_array_index (_tmp10_, i);
				_tmp12_ = _g_object_ref0 ((DcContact*) _tmp11_);
				ci = _tmp12_;
				_tmp13_ = q;
				_tmp14_ = strlen (_tmp13_);
				_tmp15_ = _tmp14_;
				if (_tmp15_ > 0) {
					gboolean _tmp16_ = FALSE;
					DcContact* _tmp17_;
					const gchar* _tmp18_;
					const gchar* _tmp19_;
					gchar* _tmp20_;
					gchar* _tmp21_;
					const gchar* _tmp22_;
					gboolean _tmp23_;
					gboolean matches = FALSE;
					_tmp17_ = ci;
					_tmp18_ = dc_contact_get_display_name (_tmp17_);
					_tmp19_ = _tmp18_;
					_tmp20_ = g_utf8_strdown (_tmp19_, (gssize) -1);
					_tmp21_ = _tmp20_;
					_tmp22_ = q;
					_tmp23_ = string_contains (_tmp21_, _tmp22_);
					_g_free0 (_tmp21_);
					if (_tmp23_) {
						_tmp16_ = TRUE;
					} else {
						DcContact* _tmp24_;
						const gchar* _tmp25_;
						const gchar* _tmp26_;
						gchar* _tmp27_;
						gchar* _tmp28_;
						const gchar* _tmp29_;
						_tmp24_ = ci;
						_tmp25_ = dc_contact_get_address (_tmp24_);
						_tmp26_ = _tmp25_;
						_tmp27_ = g_utf8_strdown (_tmp26_, (gssize) -1);
						_tmp28_ = _tmp27_;
						_tmp29_ = q;
						_tmp16_ = string_contains (_tmp28_, _tmp29_);
						_g_free0 (_tmp28_);
					}
					matches = _tmp16_;
					if (!matches) {
						_g_object_unref0 (ci);
						continue;
					}
				}
				_tmp30_ = ci;
				_tmp31_ = dc_contact_picker_dialog_build_contact_row (self, _tmp30_);
				r = _tmp31_;
				_tmp32_ = self->priv->contact_listbox;
				_tmp33_ = r;
				gtk_list_box_append (_tmp32_, (GtkWidget*) _tmp33_);
				_g_object_unref0 (r);
				_g_object_unref0 (ci);
			}
		}
	}
	_g_free0 (q);
}

static void
dc_contact_picker_dialog_rebuild_chat_list (DcContactPickerDialog* self,
                                            const gchar* query)
{
	GtkListBox* _tmp0_;
	gchar* q = NULL;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gboolean any = FALSE;
	GtkLabel* _tmp47_;
	GtkListBox* _tmp48_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (query != NULL);
	_tmp0_ = self->priv->chat_listbox;
	dc_clear_listbox (_tmp0_);
	_tmp1_ = string_strip (query);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_utf8_strdown (_tmp2_, (gssize) -1);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	q = _tmp4_;
	any = FALSE;
	if (self->priv->account_selector_enabled) {
		{
			guint i = 0U;
			i = (guint) 0;
			{
				gboolean _tmp5_ = FALSE;
				_tmp5_ = TRUE;
				while (TRUE) {
					GPtrArray* _tmp7_;
					gint _tmp8_;
					gint _tmp9_;
					DcChatEntry* chat = NULL;
					GPtrArray* _tmp10_;
					gconstpointer _tmp11_;
					DcChatEntry* _tmp12_;
					gboolean _tmp13_ = FALSE;
					const gchar* _tmp14_;
					gint _tmp15_;
					gint _tmp16_;
					GtkListBox* _tmp23_;
					DcChatEntry* _tmp24_;
					AdwActionRow* _tmp25_;
					AdwActionRow* _tmp26_;
					if (!_tmp5_) {
						guint _tmp6_;
						_tmp6_ = i;
						i = _tmp6_ + 1;
					}
					_tmp5_ = FALSE;
					_tmp7_ = self->priv->loaded_chats;
					_tmp8_ = vala_g_ptr_array_get_length (_tmp7_);
					_tmp9_ = _tmp8_;
					if (!(i < ((guint) _tmp9_))) {
						break;
					}
					_tmp10_ = self->priv->loaded_chats;
					_tmp11_ = g_ptr_array_index (_tmp10_, i);
					_tmp12_ = _g_object_ref0 ((DcChatEntry*) _tmp11_);
					chat = _tmp12_;
					_tmp14_ = q;
					_tmp15_ = strlen (_tmp14_);
					_tmp16_ = _tmp15_;
					if (_tmp16_ > 0) {
						DcChatEntry* _tmp17_;
						const gchar* _tmp18_;
						const gchar* _tmp19_;
						gchar* _tmp20_;
						gchar* _tmp21_;
						const gchar* _tmp22_;
						_tmp17_ = chat;
						_tmp18_ = dc_chat_entry_get_name (_tmp17_);
						_tmp19_ = _tmp18_;
						_tmp20_ = g_utf8_strdown (_tmp19_, (gssize) -1);
						_tmp21_ = _tmp20_;
						_tmp22_ = q;
						_tmp13_ = !string_contains (_tmp21_, _tmp22_);
						_g_free0 (_tmp21_);
					} else {
						_tmp13_ = FALSE;
					}
					if (_tmp13_) {
						_g_object_unref0 (chat);
						continue;
					}
					_tmp23_ = self->priv->chat_listbox;
					_tmp24_ = chat;
					_tmp25_ = dc_chat_pick_row (_tmp24_);
					_tmp26_ = _tmp25_;
					gtk_list_box_append (_tmp23_, (GtkWidget*) _tmp26_);
					_g_object_unref0 (_tmp26_);
					any = TRUE;
					_g_object_unref0 (chat);
				}
			}
		}
	} else {
		GListStore* _tmp27_;
		_tmp27_ = self->priv->chat_store;
		if (_tmp27_ == NULL) {
			_g_free0 (q);
			return;
		}
		{
			guint i = 0U;
			i = (guint) 0;
			{
				gboolean _tmp28_ = FALSE;
				_tmp28_ = TRUE;
				while (TRUE) {
					GListStore* _tmp30_;
					DcChatEntry* chat = NULL;
					GListStore* _tmp31_;
					GObject* _tmp32_;
					gboolean _tmp33_ = FALSE;
					const gchar* _tmp34_;
					gint _tmp35_;
					gint _tmp36_;
					GtkListBox* _tmp43_;
					DcChatEntry* _tmp44_;
					AdwActionRow* _tmp45_;
					AdwActionRow* _tmp46_;
					if (!_tmp28_) {
						guint _tmp29_;
						_tmp29_ = i;
						i = _tmp29_ + 1;
					}
					_tmp28_ = FALSE;
					_tmp30_ = self->priv->chat_store;
					if (!(i < g_list_model_get_n_items ((GListModel*) _tmp30_))) {
						break;
					}
					_tmp31_ = self->priv->chat_store;
					_tmp32_ = g_list_model_get_item ((GListModel*) _tmp31_, i);
					chat = G_TYPE_CHECK_INSTANCE_CAST (_tmp32_, DC_TYPE_CHAT_ENTRY, DcChatEntry);
					_tmp34_ = q;
					_tmp35_ = strlen (_tmp34_);
					_tmp36_ = _tmp35_;
					if (_tmp36_ > 0) {
						DcChatEntry* _tmp37_;
						const gchar* _tmp38_;
						const gchar* _tmp39_;
						gchar* _tmp40_;
						gchar* _tmp41_;
						const gchar* _tmp42_;
						_tmp37_ = chat;
						_tmp38_ = dc_chat_entry_get_name (_tmp37_);
						_tmp39_ = _tmp38_;
						_tmp40_ = g_utf8_strdown (_tmp39_, (gssize) -1);
						_tmp41_ = _tmp40_;
						_tmp42_ = q;
						_tmp33_ = !string_contains (_tmp41_, _tmp42_);
						_g_free0 (_tmp41_);
					} else {
						_tmp33_ = FALSE;
					}
					if (_tmp33_) {
						_g_object_unref0 (chat);
						continue;
					}
					_tmp43_ = self->priv->chat_listbox;
					_tmp44_ = chat;
					_tmp45_ = dc_chat_pick_row (_tmp44_);
					_tmp46_ = _tmp45_;
					gtk_list_box_append (_tmp43_, (GtkWidget*) _tmp46_);
					_g_object_unref0 (_tmp46_);
					any = TRUE;
					_g_object_unref0 (chat);
				}
			}
		}
	}
	_tmp47_ = self->priv->chats_header;
	gtk_widget_set_visible ((GtkWidget*) _tmp47_, any);
	_tmp48_ = self->priv->chat_listbox;
	gtk_widget_set_visible ((GtkWidget*) _tmp48_, any);
	_g_free0 (q);
}

static AdwActionRow*
dc_contact_picker_dialog_build_contact_row (DcContactPickerDialog* self,
                                            DcContact* ci)
{
	AdwActionRow* row = NULL;
	AdwActionRow* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	AdwActionRow* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (ci != NULL, NULL);
	_tmp0_ = dc_contact_row (ci, TRUE, TRUE);
	row = _tmp0_;
	_tmp1_ = dc_contact_get_id (ci);
	_tmp2_ = _tmp1_;
	_tmp3_ = dc_contact_get_address (ci);
	_tmp4_ = _tmp3_;
	_tmp5_ = g_strdup_printf ("%d\n%s", _tmp2_, _tmp4_);
	_tmp6_ = _tmp5_;
	gtk_widget_set_name ((GtkWidget*) row, _tmp6_);
	_g_free0 (_tmp6_);
	result = row;
	return result;
}

static void
dc_contact_picker_dialog_on_search_changed (DcContactPickerDialog* self)
{
	gchar* text = NULL;
	GtkSearchEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	const gchar* _tmp4_;
	gboolean _tmp5_ = FALSE;
	GListStore* _tmp6_;
	gboolean _tmp8_ = FALSE;
	const gchar* _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->search_entry;
	_tmp1_ = gtk_editable_get_text ((GtkEditable*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = string_strip (_tmp2_);
	text = _tmp3_;
	_tmp4_ = text;
	dc_contact_picker_dialog_rebuild_contact_list (self, _tmp4_);
	_tmp6_ = self->priv->chat_store;
	if (_tmp6_ != NULL) {
		_tmp5_ = TRUE;
	} else {
		_tmp5_ = self->priv->account_selector_enabled;
	}
	if (_tmp5_) {
		const gchar* _tmp7_;
		_tmp7_ = text;
		dc_contact_picker_dialog_rebuild_chat_list (self, _tmp7_);
	}
	_tmp9_ = text;
	if (string_contains (_tmp9_, "@")) {
		const gchar* _tmp10_;
		gint _tmp11_;
		gint _tmp12_;
		_tmp10_ = text;
		_tmp11_ = strlen (_tmp10_);
		_tmp12_ = _tmp11_;
		_tmp8_ = _tmp12_ > 3;
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		gboolean already_listed = FALSE;
		GtkButton* _tmp30_;
		const gchar* _tmp31_;
		gchar* _tmp32_;
		gchar* _tmp33_;
		GtkButton* _tmp34_;
		already_listed = FALSE;
		{
			guint i = 0U;
			i = (guint) 0;
			{
				gboolean _tmp13_ = FALSE;
				_tmp13_ = TRUE;
				while (TRUE) {
					GPtrArray* _tmp15_;
					gint _tmp16_;
					gint _tmp17_;
					DcContact* ci = NULL;
					GPtrArray* _tmp18_;
					gconstpointer _tmp19_;
					DcContact* _tmp20_;
					DcContact* _tmp21_;
					const gchar* _tmp22_;
					const gchar* _tmp23_;
					gchar* _tmp24_;
					gchar* _tmp25_;
					const gchar* _tmp26_;
					gchar* _tmp27_;
					gchar* _tmp28_;
					gboolean _tmp29_;
					if (!_tmp13_) {
						guint _tmp14_;
						_tmp14_ = i;
						i = _tmp14_ + 1;
					}
					_tmp13_ = FALSE;
					_tmp15_ = self->priv->all_contacts;
					_tmp16_ = vala_g_ptr_array_get_length (_tmp15_);
					_tmp17_ = _tmp16_;
					if (!(i < ((guint) _tmp17_))) {
						break;
					}
					_tmp18_ = self->priv->all_contacts;
					_tmp19_ = g_ptr_array_index (_tmp18_, i);
					_tmp20_ = _g_object_ref0 ((DcContact*) _tmp19_);
					ci = _tmp20_;
					_tmp21_ = ci;
					_tmp22_ = dc_contact_get_address (_tmp21_);
					_tmp23_ = _tmp22_;
					_tmp24_ = g_utf8_strdown (_tmp23_, (gssize) -1);
					_tmp25_ = _tmp24_;
					_tmp26_ = text;
					_tmp27_ = g_utf8_strdown (_tmp26_, (gssize) -1);
					_tmp28_ = _tmp27_;
					_tmp29_ = g_strcmp0 (_tmp25_, _tmp28_) == 0;
					_g_free0 (_tmp28_);
					_g_free0 (_tmp25_);
					if (_tmp29_) {
						already_listed = TRUE;
						_g_object_unref0 (ci);
						break;
					}
					_g_object_unref0 (ci);
				}
			}
		}
		_tmp30_ = self->priv->use_email_btn;
		_tmp31_ = text;
		_tmp32_ = g_strdup_printf ("Start chat with %s", _tmp31_);
		_tmp33_ = _tmp32_;
		gtk_button_set_label (_tmp30_, _tmp33_);
		_g_free0 (_tmp33_);
		_tmp34_ = self->priv->use_email_btn;
		gtk_widget_set_visible ((GtkWidget*) _tmp34_, !already_listed);
	} else {
		GtkButton* _tmp35_;
		_tmp35_ = self->priv->use_email_btn;
		gtk_widget_set_visible ((GtkWidget*) _tmp35_, FALSE);
	}
	_g_free0 (text);
}

static void
dc_contact_picker_dialog_on_activate_search (DcContactPickerDialog* self)
{
	gchar* text = NULL;
	GtkSearchEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	GListStore* _tmp4_;
	GtkListBoxRow* first = NULL;
	GtkListBox* _tmp20_;
	GtkListBoxRow* _tmp21_;
	GtkListBoxRow* _tmp22_;
	GtkListBoxRow* second = NULL;
	GtkListBox* _tmp23_;
	GtkListBoxRow* _tmp24_;
	GtkListBoxRow* _tmp25_;
	gboolean _tmp26_ = FALSE;
	GtkListBoxRow* _tmp27_;
	gboolean _tmp30_ = FALSE;
	const gchar* _tmp31_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->search_entry;
	_tmp1_ = gtk_editable_get_text ((GtkEditable*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = string_strip (_tmp2_);
	text = _tmp3_;
	_tmp4_ = self->priv->chat_store;
	if (_tmp4_ != NULL) {
		GtkListBoxRow* first_chat = NULL;
		GtkListBox* _tmp5_;
		GtkListBoxRow* _tmp6_;
		GtkListBoxRow* _tmp7_;
		GtkListBoxRow* second_chat = NULL;
		GtkListBox* _tmp8_;
		GtkListBoxRow* _tmp9_;
		GtkListBoxRow* _tmp10_;
		GtkListBoxRow* first_contact = NULL;
		GtkListBox* _tmp11_;
		GtkListBoxRow* _tmp12_;
		GtkListBoxRow* _tmp13_;
		gboolean _tmp14_ = FALSE;
		gboolean _tmp15_ = FALSE;
		GtkListBoxRow* _tmp16_;
		_tmp5_ = self->priv->chat_listbox;
		_tmp6_ = gtk_list_box_get_row_at_index (_tmp5_, 0);
		_tmp7_ = _g_object_ref0 (_tmp6_);
		first_chat = _tmp7_;
		_tmp8_ = self->priv->chat_listbox;
		_tmp9_ = gtk_list_box_get_row_at_index (_tmp8_, 1);
		_tmp10_ = _g_object_ref0 (_tmp9_);
		second_chat = _tmp10_;
		_tmp11_ = self->priv->contact_listbox;
		_tmp12_ = gtk_list_box_get_row_at_index (_tmp11_, 0);
		_tmp13_ = _g_object_ref0 (_tmp12_);
		first_contact = _tmp13_;
		_tmp16_ = first_chat;
		if (_tmp16_ != NULL) {
			GtkListBoxRow* _tmp17_;
			_tmp17_ = second_chat;
			_tmp15_ = _tmp17_ == NULL;
		} else {
			_tmp15_ = FALSE;
		}
		if (_tmp15_) {
			GtkListBoxRow* _tmp18_;
			_tmp18_ = first_contact;
			_tmp14_ = _tmp18_ == NULL;
		} else {
			_tmp14_ = FALSE;
		}
		if (_tmp14_) {
			GtkListBoxRow* _tmp19_;
			_tmp19_ = first_chat;
			dc_contact_picker_dialog_on_chat_row_activated (self, _tmp19_);
			_g_object_unref0 (first_contact);
			_g_object_unref0 (second_chat);
			_g_object_unref0 (first_chat);
			_g_free0 (text);
			return;
		}
		_g_object_unref0 (first_contact);
		_g_object_unref0 (second_chat);
		_g_object_unref0 (first_chat);
	}
	_tmp20_ = self->priv->contact_listbox;
	_tmp21_ = gtk_list_box_get_row_at_index (_tmp20_, 0);
	_tmp22_ = _g_object_ref0 (_tmp21_);
	first = _tmp22_;
	_tmp23_ = self->priv->contact_listbox;
	_tmp24_ = gtk_list_box_get_row_at_index (_tmp23_, 1);
	_tmp25_ = _g_object_ref0 (_tmp24_);
	second = _tmp25_;
	_tmp27_ = first;
	if (_tmp27_ != NULL) {
		GtkListBoxRow* _tmp28_;
		_tmp28_ = second;
		_tmp26_ = _tmp28_ == NULL;
	} else {
		_tmp26_ = FALSE;
	}
	if (_tmp26_) {
		GtkListBoxRow* _tmp29_;
		_tmp29_ = first;
		dc_contact_picker_dialog_on_contact_row_activated (self, _tmp29_);
		_g_object_unref0 (second);
		_g_object_unref0 (first);
		_g_free0 (text);
		return;
	}
	_tmp31_ = text;
	if (string_contains (_tmp31_, "@")) {
		const gchar* _tmp32_;
		gint _tmp33_;
		gint _tmp34_;
		_tmp32_ = text;
		_tmp33_ = strlen (_tmp32_);
		_tmp34_ = _tmp33_;
		_tmp30_ = _tmp34_ > 3;
	} else {
		_tmp30_ = FALSE;
	}
	if (_tmp30_) {
		dc_contact_picker_dialog_on_use_email (self);
	}
	_g_object_unref0 (second);
	_g_object_unref0 (first);
	_g_free0 (text);
}

static void
dc_contact_picker_dialog_on_contact_row_activated (DcContactPickerDialog* self,
                                                   GtkListBoxRow* row)
{
	AdwActionRow* action_row = NULL;
	AdwActionRow* _tmp0_;
	AdwActionRow* _tmp1_;
	const gchar* _tmp8_ = NULL;
	AdwActionRow* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	gchar* data = NULL;
	gchar* _tmp12_;
	gchar** parts = NULL;
	const gchar* _tmp13_;
	gchar** _tmp14_;
	gchar** _tmp15_;
	gint parts_length1;
	gint _parts_size_;
	gchar** _tmp16_;
	gint _tmp16__length1;
	gint contact_id = 0;
	gchar** _tmp17_;
	gint _tmp17__length1;
	const gchar* _tmp18_;
	gchar* email = NULL;
	gchar** _tmp19_;
	gint _tmp19__length1;
	const gchar* _tmp20_;
	gchar* _tmp21_;
	const gchar* _tmp22_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (row, adw_action_row_get_type ()) ? ((AdwActionRow*) row) : NULL);
	action_row = _tmp0_;
	_tmp1_ = action_row;
	if (_tmp1_ == NULL) {
		AdwActionRow* child = NULL;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp3_;
		AdwActionRow* _tmp4_;
		AdwActionRow* _tmp5_;
		_tmp2_ = gtk_list_box_row_get_child (row);
		_tmp3_ = _tmp2_;
		_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, adw_action_row_get_type ()) ? ((AdwActionRow*) _tmp3_) : NULL);
		child = _tmp4_;
		_tmp5_ = child;
		if (_tmp5_ != NULL) {
			AdwActionRow* _tmp6_;
			AdwActionRow* _tmp7_;
			_tmp6_ = child;
			_tmp7_ = _g_object_ref0 (_tmp6_);
			_g_object_unref0 (action_row);
			action_row = _tmp7_;
		} else {
			_g_object_unref0 (child);
			_g_object_unref0 (action_row);
			return;
		}
		_g_object_unref0 (child);
	}
	_tmp9_ = action_row;
	_tmp10_ = gtk_widget_get_name ((GtkWidget*) _tmp9_);
	_tmp11_ = _tmp10_;
	_tmp8_ = _tmp11_;
	if (_tmp8_ == NULL) {
		_tmp8_ = "";
	}
	_tmp12_ = g_strdup (_tmp8_);
	data = _tmp12_;
	_tmp13_ = data;
	_tmp15_ = _tmp14_ = g_strsplit (_tmp13_, "\n", 2);
	parts = _tmp15_;
	parts_length1 = _vala_array_length (_tmp14_);
	_parts_size_ = parts_length1;
	_tmp16_ = parts;
	_tmp16__length1 = parts_length1;
	if (_tmp16__length1 < 2) {
		parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (data);
		_g_object_unref0 (action_row);
		return;
	}
	_tmp17_ = parts;
	_tmp17__length1 = parts_length1;
	_tmp18_ = _tmp17_[0];
	contact_id = atoi (_tmp18_);
	_tmp19_ = parts;
	_tmp19__length1 = parts_length1;
	_tmp20_ = _tmp19_[1];
	_tmp21_ = g_strdup (_tmp20_);
	email = _tmp21_;
	_tmp22_ = email;
	g_signal_emit (self, dc_contact_picker_dialog_signals[DC_CONTACT_PICKER_DIALOG_CONTACT_PICKED_SIGNAL], 0, contact_id, _tmp22_);
	adw_dialog_close ((AdwDialog*) self);
	_g_free0 (email);
	parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (data);
	_g_object_unref0 (action_row);
}

static void
dc_contact_picker_dialog_on_chat_row_activated (DcContactPickerDialog* self,
                                                GtkListBoxRow* row)
{
	AdwActionRow* action_row = NULL;
	AdwActionRow* _tmp0_;
	AdwActionRow* _tmp1_;
	const gchar* _tmp8_ = NULL;
	AdwActionRow* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	gint chat_id = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (row, adw_action_row_get_type ()) ? ((AdwActionRow*) row) : NULL);
	action_row = _tmp0_;
	_tmp1_ = action_row;
	if (_tmp1_ == NULL) {
		AdwActionRow* child = NULL;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp3_;
		AdwActionRow* _tmp4_;
		AdwActionRow* _tmp5_;
		_tmp2_ = gtk_list_box_row_get_child (row);
		_tmp3_ = _tmp2_;
		_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, adw_action_row_get_type ()) ? ((AdwActionRow*) _tmp3_) : NULL);
		child = _tmp4_;
		_tmp5_ = child;
		if (_tmp5_ != NULL) {
			AdwActionRow* _tmp6_;
			AdwActionRow* _tmp7_;
			_tmp6_ = child;
			_tmp7_ = _g_object_ref0 (_tmp6_);
			_g_object_unref0 (action_row);
			action_row = _tmp7_;
		} else {
			_g_object_unref0 (child);
			_g_object_unref0 (action_row);
			return;
		}
		_g_object_unref0 (child);
	}
	_tmp9_ = action_row;
	_tmp10_ = gtk_widget_get_name ((GtkWidget*) _tmp9_);
	_tmp11_ = _tmp10_;
	_tmp8_ = _tmp11_;
	if (_tmp8_ == NULL) {
		_tmp8_ = "0";
	}
	chat_id = atoi (_tmp8_);
	if (chat_id <= 0) {
		_g_object_unref0 (action_row);
		return;
	}
	g_signal_emit (self, dc_contact_picker_dialog_signals[DC_CONTACT_PICKER_DIALOG_CHAT_PICKED_SIGNAL], 0, chat_id);
	adw_dialog_close ((AdwDialog*) self);
	_g_object_unref0 (action_row);
}

static void
dc_contact_picker_dialog_on_use_email (DcContactPickerDialog* self)
{
	gchar* email = NULL;
	GtkSearchEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gboolean _tmp4_ = FALSE;
	const gchar* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	const gchar* _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->search_entry;
	_tmp1_ = gtk_editable_get_text ((GtkEditable*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = string_strip (_tmp2_);
	email = _tmp3_;
	_tmp5_ = email;
	_tmp6_ = strlen (_tmp5_);
	_tmp7_ = _tmp6_;
	if (_tmp7_ == 0) {
		_tmp4_ = TRUE;
	} else {
		const gchar* _tmp8_;
		_tmp8_ = email;
		_tmp4_ = !string_contains (_tmp8_, "@");
	}
	if (_tmp4_) {
		_g_free0 (email);
		return;
	}
	_tmp9_ = email;
	g_signal_emit (self, dc_contact_picker_dialog_signals[DC_CONTACT_PICKER_DIALOG_CONTACT_PICKED_SIGNAL], 0, 0, _tmp9_);
	adw_dialog_close ((AdwDialog*) self);
	_g_free0 (email);
}

gint
dc_contact_picker_dialog_get_selected_account_id (DcContactPickerDialog* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = self->priv->_selected_account_id;
	return result;
}

static void
dc_contact_picker_dialog_set_selected_account_id (DcContactPickerDialog* self,
                                                  gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = dc_contact_picker_dialog_get_selected_account_id (self);
	if (old_value != value) {
		self->priv->_selected_account_id = value;
		g_object_notify_by_pspec ((GObject *) self, dc_contact_picker_dialog_properties[DC_CONTACT_PICKER_DIALOG_SELECTED_ACCOUNT_ID_PROPERTY]);
	}
}

static void
g_cclosure_user_marshal_VOID__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_STRING) (gpointer data1, gint arg_1, const char* arg_2, gpointer data2);
	register GMarshalFunc_VOID__INT_STRING 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_STRING) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_int (param_values + 1), g_value_get_string (param_values + 2), data2);
}

static void
dc_contact_picker_dialog_class_init (DcContactPickerDialogClass * klass,
                                     gpointer klass_data)
{
	dc_contact_picker_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DcContactPickerDialog_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dc_contact_picker_dialog_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_dc_contact_picker_dialog_set_property;
	G_OBJECT_CLASS (klass)->finalize = dc_contact_picker_dialog_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DC_CONTACT_PICKER_DIALOG_SELECTED_ACCOUNT_ID_PROPERTY, dc_contact_picker_dialog_properties[DC_CONTACT_PICKER_DIALOG_SELECTED_ACCOUNT_ID_PROPERTY] = g_param_spec_int ("selected-account-id", "selected-account-id", "selected-account-id", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	dc_contact_picker_dialog_signals[DC_CONTACT_PICKER_DIALOG_CONTACT_PICKED_SIGNAL] = g_signal_new ("contact-picked", DC_TYPE_CONTACT_PICKER_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT_STRING, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_STRING);
	dc_contact_picker_dialog_signals[DC_CONTACT_PICKER_DIALOG_CHAT_PICKED_SIGNAL] = g_signal_new ("chat-picked", DC_TYPE_CONTACT_PICKER_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
}

static void
dc_contact_picker_dialog_instance_init (DcContactPickerDialog * self,
                                        gpointer klass)
{
	GPtrArray* _tmp0_;
	gint* _tmp1_;
	GPtrArray* _tmp2_;
	self->priv = dc_contact_picker_dialog_get_instance_private (self);
	self->priv->_selected_account_id = 0;
	_tmp0_ = g_ptr_array_new_full ((guint) 0, _g_object_unref0_);
	self->priv->all_contacts = _tmp0_;
	self->priv->account_selector_enabled = FALSE;
	self->priv->account_dropdown = NULL;
	_tmp1_ = g_new0 (gint, 0);
	self->priv->account_ids = _tmp1_;
	self->priv->account_ids_length1 = 0;
	self->priv->_account_ids_size_ = self->priv->account_ids_length1;
	_tmp2_ = g_ptr_array_new_full ((guint) 0, _g_object_unref0_);
	self->priv->loaded_chats = _tmp2_;
	self->priv->chat_load_gen = (guint) 0;
	self->priv->contact_load_gen = (guint) 0;
}

static void
dc_contact_picker_dialog_finalize (GObject * obj)
{
	DcContactPickerDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_CONTACT_PICKER_DIALOG, DcContactPickerDialog);
	_g_object_unref0 (self->priv->rpc);
	_g_object_unref0 (self->priv->chat_store);
	_g_object_unref0 (self->priv->search_entry);
	_g_object_unref0 (self->priv->chat_listbox);
	_g_object_unref0 (self->priv->contact_listbox);
	_g_object_unref0 (self->priv->chats_header);
	_g_object_unref0 (self->priv->contacts_header);
	_g_object_unref0 (self->priv->use_email_btn);
	_g_ptr_array_unref0 (self->priv->all_contacts);
	_g_object_unref0 (self->priv->account_dropdown);
	self->priv->account_ids = (g_free (self->priv->account_ids), NULL);
	_g_ptr_array_unref0 (self->priv->loaded_chats);
	G_OBJECT_CLASS (dc_contact_picker_dialog_parent_class)->finalize (obj);
}

static GType
dc_contact_picker_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcContactPickerDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_contact_picker_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcContactPickerDialog), 0, (GInstanceInitFunc) dc_contact_picker_dialog_instance_init, NULL };
	GType dc_contact_picker_dialog_type_id;
	dc_contact_picker_dialog_type_id = g_type_register_static (adw_dialog_get_type (), "DcContactPickerDialog", &g_define_type_info, 0);
	DcContactPickerDialog_private_offset = g_type_add_instance_private (dc_contact_picker_dialog_type_id, sizeof (DcContactPickerDialogPrivate));
	return dc_contact_picker_dialog_type_id;
}

GType
dc_contact_picker_dialog_get_type (void)
{
	static volatile gsize dc_contact_picker_dialog_type_id__once = 0;
	if (g_once_init_enter (&dc_contact_picker_dialog_type_id__once)) {
		GType dc_contact_picker_dialog_type_id;
		dc_contact_picker_dialog_type_id = dc_contact_picker_dialog_get_type_once ();
		g_once_init_leave (&dc_contact_picker_dialog_type_id__once, dc_contact_picker_dialog_type_id);
	}
	return dc_contact_picker_dialog_type_id__once;
}

static void
_vala_dc_contact_picker_dialog_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec)
{
	DcContactPickerDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DC_TYPE_CONTACT_PICKER_DIALOG, DcContactPickerDialog);
	switch (property_id) {
		case DC_CONTACT_PICKER_DIALOG_SELECTED_ACCOUNT_ID_PROPERTY:
		g_value_set_int (value, dc_contact_picker_dialog_get_selected_account_id (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_dc_contact_picker_dialog_set_property (GObject * object,
                                             guint property_id,
                                             const GValue * value,
                                             GParamSpec * pspec)
{
	DcContactPickerDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DC_TYPE_CONTACT_PICKER_DIALOG, DcContactPickerDialog);
	switch (property_id) {
		case DC_CONTACT_PICKER_DIALOG_SELECTED_ACCOUNT_ID_PROPERTY:
		dc_contact_picker_dialog_set_selected_account_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 gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

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

