void chime_complete_messages()

in prpl/messages.c [86:124]


void chime_complete_messages(ChimeConnection *cxn, struct chime_msgs *msgs)
{
	GList *l = NULL;

	/* Sort messages by time */
	g_hash_table_foreach_remove(msgs->msg_gather, insert_queued_msg, &l);

	while (l) {
		struct msg_sort *ms = l->data;
		const gchar *id = ms->id;
		JsonNode *node = ms->node;
		gboolean seen_one = FALSE;

		l = g_list_remove(l, ms);

		if (is_msg_unseen(msgs->seen_msgs, id)) {
			gboolean new_msg = FALSE;
			/* Only treat it as a new message if it is the last one,
			 * and it was sent within the last day */
			if (!l && !msgs->fetch_until && ms->tm.tv_sec + 86400 < time(NULL))
				new_msg = TRUE;

			seen_one = TRUE;
			msgs->cb(cxn, msgs, node, ms->tm.tv_sec, new_msg);
		}
		g_free(ms);

		/* Last message, note down the received time */
		if (!l && !msgs->msgs_failed && seen_one) {
			const gchar *tm;
			if (parse_string(node, "CreatedOn", &tm))
				chime_update_last_msg(cxn, msgs, tm, id);
		}
		json_node_unref(node);
	}

	if (!msgs->fetch_until)
		g_clear_pointer(&msgs->msg_gather, g_hash_table_destroy);
}