mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-22 11:01:54 +03: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
|
||||
)
|
||||
|
||||
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(
|
||||
templates.class.TemplateFieldCategory,
|
||||
core.space.Model,
|
||||
|
@ -96,6 +96,8 @@
|
||||
"NumberMembers": "{count, plural, =0 {no members} =1 {1 member} other {# members}}",
|
||||
"Position": "Position",
|
||||
"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": "Прочие",
|
||||
"Position": "Должность",
|
||||
"ConfigLabel": "Контакты",
|
||||
"ConfigDescription": "Расширение по работе с сотрудниками и другими контактами."
|
||||
"ConfigDescription": "Расширение по работе с сотрудниками и другими контактами.",
|
||||
"HasMessagesIn": "имеет сообщения в",
|
||||
"HasNewMessagesIn": "имеет новые сообщения в"
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,12 @@
|
||||
|
||||
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
|
||||
|
||||
const isSelected = (element: ChannelProvider, selected: Ref<ChannelProvider>[]): boolean => {
|
||||
|
@ -84,6 +84,8 @@ import contact from './plugin'
|
||||
import {
|
||||
contactTitleProvider,
|
||||
employeeSort,
|
||||
filterChannelHasMessagesResult,
|
||||
filterChannelHasNewMessagesResult,
|
||||
filterChannelInResult,
|
||||
filterChannelNinResult,
|
||||
getContactFirstName,
|
||||
@ -324,6 +326,8 @@ export default async (): Promise<Resources> => ({
|
||||
EmployeeSort: employeeSort,
|
||||
FilterChannelInResult: filterChannelInResult,
|
||||
FilterChannelNinResult: filterChannelNinResult,
|
||||
FilterChannelHasMessagesResult: filterChannelHasMessagesResult,
|
||||
FilterChannelHasNewMessagesResult: filterChannelHasNewMessagesResult,
|
||||
GetCurrentEmployeeName: getCurrentEmployeeName,
|
||||
GetCurrentEmployeeEmail: getCurrentEmployeeEmail,
|
||||
GetCurrentEmployeePosition: getCurrentEmployeePosition,
|
||||
|
@ -76,12 +76,16 @@ export default mergeIds(contactId, contact, {
|
||||
CategoryPreviousAssigned: '' as IntlString,
|
||||
CategoryComponentLead: '' as IntlString,
|
||||
CategoryOther: '' as IntlString,
|
||||
DeleteEmployee: '' as IntlString
|
||||
DeleteEmployee: '' as IntlString,
|
||||
HasMessagesIn: '' as IntlString,
|
||||
HasNewMessagesIn: '' as IntlString
|
||||
},
|
||||
function: {
|
||||
GetContactLink: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<Location>>,
|
||||
EmployeeSort: '' as SortFunc,
|
||||
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 { get, writable } from 'svelte/store'
|
||||
import contact from './plugin'
|
||||
import notification, { DocUpdates, DocUpdateTx } from '@hcengineering/notification'
|
||||
import { getResource } from '@hcengineering/platform'
|
||||
|
||||
export function formatDate (dueDateMs: Timestamp): string {
|
||||
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>> {
|
||||
const result = await getRefs(filter, onUpdate)
|
||||
return { $in: result }
|
||||
@ -81,19 +97,33 @@ export async function filterChannelNinResult (filter: Filter, onUpdate: () => vo
|
||||
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 client = getClient()
|
||||
const mode = await client.findOne(view.class.FilterMode, { _id: filter.mode })
|
||||
if (mode === undefined) return []
|
||||
const promise = new Promise<Array<Ref<Doc>>>((resolve, reject) => {
|
||||
const hasMessagesQuery = hasMessages === true ? { items: { $gt: 0 } } : {}
|
||||
const refresh = lq.query(
|
||||
contact.class.Channel,
|
||||
{
|
||||
provider: { $in: filter.value }
|
||||
provider: { $in: filter.value },
|
||||
...hasMessagesQuery
|
||||
},
|
||||
(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)
|
||||
resolve(result)
|
||||
onUpdate()
|
||||
|
@ -274,7 +274,9 @@ export const contactPlugin = plugin(contactId, {
|
||||
},
|
||||
filter: {
|
||||
FilterChannelIn: '' as Ref<FilterMode>,
|
||||
FilterChannelNin: '' as Ref<FilterMode>
|
||||
FilterChannelNin: '' as Ref<FilterMode>,
|
||||
FilterChannelHasMessages: '' as Ref<FilterMode>,
|
||||
FilterChannelHasNewMessages: '' as Ref<FilterMode>
|
||||
},
|
||||
resolver: {
|
||||
Location: '' as Resource<(loc: Location) => Promise<ResolvedLocation | undefined>>
|
||||
|
Loading…
Reference in New Issue
Block a user