Skip to content

Commit 7e95024

Browse files
committed
fix: listen to guest changes
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
1 parent d14a110 commit 7e95024

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/eventbus.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
5+
import { NextcloudUser } from './user'
6+
7+
declare module '@nextcloud/event-bus' {
8+
export interface NextcloudEvents {
9+
// mapping of 'event name' => 'event type'
10+
'user:info:changed': NextcloudUser
11+
}
12+
}

lib/guest.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
import { getBuilder } from '@nextcloud/browser-storage'
66
import { NextcloudUser } from './user'
7-
import { emit } from '@nextcloud/event-bus'
7+
import { emit, subscribe } from '@nextcloud/event-bus'
88

99
const browserStorage = getBuilder('public').persist().build()
1010

@@ -23,6 +23,11 @@ class GuestUser implements NextcloudUser {
2323
this.uid = browserStorage.getItem('guestUid') || self.crypto.randomUUID()
2424
this.isAdmin = false
2525

26+
subscribe('user:info:changed', (guest) => {
27+
this._displayName = guest.displayName
28+
browserStorage.setItem('guestNickname', guest.displayName || '')
29+
})
30+
2631
}
2732

2833
get displayName(): string | null {

0 commit comments

Comments
 (0)