修改bug
This commit is contained in:
@@ -74,12 +74,25 @@ exports.main = async event => {
|
||||
favSet = new Set(favRes.data.map(f => f.postId))
|
||||
}
|
||||
|
||||
const list = res.data.map(post => ({
|
||||
// Resolve authors' current profile (real avatar image) so feed avatars load
|
||||
// and stay fresh, even for posts whose snapshot predates avatar upload.
|
||||
const authorIds = [...new Set(res.data.map(p => p.authorId).filter(Boolean))]
|
||||
const authorMap = new Map()
|
||||
for (let i = 0; i < authorIds.length; i += 100) {
|
||||
const chunk = authorIds.slice(i, i + 100)
|
||||
const usersRes = await safeGet('users', { _id: _.in(chunk) }, 100)
|
||||
usersRes.data.forEach(u => authorMap.set(u._id, u))
|
||||
}
|
||||
|
||||
const list = res.data.map(post => {
|
||||
const author = authorMap.get(post.authorId)
|
||||
return {
|
||||
_id: post._id,
|
||||
author: {
|
||||
id: post.authorId || '',
|
||||
name: post.authorSnapshot?.name || '用户',
|
||||
avatarKey: post.authorSnapshot?.avatarKey || 'gradient-avatar-1'
|
||||
name: (author && author.nickname) || post.authorSnapshot?.name || '用户',
|
||||
avatarKey: (author && author.avatarKey) || post.authorSnapshot?.avatarKey || 'gradient-avatar-1',
|
||||
avatarUrl: (author && author.avatarUrl) || post.authorSnapshot?.avatarUrl || ''
|
||||
},
|
||||
pet: post.petSnapshot || { name: '', breed: '' },
|
||||
body: post.content || '',
|
||||
@@ -98,7 +111,8 @@ exports.main = async event => {
|
||||
},
|
||||
likedByMe: likedSet.has(post._id),
|
||||
favoritedByMe: favSet.has(post._id)
|
||||
}))
|
||||
}
|
||||
})
|
||||
|
||||
const last = res.data[res.data.length - 1]
|
||||
return { list, nextCursor: last ? String(last.createdAt) : '' }
|
||||
|
||||
Reference in New Issue
Block a user