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

#include "libdino.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include "dino_i18n.h"
#include <glib-object.h>
#include <gio/gio.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 _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block33Data Block33Data;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block34Data Block34Data;
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))

struct _Block33Data {
	int _ref_count_;
	DinoContentItem* content_item;
	DinoEntitiesConversation* conversation;
	DinoStreamInteractor* stream_interactor;
};

struct _Block34Data {
	int _ref_count_;
	DinoContentItem* content_item;
	DinoEntitiesConversation* conversation;
};

VALA_EXTERN DinoPluginsMessageAction* dino_ui_get_reaction_action (DinoContentItem* content_item,
                                                       DinoEntitiesConversation* conversation,
                                                       DinoStreamInteractor* stream_interactor);
static Block33Data* block33_data_ref (Block33Data* _data33_);
static void block33_data_unref (void * _userdata_);
static void __lambda37_ (Block33Data* _data33_,
                  GVariant* variant);
static void ___lambda37__dino_plugins_message_action_evoked (GVariant* variant,
                                                      gpointer self);
VALA_EXTERN DinoPluginsMessageAction* dino_ui_get_reply_action (DinoContentItem* content_item,
                                                    DinoEntitiesConversation* conversation,
                                                    DinoStreamInteractor* stream_interactor);
static Block34Data* block34_data_ref (Block34Data* _data34_);
static void block34_data_unref (void * _userdata_);
static void __lambda36_ (Block34Data* _data34_);
static void ___lambda36__dino_plugins_message_action_evoked (GVariant* variant,
                                                      gpointer self);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

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

static Block33Data*
block33_data_ref (Block33Data* _data33_)
{
	g_atomic_int_inc (&_data33_->_ref_count_);
	return _data33_;
}

static void
block33_data_unref (void * _userdata_)
{
	Block33Data* _data33_;
	_data33_ = (Block33Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data33_->_ref_count_)) {
		_g_object_unref0 (_data33_->content_item);
		_g_object_unref0 (_data33_->conversation);
		_g_object_unref0 (_data33_->stream_interactor);
		g_slice_free (Block33Data, _data33_);
	}
}

static void
__lambda37_ (Block33Data* _data33_,
             GVariant* variant)
{
	gchar* emoji = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	DinoModuleIdentity* _tmp2_;
	gpointer _tmp3_;
	DinoReactions* _tmp4_;
	_tmp0_ = g_variant_get_string (variant, NULL);
	_tmp1_ = g_strdup (_tmp0_);
	emoji = _tmp1_;
	_tmp2_ = dino_reactions_IDENTITY;
	_tmp3_ = dino_stream_interactor_get_module (_data33_->stream_interactor, DINO_TYPE_REACTIONS, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp2_);
	_tmp4_ = (DinoReactions*) _tmp3_;
	dino_reactions_add_reaction (_tmp4_, _data33_->conversation, _data33_->content_item, emoji);
	_g_object_unref0 (_tmp4_);
	_g_free0 (emoji);
}

static void
___lambda37__dino_plugins_message_action_evoked (GVariant* variant,
                                                 gpointer self)
{
	__lambda37_ (self, variant);
}

DinoPluginsMessageAction*
dino_ui_get_reaction_action (DinoContentItem* content_item,
                             DinoEntitiesConversation* conversation,
                             DinoStreamInteractor* stream_interactor)
{
	Block33Data* _data33_;
	DinoContentItem* _tmp0_;
	DinoEntitiesConversation* _tmp1_;
	DinoStreamInteractor* _tmp2_;
	DinoPluginsMessageAction* action = NULL;
	DinoPluginsMessageAction* _tmp3_;
	DinoPluginsMessageAction* _tmp4_;
	gchar* _tmp5_;
	DinoPluginsMessageAction* _tmp6_;
	gchar* _tmp7_;
	DinoPluginsMessageAction* _tmp8_;
	const gchar* _tmp9_;
	gchar* _tmp10_;
	DinoPluginsMessageAction* _tmp11_;
	gboolean supports_reactions = FALSE;
	DinoModuleIdentity* _tmp12_;
	gpointer _tmp13_;
	DinoReactions* _tmp14_;
	gboolean _tmp15_;
	gchar* message_id = NULL;
	DinoModuleIdentity* _tmp16_;
	gpointer _tmp17_;
	DinoContentItemStore* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	DinoPluginsMessageAction* result;
	g_return_val_if_fail (content_item != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	_data33_ = g_slice_new0 (Block33Data);
	_data33_->_ref_count_ = 1;
	_tmp0_ = _g_object_ref0 (content_item);
	_g_object_unref0 (_data33_->content_item);
	_data33_->content_item = _tmp0_;
	_tmp1_ = _g_object_ref0 (conversation);
	_g_object_unref0 (_data33_->conversation);
	_data33_->conversation = _tmp1_;
	_tmp2_ = _g_object_ref0 (stream_interactor);
	_g_object_unref0 (_data33_->stream_interactor);
	_data33_->stream_interactor = _tmp2_;
	_tmp3_ = dino_plugins_message_action_new ();
	action = _tmp3_;
	_tmp4_ = action;
	_tmp5_ = g_strdup ("reaction");
	_g_free0 (_tmp4_->name);
	_tmp4_->name = _tmp5_;
	_tmp6_ = action;
	_tmp7_ = g_strdup ("dino-emoticon-add-symbolic");
	_g_free0 (_tmp6_->icon_name);
	_tmp6_->icon_name = _tmp7_;
	_tmp8_ = action;
	_tmp9_ = dino_gettext ("Add reaction");
	_tmp10_ = g_strdup (_tmp9_);
	_g_free0 (_tmp8_->tooltip);
	_tmp8_->tooltip = _tmp10_;
	_tmp11_ = action;
	(_tmp11_->callback_target_destroy_notify == NULL) ? NULL : (_tmp11_->callback_target_destroy_notify (_tmp11_->callback_target), NULL);
	_tmp11_->callback = NULL;
	_tmp11_->callback_target = NULL;
	_tmp11_->callback_target_destroy_notify = NULL;
	_tmp11_->callback = ___lambda37__dino_plugins_message_action_evoked;
	_tmp11_->callback_target = block33_data_ref (_data33_);
	_tmp11_->callback_target_destroy_notify = block33_data_unref;
	_tmp12_ = dino_reactions_IDENTITY;
	_tmp13_ = dino_stream_interactor_get_module (_data33_->stream_interactor, DINO_TYPE_REACTIONS, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp12_);
	_tmp14_ = (DinoReactions*) _tmp13_;
	_tmp15_ = dino_reactions_conversation_supports_reactions (_tmp14_, _data33_->conversation);
	_g_object_unref0 (_tmp14_);
	supports_reactions = _tmp15_;
	_tmp16_ = dino_content_item_store_IDENTITY;
	_tmp17_ = dino_stream_interactor_get_module (_data33_->stream_interactor, DINO_TYPE_CONTENT_ITEM_STORE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp16_);
	_tmp18_ = (DinoContentItemStore*) _tmp17_;
	_tmp19_ = dino_content_item_store_get_message_id_for_content_item (_tmp18_, _data33_->conversation, _data33_->content_item);
	_tmp20_ = _tmp19_;
	_g_object_unref0 (_tmp18_);
	message_id = _tmp20_;
	if (!supports_reactions) {
		DinoPluginsMessageAction* _tmp21_;
		const gchar* _tmp22_;
		gchar* _tmp23_;
		DinoPluginsMessageAction* _tmp24_;
		_tmp21_ = action;
		_tmp22_ = dino_gettext ("This conversation does not support reactions.");
		_tmp23_ = g_strdup (_tmp22_);
		_g_free0 (_tmp21_->tooltip);
		_tmp21_->tooltip = _tmp23_;
		_tmp24_ = action;
		_tmp24_->sensitive = FALSE;
	} else {
		const gchar* _tmp25_;
		_tmp25_ = message_id;
		if (_tmp25_ == NULL) {
			DinoPluginsMessageAction* _tmp26_;
			gchar* _tmp27_;
			DinoPluginsMessageAction* _tmp28_;
			_tmp26_ = action;
			_tmp27_ = g_strdup ("This message does not support reactions.");
			_g_free0 (_tmp26_->tooltip);
			_tmp26_->tooltip = _tmp27_;
			_tmp28_ = action;
			_tmp28_->sensitive = FALSE;
		}
	}
	result = action;
	_g_free0 (message_id);
	block33_data_unref (_data33_);
	_data33_ = NULL;
	return result;
}

static Block34Data*
block34_data_ref (Block34Data* _data34_)
{
	g_atomic_int_inc (&_data34_->_ref_count_);
	return _data34_;
}

static void
block34_data_unref (void * _userdata_)
{
	Block34Data* _data34_;
	_data34_ = (Block34Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data34_->_ref_count_)) {
		_g_object_unref0 (_data34_->content_item);
		_g_object_unref0 (_data34_->conversation);
		g_slice_free (Block34Data, _data34_);
	}
}

static void
__lambda36_ (Block34Data* _data34_)
{
	GApplication* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	GVariant* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	GVariant* _tmp6_;
	GVariant** _tmp7_;
	GVariant** _tmp8_;
	gint _tmp8__length1;
	GVariant* _tmp9_;
	GVariant* _tmp10_;
	_tmp0_ = g_application_get_default ();
	_tmp1_ = dino_entities_conversation_get_id (_data34_->conversation);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_variant_new_int32 ((gint32) _tmp2_);
	g_variant_ref_sink (_tmp3_);
	_tmp4_ = dino_content_item_get_id (_data34_->content_item);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_variant_new_int32 ((gint32) _tmp5_);
	g_variant_ref_sink (_tmp6_);
	_tmp7_ = g_new0 (GVariant*, 2 + 1);
	_tmp7_[0] = _tmp3_;
	_tmp7_[1] = _tmp6_;
	_tmp8_ = _tmp7_;
	_tmp8__length1 = 2;
	_tmp9_ = g_variant_new_tuple (_tmp8_, 2);
	g_variant_ref_sink (_tmp9_);
	_tmp10_ = _tmp9_;
	g_action_group_activate_action ((GActionGroup*) _tmp0_, "quote", _tmp10_);
	_g_variant_unref0 (_tmp10_);
	_tmp8_ = (_vala_array_free (_tmp8_, _tmp8__length1, (GDestroyNotify) g_variant_unref), NULL);
}

static void
___lambda36__dino_plugins_message_action_evoked (GVariant* variant,
                                                 gpointer self)
{
	__lambda36_ (self);
}

DinoPluginsMessageAction*
dino_ui_get_reply_action (DinoContentItem* content_item,
                          DinoEntitiesConversation* conversation,
                          DinoStreamInteractor* stream_interactor)
{
	Block34Data* _data34_;
	DinoContentItem* _tmp0_;
	DinoEntitiesConversation* _tmp1_;
	DinoPluginsMessageAction* action = NULL;
	DinoPluginsMessageAction* _tmp2_;
	DinoPluginsMessageAction* _tmp3_;
	gchar* _tmp4_;
	DinoPluginsMessageAction* _tmp5_;
	gchar* _tmp6_;
	DinoPluginsMessageAction* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	DinoPluginsMessageAction* _tmp10_;
	gchar* message_id = NULL;
	DinoModuleIdentity* _tmp11_;
	gpointer _tmp12_;
	DinoContentItemStore* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	const gchar* _tmp16_;
	DinoPluginsMessageAction* result;
	g_return_val_if_fail (content_item != NULL, NULL);
	g_return_val_if_fail (conversation != NULL, NULL);
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	_data34_ = g_slice_new0 (Block34Data);
	_data34_->_ref_count_ = 1;
	_tmp0_ = _g_object_ref0 (content_item);
	_g_object_unref0 (_data34_->content_item);
	_data34_->content_item = _tmp0_;
	_tmp1_ = _g_object_ref0 (conversation);
	_g_object_unref0 (_data34_->conversation);
	_data34_->conversation = _tmp1_;
	_tmp2_ = dino_plugins_message_action_new ();
	action = _tmp2_;
	_tmp3_ = action;
	_tmp4_ = g_strdup ("reply");
	_g_free0 (_tmp3_->name);
	_tmp3_->name = _tmp4_;
	_tmp5_ = action;
	_tmp6_ = g_strdup ("mail-reply-sender-symbolic");
	_g_free0 (_tmp5_->icon_name);
	_tmp5_->icon_name = _tmp6_;
	_tmp7_ = action;
	_tmp8_ = dino_gettext ("Reply");
	_tmp9_ = g_strdup (_tmp8_);
	_g_free0 (_tmp7_->tooltip);
	_tmp7_->tooltip = _tmp9_;
	_tmp10_ = action;
	(_tmp10_->callback_target_destroy_notify == NULL) ? NULL : (_tmp10_->callback_target_destroy_notify (_tmp10_->callback_target), NULL);
	_tmp10_->callback = NULL;
	_tmp10_->callback_target = NULL;
	_tmp10_->callback_target_destroy_notify = NULL;
	_tmp10_->callback = ___lambda36__dino_plugins_message_action_evoked;
	_tmp10_->callback_target = block34_data_ref (_data34_);
	_tmp10_->callback_target_destroy_notify = block34_data_unref;
	_tmp11_ = dino_content_item_store_IDENTITY;
	_tmp12_ = dino_stream_interactor_get_module (stream_interactor, DINO_TYPE_CONTENT_ITEM_STORE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp11_);
	_tmp13_ = (DinoContentItemStore*) _tmp12_;
	_tmp14_ = dino_content_item_store_get_message_id_for_content_item (_tmp13_, _data34_->conversation, _data34_->content_item);
	_tmp15_ = _tmp14_;
	_g_object_unref0 (_tmp13_);
	message_id = _tmp15_;
	_tmp16_ = message_id;
	if (_tmp16_ == NULL) {
		DinoPluginsMessageAction* _tmp17_;
		DinoEntitiesConversationType _tmp18_;
		DinoEntitiesConversationType _tmp19_;
		_tmp17_ = action;
		_tmp17_->sensitive = FALSE;
		_tmp18_ = dino_entities_conversation_get_type_ (_data34_->conversation);
		_tmp19_ = _tmp18_;
		if (dino_entities_conversation_type_is_muc_semantic (_tmp19_)) {
			DinoPluginsMessageAction* _tmp20_;
			const gchar* _tmp21_;
			gchar* _tmp22_;
			_tmp20_ = action;
			_tmp21_ = dino_gettext ("This conversation does not support replies.");
			_tmp22_ = g_strdup (_tmp21_);
			_g_free0 (_tmp20_->tooltip);
			_tmp20_->tooltip = _tmp22_;
		} else {
			DinoPluginsMessageAction* _tmp23_;
			gchar* _tmp24_;
			_tmp23_ = action;
			_tmp24_ = g_strdup ("This message does not support replies.");
			_g_free0 (_tmp23_->tooltip);
			_tmp23_->tooltip = _tmp24_;
		}
	}
	result = action;
	_g_free0 (message_id);
	block34_data_unref (_data34_);
	_data34_ = NULL;
	return result;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

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

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

