How does the Demo protocol create its conversations?

With RR 2280 merged you can no longer open a conversation with Demo protocol contacts because they don’t have a conversation ID set. I would’ve liked to fix that but I can’t figure out where to do that. Where is the Demo prpl creating its conversations?

So my current approach to set the conversation ID for Demo protocol conversations is this:

diff --git a/libpurple/protocols/demo/purpledemoconnection.c b/libpurple/protocols/demo/purpledemoconnection.c
--- a/libpurple/protocols/demo/purpledemoconnection.c
+++ b/libpurple/protocols/demo/purpledemoconnection.c
@@ -52,6 +52,33 @@ purple_demo_connection_disconnect(G_GNUC
 	return TRUE;
+static void
+conversation_registered_cb(G_GNUC_UNUSED PurpleConversationManager *manager,
+                           PurpleConversation *conversation,
+                           G_GNUC_UNUSED gpointer data)
+	PurpleAccount *account = purple_conversation_get_account(conversation);
+	const char *protocol_id = purple_account_get_protocol_id(account);
+	if (purple_strequal(protocol_id, "prpl-demo"))
+	{
+		const char *conversation_id = purple_conversation_get_id(conversation);
+		if (conversation_id == NULL) {
+			printf("set id for %s\n", purple_conversation_get_name(conversation));
+			g_object_set(conversation, "id", purple_conversation_get_name(conversation), NULL);
+		}
+	}
+static void
+purple_demo_connection_constructed(G_GNUC_UNUSED GObject *obj)
+	PurpleConversationManager *manager =
+		purple_conversation_manager_get_default();
+	g_signal_connect(manager, "registered",
+	                 G_CALLBACK(conversation_registered_cb),
+	                 NULL);
  * GObject Implementation
@@ -66,9 +93,11 @@ purple_demo_connection_class_finalize(G_
 static void
 purple_demo_connection_class_init(PurpleDemoConnectionClass *klass) {
 	PurpleConnectionClass *connection_class = PURPLE_CONNECTION_CLASS(klass);
+	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
 	connection_class->connect = purple_demo_connection_connect;
 	connection_class->disconnect = purple_demo_connection_disconnect;
+	obj_class->constructed = purple_demo_connection_constructed;

But this leads to a runtime warning construct property "id" for object 'PurpleConversation' can't be set after construction.

So is this approach any good, should the id property be changed so it can be set after construction? Or should the demo protocol be changed so it creates its conversations itself?

Ideally the demo protocol plugin was supposed to have static conversations or at least scripted ones but that part never got done.

Also we should probably add a create_conversation vfunc to PurpleProtocolConvversation which should be driving the rest of that.

I’ll take a look at that addition as soon as I can.

1 Like