Get rid of 'ne'/'nin' in chat queries (#6265)

This commit is contained in:
Kristina 2024-08-06 09:07:06 +04:00 committed by GitHub
parent eb1d73801b
commit 5450a0754d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 51 additions and 52 deletions

View File

@ -63,7 +63,8 @@ export async function createDocNotifyContexts (
await tx.createDoc(notification.class.DocNotifyContext, core.space.Space, { await tx.createDoc(notification.class.DocNotifyContext, core.space.Space, {
user: user._id, user: user._id,
attachedTo, attachedTo,
attachedToClass attachedToClass,
isPinned: false
}) })
} }
} }

View File

@ -210,7 +210,7 @@ export class TDocNotifyContext extends TDoc implements DocNotifyContext {
lastUpdateTimestamp?: Timestamp lastUpdateTimestamp?: Timestamp
@Prop(TypeBoolean(), notification.string.Pinned) @Prop(TypeBoolean(), notification.string.Pinned)
isPinned?: boolean isPinned!: boolean
} }
@Model(notification.class.InboxNotification, core.class.Doc, DOMAIN_NOTIFICATION) @Model(notification.class.InboxNotification, core.class.Doc, DOMAIN_NOTIFICATION)

View File

@ -187,6 +187,16 @@ export const notificationOperation: MigrateOperation = {
{ archived: false } { archived: false }
) )
} }
},
{
state: 'fill-contexts-pinned-field-v1',
func: async (client) => {
await client.update<DocNotifyContext>(
DOMAIN_DOC_NOTIFY,
{ _class: notification.class.DocNotifyContext, isPinned: { $exists: false } },
{ isPinned: false }
)
}
} }
]) ])
await client.deleteMany<BrowserNotification>(DOMAIN_USER_NOTIFY, { await client.deleteMany<BrowserNotification>(DOMAIN_USER_NOTIFY, {

View File

@ -63,7 +63,8 @@
await client.createDoc(notification.class.DocNotifyContext, channelId, { await client.createDoc(notification.class.DocNotifyContext, channelId, {
user: accountId, user: accountId,
attachedTo: channelId, attachedTo: channelId,
attachedToClass: chunter.class.Channel attachedToClass: chunter.class.Channel,
isPinned: false
}) })
openChannel(channelId, chunter.class.Channel) openChannel(channelId, chunter.class.Channel)

View File

@ -89,7 +89,8 @@
await client.createDoc(notification.class.DocNotifyContext, dmId, { await client.createDoc(notification.class.DocNotifyContext, dmId, {
user: myAccId, user: myAccId,
attachedTo: dmId, attachedTo: dmId,
attachedToClass: chunter.class.DirectMessage attachedToClass: chunter.class.DirectMessage,
isPinned: false
}) })
openChannel(dmId, chunter.class.DirectMessage) openChannel(dmId, chunter.class.DirectMessage)

View File

@ -14,8 +14,8 @@
--> -->
<script lang="ts"> <script lang="ts">
import activity from '@hcengineering/activity' import activity from '@hcengineering/activity'
import { Class, Doc, getCurrentAccount, groupByArray, reduceCalls, Ref, SortingOrder } from '@hcengineering/core' import { Class, Doc, groupByArray, reduceCalls, Ref } from '@hcengineering/core'
import notification, { DocNotifyContext } from '@hcengineering/notification' import { DocNotifyContext } from '@hcengineering/notification'
import { InboxNotificationsClientImpl } from '@hcengineering/notification-resources' import { InboxNotificationsClientImpl } from '@hcengineering/notification-resources'
import { IntlString } from '@hcengineering/platform' import { IntlString } from '@hcengineering/platform'
import { createQuery, getClient, LiveQuery } from '@hcengineering/presentation' import { createQuery, getClient, LiveQuery } from '@hcengineering/presentation'
@ -40,32 +40,23 @@
const hierarchy = client.getHierarchy() const hierarchy = client.getHierarchy()
const inboxClient = InboxNotificationsClientImpl.getClient() const inboxClient = InboxNotificationsClientImpl.getClient()
const contextByDocStore = inboxClient.contextByDoc const contextByDocStore = inboxClient.contextByDoc
const contextsStore = inboxClient.contexts
const contextsQuery = createQuery()
const objectsQueryByClass = new Map<Ref<Class<Doc>>, { query: LiveQuery, limit: number }>() const objectsQueryByClass = new Map<Ref<Class<Doc>>, { query: LiveQuery, limit: number }>()
let objectsByClass = new Map<Ref<Class<Doc>>, { docs: Doc[], total: number }>()
let contexts: DocNotifyContext[] = [] let contexts: DocNotifyContext[] = []
let objectsByClass = new Map<Ref<Class<Doc>>, { docs: Doc[], total: number }>()
let shouldPushObject = false let shouldPushObject = false
let sections: Section[] = [] let sections: Section[] = []
$: contextsQuery.query( $: contexts = $contextsStore.filter(({ attachedToClass, isPinned }) => {
notification.class.DocNotifyContext, if (model.isPinned !== isPinned) return false
{ if (model._class !== undefined && model._class !== attachedToClass) return false
...model.query, if (model.skipClasses !== undefined && model.skipClasses.includes(attachedToClass)) return false
[`${chunter.mixin.ChannelInfo}.hidden`]: { $ne: true }, if (hierarchy.classHierarchyMixin(attachedToClass, activity.mixin.ActivityDoc) === undefined) return false
user: getCurrentAccount()._id return true
}, })
(res: DocNotifyContext[]) => {
contexts = res.filter(
({ attachedToClass }) =>
hierarchy.classHierarchyMixin(attachedToClass, activity.mixin.ActivityDoc) !== undefined
)
},
{ sort: { createdOn: SortingOrder.Ascending } }
)
$: loadObjects(contexts) $: loadObjects(contexts)

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
// //
import { type Asset, type IntlString } from '@hcengineering/platform' import { type Asset, type IntlString } from '@hcengineering/platform'
import { type Account, type Doc, type DocumentQuery, type IdMap, type Ref, type UserStatus } from '@hcengineering/core' import { type Account, type Class, type Doc, type IdMap, type Ref, type UserStatus } from '@hcengineering/core'
import { type DocNotifyContext } from '@hcengineering/notification' import { type DocNotifyContext } from '@hcengineering/notification'
import { type AnySvelteComponent, type IconSize, type Action } from '@hcengineering/ui' import { type AnySvelteComponent, type IconSize, type Action } from '@hcengineering/ui'
import { type PersonAccount } from '@hcengineering/contact' import { type PersonAccount } from '@hcengineering/contact'
@ -29,11 +29,13 @@ export interface SortFnOptions {
export interface ChatNavGroupModel { export interface ChatNavGroupModel {
id: ChatGroup id: ChatGroup
label?: IntlString label?: IntlString
query: DocumentQuery<DocNotifyContext>
sortFn: (items: ChatNavItemModel[], options: SortFnOptions) => ChatNavItemModel[] sortFn: (items: ChatNavItemModel[], options: SortFnOptions) => ChatNavItemModel[]
wrap: boolean wrap: boolean
getActionsFn?: (contexts: DocNotifyContext[]) => Action[] getActionsFn?: (contexts: DocNotifyContext[]) => Action[]
maxSectionItems?: number maxSectionItems?: number
isPinned: boolean
_class?: Ref<Class<Doc>>
skipClasses?: Array<Ref<Class<Doc>>>
} }
export interface ChatNavItemModel { export interface ChatNavItemModel {

View File

@ -139,29 +139,23 @@ export const chatNavGroupModels: ChatNavGroupModel[] = [
sortFn: sortAlphabetically, sortFn: sortAlphabetically,
wrap: false, wrap: false,
getActionsFn: getPinnedActions, getActionsFn: getPinnedActions,
query: { isPinned: true
isPinned: true
}
}, },
{ {
id: 'channels', id: 'channels',
sortFn: sortAlphabetically, sortFn: sortAlphabetically,
wrap: true, wrap: true,
getActionsFn: getChannelsActions, getActionsFn: getChannelsActions,
query: { isPinned: false,
isPinned: { $ne: true }, _class: chunter.class.Channel
attachedToClass: { $in: [chunter.class.Channel] }
}
}, },
{ {
id: 'direct', id: 'direct',
sortFn: sortDirects, sortFn: sortDirects,
wrap: true, wrap: true,
getActionsFn: getDirectActions, getActionsFn: getDirectActions,
query: { isPinned: false,
isPinned: { $ne: true }, _class: chunter.class.DirectMessage
attachedToClass: { $in: [chunter.class.DirectMessage] }
}
}, },
{ {
id: 'activity', id: 'activity',
@ -169,13 +163,8 @@ export const chatNavGroupModels: ChatNavGroupModel[] = [
wrap: true, wrap: true,
getActionsFn: getActivityActions, getActionsFn: getActivityActions,
maxSectionItems: 5, maxSectionItems: 5,
query: { isPinned: false,
isPinned: { $ne: true }, skipClasses: [chunter.class.DirectMessage, chunter.class.Channel, contact.class.Channel]
attachedToClass: {
// Ignore external channels until support is provided for them
$nin: [chunter.class.DirectMessage, chunter.class.Channel, contact.class.Channel]
}
}
} }
] ]

View File

@ -91,11 +91,11 @@ export function loadNotificationSettings (): void {
loadNotificationSettings() loadNotificationSettings()
export async function hasDocNotifyContextPinAction (docNotifyContext: DocNotifyContext): Promise<boolean> { export async function hasDocNotifyContextPinAction (docNotifyContext: DocNotifyContext): Promise<boolean> {
return docNotifyContext.isPinned !== true return !docNotifyContext.isPinned
} }
export async function hasDocNotifyContextUnpinAction (docNotifyContext: DocNotifyContext): Promise<boolean> { export async function hasDocNotifyContextUnpinAction (docNotifyContext: DocNotifyContext): Promise<boolean> {
return docNotifyContext.isPinned === true return docNotifyContext.isPinned
} }
/** /**

View File

@ -276,7 +276,7 @@ export interface DocNotifyContext extends Doc {
attachedTo: Ref<Doc> attachedTo: Ref<Doc>
attachedToClass: Ref<Class<Doc>> attachedToClass: Ref<Class<Doc>>
isPinned?: boolean isPinned: boolean
lastViewedTimestamp?: Timestamp lastViewedTimestamp?: Timestamp
lastUpdateTimestamp?: Timestamp lastUpdateTimestamp?: Timestamp
} }

View File

@ -423,7 +423,8 @@ async function OnChannelMembersChanged (tx: TxUpdateDoc<Channel>, control: Trigg
attachedTo: tx.objectId, attachedTo: tx.objectId,
attachedToClass: tx.objectClass, attachedToClass: tx.objectClass,
user: addedMember, user: addedMember,
lastViewedTimestamp: tx.modifiedOn lastViewedTimestamp: tx.modifiedOn,
isPinned: false
}) })
await control.apply([createTx]) await control.apply([createTx])
@ -553,7 +554,7 @@ export async function updateChatInfo (control: TriggerControl, status: UserStatu
const contexts = await control.findAll(notification.class.DocNotifyContext, { const contexts = await control.findAll(notification.class.DocNotifyContext, {
user: account._id, user: account._id,
isPinned: { $ne: true } isPinned: false
}) })
if (contexts.length === 0) return if (contexts.length === 0) return

View File

@ -105,7 +105,8 @@ export async function OnMessageCreate (tx: Tx, control: TriggerControl): Promise
user: tx.modifiedBy, user: tx.modifiedBy,
attachedTo: channel._id, attachedTo: channel._id,
attachedToClass: channel._class, attachedToClass: channel._class,
lastUpdateTimestamp: tx.modifiedOn lastUpdateTimestamp: tx.modifiedOn,
isPinned: false
// TODO: push inbox notification // TODO: push inbox notification
// txes: [ // txes: [
// { _id: tx._id as Ref<TxCUD<Doc>>, modifiedOn: tx.modifiedOn, modifiedBy: tx.modifiedBy, isNew: true } // { _id: tx._id as Ref<TxCUD<Doc>>, modifiedOn: tx.modifiedOn, modifiedBy: tx.modifiedBy, isNew: true }

View File

@ -362,7 +362,8 @@ export async function pushInboxNotifications (
user: account._id, user: account._id,
attachedTo, attachedTo,
attachedToClass, attachedToClass,
lastUpdateTimestamp: shouldUpdateTimestamp ? modifiedOn : undefined lastUpdateTimestamp: shouldUpdateTimestamp ? modifiedOn : undefined,
isPinned: false
}) })
await control.apply([createContextTx]) await control.apply([createContextTx])
if (target.account?.email !== undefined) { if (target.account?.email !== undefined) {

View File

@ -100,7 +100,8 @@ export async function OnMessageCreate (tx: Tx, control: TriggerControl): Promise
user: tx.modifiedBy, user: tx.modifiedBy,
attachedTo: channel._id, attachedTo: channel._id,
attachedToClass: channel._class, attachedToClass: channel._class,
lastUpdateTimestamp: tx.modifiedOn lastUpdateTimestamp: tx.modifiedOn,
isPinned: false
// TODO: push inbox notifications // TODO: push inbox notifications
// txes: [ // txes: [
// { _id: tx._id as Ref<TxCUD<Doc>>, modifiedOn: tx.modifiedOn, modifiedBy: tx.modifiedBy, isNew: true } // { _id: tx._id as Ref<TxCUD<Doc>>, modifiedOn: tx.modifiedOn, modifiedBy: tx.modifiedBy, isNew: true }