satoritypes.h

Sun, 10 Aug 2025 23:53:22 +0800

author
Gong Zhile <gongzl@stu.hebust.edu.cn>
date
Sun, 10 Aug 2025 23:53:22 +0800
changeset 3
33a7b189a2c6
parent 1
98bcf06036b8
permissions
-rw-r--r--

Various improvement, Support configuration from UI

/*
 * Purple Satori Plugin - Satori Protocol Plugin for Purple3
 * Copyright (C) 2025 Gong Zhile
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
 */

#ifndef SATORI_TYPES_H
#define SATORI_TYPES_H

#include "purplesatoriprotocolconversation.h"
#include <glib.h>
#include <json-glib/json-glib.h>

typedef enum {
	SATORI_WEBSOCKET_OP_EVENT = 0,
	SATORI_WEBSOCKET_OP_PING,
	SATORI_WEBSOCKET_OP_PONG,
	SATORI_WEBSOCKET_OP_IDENTIFY,
	SATORI_WEBSOCKET_OP_READY,
	SATORI_WEBSOCKET_OP_META,
} SatoriWebsocketOpcode;

typedef struct satori_user {
	const gchar	*id;
	const gchar	*name;
	const gchar	*nick;
	const gchar	*avatar;
	gboolean	 is_bot;
} SatoriUser;

typedef enum {
	SATORI_CHANNEL_TEXT = 0,
	SATORI_CHANNEL_DIRECT,
	SATORI_CHANNEL_CATEGORY,
	SATORI_CHANNEL_VOICE,
} SatoriChannelType;

static inline void
satori_user_from_json(JsonObject *user_obj, SatoriUser *out_user) {
	out_user->id = json_object_get_string_member(user_obj, "id");
	out_user->name = json_object_get_string_member_with_default(
		user_obj, "name", NULL);
	out_user->nick = json_object_get_string_member_with_default(
		user_obj, "nick", NULL);
	out_user->avatar = json_object_get_string_member_with_default(
		user_obj, "avatar", NULL);
	out_user->is_bot = json_object_get_boolean_member_with_default(
		user_obj, "is_bot", FALSE);
}

static inline void
satori_user_from_contactinfo(PurpleContactInfo *info, SatoriUser *out_user) {
	out_user->nick = out_user->name = \
		purple_contact_info_get_display_name(info);
	out_user->id = \
		purple_contact_info_get_id(info);
}

typedef struct satori_channel {
	const gchar		*id;
	SatoriChannelType	 type;
	const gchar		*name;
	const gchar		*parent_id;
} SatoriChannel;

static inline void
satori_channel_from_json(JsonObject *obj, SatoriChannel *out_chan) {
	out_chan->id = json_object_get_string_member(obj, "id");
	out_chan->type = (SatoriChannelType) json_object_get_int_member(
		obj, "type");
	out_chan->name = json_object_get_string_member_with_default(
		obj, "name", NULL);
	out_chan->parent_id = json_object_get_string_member_with_default(
		obj, "parent_id", NULL);
}


#endif	/* SATORI_TYPES_H */

mercurial