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

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

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define DC_TYPE_PINNED_MESSAGES_MANAGER (dc_pinned_messages_manager_get_type ())
#define DC_PINNED_MESSAGES_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_PINNED_MESSAGES_MANAGER, DcPinnedMessagesManager))
#define DC_PINNED_MESSAGES_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_PINNED_MESSAGES_MANAGER, DcPinnedMessagesManagerClass))
#define DC_IS_PINNED_MESSAGES_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_PINNED_MESSAGES_MANAGER))
#define DC_IS_PINNED_MESSAGES_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_PINNED_MESSAGES_MANAGER))
#define DC_PINNED_MESSAGES_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_PINNED_MESSAGES_MANAGER, DcPinnedMessagesManagerClass))

typedef struct _DcPinnedMessagesManager DcPinnedMessagesManager;
typedef struct _DcPinnedMessagesManagerClass DcPinnedMessagesManagerClass;
typedef struct _DcPinnedMessagesManagerPrivate DcPinnedMessagesManagerPrivate;

#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_SETTINGS_MANAGER (dc_settings_manager_get_type ())
#define DC_SETTINGS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_SETTINGS_MANAGER, DcSettingsManager))
#define DC_SETTINGS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_SETTINGS_MANAGER, DcSettingsManagerClass))
#define DC_IS_SETTINGS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_SETTINGS_MANAGER))
#define DC_IS_SETTINGS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_SETTINGS_MANAGER))
#define DC_SETTINGS_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_SETTINGS_MANAGER, DcSettingsManagerClass))

typedef struct _DcSettingsManager DcSettingsManager;
typedef struct _DcSettingsManagerClass DcSettingsManagerClass;
enum  {
	DC_PINNED_MESSAGES_MANAGER_0_PROPERTY,
	DC_PINNED_MESSAGES_MANAGER_REVEALER_PROPERTY,
	DC_PINNED_MESSAGES_MANAGER_NUM_PROPERTIES
};
static GParamSpec* dc_pinned_messages_manager_properties[DC_PINNED_MESSAGES_MANAGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _DcPinnedMessagesManagerLoadForChatData DcPinnedMessagesManagerLoadForChatData;

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

typedef struct _DcMessage DcMessage;
typedef struct _DcMessageClass DcMessageClass;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _DcPinnedMessagesManagerTogglePinData DcPinnedMessagesManagerTogglePinData;
typedef struct _Block77Data Block77Data;
typedef struct _DcPinnedMessagesManagerUpdateBarData DcPinnedMessagesManagerUpdateBarData;
#define _g_key_file_unref0(var) ((var == NULL) ? NULL : (var = (g_key_file_unref (var), NULL)))
typedef struct _Block78Data Block78Data;
typedef void (*DcSettingWriter) (GKeyFile* kf, gpointer user_data);
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
enum  {
	DC_PINNED_MESSAGES_MANAGER_SCROLL_REQUESTED_SIGNAL,
	DC_PINNED_MESSAGES_MANAGER_OPERATION_FAILED_SIGNAL,
	DC_PINNED_MESSAGES_MANAGER_NUM_SIGNALS
};
static guint dc_pinned_messages_manager_signals[DC_PINNED_MESSAGES_MANAGER_NUM_SIGNALS] = {0};

struct _DcPinnedMessagesManager {
	GObject parent_instance;
	DcPinnedMessagesManagerPrivate * priv;
};

struct _DcPinnedMessagesManagerClass {
	GObjectClass parent_class;
};

struct _DcPinnedMessagesManagerPrivate {
	GtkRevealer* _revealer;
	DcRpcClient* rpc;
	GtkBox* bar_content;
	gint* msg_ids;
	gint msg_ids_length1;
	gint _msg_ids_size_;
	gint current_chat_id;
	GListStore* message_store;
	DcSettingsManager* settings;
	gboolean rpc_available;
	guint load_generation;
	guint bar_generation;
};

struct _DcPinnedMessagesManagerLoadForChatData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcPinnedMessagesManager* self;
	gint chat_id;
	guint generation;
	guint _tmp0_;
	DcRpcClient* _tmp1_;
	gint* _tmp2_;
	gint* loaded_ids;
	DcRpcClient* _tmp3_;
	gint _tmp4_;
	gint* _tmp5_;
	gint loaded_ids_length1;
	gint _loaded_ids_size_;
	gboolean _tmp6_;
	gint* _tmp7_;
	gint _tmp7__length1;
	gint* _tmp8_;
	gint _tmp8__length1;
	GError* e;
	GError* _tmp9_;
	GError* _tmp10_;
	const gchar* _tmp11_;
	GError* _inner_error0_;
};

struct _DcPinnedMessagesManagerTogglePinData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcPinnedMessagesManager* self;
	gint msg_id;
	DcRpcClient* _tmp0_;
	DcMessage* loaded_message;
	GListStore* _tmp1_;
	DcMessage* _tmp2_;
	gboolean _tmp3_;
	DcMessage* _tmp4_;
	DcMessage* _tmp5_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	gboolean current_state;
	gboolean new_state;
	DcRpcClient* _tmp8_;
	GError* e;
	GError* _tmp9_;
	GError* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	GError* _inner_error0_;
};

struct _Block77Data {
	int _ref_count_;
	DcPinnedMessagesManager* self;
	gint captured_id;
};

struct _DcPinnedMessagesManagerUpdateBarData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcPinnedMessagesManager* self;
	guint generation;
	guint _tmp0_;
	GtkBox* next_content;
	GtkBox* _tmp1_;
	GtkBox* _tmp2_;
	gint* _tmp3_;
	gint _tmp3__length1;
	GtkBox* _tmp4_;
	GtkBox* _tmp5_;
	GtkRevealer* _tmp6_;
	GtkBox* _tmp7_;
	GtkRevealer* _tmp8_;
	gint* displayed_ids;
	gint* _tmp9_;
	gint _tmp9__length1;
	gint* _tmp10_;
	gint _tmp10__length1;
	gint displayed_ids_length1;
	gint _displayed_ids_size_;
	gint* _tmp11_;
	gint _tmp11__length1;
	gint* pin_id_collection;
	gint pin_id_collection_length1;
	gint _pin_id_collection_size_;
	gint pin_id_it;
	gint pin_id;
	Block77Data* _data77_;
	gchar* text;
	gchar* sender;
	DcMessage* m;
	GListStore* _tmp12_;
	DcMessage* _tmp13_;
	DcMessage* _tmp14_;
	DcMessage* _tmp15_;
	const gchar* _tmp16_;
	const gchar* _tmp17_;
	gchar* _tmp18_;
	const gchar* _tmp19_;
	DcMessage* _tmp20_;
	gboolean _tmp21_;
	gboolean _tmp22_;
	const gchar* _tmp23_;
	DcMessage* _tmp24_;
	const gchar* _tmp25_;
	const gchar* _tmp26_;
	gchar* _tmp27_;
	gboolean _tmp28_;
	gboolean _tmp29_;
	const gchar* _tmp30_;
	const gchar* _tmp31_;
	DcRpcClient* _tmp32_;
	DcMessage* fetched;
	DcRpcClient* _tmp33_;
	DcMessage* _tmp34_;
	DcMessage* _tmp35_;
	DcMessage* _tmp36_;
	const gchar* _tmp37_;
	const gchar* _tmp38_;
	gchar* _tmp39_;
	const gchar* _tmp40_;
	DcMessage* _tmp41_;
	gboolean _tmp42_;
	gboolean _tmp43_;
	const gchar* _tmp44_;
	DcMessage* _tmp45_;
	const gchar* _tmp46_;
	const gchar* _tmp47_;
	gchar* _tmp48_;
	gboolean _tmp49_;
	const gchar* _tmp50_;
	const gchar* _tmp51_;
	GtkButton* row_btn;
	GtkButton* _tmp52_;
	GtkButton* _tmp53_;
	GtkBox* row_box;
	GtkBox* _tmp54_;
	GtkLabel* pin_icon;
	GtkLabel* _tmp55_;
	GtkBox* _tmp56_;
	GtkLabel* _tmp57_;
	GtkBox* text_box;
	GtkBox* _tmp58_;
	GtkBox* _tmp59_;
	gboolean _tmp60_;
	const gchar* _tmp61_;
	const gchar* _tmp62_;
	gint _tmp63_;
	gint _tmp64_;
	GtkLabel* sender_lbl;
	const gchar* _tmp65_;
	GtkLabel* _tmp66_;
	GtkLabel* _tmp67_;
	GtkLabel* _tmp68_;
	GtkLabel* _tmp69_;
	GtkBox* _tmp70_;
	GtkLabel* _tmp71_;
	const gchar* _tmp72_;
	const gchar* _tmp73_;
	GtkLabel* text_lbl;
	GtkLabel* _tmp74_;
	GtkLabel* _tmp75_;
	GtkLabel* _tmp76_;
	GtkLabel* _tmp77_;
	GtkLabel* _tmp78_;
	GtkBox* _tmp79_;
	GtkLabel* _tmp80_;
	GtkBox* _tmp81_;
	GtkBox* _tmp82_;
	GtkButton* _tmp83_;
	GtkBox* _tmp84_;
	GtkButton* _tmp85_;
	GtkBox* outer;
	GtkBox* _tmp86_;
	GtkBox* _tmp87_;
	GtkButton* _tmp88_;
	GtkButton* _tmp89_;
	GtkButton* unpin_btn;
	GtkButton* _tmp90_;
	GtkButton* _tmp91_;
	GtkButton* _tmp92_;
	GtkButton* _tmp93_;
	GtkButton* _tmp94_;
	GtkButton* _tmp95_;
	GtkBox* _tmp96_;
	GtkButton* _tmp97_;
	GtkBox* _tmp98_;
	GtkBox* _tmp99_;
	GtkBox* _tmp100_;
	GtkBox* _tmp101_;
	GtkRevealer* _tmp102_;
	GtkBox* _tmp103_;
	GtkRevealer* _tmp104_;
	GtkBox* _tmp105_;
	GtkWidget* _tmp106_;
	GError* _inner_error0_;
};

struct _Block78Data {
	int _ref_count_;
	DcPinnedMessagesManager* self;
	gchar* key;
	gint* ids;
	gint ids_length1;
};

static gint DcPinnedMessagesManager_private_offset;
static gpointer dc_pinned_messages_manager_parent_class = NULL;

VALA_EXTERN GType dc_pinned_messages_manager_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcPinnedMessagesManager, 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_settings_manager_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcSettingsManager, g_object_unref)
VALA_EXTERN DcPinnedMessagesManager* dc_pinned_messages_manager_new (GListStore* message_store,
                                                         DcSettingsManager* settings);
VALA_EXTERN DcPinnedMessagesManager* dc_pinned_messages_manager_construct (GType object_type,
                                                               GListStore* message_store,
                                                               DcSettingsManager* settings);
static void dc_pinned_messages_manager_set_revealer (DcPinnedMessagesManager* self,
                                              GtkRevealer* value);
VALA_EXTERN GtkRevealer* dc_pinned_messages_manager_get_revealer (DcPinnedMessagesManager* self);
VALA_EXTERN void dc_pinned_messages_manager_set_rpc (DcPinnedMessagesManager* self,
                                         DcRpcClient* r);
static void dc_pinned_messages_manager_load_for_chat_data_free (gpointer _data);
VALA_EXTERN void dc_pinned_messages_manager_load_for_chat (DcPinnedMessagesManager* self,
                                               gint chat_id,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_);
VALA_EXTERN void dc_pinned_messages_manager_load_for_chat_finish (DcPinnedMessagesManager* self,
                                                      GAsyncResult* _res_);
static gboolean dc_pinned_messages_manager_load_for_chat_co (DcPinnedMessagesManagerLoadForChatData* _data_);
static void dc_pinned_messages_manager_load_local_for_chat (DcPinnedMessagesManager* self,
                                                     gint chat_id);
static void dc_pinned_messages_manager_sync_store_state (DcPinnedMessagesManager* self);
VALA_EXTERN void dc_rpc_client_get_pinned_messages (DcRpcClient* self,
                                        gint chat_id,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_);
VALA_EXTERN gint* dc_rpc_client_get_pinned_messages_finish (DcRpcClient* self,
                                                GAsyncResult* _res_,
                                                gint* result_length1,
                                                GError** error);
static void dc_pinned_messages_manager_load_for_chat_ready (GObject* source_object,
                                                     GAsyncResult* _res_,
                                                     gpointer _user_data_);
static gint* _vala_array_dup18 (gint* self,
                         gssize length);
static gboolean dc_pinned_messages_manager_is_missing_pin_rpc (GError* e);
VALA_EXTERN gboolean dc_pinned_messages_manager_is_pinned (DcPinnedMessagesManager* self,
                                               gint msg_id);
static void dc_pinned_messages_manager_toggle_pin_data_free (gpointer _data);
VALA_EXTERN void dc_pinned_messages_manager_toggle_pin (DcPinnedMessagesManager* self,
                                            gint msg_id,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_);
VALA_EXTERN void dc_pinned_messages_manager_toggle_pin_finish (DcPinnedMessagesManager* self,
                                                   GAsyncResult* _res_);
static gboolean dc_pinned_messages_manager_toggle_pin_co (DcPinnedMessagesManagerTogglePinData* _data_);
static void dc_pinned_messages_manager_toggle_local_pin (DcPinnedMessagesManager* self,
                                                  gint msg_id);
VALA_EXTERN void dc_pinned_messages_manager_update_bar (DcPinnedMessagesManager* self,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_);
VALA_EXTERN void dc_pinned_messages_manager_update_bar_finish (DcPinnedMessagesManager* self,
                                                   GAsyncResult* _res_);
static void dc_pinned_messages_manager_toggle_pin_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_);
VALA_EXTERN GType dc_message_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcMessage, g_object_unref)
VALA_EXTERN DcMessage* dc_find_message (GListModel* store,
                            gint msg_id);
VALA_EXTERN gboolean dc_message_get_is_pinned (DcMessage* self);
VALA_EXTERN void dc_rpc_client_set_pinned_message_state (DcRpcClient* self,
                                             gint msg_id,
                                             gboolean pinned,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
VALA_EXTERN void dc_rpc_client_set_pinned_message_state_finish (DcRpcClient* self,
                                                    GAsyncResult* _res_,
                                                    GError** error);
static void dc_pinned_messages_manager_set_cached_state (DcPinnedMessagesManager* self,
                                                  gint msg_id,
                                                  gboolean pinned);
static void dc_pinned_messages_manager_update_message_state (DcPinnedMessagesManager* self,
                                                      gint msg_id,
                                                      gboolean pinned);
static void dc_pinned_messages_manager_update_bar_data_free (gpointer _data);
static gboolean dc_pinned_messages_manager_update_bar_co (DcPinnedMessagesManagerUpdateBarData* _data_);
static gint* _vala_array_dup19 (gint* self,
                         gssize length);
static Block77Data* block77_data_ref (Block77Data* _data77_);
static void block77_data_unref (void * _userdata_);
VALA_EXTERN const gchar* dc_message_get_text (DcMessage* self);
VALA_EXTERN gboolean dc_message_get_is_outgoing (DcMessage* self);
VALA_EXTERN const gchar* dc_message_get_sender_name (DcMessage* self);
VALA_EXTERN void dc_rpc_client_fetch_message (DcRpcClient* self,
                                  gint msg_id,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_);
VALA_EXTERN DcMessage* dc_rpc_client_fetch_message_finish (DcRpcClient* self,
                                               GAsyncResult* _res_,
                                               GError** error);
static void dc_pinned_messages_manager_update_bar_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_);
static void ____lambda54_ (Block77Data* _data77_);
static void _____lambda54__gtk_button_clicked (GtkButton* _sender,
                                        gpointer self);
static void ____lambda55_ (Block77Data* _data77_);
static void _____lambda55__gtk_button_clicked (GtkButton* _sender,
                                        gpointer self);
static void _vala_array_add50 (gint* * array,
                        gint* length,
                        gint* size,
                        gint value);
static void _vala_array_add51 (gint* * array,
                        gint* length,
                        gint* size,
                        gint value);
static gint* _vala_array_dup20 (gint* self,
                         gssize length);
static void dc_pinned_messages_manager_save_local_for_chat (DcPinnedMessagesManager* self,
                                                     gint chat_id,
                                                     gint* ids,
                                                     gint ids_length1);
VALA_EXTERN gchar* dc_settings_manager_get_config_path (void);
static void _vala_array_add52 (gint* * array,
                        gint* length,
                        gint* size,
                        gint value);
static Block78Data* block78_data_ref (Block78Data* _data78_);
static void block78_data_unref (void * _userdata_);
VALA_EXTERN void dc_settings_manager_save_to_file (DcSettingsManager* self,
                                       DcSettingWriter writer,
                                       gpointer writer_target);
static void __lambda53_ (Block78Data* _data78_,
                  GKeyFile* kf);
static void ___lambda53__dc_setting_writer (GKeyFile* kf,
                                     gpointer self);
VALA_EXTERN gint dc_message_get_id (DcMessage* self);
VALA_EXTERN void dc_message_set_is_pinned (DcMessage* self,
                               gboolean value);
static void dc_pinned_messages_manager_finalize (GObject * obj);
static GType dc_pinned_messages_manager_get_type_once (void);
static void _vala_dc_pinned_messages_manager_get_property (GObject * object,
                                                    guint property_id,
                                                    GValue * value,
                                                    GParamSpec * pspec);
static void _vala_dc_pinned_messages_manager_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_pinned_messages_manager_get_instance_private (DcPinnedMessagesManager* self)
{
	return G_STRUCT_MEMBER_P (self, DcPinnedMessagesManager_private_offset);
}

DcPinnedMessagesManager*
dc_pinned_messages_manager_construct (GType object_type,
                                      GListStore* message_store,
                                      DcSettingsManager* settings)
{
	DcPinnedMessagesManager * self = NULL;
	GtkBox* _tmp0_;
	GtkBox* _tmp1_;
	GtkRevealer* _tmp2_;
	GtkRevealer* _tmp3_;
	GtkRevealer* _tmp4_;
	GtkBox* _tmp5_;
	GtkRevealer* _tmp6_;
	GtkRevealer* _tmp7_;
	g_return_val_if_fail (message_store != NULL, NULL);
	g_return_val_if_fail (settings != NULL, NULL);
	self = (DcPinnedMessagesManager*) g_object_new (object_type, NULL);
	self->priv->message_store = message_store;
	self->priv->settings = settings;
	_tmp0_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->bar_content);
	self->priv->bar_content = _tmp0_;
	_tmp1_ = self->priv->bar_content;
	gtk_widget_add_css_class ((GtkWidget*) _tmp1_, "pinned-bar");
	_tmp2_ = (GtkRevealer*) gtk_revealer_new ();
	g_object_ref_sink (_tmp2_);
	_tmp3_ = _tmp2_;
	dc_pinned_messages_manager_set_revealer (self, _tmp3_);
	_g_object_unref0 (_tmp3_);
	_tmp4_ = self->priv->_revealer;
	_tmp5_ = self->priv->bar_content;
	gtk_revealer_set_child (_tmp4_, (GtkWidget*) _tmp5_);
	_tmp6_ = self->priv->_revealer;
	gtk_revealer_set_reveal_child (_tmp6_, FALSE);
	_tmp7_ = self->priv->_revealer;
	gtk_revealer_set_transition_type (_tmp7_, GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
	return self;
}

DcPinnedMessagesManager*
dc_pinned_messages_manager_new (GListStore* message_store,
                                DcSettingsManager* settings)
{
	return dc_pinned_messages_manager_construct (DC_TYPE_PINNED_MESSAGES_MANAGER, message_store, settings);
}

void
dc_pinned_messages_manager_set_rpc (DcPinnedMessagesManager* self,
                                    DcRpcClient* r)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (r != NULL);
	self->priv->rpc = r;
}

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

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

void
dc_pinned_messages_manager_load_for_chat (DcPinnedMessagesManager* self,
                                          gint chat_id,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_)
{
	DcPinnedMessagesManagerLoadForChatData* _data_;
	DcPinnedMessagesManager* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcPinnedMessagesManagerLoadForChatData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_pinned_messages_manager_load_for_chat_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->chat_id = chat_id;
	dc_pinned_messages_manager_load_for_chat_co (_data_);
}

void
dc_pinned_messages_manager_load_for_chat_finish (DcPinnedMessagesManager* self,
                                                 GAsyncResult* _res_)
{
	DcPinnedMessagesManagerLoadForChatData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dc_pinned_messages_manager_load_for_chat_ready (GObject* source_object,
                                                GAsyncResult* _res_,
                                                gpointer _user_data_)
{
	DcPinnedMessagesManagerLoadForChatData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_pinned_messages_manager_load_for_chat_co (_data_);
}

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

static gboolean
dc_pinned_messages_manager_load_for_chat_co (DcPinnedMessagesManagerLoadForChatData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->self->priv->current_chat_id = _data_->chat_id;
	_data_->self->priv->load_generation = _data_->self->priv->load_generation + 1;
	_data_->_tmp0_ = _data_->self->priv->load_generation;
	_data_->generation = _data_->_tmp0_;
	if (!_data_->self->priv->rpc_available) {
		dc_pinned_messages_manager_load_local_for_chat (_data_->self, _data_->chat_id);
		dc_pinned_messages_manager_sync_store_state (_data_->self);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = _data_->self->priv->rpc;
	if (_data_->_tmp1_ == NULL) {
		_data_->_tmp2_ = g_new0 (gint, 0);
		_data_->self->priv->msg_ids = (g_free (_data_->self->priv->msg_ids), NULL);
		_data_->self->priv->msg_ids = _data_->_tmp2_;
		_data_->self->priv->msg_ids_length1 = 0;
		_data_->self->priv->_msg_ids_size_ = _data_->self->priv->msg_ids_length1;
		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_->_tmp3_ = _data_->self->priv->rpc;
		_data_->_tmp4_ = 0;
		_data_->_state_ = 1;
		dc_rpc_client_get_pinned_messages (_data_->_tmp3_, _data_->chat_id, dc_pinned_messages_manager_load_for_chat_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp5_ = dc_rpc_client_get_pinned_messages_finish (_data_->_tmp3_, _data_->_res_, &_data_->_tmp4_, &_data_->_inner_error0_);
		_data_->loaded_ids = _data_->_tmp5_;
		_data_->loaded_ids_length1 = _data_->_tmp4_;
		_data_->_loaded_ids_size_ = _data_->loaded_ids_length1;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		if (_data_->generation != _data_->self->priv->load_generation) {
			_data_->_tmp6_ = TRUE;
		} else {
			_data_->_tmp6_ = _data_->chat_id != _data_->self->priv->current_chat_id;
		}
		if (_data_->_tmp6_) {
			_data_->loaded_ids = (g_free (_data_->loaded_ids), 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_->_tmp7_ = _data_->loaded_ids;
		_data_->_tmp7__length1 = _data_->loaded_ids_length1;
		_data_->_tmp8_ = (_data_->_tmp7_ != NULL) ? _vala_array_dup18 (_data_->_tmp7_, _data_->_tmp7__length1) : _data_->_tmp7_;
		_data_->_tmp8__length1 = _data_->_tmp7__length1;
		_data_->self->priv->msg_ids = (g_free (_data_->self->priv->msg_ids), NULL);
		_data_->self->priv->msg_ids = _data_->_tmp8_;
		_data_->self->priv->msg_ids_length1 = _data_->_tmp8__length1;
		_data_->self->priv->_msg_ids_size_ = _data_->self->priv->msg_ids_length1;
		dc_pinned_messages_manager_sync_store_state (_data_->self);
		_data_->loaded_ids = (g_free (_data_->loaded_ids), NULL);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		if (_data_->generation != _data_->self->priv->load_generation) {
			_g_error_free0 (_data_->e);
			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_->_tmp9_ = _data_->e;
		if (dc_pinned_messages_manager_is_missing_pin_rpc (_data_->_tmp9_)) {
			_data_->self->priv->rpc_available = FALSE;
			dc_pinned_messages_manager_load_local_for_chat (_data_->self, _data_->chat_id);
			dc_pinned_messages_manager_sync_store_state (_data_->self);
		} else {
			_data_->_tmp10_ = _data_->e;
			_data_->_tmp11_ = _data_->_tmp10_->message;
			g_warning ("pinned_messages_manager.vala:62: load pinned messages: %s", _data_->_tmp11_);
		}
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

gboolean
dc_pinned_messages_manager_is_pinned (DcPinnedMessagesManager* self,
                                      gint msg_id)
{
	gint* _tmp0_;
	gint _tmp0__length1;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->msg_ids;
	_tmp0__length1 = self->priv->msg_ids_length1;
	{
		gint* id_collection = NULL;
		gint id_collection_length1 = 0;
		gint _id_collection_size_ = 0;
		gint id_it = 0;
		id_collection = _tmp0_;
		id_collection_length1 = _tmp0__length1;
		for (id_it = 0; id_it < id_collection_length1; id_it = id_it + 1) {
			gint id = 0;
			id = id_collection[id_it];
			{
				if (id == msg_id) {
					result = TRUE;
					return result;
				}
			}
		}
	}
	result = FALSE;
	return result;
}

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

void
dc_pinned_messages_manager_toggle_pin (DcPinnedMessagesManager* self,
                                       gint msg_id,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_)
{
	DcPinnedMessagesManagerTogglePinData* _data_;
	DcPinnedMessagesManager* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcPinnedMessagesManagerTogglePinData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_pinned_messages_manager_toggle_pin_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->msg_id = msg_id;
	dc_pinned_messages_manager_toggle_pin_co (_data_);
}

void
dc_pinned_messages_manager_toggle_pin_finish (DcPinnedMessagesManager* self,
                                              GAsyncResult* _res_)
{
	DcPinnedMessagesManagerTogglePinData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dc_pinned_messages_manager_toggle_pin_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_)
{
	DcPinnedMessagesManagerTogglePinData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_pinned_messages_manager_toggle_pin_co (_data_);
}

static gboolean
dc_pinned_messages_manager_toggle_pin_co (DcPinnedMessagesManagerTogglePinData* _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;
		case 5:
		goto _state_5;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (!_data_->self->priv->rpc_available) {
		dc_pinned_messages_manager_toggle_local_pin (_data_->self, _data_->msg_id);
		_data_->_state_ = 1;
		dc_pinned_messages_manager_update_bar (_data_->self, dc_pinned_messages_manager_toggle_pin_ready, _data_);
		return FALSE;
		_state_1:
		dc_pinned_messages_manager_update_bar_finish (_data_->self, _data_->_res_);
		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_->_tmp0_ = _data_->self->priv->rpc;
	if (_data_->_tmp0_ == NULL) {
		g_signal_emit (_data_->self, dc_pinned_messages_manager_signals[DC_PINNED_MESSAGES_MANAGER_OPERATION_FAILED_SIGNAL], 0, "Failed to update pin: RPC is not connected");
		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->message_store;
	_data_->_tmp2_ = dc_find_message ((GListModel*) _data_->_tmp1_, _data_->msg_id);
	_data_->loaded_message = _data_->_tmp2_;
	_data_->_tmp4_ = _data_->loaded_message;
	if (_data_->_tmp4_ != NULL) {
		_data_->_tmp5_ = _data_->loaded_message;
		_data_->_tmp6_ = dc_message_get_is_pinned (_data_->_tmp5_);
		_data_->_tmp7_ = _data_->_tmp6_;
		_data_->_tmp3_ = _data_->_tmp7_;
	} else {
		_data_->_tmp3_ = dc_pinned_messages_manager_is_pinned (_data_->self, _data_->msg_id);
	}
	_data_->current_state = _data_->_tmp3_;
	_data_->new_state = !_data_->current_state;
	{
		_data_->_tmp8_ = _data_->self->priv->rpc;
		_data_->_state_ = 2;
		dc_rpc_client_set_pinned_message_state (_data_->_tmp8_, _data_->msg_id, _data_->new_state, dc_pinned_messages_manager_toggle_pin_ready, _data_);
		return FALSE;
		_state_2:
		dc_rpc_client_set_pinned_message_state_finish (_data_->_tmp8_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		dc_pinned_messages_manager_set_cached_state (_data_->self, _data_->msg_id, _data_->new_state);
		dc_pinned_messages_manager_update_message_state (_data_->self, _data_->msg_id, _data_->new_state);
		_data_->_state_ = 3;
		dc_pinned_messages_manager_load_for_chat (_data_->self, _data_->self->priv->current_chat_id, dc_pinned_messages_manager_toggle_pin_ready, _data_);
		return FALSE;
		_state_3:
		dc_pinned_messages_manager_load_for_chat_finish (_data_->self, _data_->_res_);
		_data_->_state_ = 4;
		dc_pinned_messages_manager_update_bar (_data_->self, dc_pinned_messages_manager_toggle_pin_ready, _data_);
		return FALSE;
		_state_4:
		dc_pinned_messages_manager_update_bar_finish (_data_->self, _data_->_res_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp9_ = _data_->e;
		if (dc_pinned_messages_manager_is_missing_pin_rpc (_data_->_tmp9_)) {
			_data_->self->priv->rpc_available = FALSE;
			dc_pinned_messages_manager_toggle_local_pin (_data_->self, _data_->msg_id);
			_data_->_state_ = 5;
			dc_pinned_messages_manager_update_bar (_data_->self, dc_pinned_messages_manager_toggle_pin_ready, _data_);
			return FALSE;
			_state_5:
			dc_pinned_messages_manager_update_bar_finish (_data_->self, _data_->_res_);
		} else {
			_data_->_tmp10_ = _data_->e;
			_data_->_tmp11_ = _data_->_tmp10_->message;
			_data_->_tmp12_ = g_strconcat ("Failed to update pin: ", _data_->_tmp11_, NULL);
			_data_->_tmp13_ = _data_->_tmp12_;
			g_signal_emit (_data_->self, dc_pinned_messages_manager_signals[DC_PINNED_MESSAGES_MANAGER_OPERATION_FAILED_SIGNAL], 0, _data_->_tmp13_);
			_g_free0 (_data_->_tmp13_);
		}
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->loaded_message);
		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_object_unref0 (_data_->loaded_message);
	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_pinned_messages_manager_update_bar_data_free (gpointer _data)
{
	DcPinnedMessagesManagerUpdateBarData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (DcPinnedMessagesManagerUpdateBarData, _data_);
}

void
dc_pinned_messages_manager_update_bar (DcPinnedMessagesManager* self,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_)
{
	DcPinnedMessagesManagerUpdateBarData* _data_;
	DcPinnedMessagesManager* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcPinnedMessagesManagerUpdateBarData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_pinned_messages_manager_update_bar_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	dc_pinned_messages_manager_update_bar_co (_data_);
}

void
dc_pinned_messages_manager_update_bar_finish (DcPinnedMessagesManager* self,
                                              GAsyncResult* _res_)
{
	DcPinnedMessagesManagerUpdateBarData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

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

static Block77Data*
block77_data_ref (Block77Data* _data77_)
{
	g_atomic_int_inc (&_data77_->_ref_count_);
	return _data77_;
}

static void
block77_data_unref (void * _userdata_)
{
	Block77Data* _data77_;
	_data77_ = (Block77Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data77_->_ref_count_)) {
		DcPinnedMessagesManager* self;
		self = _data77_->self;
		_g_object_unref0 (self);
		g_slice_free (Block77Data, _data77_);
	}
}

static void
dc_pinned_messages_manager_update_bar_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_)
{
	DcPinnedMessagesManagerUpdateBarData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_pinned_messages_manager_update_bar_co (_data_);
}

static void
____lambda54_ (Block77Data* _data77_)
{
	DcPinnedMessagesManager* self;
	self = _data77_->self;
	g_signal_emit (self, dc_pinned_messages_manager_signals[DC_PINNED_MESSAGES_MANAGER_SCROLL_REQUESTED_SIGNAL], 0, _data77_->captured_id);
}

static void
_____lambda54__gtk_button_clicked (GtkButton* _sender,
                                   gpointer self)
{
	____lambda54_ (self);
}

static void
____lambda55_ (Block77Data* _data77_)
{
	DcPinnedMessagesManager* self;
	self = _data77_->self;
	dc_pinned_messages_manager_toggle_pin (self, _data77_->captured_id, NULL, NULL);
}

static void
_____lambda55__gtk_button_clicked (GtkButton* _sender,
                                   gpointer self)
{
	____lambda55_ (self);
}

static gboolean
dc_pinned_messages_manager_update_bar_co (DcPinnedMessagesManagerUpdateBarData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->self->priv->bar_generation = _data_->self->priv->bar_generation + 1;
	_data_->_tmp0_ = _data_->self->priv->bar_generation;
	_data_->generation = _data_->_tmp0_;
	_data_->_tmp1_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_data_->_tmp1_);
	_data_->next_content = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->next_content;
	gtk_widget_add_css_class ((GtkWidget*) _data_->_tmp2_, "pinned-bar");
	_data_->_tmp3_ = _data_->self->priv->msg_ids;
	_data_->_tmp3__length1 = _data_->self->priv->msg_ids_length1;
	if (_data_->_tmp3__length1 == 0) {
		if (_data_->generation != _data_->self->priv->bar_generation) {
			_g_object_unref0 (_data_->next_content);
			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_->_tmp4_ = _data_->next_content;
		_data_->_tmp5_ = _g_object_ref0 (_data_->_tmp4_);
		_g_object_unref0 (_data_->self->priv->bar_content);
		_data_->self->priv->bar_content = _data_->_tmp5_;
		_data_->_tmp6_ = _data_->self->priv->_revealer;
		_data_->_tmp7_ = _data_->self->priv->bar_content;
		gtk_revealer_set_child (_data_->_tmp6_, (GtkWidget*) _data_->_tmp7_);
		_data_->_tmp8_ = _data_->self->priv->_revealer;
		gtk_revealer_set_reveal_child (_data_->_tmp8_, FALSE);
		_g_object_unref0 (_data_->next_content);
		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_->_tmp9_ = _data_->self->priv->msg_ids;
	_data_->_tmp9__length1 = _data_->self->priv->msg_ids_length1;
	_data_->_tmp10_ = (_data_->_tmp9_ != NULL) ? _vala_array_dup19 (_data_->_tmp9_, _data_->_tmp9__length1) : _data_->_tmp9_;
	_data_->_tmp10__length1 = _data_->_tmp9__length1;
	_data_->displayed_ids = _data_->_tmp10_;
	_data_->displayed_ids_length1 = _data_->_tmp10__length1;
	_data_->_displayed_ids_size_ = _data_->displayed_ids_length1;
	_data_->_tmp11_ = _data_->displayed_ids;
	_data_->_tmp11__length1 = _data_->displayed_ids_length1;
	{
		_data_->pin_id_collection_length1 = 0;
		_data_->_pin_id_collection_size_ = 0;
		_data_->pin_id_collection = _data_->_tmp11_;
		_data_->pin_id_collection_length1 = _data_->_tmp11__length1;
		for (_data_->pin_id_it = 0; _data_->pin_id_it < _data_->pin_id_collection_length1; _data_->pin_id_it = _data_->pin_id_it + 1) {
			_data_->pin_id = _data_->pin_id_collection[_data_->pin_id_it];
			{
				_data_->_data77_ = g_slice_new0 (Block77Data);
				_data_->_data77_->_ref_count_ = 1;
				_data_->_data77_->self = g_object_ref (_data_->self);
				_data_->text = NULL;
				_data_->sender = NULL;
				_data_->_tmp12_ = _data_->self->priv->message_store;
				_data_->_tmp13_ = dc_find_message ((GListModel*) _data_->_tmp12_, _data_->pin_id);
				_data_->m = _data_->_tmp13_;
				_data_->_tmp14_ = _data_->m;
				if (_data_->_tmp14_ != NULL) {
					_data_->_tmp15_ = _data_->m;
					_data_->_tmp16_ = dc_message_get_text (_data_->_tmp15_);
					_data_->_tmp17_ = _data_->_tmp16_;
					_data_->_tmp18_ = g_strdup (_data_->_tmp17_);
					_g_free0 (_data_->text);
					_data_->text = _data_->_tmp18_;
					_data_->_tmp20_ = _data_->m;
					_data_->_tmp21_ = dc_message_get_is_outgoing (_data_->_tmp20_);
					_data_->_tmp22_ = _data_->_tmp21_;
					if (_data_->_tmp22_) {
						_data_->_tmp19_ = "You";
					} else {
						_data_->_tmp24_ = _data_->m;
						_data_->_tmp25_ = dc_message_get_sender_name (_data_->_tmp24_);
						_data_->_tmp26_ = _data_->_tmp25_;
						_data_->_tmp23_ = _data_->_tmp26_;
						if (_data_->_tmp23_ == NULL) {
							_data_->_tmp23_ = "";
						}
						_data_->_tmp19_ = _data_->_tmp23_;
					}
					_data_->_tmp27_ = g_strdup (_data_->_tmp19_);
					_g_free0 (_data_->sender);
					_data_->sender = _data_->_tmp27_;
				}
				_data_->_tmp30_ = _data_->text;
				if (_data_->_tmp30_ == NULL) {
					_data_->_tmp31_ = _data_->sender;
					_data_->_tmp29_ = _data_->_tmp31_ == NULL;
				} else {
					_data_->_tmp29_ = FALSE;
				}
				if (_data_->_tmp29_) {
					_data_->_tmp32_ = _data_->self->priv->rpc;
					_data_->_tmp28_ = _data_->_tmp32_ != NULL;
				} else {
					_data_->_tmp28_ = FALSE;
				}
				if (_data_->_tmp28_) {
					{
						_data_->_tmp33_ = _data_->self->priv->rpc;
						_data_->_state_ = 1;
						dc_rpc_client_fetch_message (_data_->_tmp33_, _data_->pin_id, dc_pinned_messages_manager_update_bar_ready, _data_);
						return FALSE;
						_state_1:
						_data_->_tmp34_ = dc_rpc_client_fetch_message_finish (_data_->_tmp33_, _data_->_res_, &_data_->_inner_error0_);
						_data_->fetched = _data_->_tmp34_;
						if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
							goto __catch0_g_error;
						}
						_data_->_tmp35_ = _data_->fetched;
						if (_data_->_tmp35_ != NULL) {
							_data_->_tmp36_ = _data_->fetched;
							_data_->_tmp37_ = dc_message_get_text (_data_->_tmp36_);
							_data_->_tmp38_ = _data_->_tmp37_;
							_data_->_tmp39_ = g_strdup (_data_->_tmp38_);
							_g_free0 (_data_->text);
							_data_->text = _data_->_tmp39_;
							_data_->_tmp41_ = _data_->fetched;
							_data_->_tmp42_ = dc_message_get_is_outgoing (_data_->_tmp41_);
							_data_->_tmp43_ = _data_->_tmp42_;
							if (_data_->_tmp43_) {
								_data_->_tmp40_ = "You";
							} else {
								_data_->_tmp45_ = _data_->fetched;
								_data_->_tmp46_ = dc_message_get_sender_name (_data_->_tmp45_);
								_data_->_tmp47_ = _data_->_tmp46_;
								_data_->_tmp44_ = _data_->_tmp47_;
								if (_data_->_tmp44_ == NULL) {
									_data_->_tmp44_ = "";
								}
								_data_->_tmp40_ = _data_->_tmp44_;
							}
							_data_->_tmp48_ = g_strdup (_data_->_tmp40_);
							_g_free0 (_data_->sender);
							_data_->sender = _data_->_tmp48_;
						}
						_g_object_unref0 (_data_->fetched);
					}
					goto __finally0;
					__catch0_g_error:
					{
						g_clear_error (&_data_->_inner_error0_);
					}
					__finally0:
					if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
						_g_object_unref0 (_data_->m);
						_g_free0 (_data_->sender);
						_g_free0 (_data_->text);
						block77_data_unref (_data_->_data77_);
						_data_->_data77_ = NULL;
						_data_->displayed_ids = (g_free (_data_->displayed_ids), NULL);
						_g_object_unref0 (_data_->next_content);
						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_->generation != _data_->self->priv->bar_generation) {
					_g_object_unref0 (_data_->m);
					_g_free0 (_data_->sender);
					_g_free0 (_data_->text);
					block77_data_unref (_data_->_data77_);
					_data_->_data77_ = NULL;
					_data_->displayed_ids = (g_free (_data_->displayed_ids), NULL);
					_g_object_unref0 (_data_->next_content);
					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_->_tmp50_ = _data_->text;
				if (_data_->_tmp50_ == NULL) {
					_data_->_tmp51_ = _data_->sender;
					_data_->_tmp49_ = _data_->_tmp51_ == NULL;
				} else {
					_data_->_tmp49_ = FALSE;
				}
				if (_data_->_tmp49_) {
					_g_object_unref0 (_data_->m);
					_g_free0 (_data_->sender);
					_g_free0 (_data_->text);
					block77_data_unref (_data_->_data77_);
					_data_->_data77_ = NULL;
					continue;
				}
				_data_->_tmp52_ = (GtkButton*) gtk_button_new ();
				g_object_ref_sink (_data_->_tmp52_);
				_data_->row_btn = _data_->_tmp52_;
				_data_->_tmp53_ = _data_->row_btn;
				gtk_widget_add_css_class ((GtkWidget*) _data_->_tmp53_, "flat");
				_data_->_tmp54_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
				g_object_ref_sink (_data_->_tmp54_);
				_data_->row_box = _data_->_tmp54_;
				_data_->_tmp55_ = (GtkLabel*) gtk_label_new ("\xf0\x9f\x93\x8c");
				g_object_ref_sink (_data_->_tmp55_);
				_data_->pin_icon = _data_->_tmp55_;
				_data_->_tmp56_ = _data_->row_box;
				_data_->_tmp57_ = _data_->pin_icon;
				gtk_box_append (_data_->_tmp56_, (GtkWidget*) _data_->_tmp57_);
				_data_->_tmp58_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
				g_object_ref_sink (_data_->_tmp58_);
				_data_->text_box = _data_->_tmp58_;
				_data_->_tmp59_ = _data_->text_box;
				gtk_widget_set_hexpand ((GtkWidget*) _data_->_tmp59_, TRUE);
				_data_->_tmp61_ = _data_->sender;
				if (_data_->_tmp61_ != NULL) {
					_data_->_tmp62_ = _data_->sender;
					_data_->_tmp63_ = strlen (_data_->_tmp62_);
					_data_->_tmp64_ = _data_->_tmp63_;
					_data_->_tmp60_ = _data_->_tmp64_ > 0;
				} else {
					_data_->_tmp60_ = FALSE;
				}
				if (_data_->_tmp60_) {
					_data_->_tmp65_ = _data_->sender;
					_data_->_tmp66_ = (GtkLabel*) gtk_label_new (_data_->_tmp65_);
					g_object_ref_sink (_data_->_tmp66_);
					_data_->sender_lbl = _data_->_tmp66_;
					_data_->_tmp67_ = _data_->sender_lbl;
					gtk_widget_add_css_class ((GtkWidget*) _data_->_tmp67_, "caption");
					_data_->_tmp68_ = _data_->sender_lbl;
					gtk_widget_add_css_class ((GtkWidget*) _data_->_tmp68_, "dim-label");
					_data_->_tmp69_ = _data_->sender_lbl;
					gtk_widget_set_halign ((GtkWidget*) _data_->_tmp69_, GTK_ALIGN_START);
					_data_->_tmp70_ = _data_->text_box;
					_data_->_tmp71_ = _data_->sender_lbl;
					gtk_box_append (_data_->_tmp70_, (GtkWidget*) _data_->_tmp71_);
					_g_object_unref0 (_data_->sender_lbl);
				}
				_data_->_tmp73_ = _data_->text;
				_data_->_tmp72_ = _data_->_tmp73_;
				if (_data_->_tmp72_ == NULL) {
					_data_->_tmp72_ = "(attachment)";
				}
				_data_->_tmp74_ = (GtkLabel*) gtk_label_new (_data_->_tmp72_);
				g_object_ref_sink (_data_->_tmp74_);
				_data_->text_lbl = _data_->_tmp74_;
				_data_->_tmp75_ = _data_->text_lbl;
				gtk_widget_set_halign ((GtkWidget*) _data_->_tmp75_, GTK_ALIGN_START);
				_data_->_tmp76_ = _data_->text_lbl;
				gtk_label_set_ellipsize (_data_->_tmp76_, PANGO_ELLIPSIZE_END);
				_data_->_tmp77_ = _data_->text_lbl;
				gtk_label_set_max_width_chars (_data_->_tmp77_, 50);
				_data_->_tmp78_ = _data_->text_lbl;
				gtk_label_set_lines (_data_->_tmp78_, 1);
				_data_->_tmp79_ = _data_->text_box;
				_data_->_tmp80_ = _data_->text_lbl;
				gtk_box_append (_data_->_tmp79_, (GtkWidget*) _data_->_tmp80_);
				_data_->_tmp81_ = _data_->row_box;
				_data_->_tmp82_ = _data_->text_box;
				gtk_box_append (_data_->_tmp81_, (GtkWidget*) _data_->_tmp82_);
				_data_->_tmp83_ = _data_->row_btn;
				_data_->_tmp84_ = _data_->row_box;
				gtk_button_set_child (_data_->_tmp83_, (GtkWidget*) _data_->_tmp84_);
				_data_->_data77_->captured_id = _data_->pin_id;
				_data_->_tmp85_ = _data_->row_btn;
				g_signal_connect_data (_data_->_tmp85_, "clicked", (GCallback) _____lambda54__gtk_button_clicked, block77_data_ref (_data_->_data77_), (GClosureNotify) block77_data_unref, 0);
				_data_->_tmp86_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
				g_object_ref_sink (_data_->_tmp86_);
				_data_->outer = _data_->_tmp86_;
				_data_->_tmp87_ = _data_->outer;
				_data_->_tmp88_ = _data_->row_btn;
				gtk_box_append (_data_->_tmp87_, (GtkWidget*) _data_->_tmp88_);
				_data_->_tmp89_ = _data_->row_btn;
				gtk_widget_set_hexpand ((GtkWidget*) _data_->_tmp89_, TRUE);
				_data_->_tmp90_ = (GtkButton*) gtk_button_new_from_icon_name ("window-close-symbolic");
				g_object_ref_sink (_data_->_tmp90_);
				_data_->unpin_btn = _data_->_tmp90_;
				_data_->_tmp91_ = _data_->unpin_btn;
				gtk_widget_add_css_class ((GtkWidget*) _data_->_tmp91_, "flat");
				_data_->_tmp92_ = _data_->unpin_btn;
				gtk_widget_add_css_class ((GtkWidget*) _data_->_tmp92_, "circular");
				_data_->_tmp93_ = _data_->unpin_btn;
				gtk_widget_set_valign ((GtkWidget*) _data_->_tmp93_, GTK_ALIGN_CENTER);
				_data_->_tmp94_ = _data_->unpin_btn;
				gtk_widget_set_tooltip_text ((GtkWidget*) _data_->_tmp94_, "Unpin");
				_data_->_tmp95_ = _data_->unpin_btn;
				g_signal_connect_data (_data_->_tmp95_, "clicked", (GCallback) _____lambda55__gtk_button_clicked, block77_data_ref (_data_->_data77_), (GClosureNotify) block77_data_unref, 0);
				_data_->_tmp96_ = _data_->outer;
				_data_->_tmp97_ = _data_->unpin_btn;
				gtk_box_append (_data_->_tmp96_, (GtkWidget*) _data_->_tmp97_);
				_data_->_tmp98_ = _data_->next_content;
				_data_->_tmp99_ = _data_->outer;
				gtk_box_append (_data_->_tmp98_, (GtkWidget*) _data_->_tmp99_);
				_g_object_unref0 (_data_->unpin_btn);
				_g_object_unref0 (_data_->outer);
				_g_object_unref0 (_data_->text_lbl);
				_g_object_unref0 (_data_->text_box);
				_g_object_unref0 (_data_->pin_icon);
				_g_object_unref0 (_data_->row_box);
				_g_object_unref0 (_data_->row_btn);
				_g_object_unref0 (_data_->m);
				_g_free0 (_data_->sender);
				_g_free0 (_data_->text);
				block77_data_unref (_data_->_data77_);
				_data_->_data77_ = NULL;
			}
		}
	}
	if (_data_->generation != _data_->self->priv->bar_generation) {
		_data_->displayed_ids = (g_free (_data_->displayed_ids), NULL);
		_g_object_unref0 (_data_->next_content);
		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_->_tmp100_ = _data_->next_content;
	_data_->_tmp101_ = _g_object_ref0 (_data_->_tmp100_);
	_g_object_unref0 (_data_->self->priv->bar_content);
	_data_->self->priv->bar_content = _data_->_tmp101_;
	_data_->_tmp102_ = _data_->self->priv->_revealer;
	_data_->_tmp103_ = _data_->self->priv->bar_content;
	gtk_revealer_set_child (_data_->_tmp102_, (GtkWidget*) _data_->_tmp103_);
	_data_->_tmp104_ = _data_->self->priv->_revealer;
	_data_->_tmp105_ = _data_->self->priv->bar_content;
	_data_->_tmp106_ = gtk_widget_get_first_child ((GtkWidget*) _data_->_tmp105_);
	gtk_revealer_set_reveal_child (_data_->_tmp104_, _data_->_tmp106_ != NULL);
	_data_->displayed_ids = (g_free (_data_->displayed_ids), NULL);
	_g_object_unref0 (_data_->next_content);
	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
_vala_array_add50 (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 void
_vala_array_add51 (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_dup20 (gint* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (gint));
	}
	return NULL;
}

static void
dc_pinned_messages_manager_set_cached_state (DcPinnedMessagesManager* self,
                                             gint msg_id,
                                             gboolean pinned)
{
	gint* next_ids = NULL;
	gint* _tmp0_;
	gint next_ids_length1;
	gint _next_ids_size_;
	gint* _tmp1_;
	gint _tmp1__length1;
	gint* _tmp2_;
	gint _tmp2__length1;
	gint* _tmp3_;
	gint _tmp3__length1;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_new0 (gint, 0);
	next_ids = _tmp0_;
	next_ids_length1 = 0;
	_next_ids_size_ = next_ids_length1;
	_tmp1_ = self->priv->msg_ids;
	_tmp1__length1 = self->priv->msg_ids_length1;
	{
		gint* id_collection = NULL;
		gint id_collection_length1 = 0;
		gint _id_collection_size_ = 0;
		gint id_it = 0;
		id_collection = _tmp1_;
		id_collection_length1 = _tmp1__length1;
		for (id_it = 0; id_it < id_collection_length1; id_it = id_it + 1) {
			gint id = 0;
			id = id_collection[id_it];
			{
				if (id != msg_id) {
					_vala_array_add50 (&next_ids, &next_ids_length1, &_next_ids_size_, id);
				}
			}
		}
	}
	if (pinned) {
		_vala_array_add51 (&next_ids, &next_ids_length1, &_next_ids_size_, msg_id);
	}
	_tmp2_ = next_ids;
	_tmp2__length1 = next_ids_length1;
	_tmp3_ = (_tmp2_ != NULL) ? _vala_array_dup20 (_tmp2_, _tmp2__length1) : _tmp2_;
	_tmp3__length1 = _tmp2__length1;
	self->priv->msg_ids = (g_free (self->priv->msg_ids), NULL);
	self->priv->msg_ids = _tmp3_;
	self->priv->msg_ids_length1 = _tmp3__length1;
	self->priv->_msg_ids_size_ = self->priv->msg_ids_length1;
	next_ids = (g_free (next_ids), NULL);
}

static void
dc_pinned_messages_manager_toggle_local_pin (DcPinnedMessagesManager* self,
                                             gint msg_id)
{
	gboolean new_state = FALSE;
	gint* _tmp0_;
	gint _tmp0__length1;
	g_return_if_fail (self != NULL);
	new_state = !dc_pinned_messages_manager_is_pinned (self, msg_id);
	dc_pinned_messages_manager_set_cached_state (self, msg_id, new_state);
	_tmp0_ = self->priv->msg_ids;
	_tmp0__length1 = self->priv->msg_ids_length1;
	dc_pinned_messages_manager_save_local_for_chat (self, self->priv->current_chat_id, _tmp0_, (gint) _tmp0__length1);
	dc_pinned_messages_manager_update_message_state (self, msg_id, new_state);
}

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 void
_vala_array_add52 (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 void
dc_pinned_messages_manager_load_local_for_chat (DcPinnedMessagesManager* self,
                                                gint chat_id)
{
	gint* _tmp0_;
	GKeyFile* kf = NULL;
	GKeyFile* _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_new0 (gint, 0);
	self->priv->msg_ids = (g_free (self->priv->msg_ids), NULL);
	self->priv->msg_ids = _tmp0_;
	self->priv->msg_ids_length1 = 0;
	self->priv->_msg_ids_size_ = self->priv->msg_ids_length1;
	_tmp1_ = g_key_file_new ();
	kf = _tmp1_;
	{
		GKeyFile* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		gchar* value = NULL;
		GKeyFile* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		const gchar* _tmp10_;
		gchar** _tmp11_;
		gchar** _tmp12_;
		_tmp2_ = kf;
		_tmp3_ = dc_settings_manager_get_config_path ();
		_tmp4_ = _tmp3_;
		g_key_file_load_from_file (_tmp2_, _tmp4_, G_KEY_FILE_NONE, &_inner_error0_);
		_g_free0 (_tmp4_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp5_ = kf;
		_tmp6_ = g_strdup_printf ("chat_%d", chat_id);
		_tmp7_ = _tmp6_;
		_tmp8_ = g_key_file_get_string (_tmp5_, "PinnedMessages", _tmp7_, &_inner_error0_);
		_tmp9_ = _tmp8_;
		_g_free0 (_tmp7_);
		value = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp10_ = value;
		_tmp12_ = _tmp11_ = g_strsplit (_tmp10_, ",", 0);
		{
			gchar** item_collection = NULL;
			gint item_collection_length1 = 0;
			gint _item_collection_size_ = 0;
			gint item_it = 0;
			item_collection = _tmp12_;
			item_collection_length1 = _vala_array_length (_tmp11_);
			for (item_it = 0; item_it < item_collection_length1; item_it = item_it + 1) {
				gchar* _tmp13_;
				gchar* item = NULL;
				_tmp13_ = g_strdup (item_collection[item_it]);
				item = _tmp13_;
				{
					gchar* id = NULL;
					const gchar* _tmp14_;
					gchar* _tmp15_;
					const gchar* _tmp16_;
					gint _tmp17_;
					gint _tmp18_;
					_tmp14_ = item;
					_tmp15_ = string_strip (_tmp14_);
					id = _tmp15_;
					_tmp16_ = id;
					_tmp17_ = strlen (_tmp16_);
					_tmp18_ = _tmp17_;
					if (_tmp18_ > 0) {
						const gchar* _tmp19_;
						_tmp19_ = id;
						_vala_array_add52 (&self->priv->msg_ids, &self->priv->msg_ids_length1, &self->priv->_msg_ids_size_, atoi (_tmp19_));
					}
					_g_free0 (id);
					_g_free0 (item);
				}
			}
			item_collection = (_vala_array_free (item_collection, item_collection_length1, (GDestroyNotify) g_free), NULL);
		}
		_g_free0 (value);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_key_file_unref0 (kf);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_g_key_file_unref0 (kf);
}

static Block78Data*
block78_data_ref (Block78Data* _data78_)
{
	g_atomic_int_inc (&_data78_->_ref_count_);
	return _data78_;
}

static void
block78_data_unref (void * _userdata_)
{
	Block78Data* _data78_;
	_data78_ = (Block78Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data78_->_ref_count_)) {
		DcPinnedMessagesManager* self;
		self = _data78_->self;
		_g_free0 (_data78_->key);
		_g_object_unref0 (self);
		g_slice_free (Block78Data, _data78_);
	}
}

static void
__lambda53_ (Block78Data* _data78_,
             GKeyFile* kf)
{
	DcPinnedMessagesManager* self;
	GString* value = NULL;
	GString* _tmp0_;
	GString* _tmp6_;
	const gchar* _tmp7_;
	GError* _inner_error0_ = NULL;
	self = _data78_->self;
	g_return_if_fail (kf != NULL);
	if (_data78_->ids_length1 == 0) {
		{
			g_key_file_remove_key (kf, "PinnedMessages", _data78_->key, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			g_clear_error (&_inner_error0_);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		return;
	}
	_tmp0_ = g_string_new ("");
	value = _tmp0_;
	{
		gint* id_collection = NULL;
		gint id_collection_length1 = 0;
		gint _id_collection_size_ = 0;
		gint id_it = 0;
		id_collection = _data78_->ids;
		id_collection_length1 = _data78_->ids_length1;
		for (id_it = 0; id_it < id_collection_length1; id_it = id_it + 1) {
			gint id = 0;
			id = id_collection[id_it];
			{
				GString* _tmp1_;
				GString* _tmp3_;
				gchar* _tmp4_;
				gchar* _tmp5_;
				_tmp1_ = value;
				if (_tmp1_->len > ((gssize) 0)) {
					GString* _tmp2_;
					_tmp2_ = value;
					g_string_append (_tmp2_, ",");
				}
				_tmp3_ = value;
				_tmp4_ = g_strdup_printf ("%i", id);
				_tmp5_ = _tmp4_;
				g_string_append (_tmp3_, _tmp5_);
				_g_free0 (_tmp5_);
			}
		}
	}
	_tmp6_ = value;
	_tmp7_ = _tmp6_->str;
	g_key_file_set_string (kf, "PinnedMessages", _data78_->key, _tmp7_);
	_g_string_free0 (value);
}

static void
___lambda53__dc_setting_writer (GKeyFile* kf,
                                gpointer self)
{
	__lambda53_ (self, kf);
}

static void
dc_pinned_messages_manager_save_local_for_chat (DcPinnedMessagesManager* self,
                                                gint chat_id,
                                                gint* ids,
                                                gint ids_length1)
{
	Block78Data* _data78_;
	gchar* _tmp0_;
	DcSettingsManager* _tmp1_;
	g_return_if_fail (self != NULL);
	_data78_ = g_slice_new0 (Block78Data);
	_data78_->_ref_count_ = 1;
	_data78_->self = g_object_ref (self);
	_data78_->ids = ids;
	_data78_->ids_length1 = ids_length1;
	_tmp0_ = g_strdup_printf ("chat_%d", chat_id);
	_data78_->key = _tmp0_;
	_tmp1_ = self->priv->settings;
	dc_settings_manager_save_to_file (_tmp1_, ___lambda53__dc_setting_writer, _data78_);
	block78_data_unref (_data78_);
	_data78_ = NULL;
}

static void
dc_pinned_messages_manager_sync_store_state (DcPinnedMessagesManager* self)
{
	g_return_if_fail (self != NULL);
	{
		guint i = 0U;
		i = (guint) 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GListStore* _tmp2_;
				DcMessage* msg = NULL;
				GListStore* _tmp3_;
				GObject* _tmp4_;
				DcMessage* _tmp5_;
				gint _tmp6_;
				gint _tmp7_;
				DcMessage* _tmp8_;
				gint _tmp9_;
				gint _tmp10_;
				if (!_tmp0_) {
					guint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = self->priv->message_store;
				if (!(i < g_list_model_get_n_items ((GListModel*) _tmp2_))) {
					break;
				}
				_tmp3_ = self->priv->message_store;
				_tmp4_ = g_list_model_get_item ((GListModel*) _tmp3_, i);
				msg = G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, DC_TYPE_MESSAGE, DcMessage);
				_tmp5_ = msg;
				_tmp6_ = dc_message_get_id (_tmp5_);
				_tmp7_ = _tmp6_;
				_tmp8_ = msg;
				_tmp9_ = dc_message_get_id (_tmp8_);
				_tmp10_ = _tmp9_;
				dc_pinned_messages_manager_update_message_state (self, _tmp7_, dc_pinned_messages_manager_is_pinned (self, _tmp10_));
				_g_object_unref0 (msg);
			}
		}
	}
}

static void
dc_pinned_messages_manager_update_message_state (DcPinnedMessagesManager* self,
                                                 gint msg_id,
                                                 gboolean pinned)
{
	DcMessage* msg = NULL;
	GListStore* _tmp0_;
	DcMessage* _tmp1_;
	gboolean _tmp2_ = FALSE;
	DcMessage* _tmp3_;
	DcMessage* _tmp7_;
	DcMessage* _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->message_store;
	_tmp1_ = dc_find_message ((GListModel*) _tmp0_, msg_id);
	msg = _tmp1_;
	_tmp3_ = msg;
	if (_tmp3_ == NULL) {
		_tmp2_ = TRUE;
	} else {
		DcMessage* _tmp4_;
		gboolean _tmp5_;
		gboolean _tmp6_;
		_tmp4_ = msg;
		_tmp5_ = dc_message_get_is_pinned (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp2_ = _tmp6_ == pinned;
	}
	if (_tmp2_) {
		_g_object_unref0 (msg);
		return;
	}
	_tmp7_ = msg;
	dc_message_set_is_pinned (_tmp7_, pinned);
	_tmp8_ = msg;
	g_object_notify ((GObject*) _tmp8_, "is-pinned");
	_g_object_unref0 (msg);
}

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 gboolean
dc_pinned_messages_manager_is_missing_pin_rpc (GError* e)
{
	gchar* msg = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	const gchar* _tmp4_;
	gboolean result;
	g_return_val_if_fail (e != NULL, FALSE);
	_tmp0_ = e->message;
	_tmp1_ = g_utf8_strdown (_tmp0_, (gssize) -1);
	msg = _tmp1_;
	_tmp4_ = msg;
	if (string_contains (_tmp4_, "method not found")) {
		_tmp3_ = TRUE;
	} else {
		const gchar* _tmp5_;
		_tmp5_ = msg;
		_tmp3_ = string_contains (_tmp5_, "procedure not found");
	}
	if (_tmp3_) {
		_tmp2_ = TRUE;
	} else {
		const gchar* _tmp6_;
		_tmp6_ = msg;
		_tmp2_ = string_contains (_tmp6_, "unknown method");
	}
	result = _tmp2_;
	_g_free0 (msg);
	return result;
}

GtkRevealer*
dc_pinned_messages_manager_get_revealer (DcPinnedMessagesManager* self)
{
	GtkRevealer* result;
	GtkRevealer* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_revealer;
	result = _tmp0_;
	return result;
}

static void
dc_pinned_messages_manager_set_revealer (DcPinnedMessagesManager* self,
                                         GtkRevealer* value)
{
	GtkRevealer* old_value;
	g_return_if_fail (self != NULL);
	old_value = dc_pinned_messages_manager_get_revealer (self);
	if (old_value != value) {
		GtkRevealer* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_revealer);
		self->priv->_revealer = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, dc_pinned_messages_manager_properties[DC_PINNED_MESSAGES_MANAGER_REVEALER_PROPERTY]);
	}
}

static void
dc_pinned_messages_manager_class_init (DcPinnedMessagesManagerClass * klass,
                                       gpointer klass_data)
{
	dc_pinned_messages_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DcPinnedMessagesManager_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dc_pinned_messages_manager_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_dc_pinned_messages_manager_set_property;
	G_OBJECT_CLASS (klass)->finalize = dc_pinned_messages_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DC_PINNED_MESSAGES_MANAGER_REVEALER_PROPERTY, dc_pinned_messages_manager_properties[DC_PINNED_MESSAGES_MANAGER_REVEALER_PROPERTY] = g_param_spec_object ("revealer", "revealer", "revealer", gtk_revealer_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	dc_pinned_messages_manager_signals[DC_PINNED_MESSAGES_MANAGER_SCROLL_REQUESTED_SIGNAL] = g_signal_new ("scroll-requested", DC_TYPE_PINNED_MESSAGES_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
	dc_pinned_messages_manager_signals[DC_PINNED_MESSAGES_MANAGER_OPERATION_FAILED_SIGNAL] = g_signal_new ("operation-failed", DC_TYPE_PINNED_MESSAGES_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
}

static void
dc_pinned_messages_manager_instance_init (DcPinnedMessagesManager * self,
                                          gpointer klass)
{
	gint* _tmp0_;
	self->priv = dc_pinned_messages_manager_get_instance_private (self);
	self->priv->rpc = NULL;
	_tmp0_ = g_new0 (gint, 0);
	self->priv->msg_ids = _tmp0_;
	self->priv->msg_ids_length1 = 0;
	self->priv->_msg_ids_size_ = self->priv->msg_ids_length1;
	self->priv->current_chat_id = 0;
	self->priv->rpc_available = TRUE;
	self->priv->load_generation = (guint) 0;
	self->priv->bar_generation = (guint) 0;
}

static void
dc_pinned_messages_manager_finalize (GObject * obj)
{
	DcPinnedMessagesManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_PINNED_MESSAGES_MANAGER, DcPinnedMessagesManager);
	_g_object_unref0 (self->priv->_revealer);
	_g_object_unref0 (self->priv->bar_content);
	self->priv->msg_ids = (g_free (self->priv->msg_ids), NULL);
	G_OBJECT_CLASS (dc_pinned_messages_manager_parent_class)->finalize (obj);
}

static GType
dc_pinned_messages_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcPinnedMessagesManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_pinned_messages_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcPinnedMessagesManager), 0, (GInstanceInitFunc) dc_pinned_messages_manager_instance_init, NULL };
	GType dc_pinned_messages_manager_type_id;
	dc_pinned_messages_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "DcPinnedMessagesManager", &g_define_type_info, 0);
	DcPinnedMessagesManager_private_offset = g_type_add_instance_private (dc_pinned_messages_manager_type_id, sizeof (DcPinnedMessagesManagerPrivate));
	return dc_pinned_messages_manager_type_id;
}

GType
dc_pinned_messages_manager_get_type (void)
{
	static volatile gsize dc_pinned_messages_manager_type_id__once = 0;
	if (g_once_init_enter (&dc_pinned_messages_manager_type_id__once)) {
		GType dc_pinned_messages_manager_type_id;
		dc_pinned_messages_manager_type_id = dc_pinned_messages_manager_get_type_once ();
		g_once_init_leave (&dc_pinned_messages_manager_type_id__once, dc_pinned_messages_manager_type_id);
	}
	return dc_pinned_messages_manager_type_id__once;
}

static void
_vala_dc_pinned_messages_manager_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec)
{
	DcPinnedMessagesManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DC_TYPE_PINNED_MESSAGES_MANAGER, DcPinnedMessagesManager);
	switch (property_id) {
		case DC_PINNED_MESSAGES_MANAGER_REVEALER_PROPERTY:
		g_value_set_object (value, dc_pinned_messages_manager_get_revealer (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_dc_pinned_messages_manager_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec)
{
	DcPinnedMessagesManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DC_TYPE_PINNED_MESSAGES_MANAGER, DcPinnedMessagesManager);
	switch (property_id) {
		case DC_PINNED_MESSAGES_MANAGER_REVEALER_PROPERTY:
		dc_pinned_messages_manager_set_revealer (self, g_value_get_object (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;
}

