From fd00fec6f1f91ea55fe59b05f0658318c2738f42 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 31 Aug 2022 00:16:14 -0500 Subject: [PATCH] Fix `DisabledComposerView` description being overriden by powerlevel changes (#58) We added the description in https://github.com/matrix-org/matrix-public-archive/pull/54 but then made a fix to one of the after render errors, https://github.com/matrix-org/matrix-public-archive/pull/57, which exposed that the description is then overriden when the powerlevel changes. We now just override the getters directly instead of the internal fields which are overwritten internally. --- This also fixes a warning from Hydrogen in the console: ``` disposable not found, did it leak? {kind: 'disabled', description: Array(3)} ``` --- shared/4-hydrogen-vm-render-script.js | 41 ++++++++++++++++----------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/shared/4-hydrogen-vm-render-script.js b/shared/4-hydrogen-vm-render-script.js index 06b0fc9..b666e13 100644 --- a/shared/4-hydrogen-vm-render-script.js +++ b/shared/4-hydrogen-vm-render-script.js @@ -262,25 +262,32 @@ async function mountHydrogen() { this.navigation.applyPath(path); }; - // FIXME: We shouldn't have to dive into the internal fields to make this work - roomViewModel._timelineVM = timelineViewModel; + Object.defineProperty(roomViewModel, 'timelineViewModel', { + get() { + return timelineViewModel; + }, + }); const fromDate = new Date(fromTimestamp); const dateString = fromDate.toISOString().split('T')[0]; - roomViewModel._composerVM = { - kind: 'disabled', - description: [ - `You're viewing an archive of events from ${dateString}. Use a `, - tag.a( - { - href: matrixPublicArchiveURLCreator.permalinkForRoomId(roomData.id), - rel: 'noopener', - target: '_blank', - }, - ['Matrix client'] - ), - ` to start chatting in this room.`, - ], - }; + Object.defineProperty(roomViewModel, 'composerViewModel', { + get() { + return { + kind: 'disabled', + description: [ + `You're viewing an archive of events from ${dateString}. Use a `, + tag.a( + { + href: matrixPublicArchiveURLCreator.permalinkForRoomId(roomData.id), + rel: 'noopener', + target: '_blank', + }, + ['Matrix client'] + ), + ` to start chatting in this room.`, + ], + }; + }, + }); const archiveViewModel = new ArchiveViewModel({ // Hydrogen options