UBER-1188: Fix exception during login/logout (#4364)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2024-01-16 14:36:29 +07:00 committed by GitHub
parent 8f173069c8
commit 31b0d98d90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,15 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// //
import { import { type ActivityMessage } from '@hcengineering/activity'
type Account, import { SortingOrder, getCurrentAccount, type Class, type Doc, type Ref, type WithLookup } from '@hcengineering/core'
type Class,
type Doc,
getCurrentAccount,
type Ref,
SortingOrder,
type WithLookup
} from '@hcengineering/core'
import notification, { import notification, {
type ActivityInboxNotification, type ActivityInboxNotification,
type Collaborators, type Collaborators,
@ -28,9 +21,8 @@ import notification, {
type InboxNotification, type InboxNotification,
type InboxNotificationsClient type InboxNotificationsClient
} from '@hcengineering/notification' } from '@hcengineering/notification'
import { derived, writable } from 'svelte/store'
import { createQuery, getClient } from '@hcengineering/presentation' import { createQuery, getClient } from '@hcengineering/presentation'
import { type ActivityMessage } from '@hcengineering/activity' import { derived, writable } from 'svelte/store'
/** /**
* @public * @public
@ -73,16 +65,14 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
private readonly docNotifyContextsQuery = createQuery(true) private readonly docNotifyContextsQuery = createQuery(true)
private readonly inboxNotificationsQuery = createQuery(true) private readonly inboxNotificationsQuery = createQuery(true)
private readonly _user: Ref<Account>
private _docNotifyContextByDoc = new Map<Ref<Doc>, DocNotifyContext>() private _docNotifyContextByDoc = new Map<Ref<Doc>, DocNotifyContext>()
private _inboxNotifications: Array<WithLookup<InboxNotification>> = [] private _inboxNotifications: Array<WithLookup<InboxNotification>> = []
private constructor () { private constructor () {
this._user = getCurrentAccount()._id
this.docNotifyContextsQuery.query( this.docNotifyContextsQuery.query(
notification.class.DocNotifyContext, notification.class.DocNotifyContext,
{ {
user: this._user user: getCurrentAccount()._id
}, },
(result: DocNotifyContext[]) => { (result: DocNotifyContext[]) => {
this.docNotifyContexts.set(result) this.docNotifyContexts.set(result)
@ -93,7 +83,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
this.inboxNotificationsQuery.query( this.inboxNotificationsQuery.query(
notification.class.InboxNotification, notification.class.InboxNotification,
{ {
user: this._user user: getCurrentAccount()._id
}, },
(result: InboxNotification[]) => { (result: InboxNotification[]) => {
this.inboxNotifications.set(result) this.inboxNotifications.set(result)
@ -162,10 +152,10 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
collaboratorsMixin.space, collaboratorsMixin.space,
notification.mixin.Collaborators, notification.mixin.Collaborators,
{ {
collaborators: [this._user] collaborators: [getCurrentAccount()._id]
} }
) )
} else if (!collaboratorsMixin.collaborators.includes(this._user)) { } else if (!collaboratorsMixin.collaborators.includes(getCurrentAccount()._id)) {
await client.updateMixin( await client.updateMixin(
collaboratorsMixin._id, collaboratorsMixin._id,
collaboratorsMixin._class, collaboratorsMixin._class,
@ -173,7 +163,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
notification.mixin.Collaborators, notification.mixin.Collaborators,
{ {
$push: { $push: {
collaborators: this._user collaborators: getCurrentAccount()._id
} }
} }
) )
@ -182,7 +172,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
await client.createDoc(notification.class.DocNotifyContext, doc.space, { await client.createDoc(notification.class.DocNotifyContext, doc.space, {
attachedTo: _id, attachedTo: _id,
attachedToClass: _class, attachedToClass: _class,
user: this._user, user: getCurrentAccount()._id,
hidden: true hidden: true
}) })
} }