Fix calendar push handler and remove unused client management ()

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2025-02-24 10:37:45 +05:00 committed by GitHub
parent 238d1a2495
commit 4d3488b81e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 39 deletions
services/calendar/pod-calendar/src

View File

@ -37,7 +37,6 @@ import setting from '@hcengineering/setting'
import { htmlToMarkup, markupToHTML } from '@hcengineering/text'
import { deepEqual } from 'fast-equals'
import type { Collection, Db } from 'mongodb'
import { CalendarController } from './calendarController'
import type { CalendarHistory, DummyWatch, EventHistory, Token, User } from './types'
import { encodeReccuring, isToken, parseRecurrenceStrings } from './utils'
import type { WorkspaceClient } from './workspaceClient'
@ -105,7 +104,7 @@ export class CalendarClient {
const calendarClient = new CalendarClient(user, mongo, client, workspace)
if (isToken(user)) {
await calendarClient.googleClient.init(user)
await calendarClient.addClient()
calendarClient.updateTimer()
}
return calendarClient
}
@ -139,7 +138,7 @@ export class CalendarClient {
}
throw new Error('Not all scopes provided')
}
await this.addClient()
this.updateTimer()
const integrations = await this.client.findAll(setting.class.Integration, {
createdBy: this.user.userId,
@ -228,17 +227,6 @@ export class CalendarClient {
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
async syncCalendars (me: string): Promise<void> {

View File

@ -30,7 +30,6 @@ export class CalendarController {
>()
private readonly tokens: Collection<Token>
private readonly clients: Map<string, CalendarClient[]> = new Map<string, CalendarClient[]>()
protected static _instance: CalendarController
@ -120,7 +119,7 @@ export class CalendarController {
const workspaces = [...new Set(tokens.map((p) => p.workspace))]
const infos = await getWorkspacesInfo(token, workspaces)
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) {
continue
}
@ -147,28 +146,6 @@ export class CalendarController {
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>> {
const workspaceClient = await this.getWorkspaceClient(workspace)
return await workspaceClient.getUserId(email)

View File

@ -160,7 +160,6 @@ export class WorkspaceClient {
removeClient (email: string): void {
this.clients.delete(email)
this.serviceController.removeClient(email)
if (this.clients.size > 0) return
void this.close()
this.serviceController.removeWorkspace(this.workspace)