# HG changeset patch
# Node ID 8ceead9b1c41a53f87af74d639cbbbd2fee6d6ca
# Parent  39d5eb52b86f3d0ea37c547bef4e765e0ef4de77
diff --git a/libpurple/purpleattachment.c b/libpurple/purpleattachment.c
--- a/libpurple/purpleattachment.c
+++ b/libpurple/purpleattachment.c
@@ -20,14 +20,15 @@
  * this library; if not, see <https://www.gnu.org/licenses/>.
  */
 
-#include "libpurple/purpleattachment.h"
+#include "purpleattachment.h"
+#include "util.h"
 
 #include <glib/gi18n-lib.h>
 
 struct _PurpleAttachment {
 	GObject parent;
 
-	guint64 id;
+	char *id;
 	char *content_type;
 	gboolean _inline;
 
@@ -62,7 +63,7 @@
 
 	switch(prop_id) {
 	case PROP_ID:
-		g_value_set_uint64(value, purple_attachment_get_id(attachment));
+		g_value_set_string(value, purple_attachment_get_id(attachment));
 		break;
 	case PROP_CONTENT_TYPE:
 		g_value_set_string(value,
@@ -95,7 +96,7 @@
 
 	switch(prop_id) {
 	case PROP_ID:
-		purple_attachment_set_id(attachment, g_value_get_uint64(value));
+		purple_attachment_set_id(attachment, g_value_get_string(value));
 		break;
 	case PROP_CONTENT_TYPE:
 		purple_attachment_set_content_type(attachment,
@@ -124,6 +125,7 @@
 purple_attachment_finalize(GObject *obj) {
 	PurpleAttachment *attachment = PURPLE_ATTACHMENT(obj);
 
+	g_clear_pointer(&attachment->id, g_free);
 	g_clear_pointer(&attachment->content_type, g_free);
 	g_clear_pointer(&attachment->local_uri, g_free);
 	g_clear_pointer(&attachment->remote_uri, g_free);
@@ -150,9 +152,9 @@
 	 *
 	 * Since: 3.0
 	 */
-	properties[PROP_ID] = g_param_spec_uint64(
+	properties[PROP_ID] = g_param_spec_string(
 		"id", NULL, NULL,
-		0, G_MAXUINT64, 0,
+		NULL,
 		G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
 	/**
@@ -229,7 +231,7 @@
  * Public API
  *****************************************************************************/
 PurpleAttachment *
-purple_attachment_new(guint64 id, const char *content_type) {
+purple_attachment_new(const char *id, const char *content_type) {
 	g_return_val_if_fail(content_type != NULL, NULL);
 
 	return g_object_new(
@@ -246,34 +248,23 @@
 	g_return_val_if_fail(PURPLE_IS_ATTACHMENT(attachment1), FALSE);
 	g_return_val_if_fail(PURPLE_IS_ATTACHMENT(attachment2), FALSE);
 
-	return (attachment1->id == attachment2->id);
+	return purple_strequal(attachment1->id, attachment2->id);
 }
 
-guint64
+const char *
 purple_attachment_get_id(PurpleAttachment *attachment) {
 	g_return_val_if_fail(PURPLE_IS_ATTACHMENT(attachment), 0);
 
 	return attachment->id;
 }
 
-guint64 *
-purple_attachment_get_hash_key(PurpleAttachment *attachment) {
-	g_return_val_if_fail(PURPLE_IS_ATTACHMENT(attachment), NULL);
-
-	return &attachment->id;
-}
-
 void
-purple_attachment_set_id(PurpleAttachment *attachment, guint64 id) {
+purple_attachment_set_id(PurpleAttachment *attachment, const char *id) {
 	g_return_if_fail(PURPLE_IS_ATTACHMENT(attachment));
 
-	if(attachment->id == id) {
-		return;
+	if(g_set_str(&attachment->id, id)) {
+		g_object_notify_by_pspec(G_OBJECT(attachment), properties[PROP_ID]);
 	}
-
-	attachment->id = id;
-
-	g_object_notify_by_pspec(G_OBJECT(attachment), properties[PROP_ID]);
 }
 
 gboolean
diff --git a/libpurple/purpleattachment.h b/libpurple/purpleattachment.h
--- a/libpurple/purpleattachment.h
+++ b/libpurple/purpleattachment.h
@@ -58,7 +58,7 @@
  * Since: 3.0
  */
 PURPLE_AVAILABLE_IN_3_0
-PurpleAttachment *purple_attachment_new(guint64 id, const char *content_type);
+PurpleAttachment *purple_attachment_new(const char *id, const char *content_type);
 
 /**
  * purple_attachment_equal:
@@ -87,22 +87,7 @@
  * Since: 3.0
  */
 PURPLE_AVAILABLE_IN_3_0
-guint64 purple_attachment_get_id(PurpleAttachment *attachment);
-
-/**
- * purple_attachment_get_hash_key:
- * @attachment: The #PurpleAttachment instance.
- *
- * Gets the hash key of @attachment.  This should only be used when
- * trying to address a #PurpleAttachment in a #GHashTable that is using
- * g_int64_hash() as the key function.
- *
- * Returns: (transfer none): The hash key of @attachment.
- *
- * Since: 3.0
- */
-PURPLE_AVAILABLE_IN_3_0
-guint64 *purple_attachment_get_hash_key(PurpleAttachment *attachment);
+const char *purple_attachment_get_id(PurpleAttachment *attachment);
 
 /**
  * purple_attachment_set_id:
@@ -114,7 +99,7 @@
  * Since: 3.0
  */
 PURPLE_AVAILABLE_IN_3_0
-void purple_attachment_set_id(PurpleAttachment *attachment, guint64 id);
+void purple_attachment_set_id(PurpleAttachment *attachment, const char *id);
 
 /**
  * purple_attachment_get_inline:
diff --git a/libpurple/purpleattachments.c b/libpurple/purpleattachments.c
--- a/libpurple/purpleattachments.c
+++ b/libpurple/purpleattachments.c
@@ -23,6 +23,7 @@
 #include <gio/gio.h>
 
 #include "purpleattachments.h"
+#include "util.h"
 
 struct _PurpleAttachments {
 	GObject parent;
@@ -201,7 +202,8 @@
 }
 
 PurpleAttachment *
-purple_attachments_find_with_id(PurpleAttachments *attachments, guint64 id) {
+purple_attachments_find_with_id(PurpleAttachments *attachments, const char *id)
+{
 	g_return_val_if_fail(PURPLE_IS_ATTACHMENTS(attachments), NULL);
 
 	for(guint i = 0; i < attachments->attachments->len; i++) {
@@ -209,7 +211,7 @@
 
 		attachment = g_ptr_array_index(attachments->attachments, i);
 
-		if(purple_attachment_get_id(attachment) == id) {
+		if(purple_strequal(purple_attachment_get_id(attachment), id)) {
 			return attachment;
 		}
 	}
diff --git a/libpurple/purpleattachments.h b/libpurple/purpleattachments.h
--- a/libpurple/purpleattachments.h
+++ b/libpurple/purpleattachments.h
@@ -77,7 +77,7 @@
  * Since: 3.0
  */
 PURPLE_AVAILABLE_IN_3_0
-PurpleAttachment *purple_attachments_find_with_id(PurpleAttachments *attachments, guint64 id);
+PurpleAttachment *purple_attachments_find_with_id(PurpleAttachments *attachments, const char *id);
 
 /**
  * purple_attachments_new:
diff --git a/libpurple/tests/test_attachment.c b/libpurple/tests/test_attachment.c
--- a/libpurple/tests/test_attachment.c
+++ b/libpurple/tests/test_attachment.c
@@ -42,7 +42,7 @@
 test_purple_attachment_new(void) {
 	PurpleAttachment *attachment = NULL;
 
-	attachment = purple_attachment_new(1337lu, "text/plain");
+	attachment = purple_attachment_new("1337", "text/plain");
 
 	g_assert_true(PURPLE_IS_ATTACHMENT(attachment));
 
@@ -53,6 +53,7 @@
 test_purple_attachment_properties(void) {
 	PurpleAttachment *attachment = NULL;
 	char *content_type = NULL;
+	char *id = NULL;
 	char *local_uri = NULL;
 	char *remote_uri = NULL;
 	gboolean _inline = FALSE;
@@ -62,6 +63,7 @@
 	attachment = g_object_new(
 		PURPLE_TYPE_ATTACHMENT,
 		"content-type", "text/plain",
+		"id", "1337",
 		"inline", TRUE,
 		"local-uri", "local-uri",
 		"remote-uri", "remote-uri",
@@ -71,6 +73,7 @@
 	g_object_get(
 		attachment,
 		"content-type", &content_type,
+		"id", &id,
 		"inline", &_inline,
 		"local-uri", &local_uri,
 		"remote-uri", &remote_uri,
@@ -80,6 +83,9 @@
 	g_assert_cmpstr(content_type, ==, "text/plain");
 	g_clear_pointer(&content_type, g_free);
 
+	g_assert_cmpstr(id, ==, "1337");
+	g_clear_pointer(&id, g_free);
+
 	g_assert_true(_inline);
 
 	g_assert_cmpstr(local_uri, ==, "local-uri");
@@ -108,7 +114,7 @@
 	g_assert_cmpuint(counter, ==, 1);
 
 	counter = 0;
-	purple_attachment_set_id(attachment, 1337lu);
+	purple_attachment_set_id(attachment, "1337");
 	g_assert_cmpuint(counter, ==, 1);
 
 	counter = 0;
@@ -134,7 +140,7 @@
 test_purple_attachment_equal_self(void) {
 	PurpleAttachment *attachment = NULL;
 
-	attachment = purple_attachment_new(1337lu, "text/plain");
+	attachment = purple_attachment_new("1337", "text/plain");
 
 	g_assert_true(purple_attachment_equal(attachment, attachment));
 
@@ -146,8 +152,8 @@
 	PurpleAttachment *attachment1 = NULL;
 	PurpleAttachment *attachment2 = NULL;
 
-	attachment1 = purple_attachment_new(1337lu, "text/plain");
-	attachment2 = purple_attachment_new(1337lu, "text/html");
+	attachment1 = purple_attachment_new("1337", "text/plain");
+	attachment2 = purple_attachment_new("1337", "text/html");
 
 	g_assert_true(purple_attachment_equal(attachment1, attachment2));
 
@@ -160,8 +166,8 @@
 	PurpleAttachment *attachment1 = NULL;
 	PurpleAttachment *attachment2 = NULL;
 
-	attachment1 = purple_attachment_new(1337lu, "text/plain");
-	attachment2 = purple_attachment_new(7331lu, "text/html");
+	attachment1 = purple_attachment_new("1337", "text/plain");
+	attachment2 = purple_attachment_new("7331", "text/html");
 
 	g_assert_false(purple_attachment_equal(attachment1, attachment2));
 
diff --git a/libpurple/tests/test_attachments.c b/libpurple/tests/test_attachments.c
--- a/libpurple/tests/test_attachments.c
+++ b/libpurple/tests/test_attachments.c
@@ -90,7 +90,7 @@
 	                 G_CALLBACK(test_purple_attachments_notify),
 	                 &n_items_counter);
 
-	attachment = purple_attachment_new(1337lu, "text/plain");
+	attachment = purple_attachment_new("1337", "text/plain");
 
 	/* The first add. */
 	items_changed_counter = 0;
@@ -128,7 +128,7 @@
 	                 G_CALLBACK(test_purple_attachments_notify),
 	                 &n_items_counter);
 
-	attachment = purple_attachment_new(1337lu, "text/plain");
+	attachment = purple_attachment_new("1337", "text/plain");
 
 	/* The first add. */
 	items_changed_counter = 0;
@@ -167,19 +167,19 @@
 	attachments = purple_attachments_new();
 
 	/* Search on the empty collection. */
-	found = purple_attachments_find_with_id(attachments, 1337lu);
+	found = purple_attachments_find_with_id(attachments, "1337");
 	g_assert_null(found);
 
 	/* Create an attachment and add it. */
-	attachment = purple_attachment_new(1337lu, "text/plain");
+	attachment = purple_attachment_new("1337", "text/plain");
 	purple_attachments_add_attachment(attachments, attachment);
 
-	found = purple_attachments_find_with_id(attachments, 1337lu);
+	found = purple_attachments_find_with_id(attachments, "1337");
 	g_assert_true(PURPLE_IS_ATTACHMENT(found));
 	g_assert_true(found == attachment);
 
 	/* Search for an attachment that doesn't exist. */
-	found = purple_attachments_find_with_id(attachments, 42lu);
+	found = purple_attachments_find_with_id(attachments, "42");
 	g_assert_null(found);
 
 	g_assert_finalize_object(attachments);
