forked from mystiq/hydrogen-web
add logging for room list sorting
This commit is contained in:
parent
3e8e1bab67
commit
41a7448c74
1 changed files with 33 additions and 8 deletions
|
@ -49,34 +49,59 @@ export class RoomTileViewModel extends ViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
compare(other) {
|
compare(other) {
|
||||||
|
/*
|
||||||
|
put unread rooms first
|
||||||
|
then put rooms with a timestamp first, and sort by name
|
||||||
|
then sort by name for rooms without a timestamp
|
||||||
|
*/
|
||||||
const myRoom = this._room;
|
const myRoom = this._room;
|
||||||
const theirRoom = other._room;
|
const theirRoom = other._room;
|
||||||
|
|
||||||
|
let buf = "";
|
||||||
|
function log(...args) {
|
||||||
|
buf = buf + args.join(" ") + "\n";
|
||||||
|
}
|
||||||
|
function logResult(result) {
|
||||||
|
if (result === 0) {
|
||||||
|
log("rooms are equal (should not happen)", result);
|
||||||
|
} else if (result > 0) {
|
||||||
|
log(`${theirRoom.name || theirRoom.id} comes first`, result);
|
||||||
|
} else {
|
||||||
|
log(`${myRoom.name || myRoom.id} comes first`, result);
|
||||||
|
}
|
||||||
|
console.log(buf);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
log(`comparing ${myRoom.name || theirRoom.id} and ${theirRoom.name || theirRoom.id} ...`);
|
||||||
|
log("comparing isUnread...");
|
||||||
if (isSortedAsUnread(this) !== isSortedAsUnread(other)) {
|
if (isSortedAsUnread(this) !== isSortedAsUnread(other)) {
|
||||||
if (isSortedAsUnread(this)) {
|
if (isSortedAsUnread(this)) {
|
||||||
return -1;
|
return logResult(-1);
|
||||||
}
|
}
|
||||||
return 1;
|
return logResult(1);
|
||||||
}
|
}
|
||||||
const myTimestamp = myRoom.lastMessageTimestamp;
|
const myTimestamp = myRoom.lastMessageTimestamp;
|
||||||
const theirTimestamp = theirRoom.lastMessageTimestamp;
|
const theirTimestamp = theirRoom.lastMessageTimestamp;
|
||||||
// rooms with a timestamp come before rooms without one
|
// rooms with a timestamp come before rooms without one
|
||||||
if ((myTimestamp === null) !== (theirTimestamp === null)) {
|
if ((myTimestamp === null) !== (theirTimestamp === null)) {
|
||||||
|
log("checking if either does not have lastMessageTimestamp ...");
|
||||||
if (theirTimestamp === null) {
|
if (theirTimestamp === null) {
|
||||||
return -1;
|
return logResult(-1);
|
||||||
}
|
}
|
||||||
return 1;
|
return logResult(1);
|
||||||
}
|
}
|
||||||
const timeDiff = theirTimestamp - myTimestamp;
|
const timeDiff = theirTimestamp - myTimestamp;
|
||||||
if (timeDiff === 0) {
|
if (timeDiff === 0 || !Number.isSafeInteger(theirTimestamp) || !Number.isSafeInteger(myTimestamp)) {
|
||||||
|
log("checking name ...");
|
||||||
// sort alphabetically
|
// sort alphabetically
|
||||||
const nameCmp = this.name.localeCompare(other.name);
|
const nameCmp = this.name.localeCompare(other.name);
|
||||||
if (nameCmp === 0) {
|
if (nameCmp === 0) {
|
||||||
return this._room.id.localeCompare(other._room.id);
|
return logResult(this._room.id.localeCompare(other._room.id));
|
||||||
}
|
}
|
||||||
return nameCmp;
|
return logResult(nameCmp);
|
||||||
}
|
}
|
||||||
return timeDiff;
|
log("checking timestamp ...");
|
||||||
|
return logResult(timeDiff);
|
||||||
}
|
}
|
||||||
|
|
||||||
get isOpen() {
|
get isOpen() {
|
||||||
|
|
Loading…
Reference in a new issue