mirror of
https://github.com/hcengineering/platform.git
synced 2026-10-01 05:55:09 +02:00
* UBERF-10375: Fix full message sync Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10375: Clean up Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Init new gmail integration Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Rename package Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Add mail channel and thread master tags Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Rename Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Create messages in cards Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Use new messages Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Use mail tags and add mail-common Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Use tags for mails Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Clean up tests Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Fix tests Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Clean up Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Clean up Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Apply client fixes Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Fix communication version Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Use adapter for message manager Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Remove gmail-next and improve performance Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Fix dep mismatch Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Add prefix for new history Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Fix failed tests Signed-off-by: Artem Savchenko <armisav@gmail.com> * UBERF-10408: Fix composite emails and add channel cache Signed-off-by: Artem Savchenko <armisav@gmail.com> --------- Signed-off-by: Artem Savchenko <armisav@gmail.com>
75 lines
2.5 KiB
TypeScript
75 lines
2.5 KiB
TypeScript
//
|
|
// Copyright © 2025 Hardcore Engineering Inc.
|
|
//
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License. You may
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
//
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
|
|
import { PersonId } from '@hcengineering/core'
|
|
import { type KeyValueClient } from '@hcengineering/kvs-client'
|
|
import { type History } from './types'
|
|
import { IntegrationVersion } from '../types'
|
|
|
|
/**
|
|
* Handles persistent storage for Gmail sync state
|
|
*/
|
|
export class SyncStateManager {
|
|
constructor (
|
|
private readonly keyValueClient: KeyValueClient,
|
|
private readonly workspace: string,
|
|
private readonly version: IntegrationVersion
|
|
) {}
|
|
|
|
async getHistory (userId: PersonId): Promise<History | null> {
|
|
const historyKey = this.getHistoryKey(userId)
|
|
return await this.keyValueClient.getValue<History>(historyKey)
|
|
}
|
|
|
|
async clearHistory (userId: PersonId): Promise<void> {
|
|
const historyKey = this.getHistoryKey(userId)
|
|
await this.keyValueClient.deleteKey(historyKey)
|
|
}
|
|
|
|
async setHistoryId (userId: PersonId, historyId: string): Promise<void> {
|
|
const historyKey = this.getHistoryKey(userId)
|
|
const history: History = {
|
|
historyId,
|
|
userId,
|
|
workspace: this.workspace
|
|
}
|
|
await this.keyValueClient.setValue(historyKey, history)
|
|
}
|
|
|
|
async getPageToken (userId: PersonId): Promise<string | null> {
|
|
const pageTokenKey = this.getPageTokenKey(userId)
|
|
return await this.keyValueClient.getValue<string>(pageTokenKey)
|
|
}
|
|
|
|
async setPageToken (userId: PersonId, pageToken: string): Promise<void> {
|
|
const pageTokenKey = this.getPageTokenKey(userId)
|
|
await this.keyValueClient.setValue(pageTokenKey, pageToken)
|
|
}
|
|
|
|
private getHistoryKey (userId: PersonId): string {
|
|
if (this.version === IntegrationVersion.V2) {
|
|
return `history-v2:${this.workspace}:${userId}`
|
|
}
|
|
return `history:${this.workspace}:${userId}`
|
|
}
|
|
|
|
private getPageTokenKey (userId: PersonId): string {
|
|
if (this.version === IntegrationVersion.V2) {
|
|
return `page-token-v2:${this.workspace}:${userId}`
|
|
}
|
|
return `page-token:${this.workspace}:${userId}`
|
|
}
|
|
}
|