去掉了一些不必要的dontCreateOper,为brcxt增加了getCurrentUserId及其实现

This commit is contained in:
Xu Chang 2024-02-07 14:33:09 +08:00
parent fd20e2855e
commit 06121b50e8
5 changed files with 17 additions and 8 deletions

View File

@ -912,7 +912,7 @@ async function tryRefreshWechatPublicUserInfo<
scope: s2,
},
},
{ dontCollect: true, dontCreateModi: true, dontCreateOper: true }
{ dontCollect: true }
);
accessToken = at2;
}

View File

@ -45,7 +45,7 @@ export async function mergeUser<ED extends EntityDict & BaseEntityDict, Cxt exte
filter: {
[attr]: from,
}
} as any, { dontCollect: true, dontCreateOper: true, dontCreateModi: true });
} as any, { dontCollect: true });
}
if (attr === 'entity' && attributes.hasOwnProperty('entityId')) {
await context.operate(entity, {
@ -57,7 +57,7 @@ export async function mergeUser<ED extends EntityDict & BaseEntityDict, Cxt exte
entity: 'user',
entityId: from,
}
} as any, { dontCollect: true, dontCreateOper: true, dontCreateModi: true });
} as any, { dontCollect: true });
}
}
} */

View File

@ -32,6 +32,7 @@ export abstract class BackendRuntimeContext<ED extends EntityDict & BaseEntityDi
protected amIRoot?: boolean;
protected amIReallyRoot?: boolean;
protected rootMode?: boolean;
private userId?: string;
async refineOpRecords(): Promise<void> {
for (const opRecord of this.opRecords) {
@ -218,10 +219,18 @@ export abstract class BackendRuntimeContext<ED extends EntityDict & BaseEntityDi
}
getCurrentUserId(allowUnloggedIn?: boolean) {
const token = this.getToken(allowUnloggedIn);
if (this.userId) {
return this.userId;
}
const token = this.getToken(allowUnloggedIn);
return token?.userId as string;
}
setCurrentUserId(userId: string | undefined): void {
assert(this.isReallyRoot);
this.userId = userId;
}
protected async getSerializedData(): Promise<SerializedData> {
const data = await super.getSerializedData();
return {

View File

@ -94,7 +94,7 @@ async function setUserUnsubscribed(openId: string, context: BRC) {
id: weChatUser.id,
},
},
{ dontCollect: true, dontCreateOper: true }
{ dontCollect: true }
);
}
} else {
@ -110,7 +110,7 @@ async function setUserUnsubscribed(openId: string, context: BRC) {
openId,
},
},
{ dontCollect: true, dontCreateOper: true }
{ dontCollect: true }
);
}
return;
@ -168,7 +168,7 @@ async function setUserSubscribed(
id: wechatUser.id,
},
},
{ dontCollect: true, dontCreateOper: true }
{ dontCollect: true }
);
}

View File

@ -130,7 +130,7 @@ export class Token<
this.publish();
}
async loginWechatMp() {
async loginWechatMp() {
const { code } = await wx.login();
const env = await this.environment.getEnv();