talkatu/talkatu

Update TalkatuMessage:id to be a string.

9 months ago, Gary Kramlich
ebabd7682683
Parents 81886219e64c
Children 953536539d73
Update TalkatuMessage:id to be a string.

Many modern protocols are using uuids as id's and forcing that into a uint64 is
going to lead to collisions. So instead just use a string which should work for
everything.

Testing Done:
Ran the demo and unit tests.

Reviewed at https://reviews.imfreedom.org/r/879/
--- a/demo/talkatudemowindow.c Tue Aug 03 03:05:26 2021 -0500
+++ b/demo/talkatudemowindow.c Sat Aug 07 01:57:35 2021 -0500
@@ -211,9 +211,12 @@
static void
talkatu_demo_window_view_send_message_cb(TalkatuInput *input, gpointer data) {
TalkatuDemoWindow *window = TALKATU_DEMO_WINDOW(data);
+ gchar *sid = NULL;
static guint64 id = 0;
- talkatu_message_set_id(TALKATU_MESSAGE(input), id++);
+ sid = g_strdup_printf("%" G_GUINT64_FORMAT, id++);
+ talkatu_message_set_id(TALKATU_MESSAGE(input), sid);
+ g_free(sid);
talkatu_history_write_message(
TALKATU_HISTORY(window->history),
--- a/talkatu/talkatuinput.c Tue Aug 03 03:05:26 2021 -0500
+++ b/talkatu/talkatuinput.c Sat Aug 07 01:57:35 2021 -0500
@@ -97,7 +97,7 @@
/* TalkatuMessage properties: content type and contents are derived from
* the widget itself.
*/
- guint64 id;
+ gchar *id;
GDateTime *timestamp;
TalkatuContentType content_type;
@@ -146,7 +146,7 @@
/******************************************************************************
* TalkatuMessage Interface
*****************************************************************************/
-static guint64
+static const gchar *
talkatu_input_get_id(TalkatuInput *input) {
TalkatuInputPrivate *priv = talkatu_input_get_instance_private(input);
@@ -154,10 +154,11 @@
}
static void
-talkatu_input_set_id(TalkatuInput *input, guint64 id) {
+talkatu_input_set_id(TalkatuInput *input, const gchar *id) {
TalkatuInputPrivate *priv = talkatu_input_get_instance_private(input);
- priv->id = id;
+ g_free(priv->id);
+ priv->id = g_strdup(id);
g_object_notify(G_OBJECT(input), "id");
}
@@ -642,7 +643,7 @@
g_value_set_flags(value, talkatu_input_get_send_binding(input));
break;
case PROP_ID:
- g_value_set_uint64(value, talkatu_input_get_id(input));
+ g_value_set_string(value, talkatu_input_get_id(input));
break;
case PROP_TIMESTAMP:
g_value_set_boxed(value, talkatu_input_get_timestamp(input));
@@ -677,7 +678,7 @@
talkatu_input_set_send_binding(input, g_value_get_flags(value));
break;
case PROP_ID:
- talkatu_input_set_id(input, g_value_get_uint64(value));
+ talkatu_input_set_id(input, g_value_get_string(value));
break;
case PROP_TIMESTAMP:
talkatu_input_set_timestamp(input, g_value_get_boxed(value));
--- a/talkatu/talkatumessage.c Tue Aug 03 03:05:26 2021 -0500
+++ b/talkatu/talkatumessage.c Sat Aug 07 01:57:35 2021 -0500
@@ -89,10 +89,10 @@
*
* The identifier of the message.
*/
- pspec = g_param_spec_uint64(
+ pspec = g_param_spec_string(
"id", "id", "The identifier of the message",
- 0, G_MAXUINT64, 0,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS
);
g_object_interface_install_property(iface, pspec);
@@ -104,7 +104,7 @@
pspec = g_param_spec_boxed(
"timestamp", "timestamp", "The timestamp of the message",
G_TYPE_DATE_TIME,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS
);
g_object_interface_install_property(iface, pspec);
@@ -117,7 +117,7 @@
"content-type", "content-type", "The content-type of the message",
TALKATU_TYPE_CONTENT_TYPE,
TALKATU_CONTENT_TYPE_PLAIN,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS
);
g_object_interface_install_property(iface, pspec);
@@ -129,7 +129,7 @@
pspec = g_param_spec_string(
"author", "author", "The author of the message",
NULL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS
);
g_object_interface_install_property(iface, pspec);
@@ -155,7 +155,7 @@
pspec = g_param_spec_string(
"contents", "contents", "The contents of the message",
NULL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS
);
g_object_interface_install_property(iface, pspec);
@@ -168,7 +168,7 @@
"edited", "edited",
"Whether this message has been edited by its author",
FALSE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS
);
g_object_interface_install_property(iface, pspec);
}
@@ -183,13 +183,13 @@
*
* Gets the identifier of the @message.
*
- * Returns: The identifier of @message.
+ * Returns: (transfer full): The identifier of @message.
*/
-guint64
+gchar *
talkatu_message_get_id(TalkatuMessage *message) {
- guint64 ret = 0;
+ gchar *ret = NULL;
- g_return_val_if_fail(TALKATU_IS_MESSAGE(message), 0);
+ g_return_val_if_fail(TALKATU_IS_MESSAGE(message), NULL);
g_object_get(G_OBJECT(message), "id", &ret, NULL);
@@ -204,7 +204,7 @@
* Sets the identifier of @message.
*/
void
-talkatu_message_set_id(TalkatuMessage *message, guint64 id) {
+talkatu_message_set_id(TalkatuMessage *message, const gchar *id) {
g_return_if_fail(TALKATU_IS_MESSAGE(message));
g_object_set(G_OBJECT(message), "id", id, NULL);
--- a/talkatu/talkatumessage.h Tue Aug 03 03:05:26 2021 -0500
+++ b/talkatu/talkatumessage.h Sat Aug 07 01:57:35 2021 -0500
@@ -58,8 +58,8 @@
gpointer reserved[4];
};
-guint64 talkatu_message_get_id(TalkatuMessage *message);
-void talkatu_message_set_id(TalkatuMessage *message, guint64 id);
+gchar *talkatu_message_get_id(TalkatuMessage *message);
+void talkatu_message_set_id(TalkatuMessage *message, const gchar *id);
GDateTime *talkatu_message_get_timestamp(TalkatuMessage *message);
void talkatu_message_set_timestamp(TalkatuMessage *message, GDateTime *timestamp);