From 5148b957b7eb0df89d0fd6f20e68b83e16d6a400 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 1 May 2024 16:29:34 -0500 Subject: [PATCH] [Clipclops] Pending messages (#3803) * Make pending message like normal message * Remove getter * Make props public --- .../Messages/Conversation/MessagesList.tsx | 4 +-- src/state/messages/convo.ts | 28 ++++++++++++------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/screens/Messages/Conversation/MessagesList.tsx b/src/screens/Messages/Conversation/MessagesList.tsx index d3f9916e..381f5fe4 100644 --- a/src/screens/Messages/Conversation/MessagesList.tsx +++ b/src/screens/Messages/Conversation/MessagesList.tsx @@ -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 } else if (item.type === 'deleted-message') { return Deleted message - } else if (item.type === 'pending-message') { - return {item.message.text} } else if (item.type === 'pending-retry') { return ( diff --git a/src/state/messages/convo.ts b/src/state/messages/convo.ts index 73ef8d73..4bc9913f 100644 --- a/src/state/messages/convo.ts +++ b/src/state/messages/convo.ts @@ -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, }) })