[Clipclops] Pending messages (#3803)
* Make pending message like normal message * Remove getter * Make props publiczio/stable
parent
e2556d9f40
commit
5148b957b7
|
@ -26,12 +26,10 @@ function MaybeLoader({isLoading}: {isLoading: boolean}) {
|
|||
}
|
||||
|
||||
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} />
|
||||
} else if (item.type === 'deleted-message') {
|
||||
return <Text>Deleted message</Text>
|
||||
} else if (item.type === 'pending-message') {
|
||||
return <Text>{item.message.text}</Text>
|
||||
} else if (item.type === 'pending-retry') {
|
||||
return (
|
||||
<View>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import {AppBskyActorDefs} from '@atproto/api'
|
||||
import {
|
||||
BskyAgent,
|
||||
ChatBskyConvoDefs,
|
||||
|
@ -24,7 +25,7 @@ export enum ConvoStatus {
|
|||
|
||||
export type ConvoItem =
|
||||
| {
|
||||
type: 'message'
|
||||
type: 'message' | 'pending-message'
|
||||
key: string
|
||||
message: ChatBskyConvoDefs.MessageView
|
||||
nextMessage:
|
||||
|
@ -41,11 +42,6 @@ export type ConvoItem =
|
|||
| ChatBskyConvoDefs.DeletedMessageView
|
||||
| null
|
||||
}
|
||||
| {
|
||||
type: 'pending-message'
|
||||
key: string
|
||||
message: ChatBskyConvoSendMessage.InputSchema['message']
|
||||
}
|
||||
| {
|
||||
type: 'pending-retry'
|
||||
key: string
|
||||
|
@ -85,17 +81,19 @@ export function isConvoItemMessage(
|
|||
}
|
||||
|
||||
export class Convo {
|
||||
private convoId: string
|
||||
private agent: BskyAgent
|
||||
private __tempFromUserDid: string
|
||||
|
||||
private status: ConvoStatus = ConvoStatus.Uninitialized
|
||||
private error: any
|
||||
private convo: ChatBskyConvoDefs.ConvoView | undefined
|
||||
private historyCursor: string | undefined | null = undefined
|
||||
private isFetchingHistory = false
|
||||
private eventsCursor: string | undefined = undefined
|
||||
|
||||
convoId: string
|
||||
convo: ChatBskyConvoDefs.ConvoView | undefined
|
||||
sender: AppBskyActorDefs.ProfileViewBasic | undefined
|
||||
|
||||
private pastMessages: Map<
|
||||
string,
|
||||
ChatBskyConvoDefs.MessageView | ChatBskyConvoDefs.DeletedMessageView
|
||||
|
@ -137,6 +135,9 @@ export class Convo {
|
|||
const {convo} = response.data
|
||||
|
||||
this.convo = convo
|
||||
this.sender = this.convo.members.find(
|
||||
m => m.did === this.__tempFromUserDid,
|
||||
)
|
||||
this.status = ConvoStatus.Ready
|
||||
|
||||
this.commit()
|
||||
|
@ -324,7 +325,7 @@ export class Convo {
|
|||
this.newMessages.set(res.id, {
|
||||
...res,
|
||||
$type: 'chat.bsky.convo.defs#messageView',
|
||||
sender: this.convo?.members.find(m => m.did === this.__tempFromUserDid),
|
||||
sender: this.sender,
|
||||
})
|
||||
this.pendingMessages.delete(id)
|
||||
|
||||
|
@ -440,7 +441,14 @@ export class Convo {
|
|||
items.unshift({
|
||||
type: 'pending-message',
|
||||
key: m.id,
|
||||
message: m.message,
|
||||
message: {
|
||||
...m.message,
|
||||
id: nanoid(),
|
||||
rev: '__fake__',
|
||||
sentAt: new Date().toISOString(),
|
||||
sender: this.sender,
|
||||
},
|
||||
nextMessage: null,
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue