From 7e95024b8e28e33dffcfa7807df31eef238a21ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Tue, 13 May 2025 22:29:49 +0200 Subject: [PATCH] fix: listen to guest changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/eventbus.d.ts | 12 ++++++++++++ lib/guest.ts | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 lib/eventbus.d.ts diff --git a/lib/eventbus.d.ts b/lib/eventbus.d.ts new file mode 100644 index 00000000..cafc4da1 --- /dev/null +++ b/lib/eventbus.d.ts @@ -0,0 +1,12 @@ +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ +import { NextcloudUser } from './user' + +declare module '@nextcloud/event-bus' { + export interface NextcloudEvents { + // mapping of 'event name' => 'event type' + 'user:info:changed': NextcloudUser + } +} diff --git a/lib/guest.ts b/lib/guest.ts index d0e16b2f..110c5cfc 100644 --- a/lib/guest.ts +++ b/lib/guest.ts @@ -4,7 +4,7 @@ */ import { getBuilder } from '@nextcloud/browser-storage' import { NextcloudUser } from './user' -import { emit } from '@nextcloud/event-bus' +import { emit, subscribe } from '@nextcloud/event-bus' const browserStorage = getBuilder('public').persist().build() @@ -23,6 +23,11 @@ class GuestUser implements NextcloudUser { this.uid = browserStorage.getItem('guestUid') || self.crypto.randomUUID() this.isAdmin = false + subscribe('user:info:changed', (guest) => { + this._displayName = guest.displayName + browserStorage.setItem('guestNickname', guest.displayName || '') + }) + } get displayName(): string | null {