mirror of
https://github.com/hcengineering/platform.git
synced 2025-03-16 02:59:27 +00:00
Fix calendar push handler and remove unused client management (#8078)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
238d1a2495
commit
4d3488b81e
@ -37,7 +37,6 @@ import setting from '@hcengineering/setting'
|
|||||||
import { htmlToMarkup, markupToHTML } from '@hcengineering/text'
|
import { htmlToMarkup, markupToHTML } from '@hcengineering/text'
|
||||||
import { deepEqual } from 'fast-equals'
|
import { deepEqual } from 'fast-equals'
|
||||||
import type { Collection, Db } from 'mongodb'
|
import type { Collection, Db } from 'mongodb'
|
||||||
import { CalendarController } from './calendarController'
|
|
||||||
import type { CalendarHistory, DummyWatch, EventHistory, Token, User } from './types'
|
import type { CalendarHistory, DummyWatch, EventHistory, Token, User } from './types'
|
||||||
import { encodeReccuring, isToken, parseRecurrenceStrings } from './utils'
|
import { encodeReccuring, isToken, parseRecurrenceStrings } from './utils'
|
||||||
import type { WorkspaceClient } from './workspaceClient'
|
import type { WorkspaceClient } from './workspaceClient'
|
||||||
@ -105,7 +104,7 @@ export class CalendarClient {
|
|||||||
const calendarClient = new CalendarClient(user, mongo, client, workspace)
|
const calendarClient = new CalendarClient(user, mongo, client, workspace)
|
||||||
if (isToken(user)) {
|
if (isToken(user)) {
|
||||||
await calendarClient.googleClient.init(user)
|
await calendarClient.googleClient.init(user)
|
||||||
await calendarClient.addClient()
|
calendarClient.updateTimer()
|
||||||
}
|
}
|
||||||
return calendarClient
|
return calendarClient
|
||||||
}
|
}
|
||||||
@ -139,7 +138,7 @@ export class CalendarClient {
|
|||||||
}
|
}
|
||||||
throw new Error('Not all scopes provided')
|
throw new Error('Not all scopes provided')
|
||||||
}
|
}
|
||||||
await this.addClient()
|
this.updateTimer()
|
||||||
|
|
||||||
const integrations = await this.client.findAll(setting.class.Integration, {
|
const integrations = await this.client.findAll(setting.class.Integration, {
|
||||||
createdBy: this.user.userId,
|
createdBy: this.user.userId,
|
||||||
@ -228,17 +227,6 @@ export class CalendarClient {
|
|||||||
this.isClosed = true
|
this.isClosed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private async addClient (): Promise<void> {
|
|
||||||
try {
|
|
||||||
const me = await this.googleClient.getMe()
|
|
||||||
const controller = CalendarController.getCalendarController()
|
|
||||||
controller.addClient(me, this)
|
|
||||||
this.updateTimer()
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Add client error', this.user.workspace, this.user.userId, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// #region Calendars
|
// #region Calendars
|
||||||
|
|
||||||
async syncCalendars (me: string): Promise<void> {
|
async syncCalendars (me: string): Promise<void> {
|
||||||
|
@ -30,7 +30,6 @@ export class CalendarController {
|
|||||||
>()
|
>()
|
||||||
|
|
||||||
private readonly tokens: Collection<Token>
|
private readonly tokens: Collection<Token>
|
||||||
private readonly clients: Map<string, CalendarClient[]> = new Map<string, CalendarClient[]>()
|
|
||||||
|
|
||||||
protected static _instance: CalendarController
|
protected static _instance: CalendarController
|
||||||
|
|
||||||
@ -120,7 +119,7 @@ export class CalendarController {
|
|||||||
const workspaces = [...new Set(tokens.map((p) => p.workspace))]
|
const workspaces = [...new Set(tokens.map((p) => p.workspace))]
|
||||||
const infos = await getWorkspacesInfo(token, workspaces)
|
const infos = await getWorkspacesInfo(token, workspaces)
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
const info = infos.find((p) => p.workspace === token.workspace)
|
const info = infos.find((p) => p.workspaceId === token.workspace)
|
||||||
if (info === undefined) {
|
if (info === undefined) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -147,28 +146,6 @@ export class CalendarController {
|
|||||||
await workspaceController.pushEvent(event, type)
|
await workspaceController.pushEvent(event, type)
|
||||||
}
|
}
|
||||||
|
|
||||||
addClient (email: string, client: CalendarClient): void {
|
|
||||||
const clients = this.clients.get(email)
|
|
||||||
if (clients === undefined) {
|
|
||||||
this.clients.set(email, [client])
|
|
||||||
} else {
|
|
||||||
clients.push(client)
|
|
||||||
this.clients.set(email, clients)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
removeClient (email: string): void {
|
|
||||||
const clients = this.clients.get(email)
|
|
||||||
if (clients !== undefined) {
|
|
||||||
const filtered = clients.filter((p) => !p.isClosed)
|
|
||||||
if (filtered.length === 0) {
|
|
||||||
this.clients.delete(email)
|
|
||||||
} else {
|
|
||||||
this.clients.set(email, filtered)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async getUserId (email: string, workspace: string): Promise<Ref<Account>> {
|
async getUserId (email: string, workspace: string): Promise<Ref<Account>> {
|
||||||
const workspaceClient = await this.getWorkspaceClient(workspace)
|
const workspaceClient = await this.getWorkspaceClient(workspace)
|
||||||
return await workspaceClient.getUserId(email)
|
return await workspaceClient.getUserId(email)
|
||||||
|
@ -160,7 +160,6 @@ export class WorkspaceClient {
|
|||||||
|
|
||||||
removeClient (email: string): void {
|
removeClient (email: string): void {
|
||||||
this.clients.delete(email)
|
this.clients.delete(email)
|
||||||
this.serviceController.removeClient(email)
|
|
||||||
if (this.clients.size > 0) return
|
if (this.clients.size > 0) return
|
||||||
void this.close()
|
void this.close()
|
||||||
this.serviceController.removeWorkspace(this.workspace)
|
this.serviceController.removeWorkspace(this.workspace)
|
||||||
|
Loading…
Reference in New Issue
Block a user