libpurple/buddy.c

changeset 41820
19269097f706
parent 41771
c5877e2c93f2
child 41960
c8a4853205e3
--- a/libpurple/buddy.c	Sun Oct 23 02:26:12 2022 -0500
+++ b/libpurple/buddy.c	Sun Oct 23 02:38:25 2022 -0500
@@ -170,11 +170,24 @@
 	G_OBJECT_CLASS(purple_buddy_parent_class)->constructed(object);
 
 	if(priv->id == NULL) {
-		gchar *id = g_uuid_string_random();
+		/* If there is no id for the user, generate a SHA256 based on the
+		 * account_id and the username.
+		 */
+		GChecksum *sum = g_checksum_new(G_CHECKSUM_SHA256);
+		const guchar *data = NULL;
+
+		data = (const guchar *)purple_account_get_protocol_id(priv->account);
+		g_checksum_update(sum, data, -1);
 
-		purple_buddy_set_id(buddy, id);
+		data = (const guchar *)purple_account_get_username(priv->account);
+		g_checksum_update(sum, data, -1);
 
-		g_free(id);
+		data = (const guchar *)priv->name;
+		g_checksum_update(sum, data, -1);
+
+		purple_buddy_set_id(buddy, g_checksum_get_string(sum));
+
+		g_checksum_free(sum);
 	}
 
 	priv->presence = PURPLE_PRESENCE(purple_buddy_presence_new(buddy));
@@ -247,7 +260,7 @@
 		"name", "Name",
 		"The name of the buddy.",
 		NULL,
-		G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+		G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
 
 	properties[PROP_LOCAL_ALIAS] = g_param_spec_string(
 		"local-alias", "Local alias",

mercurial