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;
}
/* 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__ */
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 */