protocols/ircv3/purpleircv3commands.c

Thu, 05 Dec 2024 21:31:16 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Thu, 05 Dec 2024 21:31:16 -0600
changeset 43100
e6df74d36862
parent 43097
757575456cc2
child 43126
5b5a883528e0
permissions
-rw-r--r--

Change Purple.Message:author to Purple.ConversationMember

This is necessary to show conversation specific nick names and badges in each
message and potentially more.

Testing Done:
* Sent some messages to Echo on the demo protocol plugin.
* Verified that the ircv3 status conversation was working properly.
* Called in the turtles.

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

43097
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * Purple is the legal property of its developers, whose names are too numerous
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * source distribution.
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 * This library is free software; you can redistribute it and/or modify
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * (at your option) any later version.
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 * This library is distributed in the hope that it will be useful,
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 * GNU General Public License for more details.
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 *
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 * along with this library; if not, see <https://www.gnu.org/licenses/>.
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include "purpleircv3commands.h"
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 #include "purpleircv3connection.h"
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 /******************************************************************************
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 * Internal Callbacks
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 *****************************************************************************/
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 gboolean
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 purple_ircv3_command_query_cb(G_GNUC_UNUSED PurpleCommand *command,
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 PurpleConversation *conversation,
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 GStrv params,
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 G_GNUC_UNUSED gpointer data)
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 {
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 PurpleIRCv3Connection *v3_connection = NULL;
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 PurpleAccount *account = NULL;
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 PurpleConnection *connection = NULL;
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 PurpleConversation *new_conversation = NULL;
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 guint n_params = 0;
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 n_params = g_strv_length(params);
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 if(n_params < 1) {
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 return FALSE;
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 }
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 account = purple_conversation_get_account(conversation);
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 connection = purple_account_get_connection(account);
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 v3_connection = PURPLE_IRCV3_CONNECTION(connection);
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 new_conversation = purple_ircv3_connection_find_or_create_conversation(v3_connection,
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 params[0]);
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 if(n_params > 1) {
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 PurpleMessage *message = NULL;
43100
e6df74d36862 Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents: 43097
diff changeset
56 PurpleContactInfo *info = NULL;
e6df74d36862 Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents: 43097
diff changeset
57 PurpleConversationMember *member = NULL;
e6df74d36862 Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents: 43097
diff changeset
58 PurpleConversationMembers *members = NULL;
43097
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 char *contents = NULL;
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60
43100
e6df74d36862 Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents: 43097
diff changeset
61 info = purple_account_get_contact_info(account);
e6df74d36862 Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents: 43097
diff changeset
62 members = purple_conversation_get_members(conversation);
e6df74d36862 Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents: 43097
diff changeset
63 member = purple_conversation_members_find_member(members, info);
e6df74d36862 Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents: 43097
diff changeset
64
43097
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 contents = g_strjoinv(" ", params + 1);
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66
43100
e6df74d36862 Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents: 43097
diff changeset
67 message = purple_message_new(member, contents);
43097
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 g_free(contents);
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 purple_conversation_send_message_async(new_conversation, message, NULL,
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 NULL, NULL);
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 g_clear_object(&message);
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 }
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 return TRUE;
757575456cc2 IRCv3: Implement the query command
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 }

mercurial