mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-13 02:41:11 +00:00
Fix pushes for new clients in calendar (#8115)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
b858dd7696
commit
143cf905b5
@ -241,6 +241,7 @@ export class CalendarClient {
|
||||
}
|
||||
|
||||
close (): void {
|
||||
clearTimeout(this.inactiveTimer)
|
||||
this.googleClient.close()
|
||||
for (const watch of this.dummyWatches) {
|
||||
clearTimeout(watch.timer)
|
||||
|
@ -108,6 +108,12 @@ export class CalendarController {
|
||||
}
|
||||
}
|
||||
|
||||
pushWorkspaceByEmail (email: string, workspace: string): void {
|
||||
const arr = this.workspacesByEmail.get(email) ?? []
|
||||
arr.push(workspace)
|
||||
this.workspacesByEmail.set(email, arr)
|
||||
}
|
||||
|
||||
async startWorkspace (workspace: string, tokens: Token[]): Promise<WorkspaceClient> {
|
||||
const workspaceClient = await this.getWorkspaceClient(workspace)
|
||||
for (const token of tokens) {
|
||||
@ -117,9 +123,7 @@ export class CalendarController {
|
||||
}, 60000)
|
||||
console.log('init client', token.workspace, token.userId)
|
||||
await workspaceClient.createCalendarClient(token, true)
|
||||
const arr = this.workspacesByEmail.get(token.email) ?? []
|
||||
arr.push(token.workspace)
|
||||
this.workspacesByEmail.set(token.email, arr)
|
||||
this.pushWorkspaceByEmail(token.email, token.workspace)
|
||||
clearTimeout(timeout)
|
||||
} catch (err) {
|
||||
console.error(`Couldn't create client for ${workspace} ${token.userId} ${token.email}`)
|
||||
|
@ -212,10 +212,13 @@ export class GoogleClient {
|
||||
workspace: this.user.workspace,
|
||||
calendarId: null
|
||||
})
|
||||
if (current == null || current.expired < Date.now() + 24 * 60 * 60 * 1000) {
|
||||
if (current != null) {
|
||||
await this.rateLimiter.take(1)
|
||||
try {
|
||||
await this.calendar.channels.stop({ requestBody: { id: current.channelId, resourceId: current.resourceId } })
|
||||
await this.calendar.channels.stop({
|
||||
requestBody: { id: current.channelId, resourceId: current.resourceId }
|
||||
})
|
||||
} catch {}
|
||||
}
|
||||
const channelId = generateId()
|
||||
@ -250,6 +253,7 @@ export class GoogleClient {
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error('Calendar watch error', err.message)
|
||||
}
|
||||
@ -262,6 +266,7 @@ export class GoogleClient {
|
||||
workspace: this.user.workspace,
|
||||
calendarId
|
||||
})
|
||||
if (current == null || current.expired < Date.now() + 24 * 60 * 60 * 1000) {
|
||||
if (current != null) {
|
||||
await this.rateLimiter.take(1)
|
||||
try {
|
||||
@ -307,12 +312,13 @@ export class GoogleClient {
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
} catch (err: any) {
|
||||
if (err?.errors?.[0]?.reason === 'pushNotSupportedForRequestedResource') {
|
||||
return false
|
||||
} else {
|
||||
console.error('Watch error', err.message)
|
||||
console.error('Watch error', err)
|
||||
await this.checkError(err)
|
||||
return false
|
||||
}
|
||||
|
@ -116,6 +116,7 @@ export class WorkspaceClient {
|
||||
throw new Error('Client already exist')
|
||||
}
|
||||
this.clients.set(email, newClient)
|
||||
this.serviceController.pushWorkspaceByEmail(email, user.workspace)
|
||||
return newClient
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user