From 6d892f676b61bece62924ccb562f43c3511c62cf Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 30 Apr 2024 21:02:08 -0500 Subject: [PATCH] Use clipclops --- package.json | 1 + src/state/dms/chat.ts | 80 +++++++++++++++++++++++------------------ src/state/dms/index.tsx | 2 +- yarn.lock | 12 +++++++ 4 files changed, 59 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index acb9007b45..28386fc47d 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "open-analyzer": "EXPO_PUBLIC_OPEN_ANALYZER=1 yarn build-web" }, "dependencies": { + "@atproto-labs/api": "^0.12.8-clipclops.0", "@atproto/api": "^0.12.5", "@bam.tech/react-native-image-resizer": "^3.0.4", "@braintree/sanitize-url": "^6.0.2", diff --git a/src/state/dms/chat.ts b/src/state/dms/chat.ts index 98cb32e702..f89e66c119 100644 --- a/src/state/dms/chat.ts +++ b/src/state/dms/chat.ts @@ -1,4 +1,8 @@ -import {BskyAgent, TempDmDefs, TempDmSendMessage} from '@atproto/api' +import { + BskyAgent, + ChatBskyConvoDefs, + ChatBskyConvoSendMessage, +} from '@atproto-labs/api' import {EventEmitter} from 'eventemitter3' import {nanoid} from 'nanoid/non-secure' @@ -20,19 +24,25 @@ export type ChatItem = | { type: 'message' key: string - message: TempDmDefs.MessageView - nextMessage: TempDmDefs.MessageView | TempDmDefs.DeletedMessage | null + message: ChatBskyConvoDefs.MessageView + nextMessage: + | ChatBskyConvoDefs.MessageView + | ChatBskyConvoDefs.DeletedMessageView + | null } | { type: 'deleted-message' key: string - message: TempDmDefs.DeletedMessage - nextMessage: TempDmDefs.MessageView | TempDmDefs.DeletedMessage | null + message: ChatBskyConvoDefs.DeletedMessageView + nextMessage: + | ChatBskyConvoDefs.MessageView + | ChatBskyConvoDefs.DeletedMessageView + | null } | { type: 'pending-message' key: string - message: TempDmSendMessage.InputSchema['message'] + message: ChatBskyConvoSendMessage.InputSchema['message'] } export type ChatState = @@ -45,7 +55,7 @@ export type ChatState = | { status: ChatStatus.Ready items: ChatItem[] - chat: TempDmDefs.ChatView + chat: ChatBskyConvoDefs.ConvoView isFetchingHistory: boolean } | { @@ -63,22 +73,22 @@ export class Chat { private status: ChatStatus = ChatStatus.Uninitialized private error: any - private chat: TempDmDefs.ChatView | undefined + private chat: ChatBskyConvoDefs.ConvoView | undefined private historyCursor: string | undefined | null = undefined private isFetchingHistory = false private eventsCursor: string | undefined = undefined private pastMessages: Map< string, - TempDmDefs.MessageView | TempDmDefs.DeletedMessage + ChatBskyConvoDefs.MessageView | ChatBskyConvoDefs.DeletedMessageView > = new Map() private newMessages: Map< string, - TempDmDefs.MessageView | TempDmDefs.DeletedMessage + ChatBskyConvoDefs.MessageView | ChatBskyConvoDefs.DeletedMessageView > = new Map() private pendingMessages: Map< string, - {id: string; message: TempDmSendMessage.InputSchema['message']} + {id: string; message: ChatBskyConvoSendMessage.InputSchema['message']} > = new Map() private pendingEventIngestion: Promise | undefined @@ -94,9 +104,9 @@ export class Chat { this.status = ChatStatus.Initializing try { - const response = await this.agent.api.temp.dm.getChat( + const response = await this.agent.api.chat.bsky.convo.getConvo( { - chatId: this.chatId, + convoId: this.chatId, }, { headers: { @@ -104,9 +114,9 @@ export class Chat { }, }, ) - const {chat} = response.data + const {convo} = response.data - this.chat = chat + this.chat = convo this.status = ChatStatus.Ready this.commit() @@ -151,10 +161,10 @@ export class Chat { await new Promise(y => setTimeout(y, 500)) } - const response = await this.agent.api.temp.dm.getChatMessages( + const response = await this.agent.api.chat.bsky.convo.getMessages( { cursor: this.historyCursor, - chatId: this.chatId, + convoId: this.chatId, limit: 20, }, { @@ -169,8 +179,8 @@ export class Chat { for (const message of messages) { if ( - TempDmDefs.isMessageView(message) || - TempDmDefs.isDeletedMessage(message) + ChatBskyConvoDefs.isMessageView(message) || + ChatBskyConvoDefs.isDeletedMessageView(message) ) { this.pastMessages.set(message.id, message) @@ -191,7 +201,7 @@ export class Chat { async ingestLatestEvents() { if (this.status === ChatStatus.Destroyed) return - const response = await this.agent.api.temp.dm.getChatLog( + const response = await this.agent.api.chat.bsky.convo.getLog( { cursor: this.eventsCursor, }, @@ -227,8 +237,8 @@ export class Chat { if (log.chatId !== this.chatId) continue if ( - TempDmDefs.isLogCreateMessage(log) && - TempDmDefs.isMessageView(log.message) + ChatBskyConvoDefs.isLogCreateMessage(log) && + ChatBskyConvoDefs.isMessageView(log.message) ) { if (this.newMessages.has(log.message.id)) { // Trust the log as the source of truth on ordering @@ -237,8 +247,8 @@ export class Chat { } this.newMessages.set(log.message.id, log.message) } else if ( - TempDmDefs.isLogDeleteMessage(log) && - TempDmDefs.isDeletedMessage(log.message) + ChatBskyConvoDefs.isLogDeleteMessage(log) && + ChatBskyConvoDefs.isDeletedMessageView(log.message) ) { /* * Update if we have this in state. If we don't, don't worry about it. @@ -260,7 +270,7 @@ export class Chat { this.commit() } - async sendMessage(message: TempDmSendMessage.InputSchema['message']) { + async sendMessage(message: ChatBskyConvoSendMessage.InputSchema['message']) { if (this.status === ChatStatus.Destroyed) return // Ignore empty messages for now since they have no other purpose atm if (!message.text) return @@ -274,9 +284,9 @@ export class Chat { this.commit() await new Promise(y => setTimeout(y, 500)) - const response = await this.agent.api.temp.dm.sendMessage( + const response = await this.agent.api.chat.bsky.convo.sendMessage( { - chatId: this.chatId, + convoId: this.chatId, message, }, { @@ -310,14 +320,14 @@ export class Chat { // `newMessages` is in insertion order, unshift to reverse this.newMessages.forEach(m => { - if (TempDmDefs.isMessageView(m)) { + if (ChatBskyConvoDefs.isMessageView(m)) { items.unshift({ type: 'message', key: m.id, message: m, nextMessage: null, }) - } else if (TempDmDefs.isDeletedMessage(m)) { + } else if (ChatBskyConvoDefs.isDeletedMessageView(m)) { items.unshift({ type: 'deleted-message', key: m.id, @@ -337,14 +347,14 @@ export class Chat { }) this.pastMessages.forEach(m => { - if (TempDmDefs.isMessageView(m)) { + if (ChatBskyConvoDefs.isMessageView(m)) { items.push({ type: 'message', key: m.id, message: m, nextMessage: null, }) - } else if (TempDmDefs.isDeletedMessage(m)) { + } else if (ChatBskyConvoDefs.isDeletedMessageView(m)) { items.push({ type: 'deleted-message', key: m.id, @@ -358,14 +368,14 @@ export class Chat { let nextMessage = null if ( - TempDmDefs.isMessageView(item.message) || - TempDmDefs.isDeletedMessage(item.message) + ChatBskyConvoDefs.isMessageView(item.message) || + ChatBskyConvoDefs.isDeletedMessageView(item.message) ) { const next = items[i - 1] if ( next && - (TempDmDefs.isMessageView(next.message) || - TempDmDefs.isDeletedMessage(next.message)) + (ChatBskyConvoDefs.isMessageView(next.message) || + ChatBskyConvoDefs.isDeletedMessageView(next.message)) ) { nextMessage = next.message } diff --git a/src/state/dms/index.tsx b/src/state/dms/index.tsx index 45be8e001f..fafd4f18bd 100644 --- a/src/state/dms/index.tsx +++ b/src/state/dms/index.tsx @@ -1,5 +1,5 @@ import React from 'react' -import {BskyAgent} from '@atproto/api' +import {BskyAgent} from '@atproto-labs/api' import {Chat, ChatParams} from '#/state/dms/chat' import {useAgent} from '#/state/session' diff --git a/yarn.lock b/yarn.lock index 5d62929d47..8c014e28ed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -34,6 +34,18 @@ jsonpointer "^5.0.0" leven "^3.1.0" +"@atproto-labs/api@^0.12.8-clipclops.0": + version "0.12.8-clipclops.0" + resolved "https://registry.yarnpkg.com/@atproto-labs/api/-/api-0.12.8-clipclops.0.tgz#1c5d41d3396e439a0b645f7e1ccf500cc4b42580" + integrity sha512-YYDtWWk6BR+aRBVja/1v+gceNK81lkmF5bi6O4pTmJhFt/321XATx/ql8uTWta4VnVThoFeNPG6nLr7hs8b9cA== + dependencies: + "@atproto/common-web" "^0.3.0" + "@atproto/lexicon" "^0.4.0" + "@atproto/syntax" "^0.3.0" + "@atproto/xrpc" "^0.5.0" + multiformats "^9.9.0" + tlds "^1.234.0" + "@atproto/api@^0.12.3": version "0.12.3" resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.12.3.tgz#5b7b1c7d4210ee9315961504900c8409395cbb17"