From 239998ec44cc92e1c87c53ddd3056613efeaddc3 Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Fri, 14 Aug 2026 12:12:56 +0800 Subject: [PATCH] feat(mobile-h5): add local follow-confirm helpers for WeChat notify steps Co-authored-by: Cursor --- mobile-h5/utils/mp-follow-confirm.js | 34 ++++++++++++++++++++ mobile-h5/utils/mp-follow-confirm.test.js | 38 +++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 mobile-h5/utils/mp-follow-confirm.js create mode 100644 mobile-h5/utils/mp-follow-confirm.test.js diff --git a/mobile-h5/utils/mp-follow-confirm.js b/mobile-h5/utils/mp-follow-confirm.js new file mode 100644 index 00000000..a8f4e0be --- /dev/null +++ b/mobile-h5/utils/mp-follow-confirm.js @@ -0,0 +1,34 @@ +// 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 + } +} diff --git a/mobile-h5/utils/mp-follow-confirm.test.js b/mobile-h5/utils/mp-follow-confirm.test.js new file mode 100644 index 00000000..10ef596f --- /dev/null +++ b/mobile-h5/utils/mp-follow-confirm.test.js @@ -0,0 +1,38 @@ +// mobile-h5/utils/mp-follow-confirm.test.js +import assert from 'node:assert/strict' +import { + followStorageKey, + isFollowConfirmed, + setFollowConfirmed, + resolveStepDone +} from './mp-follow-confirm.js' + +assert.equal(followStorageKey('u1'), 'mp_follow_confirmed:u1') +assert.equal(followStorageKey(''), 'mp_follow_confirmed:anonymous') + +const store = new Map() +const api = { + getStorageSync: (k) => store.get(k), + setStorageSync: (k, v) => { + store.set(k, v) + } +} +assert.equal(isFollowConfirmed('u1', api), false) +setFollowConfirmed('u1', true, api) +assert.equal(isFollowConfirmed('u1', api), true) +assert.equal(isFollowConfirmed('u2', api), false) + +assert.deepEqual(resolveStepDone({ bound: true, followConfirmed: false }), { + step1Done: true, + step2Done: true +}) +assert.deepEqual(resolveStepDone({ bound: false, followConfirmed: true }), { + step1Done: true, + step2Done: false +}) +assert.deepEqual(resolveStepDone({ bound: false, followConfirmed: false }), { + step1Done: false, + step2Done: false +}) + +console.log('mp-follow-confirm: ok')