import React, { useState, useSyncExternalStore } from 'react'; import FocusTrap from 'focus-trap-react'; import { Box, Button, config, Line, Overlay, OverlayBackdrop, OverlayCenter, Text } from 'folds'; import { ContainerColor } from '../../styles/ContainerColor.css'; import { getKeyUploadWatch, subscribeKeyUploadWatch } from '../../utils/keyUploadWatch'; import { LogoutDialog } from '../../components/LogoutDialog'; import { stopPropagation } from '../../utils/keyboard'; /** * [Gitea #201 KE-1] "Encryption on this device is out of sync." Shown while * the server keeps rejecting this device's key uploads (keyUploadWatch). The * fix is a fresh login, so the action opens the normal logout dialog, which * already warns if the device isn't verified / backed up. Hideable for this * session only: the problem doesn't go away by itself. */ export function KeyUploadBanner() { const { stuck, lastError } = useSyncExternalStore(subscribeKeyUploadWatch, getKeyUploadWatch); const [hidden, setHidden] = useState(false); const [details, setDetails] = useState(false); const [logout, setLogout] = useState(false); if (!stuck || hidden) return null; return ( Encryption on this device is out of sync with the server. New encrypted messages and calls may fail until you sign out and back in. {details && ( The server already has encryption keys this device thinks it hasn't sent, so it rejects every new upload and other people can't start fresh encrypted sessions with you. This usually happens after the browser cleared this site's storage while you stayed signed in. Before signing out, make sure this device is verified or key backup is on (Settings → Privacy & security), so your message history comes back when you sign in again. {lastError && ( Server said: {lastError} )} )} {logout && ( }> setLogout(false), clickOutsideDeactivates: true, escapeDeactivates: stopPropagation, }} > setLogout(false)} /> )} ); }