Hide write email (#2826)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-03-24 15:38:42 +06:00 committed by GitHub
parent b7e4b8b8dc
commit 67fa0c0858
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 4 deletions

View File

@ -179,6 +179,7 @@ export function createModel (builder: Builder): void {
},
label: gmail.string.WriteEmail,
icon: contact.icon.Email,
visibilityTester: gmail.function.HasEmail,
keyBinding: [],
input: 'any',
category: contact.category.Contact,

View File

@ -14,8 +14,8 @@
// limitations under the License.
//
import { Ref } from '@hcengineering/core'
import { IntlString, mergeIds } from '@hcengineering/platform'
import { Doc, Ref } from '@hcengineering/core'
import { IntlString, mergeIds, Resource } from '@hcengineering/platform'
import { gmailId } from '@hcengineering/gmail'
import gmail from '@hcengineering/gmail-resources/src/plugin'
import type { AnyComponent } from '@hcengineering/ui'
@ -45,5 +45,8 @@ export default mergeIds(gmailId, gmail, {
},
activity: {
TxSharedCreate: '' as AnyComponent
},
function: {
HasEmail: '' as Resource<(doc?: Doc | Doc[] | undefined) => Promise<boolean>>
}
})

View File

@ -24,6 +24,7 @@ import IconGmail from './components/icons/GmailColor.svelte'
import Main from './components/Main.svelte'
import NewMessages from './components/NewMessages.svelte'
import gmail from '@hcengineering/gmail'
import { checkHasEmail } from './utils'
export default async (): Promise<Resources> => ({
component: {
@ -36,13 +37,18 @@ export default async (): Promise<Resources> => ({
activity: {
TxSharedCreate
},
function: {
HasEmail: checkHasEmail
},
handler: {
DisconnectHandler: async () => {
const url = getMetadata(gmail.metadata.GmailURL) ?? ''
const url = getMetadata(gmail.metadata.GmailURL)
const token = getMetadata(presentation.metadata.Token)
if (url === undefined || token === undefined) return
await fetch(concatLink(url, '/signout'), {
method: 'GET',
headers: {
Authorization: 'Bearer ' + (getMetadata(presentation.metadata.Token) ?? ''),
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json'
}
})

View File

@ -1,3 +1,7 @@
import contact from '@hcengineering/contact'
import { Doc } from '@hcengineering/core'
import { getClient } from '@hcengineering/presentation'
export function getTime (time: number): string {
let options: Intl.DateTimeFormatOptions = { hour: 'numeric', minute: 'numeric' }
if (!isCurrentYear(time)) {
@ -33,3 +37,14 @@ export function isCurrentYear (time: number): boolean {
const target = new Date(time)
return current.getFullYear() === target.getFullYear()
}
export async function checkHasEmail (doc: Doc | Doc[] | undefined): Promise<boolean> {
if (doc === undefined) return false
const client = getClient()
const arr = Array.isArray(doc) ? doc.map((p) => p._id) : [doc._id]
const res = await client.findAll(contact.class.Channel, {
provider: contact.channelProvider.Email,
attachedTo: { $in: arr }
})
return res.length === arr.length
}