minor changes
This commit is contained in:
@@ -101,7 +101,7 @@ export function ListConvosProviderInner({
|
|||||||
events => {
|
events => {
|
||||||
if (events.type !== 'logs') return
|
if (events.type !== 'logs') return
|
||||||
|
|
||||||
events.logs.forEach(log => {
|
for (const log of events.logs) {
|
||||||
if (ChatBskyConvoDefs.isLogBeginConvo(log)) {
|
if (ChatBskyConvoDefs.isLogBeginConvo(log)) {
|
||||||
debouncedRefetch()
|
debouncedRefetch()
|
||||||
} else if (ChatBskyConvoDefs.isLogLeaveConvo(log)) {
|
} else if (ChatBskyConvoDefs.isLogLeaveConvo(log)) {
|
||||||
@@ -130,19 +130,20 @@ export function ListConvosProviderInner({
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
} else if (ChatBskyConvoDefs.isLogCreateMessage(log)) {
|
} 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) => {
|
queryClient.setQueryData(RQKEY, (old: ConvoListQueryData) => {
|
||||||
if (!old) return old
|
if (!old) return old
|
||||||
|
|
||||||
function updateConvo(convo: ChatBskyConvoDefs.ConvoView) {
|
function updateConvo(convo: ChatBskyConvoDefs.ConvoView) {
|
||||||
if (!ChatBskyConvoDefs.isLogCreateMessage(log)) return convo
|
|
||||||
|
|
||||||
let unreadCount = convo.unreadCount
|
let unreadCount = convo.unreadCount
|
||||||
if (convo.id !== currentConvoId) {
|
if (convo.id !== currentConvoId) {
|
||||||
if (
|
if (
|
||||||
ChatBskyConvoDefs.isMessageView(log.message) ||
|
ChatBskyConvoDefs.isMessageView(logRef.message) ||
|
||||||
ChatBskyConvoDefs.isDeletedMessageView(log.message)
|
ChatBskyConvoDefs.isDeletedMessageView(logRef.message)
|
||||||
) {
|
) {
|
||||||
if (log.message.sender.did !== currentAccount?.did) {
|
if (logRef.message.sender.did !== currentAccount?.did) {
|
||||||
unreadCount++
|
unreadCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,8 +153,8 @@ export function ListConvosProviderInner({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...convo,
|
...convo,
|
||||||
rev: log.rev,
|
rev: logRef.rev,
|
||||||
lastMessage: log.message,
|
lastMessage: logRef.message,
|
||||||
unreadCount,
|
unreadCount,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,14 +162,10 @@ export function ListConvosProviderInner({
|
|||||||
function filterConvoFromPage(
|
function filterConvoFromPage(
|
||||||
convo: ChatBskyConvoDefs.ConvoView[],
|
convo: ChatBskyConvoDefs.ConvoView[],
|
||||||
) {
|
) {
|
||||||
return convo.filter(
|
return convo.filter(c => c.id !== logRef.convoId)
|
||||||
c =>
|
|
||||||
c.id !==
|
|
||||||
(log as ChatBskyConvoDefs.LogCreateMessage).convoId,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingConvo = getConvoFromQueryData(log.convoId, old)
|
const existingConvo = getConvoFromQueryData(logRef.convoId, old)
|
||||||
|
|
||||||
if (existingConvo) {
|
if (existingConvo) {
|
||||||
return {
|
return {
|
||||||
@@ -199,7 +196,7 @@ export function ListConvosProviderInner({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// get events for all chats
|
// get events for all chats
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import {asPredicate} from '@atproto/api'
|
|
||||||
import {ValidationResult} from '@atproto/lexicon'
|
import {ValidationResult} from '@atproto/lexicon'
|
||||||
|
|
||||||
export * as post from '#/types/bsky/post'
|
export * as post from '#/types/bsky/post'
|
||||||
@@ -30,7 +29,7 @@ export function dangerousIsType<R extends {$type?: string}>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* For faster checks with data we trust, like that from our app view, use the
|
||||||
* `dangerousIsType` export from this same file.
|
* `dangerousIsType` export from this same file.
|
||||||
@@ -42,10 +41,11 @@ export function dangerousIsType<R extends {$type?: string}>(
|
|||||||
* if (bsky.validate(item, AppBskyFeedPost.validateRecord)) {
|
* if (bsky.validate(item, AppBskyFeedPost.validateRecord)) {
|
||||||
* // `item` has type `$Typed<AppBskyFeedPost.Record>` here
|
* // `item` has type `$Typed<AppBskyFeedPost.Record>` here
|
||||||
* }
|
* }
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
export function validate<R extends {$type?: string}>(
|
export function validate<R extends {$type?: string}>(
|
||||||
record: unknown,
|
record: unknown,
|
||||||
identity: (v: unknown) => ValidationResult<R>,
|
validator: (v: unknown) => ValidationResult<R>,
|
||||||
): record is R {
|
): record is R {
|
||||||
return asPredicate(identity)(record)
|
return validator(record).success
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ export const DebugModScreen = ({}: NativeStackScreenProps<
|
|||||||
})
|
})
|
||||||
mockedProfile.did = did
|
mockedProfile.did = did
|
||||||
mockedProfile.avatar = 'https://bsky.social/about/images/favicon-32x32.png'
|
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 =
|
mockedProfile.banner =
|
||||||
'https://bsky.social/about/images/social-card-default-gradient.png'
|
'https://bsky.social/about/images/social-card-default-gradient.png'
|
||||||
return mockedProfile
|
return mockedProfile
|
||||||
|
|||||||
Reference in New Issue
Block a user