diff options
author | Eric Bailey <git@esb.lol> | 2024-05-16 14:01:39 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-16 14:01:39 -0500 |
commit | 4bceabc21cacd865f5b10684142485faca2c9bb4 (patch) | |
tree | 98201e8fc87f5f2a6e880c2bf8f2da42af5546e0 /src/state/messages/convo/index.tsx | |
parent | dff6bd7c6542b62f1ba8325d2c0520b1665d412b (diff) | |
download | voidsky-4bceabc21cacd865f5b10684142485faca2c9bb4.tar.zst |
[🐴] Error recovery (#4036)
* Handle block state when sending messages * Handle different pending failures * Use existing profile data to handle blocks * Better cleanup, leave room for more * Attempt recover upon next send * Reset pending failure * Capture unexpected error * Gracefully handle network errors and recovery * Re-align error components and types * Include history fetching in recoverable states
Diffstat (limited to 'src/state/messages/convo/index.tsx')
-rw-r--r-- | src/state/messages/convo/index.tsx | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/state/messages/convo/index.tsx b/src/state/messages/convo/index.tsx index e955d4118..d6648f480 100644 --- a/src/state/messages/convo/index.tsx +++ b/src/state/messages/convo/index.tsx @@ -1,6 +1,7 @@ import React, {useContext, useState, useSyncExternalStore} from 'react' import {AppState} from 'react-native' import {useFocusEffect, useIsFocused} from '@react-navigation/native' +import {useQueryClient} from '@tanstack/react-query' import {Convo} from '#/state/messages/convo/agent' import { @@ -13,6 +14,8 @@ import { import {isConvoActive} from '#/state/messages/convo/util' import {useMessagesEventBus} from '#/state/messages/events' import {useMarkAsReadMutation} from '#/state/queries/messages/conversation' +import {RQKEY as ListConvosQueryKey} from '#/state/queries/messages/list-converations' +import {RQKEY as createProfileQueryKey} from '#/state/queries/profile' import {useAgent} from '#/state/session' export * from '#/state/messages/convo/util' @@ -52,6 +55,7 @@ export function ConvoProvider({ children, convoId, }: Pick<ConvoParams, 'convoId'> & {children: React.ReactNode}) { + const queryClient = useQueryClient() const isScreenFocused = useIsFocused() const {getAgent} = useAgent() const events = useMessagesEventBus() @@ -79,6 +83,23 @@ export function ConvoProvider({ ) React.useEffect(() => { + return convo.on(event => { + switch (event.type) { + case 'invalidate-block-state': { + for (const did of event.accountDids) { + queryClient.invalidateQueries({ + queryKey: createProfileQueryKey(did), + }) + } + queryClient.invalidateQueries({ + queryKey: ListConvosQueryKey, + }) + } + } + }) + }, [convo, queryClient]) + + React.useEffect(() => { const handleAppStateChange = (nextAppState: string) => { if (isScreenFocused) { if (nextAppState === 'active') { |