summaryrefslogtreecommitdiff
path: root/src/models
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-04-02 04:01:34 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-04-02 04:01:34 +0900
commite8bde94e5bccf1303a1aec2f86544d59452bbb9d (patch)
tree50fb517ca91c3ba5e10b2186046880a29137877d /src/models
parentFix: Add missing bracket (diff)
downloadmisskey-e8bde94e5bccf1303a1aec2f86544d59452bbb9d.tar.gz
misskey-e8bde94e5bccf1303a1aec2f86544d59452bbb9d.tar.bz2
misskey-e8bde94e5bccf1303a1aec2f86544d59452bbb9d.zip
Refactor
Diffstat (limited to 'src/models')
-rw-r--r--src/models/user.ts20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/models/user.ts b/src/models/user.ts
index d9ac72b88f..789b28b2f3 100644
--- a/src/models/user.ts
+++ b/src/models/user.ts
@@ -39,7 +39,7 @@ export function isValidBirthday(birthday: string): boolean {
return typeof birthday == 'string' && /^([0-9]{4})\-([0-9]{2})-([0-9]{2})$/.test(birthday);
}
-export type ILocalAccount = {
+type ILocalAccount = {
keypair: string;
email: string;
links: string[];
@@ -69,7 +69,7 @@ export type ILocalAccount = {
settings: any;
};
-export type IRemoteAccount = {
+type IRemoteAccount = {
inbox: string;
uri: string;
publicKey: {
@@ -78,7 +78,7 @@ export type IRemoteAccount = {
};
};
-export type IUser = {
+type IUserBase = {
_id: mongo.ObjectID;
createdAt: Date;
deletedAt: Date;
@@ -97,13 +97,19 @@ export type IUser = {
pinnedPostId: mongo.ObjectID;
isSuspended: boolean;
keywords: string[];
- host: string;
hostLower: string;
- account: ILocalAccount | IRemoteAccount;
};
-export type ILocalUser = IUser & { account: ILocalAccount };
-export type IRemoteUser = IUser & { account: IRemoteAccount };
+export type IUser = ILocalUser | IRemoteUser;
+
+export interface ILocalUser extends IUserBase { host: null; account: ILocalAccount; }
+export interface IRemoteUser extends IUserBase { host: string; account: IRemoteAccount; }
+
+export const isLocalUser = (user: any): user is ILocalUser =>
+ user.host === null;
+
+export const isRemoteUser = (user: any): user is IRemoteUser =>
+ !isLocalUser(user);
export function init(user): IUser {
user._id = new mongo.ObjectID(user._id);