跨端: fix(推送客户端): 登记标记绑定账号(token 换账号是"转移"不是并存 ⇒ 别把登记状态缓存成长期结论)
pi 邮件 `2518e1a3` 的服务端事实:注销只认注册者本人、token 字符串不是凭证, **同一个 token 换账号登录是"转移"而不是并存** ⇒ "我登记过没有"的答案**随账号而变**。 原来的 `shouldReportToken(lastReported, current)` 只按 token 存标记 ⇒ 换账号后 (同一 token)会**错误地跳过上报**,而那个账号其实还没登记过这个 token。 改成 `reportMarker(accountKey, token) = accountKey|token` + `shouldReportToken(lastMarker, accountKey, token)`: **账号变了标记必然不同** —— 于是"换账号必然重新上报"是**性质**,不靠人记得 reset。 判据 13 条全绿(新增"换账号后必然重新上报 / 切回来也要重新上报",并断言两次 marker 不相等)。
This commit is contained in:
@ -40,12 +40,28 @@ export interface PushNotificationData {
|
||||
action: string;
|
||||
}
|
||||
|
||||
/** 上报决策:只有"有 token,且与上次上报的不同"才上报 —— 避免每次启动都打一次接口 */
|
||||
export function shouldReportToken(lastReported: string, current: string): boolean {
|
||||
if (current.length === 0) {
|
||||
/**
|
||||
* 上报标记:**必须把账号绑进去**。
|
||||
*
|
||||
* 服务端事实(pi 邮件 `2518e1a3`):注销只认**注册者本人**,token 字符串不是凭证;
|
||||
* **同一个 token 换账号登录是"转移",不是并存**。所以"我登记过没有"这个问题的答案
|
||||
* **会随账号而变** —— 若把标记只按 token 存(`lastReported === token` 就跳过上报),
|
||||
* 换了账号之后我会**错误地跳过上报**,而那个账号其实还没登记过这个 token。
|
||||
* ⇒ 标记的形状就是 `accountKey|token`:**账号变了,标记必然不同**,不必靠人记得 reset。
|
||||
*/
|
||||
export function reportMarker(accountKey: string, token: string): string {
|
||||
return `${accountKey}|${token}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上报决策:只有"有 token,且**本账号**上次上报的不是它"才上报 —— 避免每次启动都打一次接口。
|
||||
* 账号切换后必然重新上报(见 `reportMarker` 的理由),这是**性质**,不是特判。
|
||||
*/
|
||||
export function shouldReportToken(lastMarker: string, accountKey: string, token: string): boolean {
|
||||
if (token.length === 0) {
|
||||
return false;
|
||||
}
|
||||
return lastReported !== current;
|
||||
return lastMarker !== reportMarker(accountKey, token);
|
||||
}
|
||||
|
||||
/** 取尾 6 位(与服务端 `token_tail` 同口径;token 短于 6 位时取全文) */
|
||||
|
||||
Reference in New Issue
Block a user