pidgin/pidgin

Add an echo user to the demo protocol

2022-03-11, Elliott Sales de Andrade
aa8fc0497d6d
Parents 9d5a101a7663
Children c47df057a426
Add an echo user to the demo protocol

Testing Done:
Opened a conversation and typed a few message.

Reviewed at https://reviews.imfreedom.org/r/1328/
--- a/libpurple/protocols/demo/purpledemoprotocol.c Fri Mar 11 02:22:36 2022 -0600
+++ b/libpurple/protocols/demo/purpledemoprotocol.c Fri Mar 11 03:29:48 2022 -0600
@@ -29,6 +29,69 @@
};
/******************************************************************************
+ * PurpleProtocolIM Implementation
+ *****************************************************************************/
+typedef struct {
+ PurpleConnection *connection;
+ PurpleMessage *message;
+} PurpleDemoProtocolIMInfo;
+
+static void
+purple_demo_protocol_im_info_free(PurpleDemoProtocolIMInfo *info) {
+ g_object_unref(info->message);
+ g_free(info);
+}
+
+static gboolean
+purple_demo_protocol_echo_im_cb(gpointer data)
+{
+ PurpleDemoProtocolIMInfo *info = data;
+ const char *who = NULL;
+ PurpleMessageFlags flags;
+ GDateTime *timestamp = NULL;
+
+ /* Turn outgoing message back incoming. */
+ who = purple_message_get_recipient(info->message);
+ flags = purple_message_get_flags(info->message);
+ flags &= ~PURPLE_MESSAGE_SEND;
+ flags |= PURPLE_MESSAGE_RECV;
+ timestamp = purple_message_get_timestamp(info->message);
+
+ purple_serv_got_im(info->connection, who,
+ purple_message_get_contents(info->message), flags,
+ g_date_time_to_unix(timestamp));
+
+ g_date_time_unref(timestamp);
+
+ return FALSE;
+}
+
+static gint
+purple_demo_protocol_send_im(PurpleProtocolIM *im, PurpleConnection *conn,
+ PurpleMessage *msg)
+{
+ const gchar *who = purple_message_get_recipient(msg);
+
+ if(purple_strequal(who, "Echo")) {
+ PurpleDemoProtocolIMInfo *info = g_new(PurpleDemoProtocolIMInfo, 1);
+
+ info->connection = conn;
+ info->message = g_object_ref(msg);
+
+ g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
+ purple_demo_protocol_echo_im_cb, info,
+ (GDestroyNotify)purple_demo_protocol_im_info_free);
+ }
+
+ return 1;
+}
+
+static void
+purple_demo_protocol_im_iface_init(PurpleProtocolIMInterface *iface) {
+ iface->send = purple_demo_protocol_send_im;
+}
+
+/******************************************************************************
* PurpleProtocolClient Implementation
*****************************************************************************/
static gchar *
@@ -107,6 +170,8 @@
0,
G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_CLIENT,
purple_demo_protocol_client_init)
+ G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_IM,
+ purple_demo_protocol_im_iface_init)
)
static void
Binary file libpurple/protocols/demo/resources/buddy_icons/Echo.png has changed
--- a/libpurple/protocols/demo/resources/contacts.json Fri Mar 11 02:22:36 2022 -0600
+++ b/libpurple/protocols/demo/resources/contacts.json Fri Mar 11 03:29:48 2022 -0600
@@ -43,5 +43,14 @@
"message": "Writing crazy patches!"
}
}]
+ }],
+ "Nymphs": [{
+ "buddies": [{
+ "name": "Echo",
+ "status": {
+ "id": "available",
+ "message": "Cursed to speak the last words spoken to me"
+ }
+ }]
}]
}
--- a/libpurple/protocols/demo/resources/purpledemo.gresource.xml Fri Mar 11 02:22:36 2022 -0600
+++ b/libpurple/protocols/demo/resources/purpledemo.gresource.xml Fri Mar 11 03:29:48 2022 -0600
@@ -6,6 +6,7 @@
<file>icons/22x22/apps/im-purple-demo.png</file>
<file>icons/48x48/apps/im-purple-demo.png</file>
<file>icons/scalable/apps/im-purple-demo.svg</file>
+ <file>buddy_icons/Echo.png</file>
<file>buddy_icons/Eion.png</file>
<file>buddy_icons/Elliott.png</file>
<file>buddy_icons/Gary.png</file>