"use strict";

module.exports = function (a, b) {
	if (a.type === "roomStateUpdate" && b.type === "roomTimelineEvent") {
		// Sort roomStateUpdates towards the front
		return -1;
	} else if (a.type === "roomTimelineEvent" && b.type === "roomStateUpdate") {
		return 1;
	} else if (a.timestamp == null && b.timestamp != null) {
		// Sort timestamp-less events towards the front
		return -1;
	} else if (a.timestamp != null && b.timestamp == null) {
		return 1;
	} else if (a.timestamp == null && b.timestamp == null) {
		// Keep timestamp-less events stable, relative to each other
		return 0;
	} else {
		return (a.timestamp - b.timestamp);
	}
};
