fix(push): 通知开关默认改开(修正误解「可配置项=默认关」致 token 从不上报)
★ 功能性硬伤修复:用户实测「新邮件根本没有通知」。
根因:我上一版把 PushService.isEnabled 默认设成关(读不到即 false),
误解了「接入系统通知是可配置项」的本意 —— 用户要的是「服务端没配凭证时
客户端优雅降级」(enabled:false 是正常态,不报错不阻塞),不是「默认关掉
推送功能」。结果 reportToken 最前 gate 直接 return,device token 从未上报,
DB 里 0 个 token,NotifyNewMail 在 len(tokens)==0 时静默返回 ⇒ 永远发不出。
修正:
- PushContract.DEFAULT_PUSH_ENABLED: false → true(契约层默认开)
- PushService.isEnabled: getSync 默认值用 DEFAULT_PUSH_ENABLED(true),
catch 也返回 true —— 只有用户显式关才不上报
- 判据同步:harmony-push-optin ①② 改默认开口径
验证(服务端→HMS 链路实打已通):
- OAuth access_token 取得(app_secret 有效)
- POST /v1/{appId}/messages:send + test_message 调通,
HMS 回 80300007 "All tokens are invalid"(假 token 无效,但凭证/形状/认证全被接受)
⇒ 只要 DB 有真实 device token 就能送达(token 由客户端上报)
This commit is contained in:
@ -27,21 +27,21 @@ const read = p => prose(join(HARMONY_ETS, p));
|
||||
|
||||
const C = await import(join(HARMONY_ETS, 'model/PushContract.ts'));
|
||||
|
||||
test('① 契约默认关:DEFAULT_PUSH_ENABLED = false(自部署零开销的契约)', () => {
|
||||
assert.equal(C.DEFAULT_PUSH_ENABLED, false,
|
||||
'默认必须关 —— 自部署用户没配服务端推送凭证时不应被默认裹进推送链');
|
||||
test('① 契约默认开:DEFAULT_PUSH_ENABLED = true(用户要能默认收到通知)', () => {
|
||||
assert.equal(C.DEFAULT_PUSH_ENABLED, true,
|
||||
'默认必须开 —— 接入系统通知是"服务端没配凭证时优雅降级",不是"默认关掉推送"(2026-09-16 用户实测收不到通知的根因)');
|
||||
// 标签:关 ⇒ 'off'、开 ⇒ 'on'(口径稳定,给设置页用)
|
||||
assert.equal(C.pushEnabledLabel(false), 'off');
|
||||
assert.equal(C.pushEnabledLabel(true), 'on');
|
||||
});
|
||||
|
||||
test('② PushService.isEnabled 读不到即 false(默认关落点) + setEnabled 存在', () => {
|
||||
test('② PushService.isEnabled 读不到即开(默认开落点) + setEnabled 存在', () => {
|
||||
const svc = read('api/PushService.ets');
|
||||
const code_ = stripComments(svc);
|
||||
assert.match(code_, /static isEnabled\(context: common\.Context\): boolean \{/,
|
||||
'要有静态 isEnabled(ability 阶段 onCreate 要读它,不能是实例方法)');
|
||||
assert.match(code_, /return v === true;/,
|
||||
'读到 true 才返回 true —— 其它(首次/异常)都 false(默认关)');
|
||||
assert.match(code_, /getSync\(SETTING_KEY, DEFAULT_PUSH_ENABLED\)/,
|
||||
'读不到时用 DEFAULT_PUSH_ENABLED(默认开)—— 只有显式存了 false 才关');
|
||||
assert.match(code_, /static setEnabled\(context: common\.Context, enabled: boolean\): void \{/,
|
||||
'要有静态 setEnabled(设置页 Toggle 回调用)');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user