Sun, 10 Aug 2025 23:53:22 +0800
Various improvement, Support configuration from UI
| 0 | 1 | /* |
| 2 | * Purple Satori Plugin - Satori Protocol Plugin for Purple3 | |
| 3 | * Copyright (C) 2025 Gong Zhile | |
| 4 | * | |
| 5 | * This library is free software; you can redistribute it and/or | |
| 6 | * modify it under the terms of the GNU Lesser General Public | |
| 7 | * License as published by the Free Software Foundation; either | |
| 8 | * version 2 of the License, or (at your option) any later version. | |
| 9 | * | |
| 10 | * This library is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | * Lesser General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU Lesser General Public | |
| 16 | * License along with this library; if not, see <https://www.gnu.org/licenses/>. | |
| 17 | */ | |
| 18 | ||
| 19 | #ifndef SATORI_TYPES_H | |
| 20 | #define SATORI_TYPES_H | |
| 21 | ||
|
1
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
22 | #include "purplesatoriprotocolconversation.h" |
| 0 | 23 | #include <glib.h> |
|
1
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
24 | #include <json-glib/json-glib.h> |
| 0 | 25 | |
| 26 | typedef enum { | |
| 27 | SATORI_WEBSOCKET_OP_EVENT = 0, | |
| 28 | SATORI_WEBSOCKET_OP_PING, | |
| 29 | SATORI_WEBSOCKET_OP_PONG, | |
| 30 | SATORI_WEBSOCKET_OP_IDENTIFY, | |
| 31 | SATORI_WEBSOCKET_OP_READY, | |
| 32 | SATORI_WEBSOCKET_OP_META, | |
| 33 | } SatoriWebsocketOpcode; | |
| 34 | ||
|
1
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
35 | typedef struct satori_user { |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
36 | const gchar *id; |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
37 | const gchar *name; |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
38 | const gchar *nick; |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
39 | const gchar *avatar; |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
40 | gboolean is_bot; |
| 0 | 41 | } SatoriUser; |
| 42 | ||
|
1
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
43 | typedef enum { |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
44 | SATORI_CHANNEL_TEXT = 0, |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
45 | SATORI_CHANNEL_DIRECT, |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
46 | SATORI_CHANNEL_CATEGORY, |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
47 | SATORI_CHANNEL_VOICE, |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
48 | } SatoriChannelType; |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
49 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
50 | static inline void |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
51 | satori_user_from_json(JsonObject *user_obj, SatoriUser *out_user) { |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
52 | out_user->id = json_object_get_string_member(user_obj, "id"); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
53 | out_user->name = json_object_get_string_member_with_default( |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
54 | user_obj, "name", NULL); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
55 | out_user->nick = json_object_get_string_member_with_default( |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
56 | user_obj, "nick", NULL); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
57 | out_user->avatar = json_object_get_string_member_with_default( |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
58 | user_obj, "avatar", NULL); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
59 | out_user->is_bot = json_object_get_boolean_member_with_default( |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
60 | user_obj, "is_bot", FALSE); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
61 | } |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
62 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
63 | static inline void |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
64 | satori_user_from_contactinfo(PurpleContactInfo *info, SatoriUser *out_user) { |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
65 | out_user->nick = out_user->name = \ |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
66 | purple_contact_info_get_display_name(info); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
67 | out_user->id = \ |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
68 | purple_contact_info_get_id(info); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
69 | } |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
70 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
71 | typedef struct satori_channel { |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
72 | const gchar *id; |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
73 | SatoriChannelType type; |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
74 | const gchar *name; |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
75 | const gchar *parent_id; |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
76 | } SatoriChannel; |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
77 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
78 | static inline void |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
79 | satori_channel_from_json(JsonObject *obj, SatoriChannel *out_chan) { |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
80 | out_chan->id = json_object_get_string_member(obj, "id"); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
81 | out_chan->type = (SatoriChannelType) json_object_get_int_member( |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
82 | obj, "type"); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
83 | out_chan->name = json_object_get_string_member_with_default( |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
84 | obj, "name", NULL); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
85 | out_chan->parent_id = json_object_get_string_member_with_default( |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
86 | obj, "parent_id", NULL); |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
87 | } |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
88 | |
|
98bcf06036b8
Another Minor Milestone Reached, Conversation Creation & Recv works now
William Goodspeed <goodspeed@mailo.cat>
parents:
0
diff
changeset
|
89 | |
| 0 | 90 | #endif /* SATORI_TYPES_H */ |