# How does the Demo protocol create its conversations?

**URL:** <https://discourse.imfreedom.org/t/how-does-the-demo-protocol-create-its-conversations/141>\
**Category:** Libpurple\
**Tags:** pidgin3, development\
**Created:** [February 28, 2024, 8:53am UTC](https://discourse.imfreedom.org/t/how-does-the-demo-protocol-create-its-conversations/141 "2024-02-28T08:53:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivanhoe](https://discourse.imfreedom.org/user_avatar/discourse.imfreedom.org/ivanhoe/32/24_2.png) [@ivanhoe](https://discourse.imfreedom.org/u/ivanhoe)\
**Post date:** [February 28, 2024, 8:53am UTC](https://discourse.imfreedom.org/t/how-does-the-demo-protocol-create-its-conversations/141/1 "2024-02-28T08:53:18Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ivanhoe](https://discourse.imfreedom.org/user_avatar/discourse.imfreedom.org/ivanhoe/32/24_2.png) [@ivanhoe](https://discourse.imfreedom.org/u/ivanhoe)\
**Post date:** [February 28, 2024, 9:57am UTC](https://discourse.imfreedom.org/t/how-does-the-demo-protocol-create-its-conversations/141/2 "2024-02-28T09:57:23Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![grim](https://discourse.imfreedom.org/user_avatar/discourse.imfreedom.org/grim/32/4_2.png) [@grim](https://discourse.imfreedom.org/u/grim)\
**Post date:** [February 28, 2024, 10:41pm UTC](https://discourse.imfreedom.org/t/how-does-the-demo-protocol-create-its-conversations/141/3 "2024-02-28T22:41:02Z")

</div>

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](https://docs.imfreedom.org/purple3/iface.ProtocolConversation.html) which should be driving the rest of that.

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