Use clipclops
This commit is contained in:
@@ -50,6 +50,7 @@
|
|||||||
"open-analyzer": "EXPO_PUBLIC_OPEN_ANALYZER=1 yarn build-web"
|
"open-analyzer": "EXPO_PUBLIC_OPEN_ANALYZER=1 yarn build-web"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@atproto-labs/api": "^0.12.8-clipclops.0",
|
||||||
"@atproto/api": "^0.12.5",
|
"@atproto/api": "^0.12.5",
|
||||||
"@bam.tech/react-native-image-resizer": "^3.0.4",
|
"@bam.tech/react-native-image-resizer": "^3.0.4",
|
||||||
"@braintree/sanitize-url": "^6.0.2",
|
"@braintree/sanitize-url": "^6.0.2",
|
||||||
|
|||||||
+45
-35
@@ -1,4 +1,8 @@
|
|||||||
import {BskyAgent, TempDmDefs, TempDmSendMessage} from '@atproto/api'
|
import {
|
||||||
|
BskyAgent,
|
||||||
|
ChatBskyConvoDefs,
|
||||||
|
ChatBskyConvoSendMessage,
|
||||||
|
} from '@atproto-labs/api'
|
||||||
import {EventEmitter} from 'eventemitter3'
|
import {EventEmitter} from 'eventemitter3'
|
||||||
import {nanoid} from 'nanoid/non-secure'
|
import {nanoid} from 'nanoid/non-secure'
|
||||||
|
|
||||||
@@ -20,19 +24,25 @@ export type ChatItem =
|
|||||||
| {
|
| {
|
||||||
type: 'message'
|
type: 'message'
|
||||||
key: string
|
key: string
|
||||||
message: TempDmDefs.MessageView
|
message: ChatBskyConvoDefs.MessageView
|
||||||
nextMessage: TempDmDefs.MessageView | TempDmDefs.DeletedMessage | null
|
nextMessage:
|
||||||
|
| ChatBskyConvoDefs.MessageView
|
||||||
|
| ChatBskyConvoDefs.DeletedMessageView
|
||||||
|
| null
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: 'deleted-message'
|
type: 'deleted-message'
|
||||||
key: string
|
key: string
|
||||||
message: TempDmDefs.DeletedMessage
|
message: ChatBskyConvoDefs.DeletedMessageView
|
||||||
nextMessage: TempDmDefs.MessageView | TempDmDefs.DeletedMessage | null
|
nextMessage:
|
||||||
|
| ChatBskyConvoDefs.MessageView
|
||||||
|
| ChatBskyConvoDefs.DeletedMessageView
|
||||||
|
| null
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: 'pending-message'
|
type: 'pending-message'
|
||||||
key: string
|
key: string
|
||||||
message: TempDmSendMessage.InputSchema['message']
|
message: ChatBskyConvoSendMessage.InputSchema['message']
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ChatState =
|
export type ChatState =
|
||||||
@@ -45,7 +55,7 @@ export type ChatState =
|
|||||||
| {
|
| {
|
||||||
status: ChatStatus.Ready
|
status: ChatStatus.Ready
|
||||||
items: ChatItem[]
|
items: ChatItem[]
|
||||||
chat: TempDmDefs.ChatView
|
chat: ChatBskyConvoDefs.ConvoView
|
||||||
isFetchingHistory: boolean
|
isFetchingHistory: boolean
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
@@ -63,22 +73,22 @@ export class Chat {
|
|||||||
|
|
||||||
private status: ChatStatus = ChatStatus.Uninitialized
|
private status: ChatStatus = ChatStatus.Uninitialized
|
||||||
private error: any
|
private error: any
|
||||||
private chat: TempDmDefs.ChatView | undefined
|
private chat: 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
|
||||||
|
|
||||||
private pastMessages: Map<
|
private pastMessages: Map<
|
||||||
string,
|
string,
|
||||||
TempDmDefs.MessageView | TempDmDefs.DeletedMessage
|
ChatBskyConvoDefs.MessageView | ChatBskyConvoDefs.DeletedMessageView
|
||||||
> = new Map()
|
> = new Map()
|
||||||
private newMessages: Map<
|
private newMessages: Map<
|
||||||
string,
|
string,
|
||||||
TempDmDefs.MessageView | TempDmDefs.DeletedMessage
|
ChatBskyConvoDefs.MessageView | ChatBskyConvoDefs.DeletedMessageView
|
||||||
> = new Map()
|
> = new Map()
|
||||||
private pendingMessages: Map<
|
private pendingMessages: Map<
|
||||||
string,
|
string,
|
||||||
{id: string; message: TempDmSendMessage.InputSchema['message']}
|
{id: string; message: ChatBskyConvoSendMessage.InputSchema['message']}
|
||||||
> = new Map()
|
> = new Map()
|
||||||
|
|
||||||
private pendingEventIngestion: Promise<void> | undefined
|
private pendingEventIngestion: Promise<void> | undefined
|
||||||
@@ -94,9 +104,9 @@ export class Chat {
|
|||||||
this.status = ChatStatus.Initializing
|
this.status = ChatStatus.Initializing
|
||||||
|
|
||||||
try {
|
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: {
|
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.status = ChatStatus.Ready
|
||||||
|
|
||||||
this.commit()
|
this.commit()
|
||||||
@@ -151,10 +161,10 @@ export class Chat {
|
|||||||
await new Promise(y => setTimeout(y, 500))
|
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,
|
cursor: this.historyCursor,
|
||||||
chatId: this.chatId,
|
convoId: this.chatId,
|
||||||
limit: 20,
|
limit: 20,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -169,8 +179,8 @@ export class Chat {
|
|||||||
|
|
||||||
for (const message of messages) {
|
for (const message of messages) {
|
||||||
if (
|
if (
|
||||||
TempDmDefs.isMessageView(message) ||
|
ChatBskyConvoDefs.isMessageView(message) ||
|
||||||
TempDmDefs.isDeletedMessage(message)
|
ChatBskyConvoDefs.isDeletedMessageView(message)
|
||||||
) {
|
) {
|
||||||
this.pastMessages.set(message.id, message)
|
this.pastMessages.set(message.id, message)
|
||||||
|
|
||||||
@@ -191,7 +201,7 @@ export class Chat {
|
|||||||
async ingestLatestEvents() {
|
async ingestLatestEvents() {
|
||||||
if (this.status === ChatStatus.Destroyed) return
|
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,
|
cursor: this.eventsCursor,
|
||||||
},
|
},
|
||||||
@@ -227,8 +237,8 @@ export class Chat {
|
|||||||
if (log.chatId !== this.chatId) continue
|
if (log.chatId !== this.chatId) continue
|
||||||
|
|
||||||
if (
|
if (
|
||||||
TempDmDefs.isLogCreateMessage(log) &&
|
ChatBskyConvoDefs.isLogCreateMessage(log) &&
|
||||||
TempDmDefs.isMessageView(log.message)
|
ChatBskyConvoDefs.isMessageView(log.message)
|
||||||
) {
|
) {
|
||||||
if (this.newMessages.has(log.message.id)) {
|
if (this.newMessages.has(log.message.id)) {
|
||||||
// Trust the log as the source of truth on ordering
|
// 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)
|
this.newMessages.set(log.message.id, log.message)
|
||||||
} else if (
|
} else if (
|
||||||
TempDmDefs.isLogDeleteMessage(log) &&
|
ChatBskyConvoDefs.isLogDeleteMessage(log) &&
|
||||||
TempDmDefs.isDeletedMessage(log.message)
|
ChatBskyConvoDefs.isDeletedMessageView(log.message)
|
||||||
) {
|
) {
|
||||||
/*
|
/*
|
||||||
* Update if we have this in state. If we don't, don't worry about it.
|
* 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()
|
this.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendMessage(message: TempDmSendMessage.InputSchema['message']) {
|
async sendMessage(message: ChatBskyConvoSendMessage.InputSchema['message']) {
|
||||||
if (this.status === ChatStatus.Destroyed) return
|
if (this.status === ChatStatus.Destroyed) return
|
||||||
// Ignore empty messages for now since they have no other purpose atm
|
// Ignore empty messages for now since they have no other purpose atm
|
||||||
if (!message.text) return
|
if (!message.text) return
|
||||||
@@ -274,9 +284,9 @@ export class Chat {
|
|||||||
this.commit()
|
this.commit()
|
||||||
|
|
||||||
await new Promise(y => setTimeout(y, 500))
|
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,
|
message,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -310,14 +320,14 @@ export class Chat {
|
|||||||
|
|
||||||
// `newMessages` is in insertion order, unshift to reverse
|
// `newMessages` is in insertion order, unshift to reverse
|
||||||
this.newMessages.forEach(m => {
|
this.newMessages.forEach(m => {
|
||||||
if (TempDmDefs.isMessageView(m)) {
|
if (ChatBskyConvoDefs.isMessageView(m)) {
|
||||||
items.unshift({
|
items.unshift({
|
||||||
type: 'message',
|
type: 'message',
|
||||||
key: m.id,
|
key: m.id,
|
||||||
message: m,
|
message: m,
|
||||||
nextMessage: null,
|
nextMessage: null,
|
||||||
})
|
})
|
||||||
} else if (TempDmDefs.isDeletedMessage(m)) {
|
} else if (ChatBskyConvoDefs.isDeletedMessageView(m)) {
|
||||||
items.unshift({
|
items.unshift({
|
||||||
type: 'deleted-message',
|
type: 'deleted-message',
|
||||||
key: m.id,
|
key: m.id,
|
||||||
@@ -337,14 +347,14 @@ export class Chat {
|
|||||||
})
|
})
|
||||||
|
|
||||||
this.pastMessages.forEach(m => {
|
this.pastMessages.forEach(m => {
|
||||||
if (TempDmDefs.isMessageView(m)) {
|
if (ChatBskyConvoDefs.isMessageView(m)) {
|
||||||
items.push({
|
items.push({
|
||||||
type: 'message',
|
type: 'message',
|
||||||
key: m.id,
|
key: m.id,
|
||||||
message: m,
|
message: m,
|
||||||
nextMessage: null,
|
nextMessage: null,
|
||||||
})
|
})
|
||||||
} else if (TempDmDefs.isDeletedMessage(m)) {
|
} else if (ChatBskyConvoDefs.isDeletedMessageView(m)) {
|
||||||
items.push({
|
items.push({
|
||||||
type: 'deleted-message',
|
type: 'deleted-message',
|
||||||
key: m.id,
|
key: m.id,
|
||||||
@@ -358,14 +368,14 @@ export class Chat {
|
|||||||
let nextMessage = null
|
let nextMessage = null
|
||||||
|
|
||||||
if (
|
if (
|
||||||
TempDmDefs.isMessageView(item.message) ||
|
ChatBskyConvoDefs.isMessageView(item.message) ||
|
||||||
TempDmDefs.isDeletedMessage(item.message)
|
ChatBskyConvoDefs.isDeletedMessageView(item.message)
|
||||||
) {
|
) {
|
||||||
const next = items[i - 1]
|
const next = items[i - 1]
|
||||||
if (
|
if (
|
||||||
next &&
|
next &&
|
||||||
(TempDmDefs.isMessageView(next.message) ||
|
(ChatBskyConvoDefs.isMessageView(next.message) ||
|
||||||
TempDmDefs.isDeletedMessage(next.message))
|
ChatBskyConvoDefs.isDeletedMessageView(next.message))
|
||||||
) {
|
) {
|
||||||
nextMessage = next.message
|
nextMessage = next.message
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {BskyAgent} from '@atproto/api'
|
import {BskyAgent} from '@atproto-labs/api'
|
||||||
|
|
||||||
import {Chat, ChatParams} from '#/state/dms/chat'
|
import {Chat, ChatParams} from '#/state/dms/chat'
|
||||||
import {useAgent} from '#/state/session'
|
import {useAgent} from '#/state/session'
|
||||||
|
|||||||
@@ -34,6 +34,18 @@
|
|||||||
jsonpointer "^5.0.0"
|
jsonpointer "^5.0.0"
|
||||||
leven "^3.1.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":
|
"@atproto/api@^0.12.3":
|
||||||
version "0.12.3"
|
version "0.12.3"
|
||||||
resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.12.3.tgz#5b7b1c7d4210ee9315961504900c8409395cbb17"
|
resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.12.3.tgz#5b7b1c7d4210ee9315961504900c8409395cbb17"
|
||||||
|
|||||||
Reference in New Issue
Block a user