425ca29 / anbot.mjs
diff --git a/anbot.mjs b/anbot.mjs
index de0e0bf..d5086fa 100644
--- a/anbot.mjs
+++ b/anbot.mjs
@@ -6,7 +6,7 @@ import { basename, dirname, isAbsolute, relative, resolve, sep } from 'node:path
import { parseArgs } from 'node:util'
import {
checkoutRoot, clonePath, commitStat, gitEnv, gitOptions, listCommits, listTree,
- publish, readBlob, readCommit, repositoryName, selectedRepository
+ publish, readBlob, readCommit, readPushAnnouncements, repositoryName, selectedRepository
} from './repository.mjs'
import { initializeStore, loadIdentity, recordPath, requireThat } from './storage.mjs'
import { pushAuth, pushWithIdentity } from './push-auth.mjs'
@@ -128,23 +128,25 @@ function matchWebRoute(pathname) {
return null
}
-async function serveFeed(root, query, response) {
+async function serveFeed(root, identity, query, response) {
const params = new URLSearchParams(query)
const author = params.get('author')
const postId = params.get('post')
+ const updateId = params.get('update')
try {
- requireThat(author === null || postId === null, 'Choose one feed view')
- const id = author ?? postId
+ requireThat([author, postId, updateId].filter(id => id !== null).length <= 1, 'Choose one feed view')
+ const id = author ?? postId ?? updateId
if (id !== null) recordPath(id)
} catch {
serveHtml(response, 404, feedPage({ missing: true }))
return
}
- const posts = await readFeed(root)
- const post = postId === null ? undefined : posts.find(item => item.id === postId)
- const missing = postId !== null && !post
+ const [social, pushes] = await Promise.all([readFeed(root), readPushAnnouncements(root, identity)])
+ const posts = [...social, ...pushes].sort((a, b) => b.timestamp - a.timestamp || a.id.localeCompare(b.id))
+ const post = posts.find(item => item.id === postId || item.updateId === updateId)
+ const missing = (postId !== null || updateId !== null) && !post
const matching = posts.filter(item =>
- postId !== null ? item.replyTo === postId : author === null || item.author === author)
+ post ? item.replyTo === post.id : author === null || item.author === author)
serveHtml(response, missing ? 404 : 200, feedPage({ posts: matching, author, post, missing }))
}
@@ -162,7 +164,7 @@ async function runServer(root, identity, host, port, baseUrl, allowlist, pushOri
if (request.method === 'GET') {
if (pathname === '/feed') {
try {
- await serveFeed(root, query, response)
+ await serveFeed(root, identity, query, response)
} catch (error) {
console.error(error.message)
response.writeHead(503).end('Feed unavailable\n')
Git ยท Social feed