chore: standardize protocol
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -37,6 +37,7 @@ export function useMailSync(options: SyncOptions = {}) {
|
||||
const lastSync = ref<Date | null>(null);
|
||||
const error = ref<string | null>(null);
|
||||
const sources = ref<SyncSource[]>([]);
|
||||
const signatures = ref<Record<string, Record<string, Record<string, string>>>>({});
|
||||
|
||||
let syncInterval: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
@@ -101,12 +102,12 @@ export function useMailSync(options: SyncOptions = {}) {
|
||||
|
||||
// Add collections to check with their signatures
|
||||
source.collections.forEach(collection => {
|
||||
// Look up signature from entities store first (updated by delta), fallback to collections store
|
||||
let signature = entitiesStore.signatures[source.provider]?.[String(source.service)]?.[String(collection)];
|
||||
// Look up signature from local tracking (updated by delta)
|
||||
let signature = signatures.value[source.provider]?.[String(source.service)]?.[String(collection)];
|
||||
|
||||
// Fallback to collection signature if not yet synced
|
||||
if (!signature) {
|
||||
const collectionData = collectionsStore.collections[source.provider]?.[String(source.service)]?.[String(collection)];
|
||||
const collectionData = collectionsStore.collection(source.provider, source.service, collection);
|
||||
signature = collectionData?.signature || '';
|
||||
}
|
||||
|
||||
@@ -118,7 +119,7 @@ export function useMailSync(options: SyncOptions = {}) {
|
||||
});
|
||||
|
||||
// Get delta changes
|
||||
const deltaResponse = await entitiesStore.getDelta(deltaSources);
|
||||
const deltaResponse = await entitiesStore.delta(deltaSources);
|
||||
// If fetchDetails is enabled, fetch full entity data for additions and modifications
|
||||
if (fetchDetails) {
|
||||
const fetchPromises: Promise<any>[] = [];
|
||||
@@ -131,6 +132,18 @@ export function useMailSync(options: SyncOptions = {}) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update signature tracking
|
||||
if (collectionData.signature) {
|
||||
if (!signatures.value[provider]) {
|
||||
signatures.value[provider] = {};
|
||||
}
|
||||
if (!signatures.value[provider][service]) {
|
||||
signatures.value[provider][service] = {};
|
||||
}
|
||||
signatures.value[provider][service][collection] = collectionData.signature;
|
||||
console.log(`[Sync] Updated signature for ${provider}/${service}/${collection}: "${collectionData.signature}"`);
|
||||
}
|
||||
|
||||
// Check if signature actually changed (if not, skip fetching)
|
||||
const oldSignature = deltaSources[provider]?.[service]?.[collection];
|
||||
const newSignature = collectionData.signature;
|
||||
@@ -149,7 +162,7 @@ export function useMailSync(options: SyncOptions = {}) {
|
||||
if (identifiersToFetch.length > 0) {
|
||||
console.log(`[Sync] Fetching ${identifiersToFetch.length} entities for ${provider}/${service}/${collection}`);
|
||||
fetchPromises.push(
|
||||
entitiesStore.getMessages(
|
||||
entitiesStore.fetch(
|
||||
provider,
|
||||
service,
|
||||
collection,
|
||||
|
||||
Reference in New Issue
Block a user