Skip to content

Commit

Permalink
Get rid of 'ne' in inbox queries (#6258)
Browse files Browse the repository at this point in the history
Signed-off-by: Kristina Fefelova <[email protected]>
  • Loading branch information
kristina-fefelova authored Aug 5, 2024
1 parent c150830 commit 32f0a7d
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion models/notification/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class TInboxNotification extends TDoc implements InboxNotification {
isViewed!: boolean

@Prop(TypeBoolean(), core.string.Boolean)
archived?: boolean
archived!: boolean

title?: IntlString
body?: IntlString
Expand Down
23 changes: 22 additions & 1 deletion models/notification/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import notification, {
notificationId,
NotificationStatus,
type BrowserNotification,
type DocNotifyContext
type DocNotifyContext,
type InboxNotification
} from '@hcengineering/notification'
import { DOMAIN_PREFERENCE } from '@hcengineering/preference'

Expand Down Expand Up @@ -166,6 +167,26 @@ export const notificationOperation: MigrateOperation = {
DOMAIN_USER_NOTIFY
)
}
},
{
state: 'fill-notification-archived-field-v1',
func: async (client) => {
await client.update<InboxNotification>(
DOMAIN_NOTIFICATION,
{ _class: notification.class.ActivityInboxNotification, archived: { $exists: false } },
{ archived: false }
)
await client.update<InboxNotification>(
DOMAIN_NOTIFICATION,
{ _class: notification.class.CommonInboxNotification, archived: { $exists: false } },
{ archived: false }
)
await client.update<InboxNotification>(
DOMAIN_NOTIFICATION,
{ _class: notification.class.MentionInboxNotification, archived: { $exists: false } },
{ archived: false }
)
}
}
])
await client.deleteMany<BrowserNotification>(DOMAIN_USER_NOTIFY, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@
)
archivedOtherNotificationsQuery.query(
notification.class.InboxNotification,
{ _class: { $ne: notification.class.ActivityInboxNotification }, archived: true, user: me._id },
notification.class.CommonInboxNotification,
{ archived: true, user: me._id },
(res) => {
archivedOtherNotifications = res
},
Expand Down
16 changes: 8 additions & 8 deletions plugins/notification-resources/src/inboxNotificationsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import notification, {
} from '@hcengineering/notification'
import { createQuery, getClient } from '@hcengineering/presentation'
import { derived, get, writable } from 'svelte/store'

import { isActivityNotification } from './utils'

/**
Expand Down Expand Up @@ -101,10 +102,9 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
}
)
this.otherInboxNotificationsQuery.query(
notification.class.InboxNotification,
notification.class.CommonInboxNotification,
{
_class: { $ne: notification.class.ActivityInboxNotification },
archived: { $ne: true },
archived: false,
user: getCurrentAccount()._id
},
(result: InboxNotification[]) => {
Expand All @@ -120,7 +120,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
this.activityInboxNotificationsQuery.query(
notification.class.ActivityInboxNotification,
{
archived: { $ne: true },
archived: false,
user: getCurrentAccount()._id
},
(result: ActivityInboxNotification[]) => {
Expand Down Expand Up @@ -242,7 +242,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
notification.class.InboxNotification,
{
user: getCurrentAccount()._id,
archived: { $ne: true }
archived: false
},
{ projection: { _id: 1, _class: 1, space: 1 } }
)
Expand All @@ -267,8 +267,8 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
notification.class.InboxNotification,
{
user: getCurrentAccount()._id,
isViewed: { $ne: true },
archived: { $ne: true }
isViewed: false,
archived: false
},
{ projection: { _id: 1, _class: 1, space: 1 } }
)
Expand All @@ -293,7 +293,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
{
user: getCurrentAccount()._id,
isViewed: true,
archived: { $ne: true }
archived: false
},
{
projection: { _id: 1, _class: 1, space: 1, docNotifyContext: 1 },
Expand Down
2 changes: 1 addition & 1 deletion plugins/notification-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export async function archiveContextNotifications (doc?: DocNotifyContext): Prom
try {
const notifications = await ops.findAll(
notification.class.InboxNotification,
{ docNotifyContext: doc._id, archived: { $ne: true } },
{ docNotifyContext: doc._id, archived: false },
{ projection: { _id: 1, _class: 1, space: 1 } }
)

Expand Down
2 changes: 1 addition & 1 deletion plugins/notification/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export interface InboxNotification extends Doc {
body?: IntlString
intlParams?: Record<string, string | number>
intlParamsNotLocalized?: Record<string, IntlString>
archived?: boolean
archived: boolean
}

export interface ActivityInboxNotification extends InboxNotification {
Expand Down
3 changes: 2 additions & 1 deletion server-plugins/activity-resources/src/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ export async function getPersonNotificationTxes (
mentionedIn: reference.attachedDocId ?? reference.srcDocId,
mentionedInClass: reference.attachedDocClass ?? reference.srcDocClass,
user: receiver._id,
isViewed: false
isViewed: false,
archived: false
}

const sender = (
Expand Down
1 change: 1 addition & 0 deletions server-plugins/notification-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ export async function pushInboxNotifications (
user: account._id,
isViewed: false,
docNotifyContext: docNotifyContextId,
archived: false,
...data
}
const notificationTx = control.txFactory.createTxCreateDoc(_class, space, notificationData)
Expand Down
1 change: 1 addition & 0 deletions services/github/pod-github/src/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export async function createNotification (
message: data.message,
props: data.props,
isViewed: false,
archived: false,
docNotifyContext: docNotifyContext?._id as Ref<DocNotifyContext>
})
}
Expand Down

0 comments on commit 32f0a7d

Please sign in to comment.