From 404e6f8b870409de63adcefee844ab7ce5110780 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 17 Aug 2020 10:47:27 +0200 Subject: [PATCH 1/3] make alphabetical sort order stable --- src/domain/session/roomlist/RoomTileViewModel.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/domain/session/roomlist/RoomTileViewModel.js b/src/domain/session/roomlist/RoomTileViewModel.js index a638ebd4..9f527f65 100644 --- a/src/domain/session/roomlist/RoomTileViewModel.js +++ b/src/domain/session/roomlist/RoomTileViewModel.js @@ -45,8 +45,12 @@ export class RoomTileViewModel extends ViewModel { } compare(other) { - // sort by name for now - return this._room.name.localeCompare(other._room.name); + // sort alphabetically + const nameCmp = this._room.name.localeCompare(other._room.name); + if (nameCmp === 0) { + return this._room.id.localeCompare(other._room.id); + } + return nameCmp; } get isOpen() { From b5e713105043514db8ab3c5f4b674287701364e8 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 17 Aug 2020 10:47:47 +0200 Subject: [PATCH 2/3] only use 1 letter for avatar initial --- src/domain/avatar.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/domain/avatar.js b/src/domain/avatar.js index 9184762b..f94ba3b2 100644 --- a/src/domain/avatar.js +++ b/src/domain/avatar.js @@ -15,18 +15,11 @@ limitations under the License. */ export function avatarInitials(name) { - let words = name.split(" "); - if (words.length === 1) { - words = words[0].split("-"); + let firstChar = name.charAt(0); + if (firstChar === "!" || firstChar === "@" || firstChar === "#") { + firstChar = name.charAt(1); } - words = words.slice(0, 2); - return words.reduce((i, w) => { - let firstChar = w.charAt(0); - if (firstChar === "!" || firstChar === "@" || firstChar === "#") { - firstChar = w.charAt(1); - } - return i + firstChar.toUpperCase(); - }, ""); + return firstChar.toUpperCase(); } /** From 306309c4f8c79bb1e8f3e6c0da8cc26a5f56702d Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 17 Aug 2020 10:48:00 +0200 Subject: [PATCH 3/3] wrap error and expose room id this makes it easier to track down a (storage) error to a room --- src/matrix/error.js | 11 +++++++++++ src/matrix/room/Room.js | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/matrix/error.js b/src/matrix/error.js index 6f7a200e..07144acd 100644 --- a/src/matrix/error.js +++ b/src/matrix/error.js @@ -14,6 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ +export class WrappedError extends Error { + constructor(message, cause) { + super(`${message}: ${cause.message}`); + this.cause = cause; + } + + get name() { + return "WrappedError"; + } +} + export class HomeServerError extends Error { constructor(method, url, body, status) { super(`${body ? body.error : status} on ${method} ${url}`); diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 5f3b7cf5..1b038972 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -21,6 +21,7 @@ import {GapWriter} from "./timeline/persistence/GapWriter.js"; import {Timeline} from "./timeline/Timeline.js"; import {FragmentIdComparer} from "./timeline/FragmentIdComparer.js"; import {SendQueue} from "./sending/SendQueue.js"; +import {WrappedError} from "../error.js" export class Room extends EventEmitter { constructor({roomId, storage, hsApi, emitCollectionChange, sendScheduler, pendingEvents, user}) { @@ -67,8 +68,12 @@ export class Room extends EventEmitter { } load(summary, txn) { - this._summary.load(summary); - return this._syncWriter.load(txn); + try { + this._summary.load(summary); + return this._syncWriter.load(txn); + } catch (err) { + throw new WrappedError(`Could not load room ${this._roomId}`, err); + } } sendEvent(eventType, content) {