fix: 修复消息未读数同步和帖子详情快照逻辑

- MessagesPage: 新增 updateConvUnread 统一更新会话未读数及 session 缓存,
  缓存命中时仍调用 markConversationRead 并触发未读刷新,
  全部标为已读时同步更新 session 缓存避免 stale 数据
- PostDetailPage: 仅 POP 导航类型使用 session 快照恢复,
  非 POP 导航和下拉刷新始终强制重拉确保拿到最新数据
This commit is contained in:
2026-09-02 19:29:01 +08:00
parent 76be8926f2
commit cad53942e8
2 changed files with 34 additions and 17 deletions

View File

@@ -109,7 +109,7 @@ export default function PostDetailPage() {
const { limits } = useForumLimits();
const { setPostOutline, isMobile } = useOutletContext<LayoutCtx>();
const initialSnap = (postId && !Number.isNaN(postId))
const initialSnap = (postId && !Number.isNaN(postId) && navType === 'POP')
? getSessionSnapshot<PostDetailSnapshot>(postDetailCacheKey(postId))
: undefined;
@@ -259,7 +259,7 @@ export default function PostDetailPage() {
if (mode === 'force') {
deleteSessionSnapshot(postDetailCacheKey(postId));
}
const cached = mode === 'force'
const cached = mode === 'force' || navType !== 'POP'
? undefined
: getSessionSnapshot<PostDetailSnapshot>(postDetailCacheKey(postId));
if (cached) {
@@ -329,19 +329,9 @@ export default function PostDetailPage() {
}, [postId]);
useEffect(() => {
// 下拉已预热则应用快照;否则强制重拉
// 下拉/软刷新:始终强制重拉,确保拿到最新数据
const onForce = () => {
if (!postId || Number.isNaN(postId)) return;
const warm = getSessionSnapshot<PostDetailSnapshot>(postDetailCacheKey(postId));
if (warm) {
loadSeq.current += 1;
applySnapshot(warm, { restoreScroll: false });
setLoading(false);
const el = pageRef.current;
if (el) el.scrollTop = 0;
scrollTopRef.current = 0;
return;
}
loadPostRef.current('force');
};
window.addEventListener(PAGE_FORCE_REFRESH_EVENT, onForce);