- 新增 addComment/getComments/getFollowList/followUser/getUser/updateProfile/updatePet/deletePet 云函数并完成部署 - 统一通过 app.globalData.navBarInfo 避让系统胶囊按钮(编辑资料/编辑宠物等页面保存按钮被遮挡问题) - 编辑资料页所在城市改为省份 picker 选择 - 修复"我的"页动态为空(getUserPosts 应传 openid 而非数据库 _id) - 重构编辑宠物页:品种改用 picker 滚轮(替代有数量上限的 actionSheet),标签改用 selectedTagSet 映射 + 自定义标签输入(5字以内、仅中英文/数字、最多8个) - 接通宠物保存/删除真实云函数调用并同步本地缓存 - 移除 feed 页对不存在的 getStories 云函数调用,修复模拟器卡死 - 移除 post 页对不存在的 wx.reverseGeocoder API 的调用 - 统一扩展 AppGlobalData 类型并修正所有 getApp 调用的泛型,解决 TS 报错
52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
const cloud = require('wx-server-sdk')
|
|
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })
|
|
const db = cloud.database()
|
|
const _ = db.command
|
|
|
|
exports.main = async (event, context) => {
|
|
const { OPENID } = cloud.getWXContext()
|
|
const { type = 'following', userId } = event
|
|
const targetId = userId || OPENID
|
|
|
|
try {
|
|
let followIds = []
|
|
|
|
if (type === 'following') {
|
|
const res = await db.collection('follows')
|
|
.where({ followerId: targetId })
|
|
.field({ followeeId: true })
|
|
.get()
|
|
followIds = res.data.map(f => f.followeeId)
|
|
} else {
|
|
const res = await db.collection('follows')
|
|
.where({ followeeId: targetId })
|
|
.field({ followerId: true })
|
|
.get()
|
|
followIds = res.data.map(f => f.followerId)
|
|
}
|
|
|
|
if (followIds.length === 0) {
|
|
return { code: 0, data: [] }
|
|
}
|
|
|
|
const usersRes = await db.collection('users')
|
|
.where({ openid: _.in(followIds) })
|
|
.field({ nickName: true, openid: true, avatarUrl: true, bio: true, location: true, isOnline: true, lastSeen: true, pets: true, stats: true })
|
|
.get()
|
|
|
|
// check if current user follows each
|
|
const myFollowsRes = await db.collection('follows')
|
|
.where({ followerId: OPENID, followeeId: _.in(followIds) })
|
|
.field({ followeeId: true })
|
|
.get()
|
|
const myFollowSet = new Set(myFollowsRes.data.map(f => f.followeeId))
|
|
|
|
return {
|
|
code: 0,
|
|
data: usersRes.data.map(u => ({ ...u, _id: u._id, isFollowing: myFollowSet.has(u.openid) })),
|
|
}
|
|
} catch (e) {
|
|
return { code: -1, message: e.message }
|
|
}
|
|
}
|