--- a/protocols/demo/purpledemoprotocolconversation.c Tue Apr 16 22:29:14 2024 -0500
+++ b/protocols/demo/purpledemoprotocolconversation.c Thu Apr 18 00:42:04 2024 -0500
@@ -97,23 +97,8 @@
purple_demo_protocol_echo_im_cb(gpointer data) {
PurpleDemoProtocolIMInfo *info = data;
- PurpleMessage *message = NULL;
- PurpleMessageFlags flags;
- const char *who = NULL;
- /* Turn outgoing message back incoming. */
- who = purple_conversation_get_name(info->conversation);
- flags = purple_message_get_flags(info->message);
- flags &= ~PURPLE_MESSAGE_SEND;
- flags |= PURPLE_MESSAGE_RECV;
- message = purple_message_new_incoming(who,
- purple_message_get_contents(info->message),
- purple_conversation_write_message(info->conversation, message);
- g_clear_object(&message);
+ purple_conversation_write_message(info->conversation, info->message); @@ -159,7 +144,6 @@
PURPLE_TYPE_CONVERSATION,
- "name", "this is required for some reason",
g_clear_pointer(&id, g_free);
@@ -209,41 +193,72 @@
- const char *who = NULL;
- who = purple_conversation_get_name(conversation);
- if(purple_strempty(who)) {
- who = purple_message_get_recipient(message);
+ if(purple_conversation_is_dm(conversation)) { + PurpleAccount *account = NULL; + PurpleContact *contact = NULL; + PurpleContactManager *manager = NULL; - if(purple_strequal(who, "Echo")) {
- PurpleDemoProtocolIMInfo *info = g_new(PurpleDemoProtocolIMInfo, 1);
+ account = purple_conversation_get_account(conversation); - info->conversation = g_object_ref(conversation);
- info->message = g_object_ref(message);
+ manager = purple_contact_manager_get_default(); - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
- purple_demo_protocol_echo_im_cb, info,
- (GDestroyNotify)purple_demo_protocol_im_info_free);
- } else if(purple_strequal(who, "Aegina")) {
- PurpleDemoProtocolIMInfo *info = g_new(PurpleDemoProtocolIMInfo, 1);
- const char *author = purple_message_get_author(message);
- const char *contents = NULL;
+ /* Check if this dm is with echo. */ + contact = purple_contact_manager_find_with_username(manager, account, + if(purple_conversation_has_member(conversation, + PURPLE_CONTACT_INFO(contact), NULL)) + PurpleDemoProtocolIMInfo *info = NULL; + PurpleMessageFlags flags; + flags = purple_message_get_flags(message); + flags &= ~PURPLE_MESSAGE_SEND; + flags |= PURPLE_MESSAGE_RECV; - if(purple_strequal(author, "Hades")) {
- /* TRANSLATORS: This is a reference to the Cap of Invisibility owned by
- * various Greek gods, such as Hades, as mentioned. */
- contents = _("Don't tell Hades I have his Cap");
+ info = g_new(PurpleDemoProtocolIMInfo, 1); + info->conversation = g_object_ref(conversation); + info->message = g_object_new( + "contents", purple_message_get_contents(message), + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + purple_demo_protocol_echo_im_cb, info, + (GDestroyNotify)purple_demo_protocol_im_info_free); - info->conversation = g_object_ref(conversation);
- info->message = purple_message_new_outgoing(author, who, contents,
+ /* Check if this dm is with aegina. */ + contact = purple_contact_manager_find_with_username(manager, account, + if(purple_conversation_has_member(conversation, + PURPLE_CONTACT_INFO(contact), NULL)) + PurpleDemoProtocolIMInfo *info = g_new(PurpleDemoProtocolIMInfo, 1); + const char *author = purple_message_get_author(message); + const char *contents = NULL; - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, purple_demo_protocol_echo_im_cb,
- info, (GDestroyNotify)purple_demo_protocol_im_info_free);
+ if(purple_strequal(author, "Hades")) { + /* TRANSLATORS: This is a reference to the Cap of Invisibility owned by + * various Greek gods, such as Hades, as mentioned. */ + contents = _("Don't tell Hades I have his Cap"); + info->conversation = g_object_ref(conversation); + info->message = g_object_new( + "flags", PURPLE_MESSAGE_SEND, + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, purple_demo_protocol_echo_im_cb, + info, (GDestroyNotify)purple_demo_protocol_im_info_free); purple_conversation_write_message(conversation, message);