diff --git a/App.tsx b/App.tsx index 613426dc..7101c1bf 100644 --- a/App.tsx +++ b/App.tsx @@ -222,8 +222,12 @@ const App = () => { }, []); const fetchServerStatusState = useCallback(async () => { - const response = await fetch(STATUS_URL, {cache: 'no-cache'}); - if (!response.ok) { + let response: Response | null = null + try { + response = await fetch(STATUS_URL, {cache: 'no-cache'}); + } catch (e) {}; + + if (response === null || !response.ok) { // If even the status server is down, things are *very* not-okay. But odds // are it can't be contacted because the user has a crappy internet // connection. The "You're offline" notice should still provide some diff --git a/xmpp/xmpp.tsx b/xmpp/xmpp.tsx index 05fcef32..c3bc02c3 100644 --- a/xmpp/xmpp.tsx +++ b/xmpp/xmpp.tsx @@ -24,10 +24,7 @@ import { AppState, AppStateStatus } from 'react-native'; const messageTimeout = 10000; const fetchConversationTimeout = 15000; const fetchInboxTimeout = 30000; -const pingTimeout = 5000; // TODO - -// TODO What happens if the app is offline? -// TODO What happens if the server is offline? +const pingTimeout = 5000; const _xmpp: { current: { @@ -504,7 +501,6 @@ const login = async (username: string, password: string) => { await _xmpp.current.client.start(); } catch (e) { - _xmpp.current = null; notify('xmpp-is-online', false); console.error(e); @@ -608,8 +604,6 @@ const sendMessage = async ( recipientPersonUuid: string, message: string, ): Promise => { - console.log('sendMessage'); // TODO - const __sendMessage = new Promise( (resolve: (messageStatus: MessageStatus) => void) => _sendMessage(recipientPersonUuid, message, resolve) @@ -844,8 +838,6 @@ const fetchConversation = async ( withPersonUuid: string, beforeId: string = '', ): Promise => { - console.log('fetchConversation'); // TODO - const __fetchConversation = new Promise( (resolve: (messages: Message[] | undefined | 'timeout') => void) => _fetchConversation(withPersonUuid, resolve, beforeId) @@ -999,8 +991,6 @@ const fetchInboxPage = async ( endTimestamp: Date | null = null, pageSize: number | null = null, ): Promise => { - console.log('fetchInboxPage'); // TODO - const __fetchInboxPage = new Promise( (resolve: (inbox: Inbox | undefined) => void) => _fetchInboxPage(resolve, endTimestamp, pageSize) @@ -1046,12 +1036,9 @@ const logout = async () => { return; } - const currentClient = _xmpp.current.client; - _xmpp.current = null; - notify('xmpp-is-online', false); - await currentClient.reconnect.stop(); - await currentClient.stop().catch(console.warn); + await _xmpp.current.client.reconnect.stop(); + await _xmpp.current.client.stop().catch(console.warn); notify('inbox', null); _xmpp.current = null; }; @@ -1069,16 +1056,12 @@ const registerPushToken = async (token: string | null) => { }; const _pingServer = (resolve: (result: Pong | null | 'timeout') => void) => { - console.log('_pingServer'); // TODO - if (!_xmpp.current) { - console.log('_pingServer: no current'); // TODO resolve(null); return; } if (_xmpp.current.client.status !== 'online') { - console.log('_pingServer: status', _xmpp.current.client.status); // TODO resolve(null); return; } @@ -1174,8 +1157,6 @@ const withReconnectOnTimeout = async (ms: number, promise: Promise): Prom }; const onChangeAppState = (state: AppStateStatus) => { - console.log('state', state); // TODO - if (state === 'active') { pingServer(); }