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, {
user: user._id,
attachedTo,
attachedToClass
attachedToClass,
isPinned: false
})
}
}

View File

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

View File

@ -187,6 +187,16 @@ export const notificationOperation: MigrateOperation = {
{ 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, {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -91,11 +91,11 @@ export function loadNotificationSettings (): void {
loadNotificationSettings()
export async function hasDocNotifyContextPinAction (docNotifyContext: DocNotifyContext): Promise<boolean> {
return docNotifyContext.isPinned !== true
return !docNotifyContext.isPinned
}
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>
attachedToClass: Ref<Class<Doc>>
isPinned?: boolean
isPinned: boolean
lastViewedTimestamp?: Timestamp
lastUpdateTimestamp?: Timestamp
}

View File

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

View File

@ -105,7 +105,8 @@ export async function OnMessageCreate (tx: Tx, control: TriggerControl): Promise
user: tx.modifiedBy,
attachedTo: channel._id,
attachedToClass: channel._class,
lastUpdateTimestamp: tx.modifiedOn
lastUpdateTimestamp: tx.modifiedOn,
isPinned: false
// TODO: push inbox notification
// txes: [
// { _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,
attachedTo,
attachedToClass,
lastUpdateTimestamp: shouldUpdateTimestamp ? modifiedOn : undefined
lastUpdateTimestamp: shouldUpdateTimestamp ? modifiedOn : undefined,
isPinned: false
})
await control.apply([createContextTx])
if (target.account?.email !== undefined) {

View File

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