Skip to content

Commit

Permalink
feat(core): use session.locales for new users, fix #1116
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Sep 1, 2023
1 parent 7d8e866 commit 9dbbf71
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"@koishijs/i18n-utils": "^1.0.0",
"@koishijs/utils": "^7.0.5",
"@minatojs/core": "^2.4.0",
"@satorijs/core": "^2.6.3",
"cordis": "^2.8.7",
"@satorijs/core": "^2.7.0",
"cordis": "^2.8.8",
"cosmokit": "^1.4.5",
"fastest-levenshtein": "^1.0.16"
}
Expand Down
9 changes: 3 additions & 6 deletions packages/core/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ declare module '@satorijs/core' {
_next(): void
_observeChannelLike<T extends Channel.Field = never>(channelId: string, fields: Iterable<T>): Promise<any>
}

export interface Payload {
locales?: string[]
}
}
}

Expand Down Expand Up @@ -223,11 +219,12 @@ extend(Session.prototype as Session.Private, {
const user = await app.database.getUser(platform, id, fields)
if (user) return user
const authority = await this.resolve(app.config.autoAuthorize)
const data = { locales: this.locales, authority, createdAt: new Date() }
if (authority) {
return app.database.createUser(platform, id, { authority, createdAt: new Date() })
return app.database.createUser(platform, id, data)
} else {
const user = app.model.tables.user.create()
Object.assign(user, { authority, $detached: true })
Object.assign(user, { ...data, $detached: true })
return user
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@koishijs/core": "4.14.3",
"@koishijs/loader": "4.1.3",
"@koishijs/utils": "^7.0.5",
"@satorijs/satori": "^2.6.3",
"@satorijs/satori": "^2.7.0",
"cac": "^6.7.14",
"kleur": "^4.1.5",
"ns-require": "^1.1.4"
Expand Down

0 comments on commit 9dbbf71

Please sign in to comment.