Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into staging
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <[email protected]>
  • Loading branch information
haiodo committed Dec 26, 2024
2 parents f4fc107 + 4214ace commit 43f584b
Show file tree
Hide file tree
Showing 38 changed files with 182 additions and 1,523 deletions.
109 changes: 0 additions & 109 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions packages/presentation/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import core, {
TxProcessor,
getCurrentAccount,
reduceCalls,
type Account,
type AnyAttribute,
type ArrOf,
type AttachedDoc,
Expand Down Expand Up @@ -253,6 +254,18 @@ export function getClient (): TxOperations & Client {
return clientProxy
}

export type OnClientListener = (client: Client, account: Account) => void
const onClientListeners: OnClientListener[] = []

export function onClient (l: OnClientListener): void {
onClientListeners.push(l)
if (client !== undefined) {
setTimeout(() => {
l(client, getCurrentAccount())
})
}
}

let txQueue: Tx[] = []

export type RefreshListener = () => void
Expand Down Expand Up @@ -306,6 +319,10 @@ export async function setClient (_client: Client): Promise<void> {
if (needRefresh || globalQueries.length > 0) {
await refreshClient(true)
}
const acc = getCurrentAccount()
onClientListeners.forEach((l) => {
l(_client, acc)
})
}
/**
* @public
Expand Down
32 changes: 11 additions & 21 deletions plugins/activity-resources/src/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,21 @@
//
import activity, { type ActivityMessage, type SavedMessage } from '@hcengineering/activity'
import core, { type Ref, SortingOrder, type WithLookup } from '@hcengineering/core'
import { createQuery, onClient } from '@hcengineering/presentation'
import { writable } from 'svelte/store'
import { createQuery, getClient } from '@hcengineering/presentation'

export const savedMessagesStore = writable<Array<WithLookup<SavedMessage>>>([])
export const messageInFocus = writable<Ref<ActivityMessage> | undefined>(undefined)

const savedMessagesQuery = createQuery(true)

export function loadSavedMessages (): void {
const client = getClient()

if (client !== undefined) {
savedMessagesQuery.query(
activity.class.SavedMessage,
{ space: core.space.Workspace },
(res) => {
savedMessagesStore.set(res.filter(({ $lookup }) => $lookup?.attachedTo !== undefined))
},
{ lookup: { attachedTo: activity.class.ActivityMessage }, sort: { modifiedOn: SortingOrder.Descending } }
)
} else {
setTimeout(() => {
loadSavedMessages()
}, 50)
}
}

loadSavedMessages()
onClient(() => {
savedMessagesQuery.query(
activity.class.SavedMessage,
{ space: core.space.Workspace },
(res) => {
savedMessagesStore.set(res.filter(({ $lookup }) => $lookup?.attachedTo !== undefined))
},
{ lookup: { attachedTo: activity.class.ActivityMessage }, sort: { modifiedOn: SortingOrder.Descending } }
)
})
34 changes: 12 additions & 22 deletions plugins/calendar-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
type ReccuringInstance,
generateEventId
} from '@hcengineering/calendar'
import { type IdMap, type Timestamp, getCurrentAccount, toIdMap, type DocumentUpdate } from '@hcengineering/core'
import { createQuery, getClient } from '@hcengineering/presentation'
import { showPopup, closePopup, DAY } from '@hcengineering/ui'
import { type DocumentUpdate, type IdMap, type Timestamp, getCurrentAccount, toIdMap } from '@hcengineering/core'
import { createQuery, getClient, onClient } from '@hcengineering/presentation'
import { closePopup, DAY, showPopup } from '@hcengineering/ui'
import { writable } from 'svelte/store'
import calendar from './plugin'
import UpdateRecInstancePopup from './components/UpdateRecInstancePopup.svelte'
import calendar from './plugin'

export function saveUTC (date: Timestamp): Timestamp {
const utcdate = new Date(date)
Expand Down Expand Up @@ -74,24 +74,14 @@ export const calendarByIdStore = writable<IdMap<Calendar>>(new Map())
export const calendarStore = writable<Calendar[]>([])
export const visibleCalendarStore = writable<Calendar[]>([])

function fillStores (): void {
const client = getClient()

if (client !== undefined) {
const query = createQuery(true)
query.query(calendar.class.Calendar, {}, (res) => {
calendarStore.set(res)
visibleCalendarStore.set(res.filter((p) => !p.hidden))
calendarByIdStore.set(toIdMap(res))
})
} else {
setTimeout(() => {
fillStores()
}, 50)
}
}

fillStores()
const query = createQuery(true)
onClient((client, account) => {
query.query(calendar.class.Calendar, {}, (res) => {
calendarStore.set(res)
visibleCalendarStore.set(res.filter((p) => !p.hidden))
calendarByIdStore.set(toIdMap(res))
})
})

export async function updatePast (ops: DocumentUpdate<Event>, object: ReccuringInstance): Promise<void> {
const client = getClient()
Expand Down
15 changes: 4 additions & 11 deletions plugins/chunter-resources/src/components/chat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import core, {
} from '@hcengineering/core'
import notification, { type DocNotifyContext } from '@hcengineering/notification'
import { InboxNotificationsClientImpl } from '@hcengineering/notification-resources'
import { createQuery, getClient, MessageBox } from '@hcengineering/presentation'
import { createQuery, getClient, MessageBox, onClient } from '@hcengineering/presentation'
import { type Action, showPopup } from '@hcengineering/ui'
import view from '@hcengineering/view'
import workbench, { type SpecialNavModel } from '@hcengineering/workbench'
Expand Down Expand Up @@ -364,12 +364,9 @@ function archiveActivityChannels (contexts: DocNotifyContext[]): void {
)
}

const savedAttachmentsQuery = createQuery(true)
export function loadSavedAttachments (): void {
const client = getClient()

if (client !== undefined) {
const savedAttachmentsQuery = createQuery(true)

onClient(() => {
savedAttachmentsQuery.query(
attachment.class.SavedAttachments,
{ space: core.space.Workspace },
Expand All @@ -378,11 +375,7 @@ export function loadSavedAttachments (): void {
},
{ lookup: { attachedTo: attachment.class.Attachment }, sort: { modifiedOn: SortingOrder.Descending } }
)
} else {
setTimeout(() => {
loadSavedAttachments()
}, 50)
}
})
}

export async function hideActivityChannels (contexts: DocNotifyContext[]): Promise<void> {
Expand Down
52 changes: 21 additions & 31 deletions plugins/contact-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import core, {
} from '@hcengineering/core'
import notification, { type DocNotifyContext, type InboxNotification } from '@hcengineering/notification'
import { type IntlString, getEmbeddedLabel, getResource, translate } from '@hcengineering/platform'
import { createQuery, getClient } from '@hcengineering/presentation'
import { createQuery, getClient, onClient } from '@hcengineering/presentation'
import { type TemplateDataProvider } from '@hcengineering/templates'
import {
getCurrentResolvedLocation,
Expand Down Expand Up @@ -323,42 +323,32 @@ export const personByIdStore = derived([personAccountPersonByIdStore, employeeBy
return new Map([...m1, ...m2])
})

function fillStores (): void {
const client = getClient()

if (client !== undefined) {
const accountPersonQuery = createQuery(true)

const query = createQuery(true)
query.query(contact.mixin.Employee, { active: { $in: [true, false] } }, (res) => {
employeesStore.set(res)
employeeByIdStore.set(toIdMap(res))
})
const query = createQuery(true)
const accountQ = createQuery(true)
const accountPersonQuery = createQuery(true)
const providerQuery = createQuery(true)

const accountQ = createQuery(true)
accountQ.query(contact.class.PersonAccount, {}, (res) => {
personAccountByIdStore.set(toIdMap(res))
onClient(() => {
query.query(contact.mixin.Employee, { active: { $in: [true, false] } }, (res) => {
employeesStore.set(res)
employeeByIdStore.set(toIdMap(res))
})

const persons = res.map((it) => it.person)
accountQ.query(contact.class.PersonAccount, {}, (res) => {
personAccountByIdStore.set(toIdMap(res))

accountPersonQuery.query<Person>(contact.class.Person, { _id: { $in: persons } }, (res) => {
const personIn = toIdMap(res)
personAccountPersonByIdStore.set(personIn)
})
})
const persons = res.map((it) => it.person)

const providerQuery = createQuery(true)
providerQuery.query(contact.class.ChannelProvider, {}, (res) => {
channelProviders.set(res)
accountPersonQuery.query<Person>(contact.class.Person, { _id: { $in: persons } }, (res) => {
const personIn = toIdMap(res)
personAccountPersonByIdStore.set(personIn)
})
} else {
setTimeout(() => {
fillStores()
}, 50)
}
}
})

fillStores()
providerQuery.query(contact.class.ChannelProvider, {}, (res) => {
channelProviders.set(res)
})
})

const userStatusesQuery = createQuery(true)

Expand Down
Loading

0 comments on commit 43f584b

Please sign in to comment.