diff --git a/src/state/queries/messages/list-conversations.tsx b/src/state/queries/messages/list-conversations.tsx index 63074b321a..8c9d6c4293 100644 --- a/src/state/queries/messages/list-conversations.tsx +++ b/src/state/queries/messages/list-conversations.tsx @@ -101,7 +101,7 @@ export function ListConvosProviderInner({ events => { if (events.type !== 'logs') return - events.logs.forEach(log => { + for (const log of events.logs) { if (ChatBskyConvoDefs.isLogBeginConvo(log)) { debouncedRefetch() } else if (ChatBskyConvoDefs.isLogLeaveConvo(log)) { @@ -130,19 +130,20 @@ export function ListConvosProviderInner({ }), ) } else if (ChatBskyConvoDefs.isLogCreateMessage(log)) { + // Store in a new var to avoid TS errors due to closures. + const logRef: ChatBskyConvoDefs.LogCreateMessage = log + queryClient.setQueryData(RQKEY, (old: ConvoListQueryData) => { if (!old) return old function updateConvo(convo: ChatBskyConvoDefs.ConvoView) { - if (!ChatBskyConvoDefs.isLogCreateMessage(log)) return convo - let unreadCount = convo.unreadCount if (convo.id !== currentConvoId) { if ( - ChatBskyConvoDefs.isMessageView(log.message) || - ChatBskyConvoDefs.isDeletedMessageView(log.message) + ChatBskyConvoDefs.isMessageView(logRef.message) || + ChatBskyConvoDefs.isDeletedMessageView(logRef.message) ) { - if (log.message.sender.did !== currentAccount?.did) { + if (logRef.message.sender.did !== currentAccount?.did) { unreadCount++ } } @@ -152,8 +153,8 @@ export function ListConvosProviderInner({ return { ...convo, - rev: log.rev, - lastMessage: log.message, + rev: logRef.rev, + lastMessage: logRef.message, unreadCount, } } @@ -161,14 +162,10 @@ export function ListConvosProviderInner({ function filterConvoFromPage( convo: ChatBskyConvoDefs.ConvoView[], ) { - return convo.filter( - c => - c.id !== - (log as ChatBskyConvoDefs.LogCreateMessage).convoId, - ) + return convo.filter(c => c.id !== logRef.convoId) } - const existingConvo = getConvoFromQueryData(log.convoId, old) + const existingConvo = getConvoFromQueryData(logRef.convoId, old) if (existingConvo) { return { @@ -199,7 +196,7 @@ export function ListConvosProviderInner({ } }) } - }) + } }, { // get events for all chats diff --git a/src/types/bsky/index.ts b/src/types/bsky/index.ts index 8d77f9580b..d5acbdbb59 100644 --- a/src/types/bsky/index.ts +++ b/src/types/bsky/index.ts @@ -1,4 +1,3 @@ -import {asPredicate} from '@atproto/api' import {ValidationResult} from '@atproto/lexicon' export * as post from '#/types/bsky/post' @@ -30,7 +29,7 @@ export function dangerousIsType( } /** - * Fully validates the object schema, which as a performance cost. + * Fully validates the object schema, which has a performance cost. * * For faster checks with data we trust, like that from our app view, use the * `dangerousIsType` export from this same file. @@ -42,10 +41,11 @@ export function dangerousIsType( * if (bsky.validate(item, AppBskyFeedPost.validateRecord)) { * // `item` has type `$Typed` here * } + * ``` */ export function validate( record: unknown, - identity: (v: unknown) => ValidationResult, + validator: (v: unknown) => ValidationResult, ): record is R { - return asPredicate(identity)(record) + return validator(record).success } diff --git a/src/view/screens/DebugMod.tsx b/src/view/screens/DebugMod.tsx index e515a9a0f1..34a1a7633b 100644 --- a/src/view/screens/DebugMod.tsx +++ b/src/view/screens/DebugMod.tsx @@ -133,7 +133,7 @@ export const DebugModScreen = ({}: NativeStackScreenProps< }) mockedProfile.did = did mockedProfile.avatar = 'https://bsky.social/about/images/favicon-32x32.png' - // @ts-ignore ProfileViewBasic is close enough -esb + // @ts-expect-error ProfileViewBasic is close enough -esb mockedProfile.banner = 'https://bsky.social/about/images/social-card-default-gradient.png' return mockedProfile