修复动态发布与互动问题
This commit is contained in:
@@ -9,11 +9,16 @@ function makeHandle(openid) {
|
||||
return `@user_${suffix}`
|
||||
}
|
||||
|
||||
// Default avatar pool to randomise new user avatars
|
||||
const AVATAR_KEYS = [
|
||||
'gradient-avatar-1', 'gradient-avatar-2', 'gradient-avatar-3',
|
||||
'gradient-avatar-4', 'gradient-avatar-5', 'gradient-avatar-6'
|
||||
]
|
||||
// Deterministic gradient swatch (.gradient-avatar-1..6) from the user's openid, so
|
||||
// a user who hasn't set a real avatar always gets the same stable colour.
|
||||
function gradientAvatarKey(seed) {
|
||||
let h = 5381
|
||||
for (let i = 0; i < seed.length; i++) {
|
||||
h = ((h << 5) + h) ^ seed.charCodeAt(i)
|
||||
h >>>= 0
|
||||
}
|
||||
return `gradient-avatar-${(h % 6) + 1}`
|
||||
}
|
||||
|
||||
exports.main = async event => {
|
||||
const { OPENID } = cloud.getWXContext()
|
||||
@@ -35,7 +40,7 @@ exports.main = async event => {
|
||||
}
|
||||
|
||||
// New user — create with sensible defaults
|
||||
const avatarKey = AVATAR_KEYS[Math.floor(Math.random() * AVATAR_KEYS.length)]
|
||||
const avatarKey = gradientAvatarKey(OPENID)
|
||||
const user = {
|
||||
openid: OPENID,
|
||||
nickname: event.userInfo?.nickname || '宠物达人',
|
||||
@@ -48,7 +53,7 @@ exports.main = async event => {
|
||||
level: 1,
|
||||
bio: '',
|
||||
verified: false,
|
||||
stats: { posts: 0, following: 0, followers: 0, favorites: 0 },
|
||||
stats: { posts: 0, following: 0, followers: 0 },
|
||||
preferences: { notifications: true, nearbyVisible: true },
|
||||
createdAt: now,
|
||||
lastLoginAt: now
|
||||
|
||||
Reference in New Issue
Block a user