protocols/demo/purpledemocommands.c

Sun, 10 Aug 2025 23:44:08 +0800

author
Gong Zhile <gongzl@stu.hebust.edu.cn>
date
Sun, 10 Aug 2025 23:44:08 +0800
branch
purple_conversation_find_message_by_id
changeset 43309
099e1dfb856b
parent 43100
e6df74d36862
permissions
-rw-r--r--

Add Purple.Conversation.find_message_by_id

The method was added so that a protocol or plugin could easily lookup
for the reference for a message. This will be especially useful when a
protocol received a quoted message but only with an id.

43066
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * Lesser General Public License for more details.
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include <glib/gi18n-lib.h>
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 #include "purpledemocommands.h"
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #define PURPLE_DEMO_COMMAND_SOURCE N_("Demo Protocol")
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 /******************************************************************************
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 * Command Implementations
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 *****************************************************************************/
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 static void
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 purple_demo_command_edited_executed(G_GNUC_UNUSED PurpleCommand *command,
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 PurpleConversation *conversation,
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 GStrv params,
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 G_GNUC_UNUSED gpointer data)
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 {
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 PurpleAccount *account = NULL;
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 PurpleContactInfo *info = NULL;
43100
e6df74d36862 Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents: 43066
diff changeset
36 PurpleConversationMember *member = NULL;
e6df74d36862 Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents: 43066
diff changeset
37 PurpleConversationMembers *members = NULL;
43066
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 PurpleMessage *message = NULL;
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 char *contents = NULL;
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40
43100
e6df74d36862 Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents: 43066
diff changeset
41 members = purple_conversation_get_members(conversation);
e6df74d36862 Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents: 43066
diff changeset
42
43066
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 account = purple_conversation_get_account(conversation);
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 info = purple_account_get_contact_info(account);
43100
e6df74d36862 Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents: 43066
diff changeset
45 member = purple_conversation_members_find_member(members, info);
43066
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 contents = g_strjoinv(" ", params);
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48
43100
e6df74d36862 Change Purple.Message:author to Purple.ConversationMember
Gary Kramlich <grim@reaperworld.com>
parents: 43066
diff changeset
49 message = purple_message_new(member, contents);
43066
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 purple_message_set_edited(message, TRUE);
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 g_clear_pointer(&contents, g_free);
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 purple_conversation_send_message_async(conversation, message, NULL, NULL,
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 NULL);
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 g_clear_object(&message);
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 }
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 /******************************************************************************
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 * Public API
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 *****************************************************************************/
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 void
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 purple_demo_commands_add(void) {
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 PurpleCommand *command = NULL;
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 PurpleCommandManager *manager = NULL;
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 PurpleTags *tags = NULL;
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 manager = purple_command_manager_get_default();
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 command = purple_command_new("edited", PURPLE_DEMO_COMMAND_SOURCE, 1000);
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 purple_command_set_summary(command,
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 N_("Sends the contents as an edited message"));
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 g_signal_connect(command, "executed",
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 G_CALLBACK(purple_demo_command_edited_executed), NULL);
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 tags = purple_command_get_tags(command);
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 purple_tags_add(tags, "protocol-id:prpl-demo");
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 purple_command_manager_add(manager, command);
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 }
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 void
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 purple_demo_commands_remove(void) {
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 PurpleCommandManager *manager = purple_command_manager_get_default();
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 purple_command_manager_remove_all_with_source(manager,
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 PURPLE_DEMO_COMMAND_SOURCE);
850400fb36c0 Add an edited command to the demo protocol
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 }

mercurial