Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 3 additions & 20 deletions infrastructure/eid-wallet/src/routes/(app)/scan-qr/scanLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,7 @@ export function createScanLogic({
created ? "key-generated" : "key-exists",
);

const w3idResult = await globalState.keyService.getPublicKey(
vault.ename,
"signing",
);
const w3idResult = vault.ename;
if (!w3idResult) {
throw new Error("Failed to get W3ID");
}
Expand All @@ -260,18 +257,10 @@ export function createScanLogic({
const authPayload = {
ename: vault.ename,
session: get(session),
w3id: w3idResult,
signature: signature,
appVersion: "0.4.0",
};

console.log("🔐 Auth payload with signature:", {
ename: authPayload.ename,
session: authPayload.session,
w3id: authPayload.w3id,
signatureLength: authPayload.signature.length,
});

const redirectUrl = get(redirect);
if (!redirectUrl) {
throw new Error(
Expand Down Expand Up @@ -534,10 +523,7 @@ export function createScanLogic({
created ? "key-generated" : "key-exists",
);

const w3idResult = await globalState.keyService.getPublicKey(
vault.ename,
"signing",
);
const w3idResult = vault.ename;
if (!w3idResult) {
throw new Error("Failed to get W3ID");
}
Expand Down Expand Up @@ -678,10 +664,7 @@ export function createScanLogic({
created ? "key-generated" : "key-exists",
);

const w3idResult = await globalState.keyService.getPublicKey(
vault.ename,
"signing",
);
const w3idResult = vault.ename;
if (!w3idResult) {
throw new Error("Failed to get W3ID");
}
Expand Down
1 change: 1 addition & 0 deletions infrastructure/evault-core/src/core/db/db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ export class DbService {
id,
ontology: meta.ontology,
acl,
parsed: meta.payload,
},
envelopes: createdEnvelopes,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ export class VaultAccessGuard {

// Check if envelope exists and user has access
const { hasAccess, exists } = await this.checkAccess(metaEnvelopeId, context);

// For update operations, if envelope doesn't exist, allow the resolver to create it
if (!exists && args.input) {
// This is an update/create operation - let the resolver handle it
const result = await resolver(parent, args, context);
return this.filterACL(result);
}

if (!hasAccess) {
// If envelope doesn't exist, return null (not found)
if (!exists) {
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/web3-adapter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ async function createGroupManifestWithRetry(
STORE_META_ENVELOPE,
{
input: {
ontology: "550e8400-e29b-41d4-a716-446655440001", // GroupManifest schema ID
ontology: "550e8400-e29b-41d4-a716-446655440003", // GroupManifest schema ID
payload: groupManifest,
acl: ["*"],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export class FirestoreWatcher {
private retryCount = 0;
private readonly maxRetries: number = 10; // Increased retries
private readonly retryDelay: number = 1000; // 1 second
private isFirstSnapshot = true; // Skip the initial snapshot that contains all existing documents
private watcherStartTime: number = Date.now(); // Track when watcher starts
private firstSnapshotReceived = false; // Track if we've received the first snapshot

// Track processed document IDs to prevent duplicates
private processedIds = new Set<string>();
Expand Down Expand Up @@ -57,23 +58,53 @@ export class FirestoreWatcher {

// Reset stopped flag when starting
this.stopped = false;

// Reset watcher start time
this.watcherStartTime = Date.now();
this.firstSnapshotReceived = false;

try {
// Set up real-time listener (only for new changes, not existing documents)
// Set up real-time listener
this.unsubscribe = this.collection.onSnapshot(
async (snapshot) => {
// Update last snapshot time for health monitoring
this.lastSnapshotTime = Date.now();

// Skip the first snapshot which contains all existing documents
if (this.isFirstSnapshot) {
console.log(`Skipping initial snapshot for ${collectionPath} (contains all existing documents)`);
this.isFirstSnapshot = false;
// On first snapshot, only skip documents that were created/modified BEFORE watcher started
// This ensures we don't miss any new documents created right as the watcher starts
if (!this.firstSnapshotReceived) {
console.log(`First snapshot received for ${collectionPath} with ${snapshot.size} documents`);
this.firstSnapshotReceived = true;

// Process only documents modified AFTER watcher start time
const recentChanges = snapshot.docChanges().filter((change) => {
const doc = change.doc;
const data = doc.data();

// Check if document was modified after watcher started
// Use updatedAt if available, otherwise createdAt
const timestamp = data.updatedAt || data.createdAt;
if (timestamp && timestamp.toMillis) {
const docTime = timestamp.toMillis();
return docTime >= this.watcherStartTime;
}

// If no timestamp, process it to be safe
return true;
});

if (recentChanges.length > 0) {
console.log(`Processing ${recentChanges.length} recent changes from first snapshot`);
await this.processChanges(recentChanges);
} else {
console.log(`No recent changes in first snapshot, skipping`);
}

this.retryCount = 0;
return;
}

// Don't skip snapshots - queue them instead to handle large databases
// Process snapshot asynchronously without blocking new snapshots
// For subsequent snapshots, process all changes normally
this.processSnapshot(snapshot).catch((error) => {
console.error("Error processing snapshot:", error);
this.handleError(error);
Expand Down Expand Up @@ -205,8 +236,9 @@ export class FirestoreWatcher {
this.unsubscribe = null;
}

// Reset first snapshot flag
this.isFirstSnapshot = true;
// Reset watcher state
this.watcherStartTime = Date.now();
this.firstSnapshotReceived = false;
this.lastSnapshotTime = Date.now();

// Reset reconnection attempt counter on successful reconnect
Expand Down Expand Up @@ -323,8 +355,9 @@ export class FirestoreWatcher {
this.unsubscribe = null;
}

// Reset first snapshot flag when restarting
this.isFirstSnapshot = true;
// Reset watcher state when restarting
this.watcherStartTime = Date.now();
this.firstSnapshotReceived = false;
this.lastSnapshotTime = Date.now();

try {
Expand All @@ -343,8 +376,10 @@ export class FirestoreWatcher {
}
}

private async processSnapshot(snapshot: QuerySnapshot): Promise<void> {
const changes = snapshot.docChanges();
/**
* Processes an array of document changes
*/
private async processChanges(changes: DocumentChange[]): Promise<void> {
const collectionPath =
this.collection instanceof CollectionReference
? this.collection.path
Expand Down Expand Up @@ -412,6 +447,12 @@ export class FirestoreWatcher {
await Promise.all(processPromises);
}

private async processSnapshot(snapshot: QuerySnapshot): Promise<void> {
const changes = snapshot.docChanges();
await this.processChanges(changes);
}


private async handleCreateOrUpdate(
doc: FirebaseFirestore.QueryDocumentSnapshot<DocumentData>,
data: DocumentData
Expand Down
15 changes: 13 additions & 2 deletions platforms/blabsy/src/lib/context/chat-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,19 @@ export function ChatContextProvider({
return -1;
if (!a.lastMessage?.timestamp && b.lastMessage?.timestamp)
return 1;
// If neither has lastMessage, sort by updatedAt
return b.updatedAt.toMillis() - a.updatedAt.toMillis();
// If neither has lastMessage, sort by updatedAt (with null checks)
if (a.updatedAt && b.updatedAt) {
return b.updatedAt.toMillis() - a.updatedAt.toMillis();
}
// If only one has updatedAt, prioritize it
if (a.updatedAt && !b.updatedAt) return -1;
if (!a.updatedAt && b.updatedAt) return 1;
// If both are null, sort by createdAt as fallback
if (a.createdAt && b.createdAt) {
return b.createdAt.toMillis() - a.createdAt.toMillis();
}
// If all else fails, maintain order
return 0;
});

setChats(sortedChats);
Expand Down
Loading
Loading