purplesatoriprotocolconversation.c

Fri, 08 Aug 2025 09:46:55 +0800

author
William Goodspeed <goodspeed@mailo.cat>
date
Fri, 08 Aug 2025 09:46:55 +0800
changeset 0
cc7c1f9d20f7
child 1
98bcf06036b8
permissions
-rw-r--r--

Initial Commit

0
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
1 /*
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
2 * Purple Satori Plugin - Satori Protocol Plugin for Purple3
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
3 * Copyright (C) 2025 Gong Zhile
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
4 *
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
9 *
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
13 * Lesser General Public License for more details.
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
14 *
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
17 */
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
18
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
19 #include <glib/gi18n-lib.h>
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
20
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
21 #include "purplesatoriprotocolconversation.h"
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
22
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
23 #include "purplesatoriplugin.h"
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
24 #include "purplesatoriprotocol.h"
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
25
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
26 typedef struct {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
27 PurpleConversation *conversation;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
28 PurpleMessage *message;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
29 } PurpleSatoriProtocolIMInfo;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
30
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
31 /******************************************************************************
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
32 * Helpers
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
33 *****************************************************************************/
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
34 static void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
35 purple_satori_protocol_im_info_free(PurpleSatoriProtocolIMInfo *info) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
36 g_clear_object(&info->conversation);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
37 g_clear_object(&info->message);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
38 g_free(info);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
39 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
40
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
41 static gint
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
42 purple_satori_protocol_contact_sort(gconstpointer a, gconstpointer b,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
43 G_GNUC_UNUSED gpointer data)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
44 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
45 return purple_contact_info_compare(PURPLE_CONTACT_INFO((gpointer)a),
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
46 PURPLE_CONTACT_INFO((gpointer)b));
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
47 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
48
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
49 static char *
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
50 purple_satori_protocol_generate_conversation_id(PurpleAccount *account,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
51 PurpleCreateConversationDetails *details)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
52 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
53 GChecksum *checksum = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
54 GListModel *participants = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
55 GListStore *sorted = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
56 char *ret = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
57 const char *id = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
58
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
59 /* Sort the participants. */
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
60 sorted = g_list_store_new(PURPLE_TYPE_CONTACT);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
61 participants = purple_create_conversation_details_get_participants(details);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
62 for(guint i = 0; i < g_list_model_get_n_items(participants); i++) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
63 PurpleContactInfo *info = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
64
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
65 info = g_list_model_get_item(participants, i);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
66 g_list_store_insert_sorted(sorted, info,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
67 purple_satori_protocol_contact_sort,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
68 NULL);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
69 g_clear_object(&info);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
70 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
71
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
72 /* Build a checksum of the account and the sorted participants. */
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
73 checksum = g_checksum_new(G_CHECKSUM_SHA256);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
74
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
75 id = purple_account_get_id(account);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
76 g_checksum_update(checksum, (guchar *)id, -1);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
77
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
78 for(guint i = 0; i < g_list_model_get_n_items(G_LIST_MODEL(sorted)); i++) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
79 PurpleContactInfo *info = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
80
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
81 info = g_list_model_get_item(G_LIST_MODEL(sorted), i);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
82 id = purple_contact_info_get_id(info);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
83 g_checksum_update(checksum, (guchar *)id, -1);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
84 g_clear_object(&info);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
85 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
86
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
87 ret = g_strdup(g_checksum_get_string(checksum));
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
88
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
89 g_clear_pointer(&checksum, g_checksum_free);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
90 g_clear_object(&sorted);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
91
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
92 return ret;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
93 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
94
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
95 /******************************************************************************
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
96 * Callbacks
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
97 *****************************************************************************/
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
98 static gboolean
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
99 purple_satori_protocol_echo_im_cb(gpointer data) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
100 PurpleSatoriProtocolIMInfo *info = data;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
101
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
102 purple_conversation_write_message(info->conversation, info->message);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
103
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
104 return G_SOURCE_REMOVE;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
105 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
106
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
107 /******************************************************************************
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
108 * PurpleProtocolConversation Implementation
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
109 *****************************************************************************/
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
110 static PurpleCreateConversationDetails *
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
111 purple_satori_protocol_get_create_conversation_details(G_GNUC_UNUSED PurpleProtocolConversation *protocol,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
112 G_GNUC_UNUSED PurpleAccount *account)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
113 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
114 return purple_create_conversation_details_new(9);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
115 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
116
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
117 static void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
118 purple_satori_protocol_create_conversation_async(PurpleProtocolConversation *protocol,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
119 PurpleAccount *account,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
120 PurpleCreateConversationDetails *details,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
121 GCancellable *cancellable,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
122 GAsyncReadyCallback callback,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
123 gpointer data)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
124 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
125 PurpleConversation *conversation = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
126 PurpleConversationManager *manager = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
127 PurpleConversationType type = PURPLE_CONVERSATION_TYPE_UNSET;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
128 GListModel *participants = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
129 GTask *task = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
130 char *id = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
131 guint n_participants = 0;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
132
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
133 task = g_task_new(protocol, cancellable, callback, data);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
134 g_task_set_source_tag(task,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
135 purple_satori_protocol_create_conversation_async);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
136
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
137 participants = purple_create_conversation_details_get_participants(details);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
138 n_participants = g_list_model_get_n_items(participants);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
139 if(n_participants == 0) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
140 g_task_return_new_error_literal(task, PURPLE_SATORI_DOMAIN, 0,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
141 _("no participants were provided"));
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
142 g_clear_object(&task);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
143
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
144 return;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
145 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
146
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
147 if(n_participants == 1) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
148 type = PURPLE_CONVERSATION_TYPE_DM;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
149 } else {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
150 type = PURPLE_CONVERSATION_TYPE_GROUP_DM;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
151 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
152 id = purple_satori_protocol_generate_conversation_id(account, details);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
153
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
154 conversation = g_object_new(
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
155 PURPLE_TYPE_CONVERSATION,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
156 "account", account,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
157 "id", id,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
158 "type", type,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
159 "online", TRUE,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
160 NULL);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
161 g_clear_pointer(&id, g_free);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
162
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
163 for(guint i = 0; i < g_list_model_get_n_items(participants); i++) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
164 PurpleContactInfo *info = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
165 PurpleConversationMember *member = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
166 PurpleConversationMembers *members = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
167 PurpleTags *tags = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
168 const char *badge_id = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
169
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
170 info = g_list_model_get_item(participants, i);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
171 members = purple_conversation_get_members(conversation);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
172 member = purple_conversation_members_add_member(members, info, FALSE,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
173 NULL);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
174
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
175 tags = purple_contact_info_get_tags(info);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
176 badge_id = purple_tags_get(tags, "satori-badge");
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
177 if(!purple_strempty(badge_id)) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
178 PurpleBadge *badge = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
179 PurpleBadgeManager *manager = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
180 PurpleBadges *badges = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
181
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
182 badges = purple_conversation_member_get_badges(member);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
183
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
184 manager = purple_badge_manager_get_default();
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
185 badge = purple_badge_manager_find(manager, badge_id);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
186 if(PURPLE_IS_BADGE(badge)) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
187 purple_badges_add_badge(badges, badge);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
188 } else {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
189 char *icon_name = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
190 char *id = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
191
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
192 id = g_strdup_printf("satori-badge-%s", badge_id);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
193 icon_name = g_strdup_printf("satori-badge-%s", badge_id);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
194 badge = purple_badge_new(id, 0, icon_name, " ");
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
195 purple_badge_set_description(badge, badge_id);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
196 g_free(id);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
197 g_free(icon_name);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
198
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
199 purple_badge_manager_add(manager, badge);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
200 purple_badges_add_badge(badges, badge);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
201 g_clear_object(&badge);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
202 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
203 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
204
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
205 g_clear_object(&info);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
206 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
207 g_clear_object(&details);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
208
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
209 manager = purple_conversation_manager_get_default();
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
210 if(!purple_conversation_manager_add(manager, conversation)) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
211 g_task_return_new_error(task, PURPLE_SATORI_DOMAIN, 0,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
212 _("This conversation already exists."));
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
213 g_clear_object(&task);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
214
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
215 return;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
216 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
217
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
218 g_task_return_pointer(task, conversation, g_object_unref);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
219
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
220 g_clear_object(&task);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
221 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
222
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
223 static PurpleConversation *
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
224 purple_satori_protocol_create_conversation_finish(G_GNUC_UNUSED PurpleProtocolConversation *protocol,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
225 GAsyncResult *result,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
226 GError **error)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
227 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
228 GTask *task = G_TASK(result);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
229
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
230 g_return_val_if_fail(g_task_get_source_tag(task) ==
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
231 purple_satori_protocol_create_conversation_async,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
232 NULL);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
233
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
234 return g_task_propagate_pointer(task, error);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
235 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
236
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
237 static void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
238 purple_satori_protocol_conversation_leave_conversation_async(PurpleProtocolConversation *protocol,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
239 G_GNUC_UNUSED PurpleConversation *conversation,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
240 GCancellable *cancellable,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
241 GAsyncReadyCallback callback,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
242 gpointer data)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
243 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
244 GTask *task = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
245
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
246 task = g_task_new(protocol, cancellable, callback, data);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
247 g_task_set_source_tag(task,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
248 purple_satori_protocol_conversation_leave_conversation_async);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
249
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
250 g_task_return_boolean(task, TRUE);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
251 g_clear_object(&task);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
252 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
253
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
254 static gboolean
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
255 purple_satori_protocol_conversation_leave_conversation_finish(G_GNUC_UNUSED PurpleProtocolConversation *protocol,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
256 GAsyncResult *result,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
257 GError **error)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
258 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
259 gpointer tag = purple_satori_protocol_conversation_leave_conversation_async;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
260
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
261 g_return_val_if_fail(g_async_result_is_tagged(result, tag), FALSE);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
262
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
263 return g_task_propagate_boolean(G_TASK(result), error);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
264 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
265
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
266 static void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
267 purple_satori_protocol_send_message_async(G_GNUC_UNUSED PurpleProtocolConversation *protocol,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
268 PurpleConversation *conversation,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
269 PurpleMessage *message,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
270 GCancellable *cancellable,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
271 GAsyncReadyCallback callback,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
272 gpointer data)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
273 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
274 GTask *task = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
275
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
276 if(purple_conversation_is_dm(conversation)) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
277 PurpleAccount *account = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
278 PurpleContact *contact = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
279 PurpleContactInfo *contact_info = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
280 PurpleContactManager *manager = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
281 PurpleConversationMember *member = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
282 PurpleConversationMembers *members = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
283
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
284 account = purple_conversation_get_account(conversation);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
285 members = purple_conversation_get_members(conversation);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
286
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
287 manager = purple_contact_manager_get_default();
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
288
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
289 /* Check if this dm is with echo. */
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
290 contact = purple_contact_manager_find_with_id(manager, account,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
291 "echo");
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
292 contact_info = PURPLE_CONTACT_INFO(contact);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
293 member = purple_conversation_members_find_member(members, contact_info);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
294 if(PURPLE_IS_CONVERSATION_MEMBER(member)) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
295 PurpleSatoriProtocolIMInfo *info = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
296 const char *contents = purple_message_get_contents(message);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
297
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
298 info = g_new(PurpleSatoriProtocolIMInfo, 1);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
299 info->conversation = g_object_ref(conversation);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
300 info->message = purple_message_new(member, contents);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
301 purple_message_set_edited(info->message,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
302 purple_message_get_edited(message));
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
303
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
304 g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
305 purple_satori_protocol_echo_im_cb, info,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
306 (GDestroyNotify)purple_satori_protocol_im_info_free);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
307 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
308
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
309 /* Check if this dm is with aegina. */
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
310 contact = purple_contact_manager_find_with_id(manager, account,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
311 "aegina");
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
312 contact_info = PURPLE_CONTACT_INFO(contact);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
313 member = purple_conversation_members_find_member(members, contact_info);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
314 if(PURPLE_IS_CONVERSATION_MEMBER(member)) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
315 PurpleSatoriProtocolIMInfo *info = g_new(PurpleSatoriProtocolIMInfo, 1);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
316 PurpleConversationMember *author = purple_message_get_author(message);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
317 PurpleContactInfo *author_info = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
318 const char *contents = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
319 const char *author_id = NULL;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
320
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
321 author_info = purple_conversation_member_get_contact_info(author);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
322 author_id = purple_contact_info_get_id(author_info);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
323 if(purple_strequal(author_id, "hades")) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
324 contents = "🫥️";
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
325 } else {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
326 /* TRANSLATORS: This is a reference to the Cap of Invisibility owned by
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
327 * various Greek gods, such as Hades, as mentioned. */
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
328 contents = _("Don't tell Hades I have his Cap");
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
329 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
330
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
331 info->conversation = g_object_ref(conversation);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
332 info->message = purple_message_new(member, contents);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
333
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
334 g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, purple_satori_protocol_echo_im_cb,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
335 info, (GDestroyNotify)purple_satori_protocol_im_info_free);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
336 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
337 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
338
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
339 purple_conversation_write_message(conversation, message);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
340
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
341 task = g_task_new(protocol, cancellable, callback, data);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
342 g_task_return_boolean(task, TRUE);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
343
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
344 g_clear_object(&task);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
345 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
346
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
347 static gboolean
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
348 purple_satori_protocol_send_message_finish(G_GNUC_UNUSED PurpleProtocolConversation *protocol,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
349 GAsyncResult *result,
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
350 GError **error)
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
351 {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
352 g_return_val_if_fail(G_IS_TASK(result), FALSE);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
353
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
354 return g_task_propagate_boolean(G_TASK(result), error);
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
355 }
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
356
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
357 void
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
358 purple_satori_protocol_conversation_init(PurpleProtocolConversationInterface *iface) {
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
359 iface->get_create_conversation_details =
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
360 purple_satori_protocol_get_create_conversation_details;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
361 iface->create_conversation_async =
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
362 purple_satori_protocol_create_conversation_async;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
363 iface->create_conversation_finish =
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
364 purple_satori_protocol_create_conversation_finish;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
365
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
366 iface->leave_conversation_async =
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
367 purple_satori_protocol_conversation_leave_conversation_async;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
368 iface->leave_conversation_finish =
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
369 purple_satori_protocol_conversation_leave_conversation_finish;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
370
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
371 iface->send_message_async = purple_satori_protocol_send_message_async;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
372 iface->send_message_finish = purple_satori_protocol_send_message_finish;
cc7c1f9d20f7 Initial Commit
William Goodspeed <goodspeed@mailo.cat>
parents:
diff changeset
373 }

mercurial