function createReconnectOutboxes({ refresh, restoreIdentity, flushIssue, flushAuthored, flushNotificationReads, }) { return async function reconnectOutboxes() { const snapshot = await refresh(); const freshness = snapshot?.freshness?.sections?.context; const identityFresh = snapshot?.context && !snapshot.context.error && !freshness?.stale && !freshness?.degraded && !freshness?.revalidating; const login = identityFresh ? String(snapshot.context.user?.login || '').trim() : ''; if (!login) return false; restoreIdentity(login); await Promise.all([ flushIssue(), flushAuthored(), flushNotificationReads(), ]); return true; }; } if (typeof module !== 'undefined' && module.exports) module.exports = createReconnectOutboxes;