test chat edit
This commit is contained in:
@@ -254,8 +254,8 @@ export async function updatePost(
|
||||
|
||||
try {
|
||||
// Fetch existing record to preserve translations
|
||||
let existingTranslations = undefined
|
||||
let existingCreatedAt = new Date().toISOString()
|
||||
let existingTranslations: unknown = undefined
|
||||
let existingCreatedAt: unknown = new Date().toISOString()
|
||||
try {
|
||||
const existing = await agent.com.atproto.repo.getRecord({
|
||||
repo: agent.assertDid,
|
||||
@@ -266,7 +266,7 @@ export async function updatePost(
|
||||
const value = existing.data.value as Record<string, unknown>
|
||||
existingTranslations = value.translations
|
||||
if (value.createdAt) {
|
||||
existingCreatedAt = value.createdAt as string
|
||||
existingCreatedAt = value.createdAt
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
@@ -298,6 +298,51 @@ export async function updatePost(
|
||||
}
|
||||
}
|
||||
|
||||
// Update chat message
|
||||
export async function updateChat(
|
||||
collection: string,
|
||||
rkey: string,
|
||||
content: string
|
||||
): Promise<{ uri: string; cid: string } | null> {
|
||||
if (!agent) return null
|
||||
|
||||
try {
|
||||
// Fetch existing record to preserve translations and other fields
|
||||
let existingRecord: Record<string, unknown> = {}
|
||||
try {
|
||||
const existing = await agent.com.atproto.repo.getRecord({
|
||||
repo: agent.assertDid,
|
||||
collection,
|
||||
rkey,
|
||||
})
|
||||
if (existing.data.value) {
|
||||
existingRecord = existing.data.value as Record<string, unknown>
|
||||
}
|
||||
} catch {
|
||||
// Record doesn't exist
|
||||
throw new Error('Record not found')
|
||||
}
|
||||
|
||||
const record: Record<string, unknown> = {
|
||||
...existingRecord,
|
||||
$type: collection,
|
||||
content,
|
||||
}
|
||||
|
||||
const result = await agent.com.atproto.repo.putRecord({
|
||||
repo: agent.assertDid,
|
||||
collection,
|
||||
rkey,
|
||||
record,
|
||||
})
|
||||
|
||||
return { uri: result.data.uri, cid: result.data.cid }
|
||||
} catch (err) {
|
||||
console.error('Update chat error:', err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
// Save migrated card data to ai.syui.card.old
|
||||
export async function saveMigratedCardData(
|
||||
user: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export interface Route {
|
||||
type: 'home' | 'user' | 'post' | 'postpage' | 'atbrowser' | 'service' | 'collection' | 'record' | 'chat' | 'chat-thread' | 'card' | 'card-old' | 'rse'
|
||||
type: 'home' | 'user' | 'post' | 'postpage' | 'atbrowser' | 'service' | 'collection' | 'record' | 'chat' | 'chat-thread' | 'chat-edit' | 'card' | 'card-old' | 'rse'
|
||||
handle?: string
|
||||
rkey?: string
|
||||
service?: string
|
||||
@@ -69,6 +69,12 @@ export function parseRoute(): Route {
|
||||
return { type: 'rse', handle: rseMatch[1] }
|
||||
}
|
||||
|
||||
// Chat edit: /@handle/at/chat/{rkey}/edit
|
||||
const chatEditMatch = path.match(/^\/@([^/]+)\/at\/chat\/([^/]+)\/edit$/)
|
||||
if (chatEditMatch) {
|
||||
return { type: 'chat-edit', handle: chatEditMatch[1], rkey: chatEditMatch[2] }
|
||||
}
|
||||
|
||||
// Chat thread: /@handle/at/chat/{rkey}
|
||||
const chatThreadMatch = path.match(/^\/@([^/]+)\/at\/chat\/([^/]+)$/)
|
||||
if (chatThreadMatch) {
|
||||
@@ -117,6 +123,8 @@ export function navigate(route: Route): void {
|
||||
path = `/@${route.handle}/at/chat`
|
||||
} else if (route.type === 'chat-thread' && route.handle && route.rkey) {
|
||||
path = `/@${route.handle}/at/chat/${route.rkey}`
|
||||
} else if (route.type === 'chat-edit' && route.handle && route.rkey) {
|
||||
path = `/@${route.handle}/at/chat/${route.rkey}/edit`
|
||||
}
|
||||
|
||||
window.history.pushState({}, '', path)
|
||||
|
||||
Reference in New Issue
Block a user