[Clipclops] Pending messages (#3803)

* Make pending message like normal message

* Remove getter

* Make props public
zio/stable
Eric Bailey 2024-05-01 16:29:34 -05:00 committed by GitHub
parent e2556d9f40
commit 5148b957b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 13 deletions

View File

@ -26,12 +26,10 @@ function MaybeLoader({isLoading}: {isLoading: boolean}) {
} }
function renderItem({item}: {item: ConvoItem}) { function renderItem({item}: {item: ConvoItem}) {
if (item.type === 'message') { if (item.type === 'message' || item.type === 'pending-message') {
return <MessageItem item={item.message} next={item.nextMessage} /> return <MessageItem item={item.message} next={item.nextMessage} />
} else if (item.type === 'deleted-message') { } else if (item.type === 'deleted-message') {
return <Text>Deleted message</Text> return <Text>Deleted message</Text>
} else if (item.type === 'pending-message') {
return <Text>{item.message.text}</Text>
} else if (item.type === 'pending-retry') { } else if (item.type === 'pending-retry') {
return ( return (
<View> <View>

View File

@ -1,3 +1,4 @@
import {AppBskyActorDefs} from '@atproto/api'
import { import {
BskyAgent, BskyAgent,
ChatBskyConvoDefs, ChatBskyConvoDefs,
@ -24,7 +25,7 @@ export enum ConvoStatus {
export type ConvoItem = export type ConvoItem =
| { | {
type: 'message' type: 'message' | 'pending-message'
key: string key: string
message: ChatBskyConvoDefs.MessageView message: ChatBskyConvoDefs.MessageView
nextMessage: nextMessage:
@ -41,11 +42,6 @@ export type ConvoItem =
| ChatBskyConvoDefs.DeletedMessageView | ChatBskyConvoDefs.DeletedMessageView
| null | null
} }
| {
type: 'pending-message'
key: string
message: ChatBskyConvoSendMessage.InputSchema['message']
}
| { | {
type: 'pending-retry' type: 'pending-retry'
key: string key: string
@ -85,17 +81,19 @@ export function isConvoItemMessage(
} }
export class Convo { export class Convo {
private convoId: string
private agent: BskyAgent private agent: BskyAgent
private __tempFromUserDid: string private __tempFromUserDid: string
private status: ConvoStatus = ConvoStatus.Uninitialized private status: ConvoStatus = ConvoStatus.Uninitialized
private error: any private error: any
private convo: ChatBskyConvoDefs.ConvoView | undefined
private historyCursor: string | undefined | null = undefined private historyCursor: string | undefined | null = undefined
private isFetchingHistory = false private isFetchingHistory = false
private eventsCursor: string | undefined = undefined private eventsCursor: string | undefined = undefined
convoId: string
convo: ChatBskyConvoDefs.ConvoView | undefined
sender: AppBskyActorDefs.ProfileViewBasic | undefined
private pastMessages: Map< private pastMessages: Map<
string, string,
ChatBskyConvoDefs.MessageView | ChatBskyConvoDefs.DeletedMessageView ChatBskyConvoDefs.MessageView | ChatBskyConvoDefs.DeletedMessageView
@ -137,6 +135,9 @@ export class Convo {
const {convo} = response.data const {convo} = response.data
this.convo = convo this.convo = convo
this.sender = this.convo.members.find(
m => m.did === this.__tempFromUserDid,
)
this.status = ConvoStatus.Ready this.status = ConvoStatus.Ready
this.commit() this.commit()
@ -324,7 +325,7 @@ export class Convo {
this.newMessages.set(res.id, { this.newMessages.set(res.id, {
...res, ...res,
$type: 'chat.bsky.convo.defs#messageView', $type: 'chat.bsky.convo.defs#messageView',
sender: this.convo?.members.find(m => m.did === this.__tempFromUserDid), sender: this.sender,
}) })
this.pendingMessages.delete(id) this.pendingMessages.delete(id)
@ -440,7 +441,14 @@ export class Convo {
items.unshift({ items.unshift({
type: 'pending-message', type: 'pending-message',
key: m.id, key: m.id,
message: m.message, message: {
...m.message,
id: nanoid(),
rev: '__fake__',
sentAt: new Date().toISOString(),
sender: this.sender,
},
nextMessage: null,
}) })
}) })