mirror of
https://github.com/svemagie/indiekit-endpoint-microsub.git
synced 2026-04-02 15:35:00 +02:00
fix: mark-as-read for items from orphan channels
Items from channels with userId: null (created during earlier setup) appeared in the unified timeline but had no _channelUid, causing the mark-read JS handler to silently abort. Fall back to channelId (MongoDB ObjectId) when channelUid is unavailable, and resolve it server-side via getChannelById. Confab-Link: http://localhost:8080/sessions/4d40ef89-a713-48c1-b4ed-0ffafca25677
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
import { IndiekitError } from "@indiekit/error";
|
||||
|
||||
import { proxyItemImages } from "../media/proxy.js";
|
||||
import { getChannel } from "../storage/channels.js";
|
||||
import { getChannel, getChannelById } from "../storage/channels.js";
|
||||
import {
|
||||
getTimelineItems,
|
||||
markItemsRead,
|
||||
@@ -72,8 +72,16 @@ export async function action(request, response) {
|
||||
|
||||
validateChannel(channel);
|
||||
|
||||
// Verify channel exists
|
||||
const channelDocument = await getChannel(application, channel, userId);
|
||||
// Verify channel exists — try by UID first, fall back to ObjectId
|
||||
// (timeline view may send ObjectId string for items from orphan channels)
|
||||
let channelDocument = await getChannel(application, channel, userId);
|
||||
if (!channelDocument) {
|
||||
try {
|
||||
channelDocument = await getChannelById(application, channel);
|
||||
} catch {
|
||||
// Invalid ObjectId format — channel string is not a valid ObjectId
|
||||
}
|
||||
}
|
||||
if (!channelDocument) {
|
||||
throw new IndiekitError("Channel not found", {
|
||||
status: 404,
|
||||
|
||||
Reference in New Issue
Block a user