mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-16 13:21:57 +00:00
UBER-276: New messages and Has messages option for filter (#3326)
* UBER-276: New messages and Has messages option for filter Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me> * UBER-263: made it as mode Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me> --------- Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
parent
8802e3204f
commit
4edbdc1641
@ -815,6 +815,26 @@ export function createModel (builder: Builder): void {
|
|||||||
contact.filter.FilterChannelNin
|
contact.filter.FilterChannelNin
|
||||||
)
|
)
|
||||||
|
|
||||||
|
builder.createDoc(
|
||||||
|
view.class.FilterMode,
|
||||||
|
core.space.Model,
|
||||||
|
{
|
||||||
|
label: contact.string.HasMessagesIn,
|
||||||
|
result: contact.function.FilterChannelHasMessagesResult
|
||||||
|
},
|
||||||
|
contact.filter.FilterChannelHasMessages
|
||||||
|
)
|
||||||
|
|
||||||
|
builder.createDoc(
|
||||||
|
view.class.FilterMode,
|
||||||
|
core.space.Model,
|
||||||
|
{
|
||||||
|
label: contact.string.HasNewMessagesIn,
|
||||||
|
result: contact.function.FilterChannelHasNewMessagesResult
|
||||||
|
},
|
||||||
|
contact.filter.FilterChannelHasNewMessages
|
||||||
|
)
|
||||||
|
|
||||||
builder.createDoc(
|
builder.createDoc(
|
||||||
templates.class.TemplateFieldCategory,
|
templates.class.TemplateFieldCategory,
|
||||||
core.space.Model,
|
core.space.Model,
|
||||||
|
@ -96,6 +96,8 @@
|
|||||||
"NumberMembers": "{count, plural, =0 {no members} =1 {1 member} other {# members}}",
|
"NumberMembers": "{count, plural, =0 {no members} =1 {1 member} other {# members}}",
|
||||||
"Position": "Position",
|
"Position": "Position",
|
||||||
"ConfigLabel": "Contacts",
|
"ConfigLabel": "Contacts",
|
||||||
"ConfigDescription": "Extension to hold information about all Employees and other Person/Organization contacts."
|
"ConfigDescription": "Extension to hold information about all Employees and other Person/Organization contacts.",
|
||||||
|
"HasMessagesIn": "has messages in",
|
||||||
|
"HasNewMessagesIn": "has new messages in"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,8 @@
|
|||||||
"CategoryOther": "Прочие",
|
"CategoryOther": "Прочие",
|
||||||
"Position": "Должность",
|
"Position": "Должность",
|
||||||
"ConfigLabel": "Контакты",
|
"ConfigLabel": "Контакты",
|
||||||
"ConfigDescription": "Расширение по работе с сотрудниками и другими контактами."
|
"ConfigDescription": "Расширение по работе с сотрудниками и другими контактами.",
|
||||||
|
"HasMessagesIn": "имеет сообщения в",
|
||||||
|
"HasNewMessagesIn": "имеет новые сообщения в"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,12 @@
|
|||||||
|
|
||||||
let filterUpdateTimeout: number | undefined
|
let filterUpdateTimeout: number | undefined
|
||||||
|
|
||||||
filter.modes = [contact.filter.FilterChannelIn, contact.filter.FilterChannelNin]
|
filter.modes = [
|
||||||
|
contact.filter.FilterChannelIn,
|
||||||
|
contact.filter.FilterChannelNin,
|
||||||
|
contact.filter.FilterChannelHasMessages,
|
||||||
|
contact.filter.FilterChannelHasNewMessages
|
||||||
|
]
|
||||||
filter.mode = filter.mode === undefined ? filter.modes[0] : filter.mode
|
filter.mode = filter.mode === undefined ? filter.modes[0] : filter.mode
|
||||||
|
|
||||||
const isSelected = (element: ChannelProvider, selected: Ref<ChannelProvider>[]): boolean => {
|
const isSelected = (element: ChannelProvider, selected: Ref<ChannelProvider>[]): boolean => {
|
||||||
|
@ -84,6 +84,8 @@ import contact from './plugin'
|
|||||||
import {
|
import {
|
||||||
contactTitleProvider,
|
contactTitleProvider,
|
||||||
employeeSort,
|
employeeSort,
|
||||||
|
filterChannelHasMessagesResult,
|
||||||
|
filterChannelHasNewMessagesResult,
|
||||||
filterChannelInResult,
|
filterChannelInResult,
|
||||||
filterChannelNinResult,
|
filterChannelNinResult,
|
||||||
getContactFirstName,
|
getContactFirstName,
|
||||||
@ -324,6 +326,8 @@ export default async (): Promise<Resources> => ({
|
|||||||
EmployeeSort: employeeSort,
|
EmployeeSort: employeeSort,
|
||||||
FilterChannelInResult: filterChannelInResult,
|
FilterChannelInResult: filterChannelInResult,
|
||||||
FilterChannelNinResult: filterChannelNinResult,
|
FilterChannelNinResult: filterChannelNinResult,
|
||||||
|
FilterChannelHasMessagesResult: filterChannelHasMessagesResult,
|
||||||
|
FilterChannelHasNewMessagesResult: filterChannelHasNewMessagesResult,
|
||||||
GetCurrentEmployeeName: getCurrentEmployeeName,
|
GetCurrentEmployeeName: getCurrentEmployeeName,
|
||||||
GetCurrentEmployeeEmail: getCurrentEmployeeEmail,
|
GetCurrentEmployeeEmail: getCurrentEmployeeEmail,
|
||||||
GetCurrentEmployeePosition: getCurrentEmployeePosition,
|
GetCurrentEmployeePosition: getCurrentEmployeePosition,
|
||||||
|
@ -76,12 +76,16 @@ export default mergeIds(contactId, contact, {
|
|||||||
CategoryPreviousAssigned: '' as IntlString,
|
CategoryPreviousAssigned: '' as IntlString,
|
||||||
CategoryComponentLead: '' as IntlString,
|
CategoryComponentLead: '' as IntlString,
|
||||||
CategoryOther: '' as IntlString,
|
CategoryOther: '' as IntlString,
|
||||||
DeleteEmployee: '' as IntlString
|
DeleteEmployee: '' as IntlString,
|
||||||
|
HasMessagesIn: '' as IntlString,
|
||||||
|
HasNewMessagesIn: '' as IntlString
|
||||||
},
|
},
|
||||||
function: {
|
function: {
|
||||||
GetContactLink: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<Location>>,
|
GetContactLink: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<Location>>,
|
||||||
EmployeeSort: '' as SortFunc,
|
EmployeeSort: '' as SortFunc,
|
||||||
FilterChannelInResult: '' as FilterFunction,
|
FilterChannelInResult: '' as FilterFunction,
|
||||||
FilterChannelNinResult: '' as FilterFunction
|
FilterChannelNinResult: '' as FilterFunction,
|
||||||
|
FilterChannelHasMessagesResult: '' as FilterFunction,
|
||||||
|
FilterChannelHasNewMessagesResult: '' as FilterFunction
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -35,6 +35,8 @@ import view, { Filter } from '@hcengineering/view'
|
|||||||
import { FilterQuery } from '@hcengineering/view-resources'
|
import { FilterQuery } from '@hcengineering/view-resources'
|
||||||
import { get, writable } from 'svelte/store'
|
import { get, writable } from 'svelte/store'
|
||||||
import contact from './plugin'
|
import contact from './plugin'
|
||||||
|
import notification, { DocUpdates, DocUpdateTx } from '@hcengineering/notification'
|
||||||
|
import { getResource } from '@hcengineering/platform'
|
||||||
|
|
||||||
export function formatDate (dueDateMs: Timestamp): string {
|
export function formatDate (dueDateMs: Timestamp): string {
|
||||||
return new Date(dueDateMs).toLocaleString('default', {
|
return new Date(dueDateMs).toLocaleString('default', {
|
||||||
@ -71,6 +73,20 @@ export async function employeeSort (value: Array<Ref<Employee>>): Promise<Array<
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function filterChannelHasMessagesResult (filter: Filter, onUpdate: () => void): Promise<ObjQueryType<any>> {
|
||||||
|
const result = await getRefs(filter, onUpdate, true)
|
||||||
|
return { $in: result }
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function filterChannelHasNewMessagesResult (
|
||||||
|
filter: Filter,
|
||||||
|
onUpdate: () => void
|
||||||
|
): Promise<ObjQueryType<any>> {
|
||||||
|
const docUpdates = await get((await getResource(notification.function.GetNotificationClient))().docUpdatesStore)
|
||||||
|
const result = await getRefs(filter, onUpdate, undefined, docUpdates)
|
||||||
|
return { $in: result }
|
||||||
|
}
|
||||||
|
|
||||||
export async function filterChannelInResult (filter: Filter, onUpdate: () => void): Promise<ObjQueryType<any>> {
|
export async function filterChannelInResult (filter: Filter, onUpdate: () => void): Promise<ObjQueryType<any>> {
|
||||||
const result = await getRefs(filter, onUpdate)
|
const result = await getRefs(filter, onUpdate)
|
||||||
return { $in: result }
|
return { $in: result }
|
||||||
@ -81,19 +97,33 @@ export async function filterChannelNinResult (filter: Filter, onUpdate: () => vo
|
|||||||
return { $nin: result }
|
return { $nin: result }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getRefs (filter: Filter, onUpdate: () => void): Promise<Array<Ref<Doc>>> {
|
export async function getRefs (
|
||||||
|
filter: Filter,
|
||||||
|
onUpdate: () => void,
|
||||||
|
hasMessages?: boolean,
|
||||||
|
docUpdates?: Map<Ref<Doc>, DocUpdates>
|
||||||
|
): Promise<Array<Ref<Doc>>> {
|
||||||
const lq = FilterQuery.getLiveQuery(filter.index)
|
const lq = FilterQuery.getLiveQuery(filter.index)
|
||||||
const client = getClient()
|
const client = getClient()
|
||||||
const mode = await client.findOne(view.class.FilterMode, { _id: filter.mode })
|
const mode = await client.findOne(view.class.FilterMode, { _id: filter.mode })
|
||||||
if (mode === undefined) return []
|
if (mode === undefined) return []
|
||||||
const promise = new Promise<Array<Ref<Doc>>>((resolve, reject) => {
|
const promise = new Promise<Array<Ref<Doc>>>((resolve, reject) => {
|
||||||
|
const hasMessagesQuery = hasMessages === true ? { items: { $gt: 0 } } : {}
|
||||||
const refresh = lq.query(
|
const refresh = lq.query(
|
||||||
contact.class.Channel,
|
contact.class.Channel,
|
||||||
{
|
{
|
||||||
provider: { $in: filter.value }
|
provider: { $in: filter.value },
|
||||||
|
...hasMessagesQuery
|
||||||
},
|
},
|
||||||
(refs) => {
|
(refs) => {
|
||||||
const result = Array.from(new Set(refs.map((p) => p.attachedTo)))
|
const filteredRefs =
|
||||||
|
docUpdates !== undefined
|
||||||
|
? refs.filter((channel) => {
|
||||||
|
const docUpdate = docUpdates.get(channel._id)
|
||||||
|
return docUpdate != null ? docUpdate.txes.some((p: DocUpdateTx) => p.isNew) : (channel.items ?? 0) > 0
|
||||||
|
})
|
||||||
|
: refs
|
||||||
|
const result = Array.from(new Set(filteredRefs.map((p) => p.attachedTo)))
|
||||||
FilterQuery.results.set(filter.index, result)
|
FilterQuery.results.set(filter.index, result)
|
||||||
resolve(result)
|
resolve(result)
|
||||||
onUpdate()
|
onUpdate()
|
||||||
|
@ -274,7 +274,9 @@ export const contactPlugin = plugin(contactId, {
|
|||||||
},
|
},
|
||||||
filter: {
|
filter: {
|
||||||
FilterChannelIn: '' as Ref<FilterMode>,
|
FilterChannelIn: '' as Ref<FilterMode>,
|
||||||
FilterChannelNin: '' as Ref<FilterMode>
|
FilterChannelNin: '' as Ref<FilterMode>,
|
||||||
|
FilterChannelHasMessages: '' as Ref<FilterMode>,
|
||||||
|
FilterChannelHasNewMessages: '' as Ref<FilterMode>
|
||||||
},
|
},
|
||||||
resolver: {
|
resolver: {
|
||||||
Location: '' as Resource<(loc: Location) => Promise<ResolvedLocation | undefined>>
|
Location: '' as Resource<(loc: Location) => Promise<ResolvedLocation | undefined>>
|
||||||
|
Loading…
Reference in New Issue
Block a user