|
|
|
@@ -83,14 +83,11 @@ export const atproto = {
|
|
|
|
|
return await request(`${apiEndpoint}/xrpc/${ENDPOINTS.getProfile}?actor=${actor}`)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async getRecords(pds, repo, collection, limit = 10, cursor = null, reverse = false) {
|
|
|
|
|
async getRecords(pds, repo, collection, limit = 10, cursor = null) {
|
|
|
|
|
let url = `${pds}/xrpc/${ENDPOINTS.listRecords}?repo=${repo}&collection=${collection}&limit=${limit}`
|
|
|
|
|
if (cursor) {
|
|
|
|
|
url += `&cursor=${cursor}`
|
|
|
|
|
}
|
|
|
|
|
if (reverse) {
|
|
|
|
|
url += `&reverse=true`
|
|
|
|
|
}
|
|
|
|
|
const res = await request(url)
|
|
|
|
|
return {
|
|
|
|
|
records: res.records || [],
|
|
|
|
@@ -154,7 +151,7 @@ export const collections = {
|
|
|
|
|
const cached = dataCache.get(cacheKey)
|
|
|
|
|
if (cached) return cached
|
|
|
|
|
|
|
|
|
|
const data = await atproto.getRecords(pds, repo, `${collection}.chat.comment`, limit, null, true) // reverse=true for chronological order
|
|
|
|
|
const data = await atproto.getRecords(pds, repo, `${collection}.chat.comment`, limit)
|
|
|
|
|
// Extract records array for backward compatibility
|
|
|
|
|
const records = data.records || data
|
|
|
|
|
dataCache.set(cacheKey, records)
|
|
|
|
@@ -164,7 +161,7 @@ export const collections = {
|
|
|
|
|
async getChat(pds, repo, collection, limit = 10, cursor = null) {
|
|
|
|
|
// Don't use cache for pagination requests
|
|
|
|
|
if (cursor) {
|
|
|
|
|
const result = await atproto.getRecords(pds, repo, `${collection}.chat`, limit, cursor, true) // reverse=true for chronological order
|
|
|
|
|
const result = await atproto.getRecords(pds, repo, `${collection}.chat`, limit, cursor)
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -175,7 +172,7 @@ export const collections = {
|
|
|
|
|
return Array.isArray(cached) ? { records: cached, cursor: null } : cached
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const data = await atproto.getRecords(pds, repo, `${collection}.chat`, limit, null, true) // reverse=true for chronological order
|
|
|
|
|
const data = await atproto.getRecords(pds, repo, `${collection}.chat`, limit)
|
|
|
|
|
// Cache only the records array for backward compatibility
|
|
|
|
|
dataCache.set(cacheKey, data.records || data)
|
|
|
|
|
return data
|
|
|
|
|