libpurple/protocols/ircv3/purpleircv3protocolconversation.c

Mon, 04 Dec 2023 02:21:08 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Mon, 04 Dec 2023 02:21:08 -0600
changeset 42544
95d36c221e21
parent 42511
77d01d3cf007
child 42568
31e8c7c92e2f
permissions
-rw-r--r--

Implement CTCP ACTION and VERSION

Testing Done:
Used irssi to send `CTCP VERSION` to a channel and the pidgin3 user directly and verified the response was sent and that the default message was still displayed.

Bugs closed: PIDGIN-17721

Reviewed at https://reviews.imfreedom.org/r/2863/

42320
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * Lesser General Public License for more details.
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include <glib/gi18n-lib.h>
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 #include "purpleircv3protocolconversation.h"
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include "purpleircv3connection.h"
42511
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42450
diff changeset
24 #include "purpleircv3constants.h"
42378
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
25 #include "purpleircv3core.h"
42320
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 /******************************************************************************
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 * PurpleProtocolConversation Implementation
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 *****************************************************************************/
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 static void
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 purple_ircv3_protocol_conversation_send_message_async(PurpleProtocolConversation *protocol,
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 PurpleConversation *conversation,
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 PurpleMessage *message,
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 GCancellable *cancellable,
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 GAsyncReadyCallback callback,
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 gpointer data)
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 {
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 PurpleIRCv3Connection *v3_connection = NULL;
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 PurpleAccount *account = NULL;
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 PurpleConnection *connection = NULL;
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 GTask *task = NULL;
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 const char *id = NULL;
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 account = purple_conversation_get_account(conversation);
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 connection = purple_account_get_connection(account);
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 v3_connection = PURPLE_IRCV3_CONNECTION(connection);
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 id = purple_conversation_get_id(conversation);
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 /* TODO: the new message dialog sets the name but not the id and we want to
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 * use the id only, so for now if id is NULL we grab the name.
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 */
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 if(purple_strempty(id)) {
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 id = purple_conversation_get_name(conversation);
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 }
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 purple_ircv3_connection_writef(v3_connection, "PRIVMSG %s :%s", id,
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 purple_message_get_contents(message));
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 task = g_task_new(protocol, cancellable, callback, data);
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 g_task_return_boolean(task, TRUE);
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 g_clear_object(&task);
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 /* This will be made conditional when we add echo-message support.
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 * https://ircv3.net/specs/extensions/echo-message
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 */
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 purple_conversation_write_message(conversation, message);
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 }
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 static gboolean
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 purple_ircv3_protocol_conversation_send_message_finish(G_GNUC_UNUSED PurpleProtocolConversation *protocol,
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 GAsyncResult *result,
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 GError **error)
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 {
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 return g_task_propagate_boolean(G_TASK(result), error);
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 }
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76
42378
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
77 static PurpleChannelJoinDetails *
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
78 purple_ircv3_protocol_conversation_get_channel_join_details(G_GNUC_UNUSED PurpleProtocolConversation *protocol,
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
79 G_GNUC_UNUSED PurpleAccount *account)
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
80 {
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
81 return purple_channel_join_details_new(FALSE, TRUE);
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
82 }
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
83
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
84 static void
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
85 purple_ircv3_protocol_conversation_join_channel_async(PurpleProtocolConversation *protocol,
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
86 PurpleAccount *account,
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
87 PurpleChannelJoinDetails* details,
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
88 GCancellable* cancellable,
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
89 GAsyncReadyCallback callback,
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
90 gpointer data)
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
91 {
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
92 PurpleIRCv3Connection *v3_connection = NULL;
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
93 PurpleConnection *connection = NULL;
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
94 PurpleConversation *conversation = NULL;
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
95 PurpleConversationManager *manager = NULL;
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
96 GString *cmd = NULL;
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
97 GTask *task = NULL;
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
98 const char *name = NULL;
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
99 const char *password = NULL;
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
100
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
101 connection = purple_account_get_connection(account);
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
102 v3_connection = PURPLE_IRCV3_CONNECTION(connection);
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
103
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
104 task = g_task_new(protocol, cancellable, callback, data);
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
105
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
106 /* Validate that the name isn't empty. */
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
107 /* TODO: check that name match the ISUPPORT channel prefixes. */
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
108 name = purple_channel_join_details_get_name(details);
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
109 if(purple_strempty(name)) {
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
110 g_task_return_new_error(task, PURPLE_IRCV3_DOMAIN, 0,
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
111 "channel name is empty");
42450
bd1327c022d4 fix some memory leaks
Markus Fischer <ivanhoe@fiscari.de>
parents: 42378
diff changeset
112 g_clear_object(&task);
42378
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
113
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
114 return;
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
115 }
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
116
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
117 manager = purple_conversation_manager_get_default();
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
118 conversation = purple_conversation_manager_find_with_id(manager, account,
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
119 name);
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
120
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
121 /* If the conversation already exists, just return TRUE. */
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
122 if(PURPLE_IS_CONVERSATION(conversation)) {
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
123 g_task_return_boolean(task, TRUE);
42450
bd1327c022d4 fix some memory leaks
Markus Fischer <ivanhoe@fiscari.de>
parents: 42378
diff changeset
124 g_clear_object(&task);
42378
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
125
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
126 return;
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
127 }
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
128
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
129 /* Build our join string. */
42511
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42450
diff changeset
130 cmd = g_string_new(NULL);
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42450
diff changeset
131 g_string_append_printf(cmd, "%s %s", PURPLE_IRCV3_MSG_JOIN, name);
42378
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
132
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
133 password = purple_channel_join_details_get_password(details);
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
134 if(!purple_strempty(password)) {
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
135 g_string_append_printf(cmd, " %s", password);
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
136 }
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
137
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
138 conversation = g_object_new(
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
139 PURPLE_TYPE_CONVERSATION,
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
140 "account", account,
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
141 "type", PurpleConversationTypeChannel,
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
142 "id", name,
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
143 "name", name,
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
144 NULL);
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
145 purple_conversation_manager_register(manager, conversation);
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
146 g_clear_object(&conversation);
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
147
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
148 purple_ircv3_connection_writef(v3_connection, "%s", cmd->str);
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
149 g_string_free(cmd, TRUE);
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
150
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
151 g_task_return_boolean(task, TRUE);
42450
bd1327c022d4 fix some memory leaks
Markus Fischer <ivanhoe@fiscari.de>
parents: 42378
diff changeset
152 g_clear_object(&task);
42378
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
153 }
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
154
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
155 static gboolean
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
156 purple_ircv3_protocol_conversation_join_channel_finish(G_GNUC_UNUSED PurpleProtocolConversation *protocol,
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
157 GAsyncResult *result,
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
158 GError **error)
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
159 {
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
160 return g_task_propagate_boolean(G_TASK(result), error);
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
161 }
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
162
42320
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163 void
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 purple_ircv3_protocol_conversation_init(PurpleProtocolConversationInterface *iface) {
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 iface->send_message_async =
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 purple_ircv3_protocol_conversation_send_message_async;
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 iface->send_message_finish =
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 purple_ircv3_protocol_conversation_send_message_finish;
42378
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
169
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
170 iface->get_channel_join_details =
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
171 purple_ircv3_protocol_conversation_get_channel_join_details;
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
172 iface->join_channel_async =
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
173 purple_ircv3_protocol_conversation_join_channel_async;
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
174 iface->join_channel_finish =
b64cb320215a IRCv3: Implement the channel joining functions in PurpleProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
175 purple_ircv3_protocol_conversation_join_channel_finish;
42320
21cab78fb7d2 IRCv3: Move from ProtocolIM to ProtocolConversation
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176 }

mercurial