From 386341e96d812160ec18dbcfcd771930a031ea80 Mon Sep 17 00:00:00 2001 From: Rongrong Date: Tue, 5 Mar 2024 00:08:41 +0800 Subject: [PATCH] fix(route/weibo/user): remove all pinned weibo if any is too old (#14637) Signed-off-by: Rongrong --- lib/routes/weibo/user.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/routes/weibo/user.ts b/lib/routes/weibo/user.ts index 48ea8f302..3c7b7daa2 100644 --- a/lib/routes/weibo/user.ts +++ b/lib/routes/weibo/user.ts @@ -126,13 +126,18 @@ export default async (ctx) => { }) ); - // remove pinned weibo if they are too old (older than all the rest weibo) - // the character of pinned weibo is `card.profile_type_id.startsWith('proweibotop')` - // there can be 1 or 2 (WHAT A FANTASTIC BRAIN THE PM HAS?) pinned weibo at the same time + // remove pinned weibo if they are posted before the earliest **ordinary** weibo + // there may be multiple pinned weibo at the same time, only remove the ones that meet the above condition const pinnedItems = resultItems.filter((item) => item.isPinned); const ordinaryItems = resultItems.filter((item) => !item.isPinned); - if (pinnedItems.length > 0 && ordinaryItems.length > 0 && Math.max(...pinnedItems.map((i) => i.pubDate).filter(Boolean)) < Math.min(...ordinaryItems.map((i) => i.pubDate).filter(Boolean))) { + if (pinnedItems.length > 0 && ordinaryItems.length > 0) { + const earliestOrdinaryPostTime = Math.min(...ordinaryItems.map((i) => i.pubDate).filter(Boolean)); resultItems = ordinaryItems; + for (const item of pinnedItems) { + if (item.pubDate > earliestOrdinaryPostTime) { + resultItems.unshift(item); + } + } } ctx.set(