35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
// mobile-h5/utils/mp-follow-confirm.js
|
|
export function followStorageKey(userId) {
|
|
const id = String(userId || '').trim() || 'anonymous'
|
|
return 'mp_follow_confirmed:' + id
|
|
}
|
|
|
|
export function isFollowConfirmed(userId, storage) {
|
|
const s = storage || (typeof uni !== 'undefined' ? uni : null)
|
|
if (!s || typeof s.getStorageSync !== 'function') return false
|
|
try {
|
|
return String(s.getStorageSync(followStorageKey(userId)) || '') === '1'
|
|
} catch (_) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
export function setFollowConfirmed(userId, confirmed, storage) {
|
|
const s = storage || (typeof uni !== 'undefined' ? uni : null)
|
|
if (!s || typeof s.setStorageSync !== 'function') return
|
|
try {
|
|
s.setStorageSync(followStorageKey(userId), confirmed ? '1' : '0')
|
|
} catch (_) {
|
|
/* ignore */
|
|
}
|
|
}
|
|
|
|
/** @returns {{ step1Done: boolean, step2Done: boolean }} */
|
|
export function resolveStepDone({ bound, followConfirmed }) {
|
|
if (bound) return { step1Done: true, step2Done: true }
|
|
return {
|
|
step1Done: !!followConfirmed,
|
|
step2Done: false
|
|
}
|
|
}
|