]> www.infradead.org Git - pidgin-chime.git/commitdiff
Kill parse_time() and replace it with iso8601_to_ms()
authorDavid Woodhouse <dwmw@amazon.co.uk>
Sat, 11 Nov 2023 17:15:19 +0000 (17:15 +0000)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Sat, 11 Nov 2023 21:02:53 +0000 (16:02 -0500)
GTimeVal has been deprecated; we need to use GDateTime to parse ISO8601
strings. All we really want is milliseconds so just create a helper to
do that, and convert the one user of parse_time() to it for now. Other
callers of g_time_val_from_iso8601() will use it next...

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
chime/chime-connection.c
chime/chime-connection.h
prpl/messages.c

index bc8e4a935376a940498b8f464e2785e5cb19d2e3..06ff42e431b978b184ccad7e9bacf165246bb1c0 100644 (file)
@@ -1012,17 +1012,20 @@ gboolean parse_string(JsonNode *parent, const gchar *name, const gchar **res)
        return TRUE;
 }
 
-gboolean parse_time(JsonNode *parent, const gchar *name, const gchar **time_str, GTimeVal *tv)
+gboolean iso8601_to_ms(const gchar *str, gint64 *ms)
 {
-       const gchar *msg_time;
+       /* I *believe* this doesn't leak a new one every time! */
+       GTimeZone *utc = g_time_zone_new_utc();
+       GDateTime *dt;
 
-       if (!parse_string(parent, name, &msg_time) ||
-           !g_time_val_from_iso8601(msg_time, tv))
+       dt = g_date_time_new_from_iso8601(str, utc);
+       if (!dt)
                return FALSE;
 
-       if (time_str)
-               *time_str = msg_time;
+       *ms = (g_date_time_to_unix(dt) * 1000) +
+               (g_date_time_get_microsecond(dt) / 1000000);
 
+       g_date_time_unref(dt);
        return TRUE;
 }
 
index 33d24c022e486f4dea8c9e48732d158b2db068f0..2b4ac24fb88ec3120e2ea01913e63b1965a2d519 100644 (file)
@@ -108,8 +108,9 @@ void chime_connection_disconnect(ChimeConnection *cxn);
 /* XXX: Expose something other than a JsonNode for messages? */
 gboolean parse_int(JsonNode *node, const gchar *member, gint64 *val);
 gboolean parse_string(JsonNode *parent, const gchar *name, const gchar **res);
-gboolean parse_time(JsonNode *parent, const gchar *name, const gchar **time_str, GTimeVal *tv);
 gboolean parse_boolean(JsonNode *node, const gchar *member, gboolean *val);
+gboolean iso8601_to_ms(const gchar *str, gint64 *ms);
+
 G_END_DECLS
 
 #endif /* __CHIME_CONNECTION_H__ */
index f87848994ad7ac82724960c5ec84218a4fd80b5f..17a74e02f4cb527531a39c86d54402abb49f8822 100644 (file)
@@ -177,16 +177,19 @@ static void on_message_received(ChimeObject *obj, JsonNode *node, struct chime_m
                g_hash_table_insert(msgs->msg_gather, (gchar *)id, json_node_ref(node));
                return;
        }
-       GTimeVal tv;
        const gchar *created;
-       if (!parse_time(node, "CreatedOn", &created, &tv))
+       if (!parse_string(node, "CreatedOn", &created))
+               return;
+
+       gint64 created_ms;
+       if (!iso8601_to_ms(created, &created_ms))
                return;
 
        if (!msgs->msgs_failed)
                chime_update_last_msg(cxn, msgs, created, id);
 
        if (is_msg_unseen(msgs->seen_msgs, id))
-               msgs->cb(cxn, msgs, node, tv.tv_sec, TRUE);
+               msgs->cb(cxn, msgs, node, created_ms / 1000, TRUE);
 }
 
 /* Once the message fetching is complete, we can play the fetched messages in order */