mp-follow-confirm.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. // mobile-h5/utils/mp-follow-confirm.js
  2. export function followStorageKey(userId) {
  3. const id = String(userId || '').trim() || 'anonymous'
  4. return 'mp_follow_confirmed:' + id
  5. }
  6. export function isFollowConfirmed(userId, storage) {
  7. const s = storage || (typeof uni !== 'undefined' ? uni : null)
  8. if (!s || typeof s.getStorageSync !== 'function') return false
  9. try {
  10. return String(s.getStorageSync(followStorageKey(userId)) || '') === '1'
  11. } catch (_) {
  12. return false
  13. }
  14. }
  15. export function setFollowConfirmed(userId, confirmed, storage) {
  16. const s = storage || (typeof uni !== 'undefined' ? uni : null)
  17. if (!s || typeof s.setStorageSync !== 'function') return
  18. try {
  19. s.setStorageSync(followStorageKey(userId), confirmed ? '1' : '0')
  20. } catch (_) {
  21. /* ignore */
  22. }
  23. }
  24. /** @returns {{ step1Done: boolean, step2Done: boolean }} */
  25. export function resolveStepDone({ bound, followConfirmed }) {
  26. if (bound) return { step1Done: true, step2Done: true }
  27. return {
  28. step1Done: !!followConfirmed,
  29. step2Done: false
  30. }
  31. }