diff --git a/models/contact/src/index.ts b/models/contact/src/index.ts index e43f36f8f1..296cbc74b4 100644 --- a/models/contact/src/index.ts +++ b/models/contact/src/index.ts @@ -16,6 +16,7 @@ import { AvatarProvider, AvatarType, + GetAvatarUrl, Channel, ChannelProvider, Contact, @@ -49,9 +50,8 @@ import core, { TAccount, TAttachedDoc, TDoc, TSpace } from '@hcengineering/model import presentation from '@hcengineering/model-presentation' import view, { actionTemplates, createAction, ViewAction } from '@hcengineering/model-view' import workbench from '@hcengineering/model-workbench' -import type { Asset, IntlString } from '@hcengineering/platform' +import type { Asset, IntlString, Resource } from '@hcengineering/platform' import setting from '@hcengineering/setting' -import { IconSize } from '@hcengineering/ui' import contact from './plugin' export const DOMAIN_CONTACT = 'contact' as Domain @@ -60,7 +60,7 @@ export const DOMAIN_CHANNEL = 'channel' as Domain @Model(contact.class.AvatarProvider, core.class.Doc, DOMAIN_MODEL) export class TAvatarProvider extends TDoc implements AvatarProvider { type!: AvatarType - getUrl!: (uri: string, size: IconSize) => string + getUrl!: Resource } @Model(contact.class.ChannelProvider, core.class.Doc, DOMAIN_MODEL) @@ -370,6 +370,36 @@ export function createModel (builder: Builder): void { contact.channelProvider.Homepage ) + builder.createDoc( + contact.class.AvatarProvider, + core.space.Model, + { + type: AvatarType.COLOR, + getUrl: contact.function.GetColorUrl + }, + contact.avatarProvider.Color + ) + + builder.createDoc( + contact.class.AvatarProvider, + core.space.Model, + { + type: AvatarType.IMAGE, + getUrl: contact.function.GetFileUrl + }, + contact.avatarProvider.Image + ) + + builder.createDoc( + contact.class.AvatarProvider, + core.space.Model, + { + type: AvatarType.GRAVATAR, + getUrl: contact.function.GetGravatarUrl + }, + contact.avatarProvider.Gravatar + ) + builder.mixin(contact.class.Person, core.class.Class, view.mixin.AttributePresenter, { presenter: contact.component.PersonPresenter }) diff --git a/packages/presentation/src/components/Avatar.svelte b/packages/presentation/src/components/Avatar.svelte index 619b3fec4a..47c01f9b12 100644 --- a/packages/presentation/src/components/Avatar.svelte +++ b/packages/presentation/src/components/Avatar.svelte @@ -13,10 +13,10 @@ // limitations under the License. -->
diff --git a/packages/presentation/src/utils.ts b/packages/presentation/src/utils.ts index 11c27d0727..d3461f4590 100644 --- a/packages/presentation/src/utils.ts +++ b/packages/presentation/src/utils.ts @@ -34,7 +34,7 @@ import core, { TxResult } from '@hcengineering/core' import login from '@hcengineering/login' -import { getMetadata, Resource } from '@hcengineering/platform' +import { getMetadata } from '@hcengineering/platform' import { LiveQuery as LQ } from '@hcengineering/query' import { onDestroy } from 'svelte' import { deepEqual } from 'fast-equals' @@ -281,7 +281,7 @@ export function getAvatarColorForId (id: string): string { return AVATAR_COLORS[hash % AVATAR_COLORS.length] } -export function getAvatarProviderId (avatar?: string | null): Resource | undefined { +export function getAvatarProviderId (avatar?: string | null): Ref | undefined { if (avatar === null || avatar === undefined || avatar === '') { return } diff --git a/plugins/contact-resources/src/index.ts b/plugins/contact-resources/src/index.ts index 418180d625..4d0a4a6e85 100644 --- a/plugins/contact-resources/src/index.ts +++ b/plugins/contact-resources/src/index.ts @@ -14,7 +14,7 @@ // limitations under the License. // -import { AvatarType, Channel, Contact, Employee, formatName } from '@hcengineering/contact' +import { Channel, Contact, Employee, formatName } from '@hcengineering/contact' import { Class, Client, DocumentQuery, Ref, RelatedDocument, WithLookup } from '@hcengineering/core' import { leaveWorkspace } from '@hcengineering/login-resources' import { Resources } from '@hcengineering/platform' @@ -168,9 +168,9 @@ export default async (): Promise => ({ filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] } ) => await queryContact(contact.class.Organization, client, query, filter) }, - avatarProvider: { - Image: { type: AvatarType.IMAGE, getUrl: getFileUrl }, - Gravatar: { type: AvatarType.GRAVATAR, getUrl: getGravatarUrl }, - Color: { type: AvatarType.COLOR, getUrl: (uri: string) => uri } + function: { + GetFileUrl: getFileUrl, + GetGravatarUrl: getGravatarUrl, + GetColorUrl: (uri: string) => uri } }) diff --git a/plugins/contact/src/index.ts b/plugins/contact/src/index.ts index 7f65eeb9e8..f9029d71da 100644 --- a/plugins/contact/src/index.ts +++ b/plugins/contact/src/index.ts @@ -78,12 +78,17 @@ export enum AvatarType { GRAVATAR = 'gravatar' } +/** + * @public + */ +export type GetAvatarUrl = (uri: string, size: IconSize) => string + /** * @public */ export interface AvatarProvider extends Doc { type: AvatarType - getUrl: (uri: string, size: IconSize) => string + getUrl: Resource } /** @@ -214,9 +219,14 @@ const contactPlugin = plugin(contactId, { Homepage: '' as Ref }, avatarProvider: { - Color: '' as Resource, - Image: '' as Resource, - Gravatar: '' as Resource + Color: '' as Ref, + Image: '' as Ref, + Gravatar: '' as Ref + }, + function: { + GetColorUrl: '' as Resource, + GetFileUrl: '' as Resource, + GetGravatarUrl: '' as Resource }, icon: { ContactApplication: '' as Asset,