2019-04-07 21:50:36 +09:00
|
|
|
import { Entity, Column, Index, OneToOne, JoinColumn, PrimaryColumn } from 'typeorm';
|
2021-08-19 18:33:41 +09:00
|
|
|
import { DriveFile } from './drive-file.js';
|
|
|
|
import { id } from '../id.js';
|
2019-04-07 21:50:36 +09:00
|
|
|
|
|
|
|
@Entity()
|
|
|
|
@Index(['usernameLower', 'host'], { unique: true })
|
|
|
|
export class User {
|
|
|
|
@PrimaryColumn(id())
|
|
|
|
public id: string;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column('timestamp with time zone', {
|
|
|
|
comment: 'The created date of the User.'
|
|
|
|
})
|
|
|
|
public createdAt: Date;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column('timestamp with time zone', {
|
|
|
|
nullable: true,
|
|
|
|
comment: 'The updated date of the User.'
|
|
|
|
})
|
|
|
|
public updatedAt: Date | null;
|
|
|
|
|
|
|
|
@Column('timestamp with time zone', {
|
|
|
|
nullable: true
|
|
|
|
})
|
|
|
|
public lastFetchedAt: Date | null;
|
|
|
|
|
2021-04-17 15:30:26 +09:00
|
|
|
@Index()
|
|
|
|
@Column('timestamp with time zone', {
|
|
|
|
nullable: true
|
|
|
|
})
|
|
|
|
public lastActiveDate: Date | null;
|
|
|
|
|
|
|
|
@Column('boolean', {
|
|
|
|
default: false,
|
|
|
|
})
|
|
|
|
public hideOnlineStatus: boolean;
|
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
@Column('varchar', {
|
|
|
|
length: 128,
|
|
|
|
comment: 'The username of the User.'
|
|
|
|
})
|
|
|
|
public username: string;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column('varchar', {
|
|
|
|
length: 128, select: false,
|
|
|
|
comment: 'The username (lowercased) of the User.'
|
|
|
|
})
|
|
|
|
public usernameLower: string;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
|
|
|
length: 128, nullable: true,
|
|
|
|
comment: 'The name of the User.'
|
|
|
|
})
|
|
|
|
public name: string | null;
|
|
|
|
|
|
|
|
@Column('integer', {
|
|
|
|
default: 0,
|
|
|
|
comment: 'The count of followers.'
|
|
|
|
})
|
|
|
|
public followersCount: number;
|
|
|
|
|
|
|
|
@Column('integer', {
|
|
|
|
default: 0,
|
|
|
|
comment: 'The count of following.'
|
|
|
|
})
|
|
|
|
public followingCount: number;
|
|
|
|
|
|
|
|
@Column('integer', {
|
|
|
|
default: 0,
|
|
|
|
comment: 'The count of notes.'
|
|
|
|
})
|
|
|
|
public notesCount: number;
|
|
|
|
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
nullable: true,
|
|
|
|
comment: 'The ID of avatar DriveFile.'
|
|
|
|
})
|
|
|
|
public avatarId: DriveFile['id'] | null;
|
|
|
|
|
|
|
|
@OneToOne(type => DriveFile, {
|
|
|
|
onDelete: 'SET NULL'
|
|
|
|
})
|
|
|
|
@JoinColumn()
|
|
|
|
public avatar: DriveFile | null;
|
|
|
|
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
nullable: true,
|
|
|
|
comment: 'The ID of banner DriveFile.'
|
|
|
|
})
|
|
|
|
public bannerId: DriveFile['id'] | null;
|
|
|
|
|
|
|
|
@OneToOne(type => DriveFile, {
|
|
|
|
onDelete: 'SET NULL'
|
|
|
|
})
|
|
|
|
@JoinColumn()
|
|
|
|
public banner: DriveFile | null;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column('varchar', {
|
|
|
|
length: 128, array: true, default: '{}'
|
|
|
|
})
|
|
|
|
public tags: string[];
|
|
|
|
|
|
|
|
@Column('varchar', {
|
2019-04-11 19:03:49 +09:00
|
|
|
length: 512, nullable: true,
|
2019-04-07 21:50:36 +09:00
|
|
|
})
|
|
|
|
public avatarUrl: string | null;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
2019-04-11 19:03:49 +09:00
|
|
|
length: 512, nullable: true,
|
2019-04-07 21:50:36 +09:00
|
|
|
})
|
|
|
|
public bannerUrl: string | null;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
2020-07-19 00:24:07 +09:00
|
|
|
length: 128, nullable: true,
|
2019-04-07 21:50:36 +09:00
|
|
|
})
|
2020-07-19 00:24:07 +09:00
|
|
|
public avatarBlurhash: string | null;
|
2019-04-07 21:50:36 +09:00
|
|
|
|
|
|
|
@Column('varchar', {
|
2020-07-19 00:24:07 +09:00
|
|
|
length: 128, nullable: true,
|
2019-04-07 21:50:36 +09:00
|
|
|
})
|
2020-07-19 00:24:07 +09:00
|
|
|
public bannerBlurhash: string | null;
|
2019-04-07 21:50:36 +09:00
|
|
|
|
|
|
|
@Column('boolean', {
|
|
|
|
default: false,
|
|
|
|
comment: 'Whether the User is suspended.'
|
|
|
|
})
|
|
|
|
public isSuspended: boolean;
|
|
|
|
|
|
|
|
@Column('boolean', {
|
|
|
|
default: false,
|
|
|
|
comment: 'Whether the User is silenced.'
|
|
|
|
})
|
|
|
|
public isSilenced: boolean;
|
|
|
|
|
|
|
|
@Column('boolean', {
|
|
|
|
default: false,
|
|
|
|
comment: 'Whether the User is locked.'
|
|
|
|
})
|
|
|
|
public isLocked: boolean;
|
|
|
|
|
|
|
|
@Column('boolean', {
|
|
|
|
default: false,
|
|
|
|
comment: 'Whether the User is a bot.'
|
|
|
|
})
|
|
|
|
public isBot: boolean;
|
|
|
|
|
|
|
|
@Column('boolean', {
|
|
|
|
default: false,
|
|
|
|
comment: 'Whether the User is a cat.'
|
|
|
|
})
|
|
|
|
public isCat: boolean;
|
|
|
|
|
|
|
|
@Column('boolean', {
|
|
|
|
default: false,
|
|
|
|
comment: 'Whether the User is the admin.'
|
|
|
|
})
|
|
|
|
public isAdmin: boolean;
|
|
|
|
|
|
|
|
@Column('boolean', {
|
|
|
|
default: false,
|
|
|
|
comment: 'Whether the User is a moderator.'
|
|
|
|
})
|
|
|
|
public isModerator: boolean;
|
|
|
|
|
2020-12-11 21:16:20 +09:00
|
|
|
@Index()
|
|
|
|
@Column('boolean', {
|
|
|
|
default: true,
|
|
|
|
comment: 'Whether the User is explorable.'
|
|
|
|
})
|
|
|
|
public isExplorable: boolean;
|
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
@Column('varchar', {
|
|
|
|
length: 128, array: true, default: '{}'
|
|
|
|
})
|
|
|
|
public emojis: string[];
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column('varchar', {
|
|
|
|
length: 128, nullable: true,
|
|
|
|
comment: 'The host of the User. It will be null if the origin of the user is local.'
|
|
|
|
})
|
|
|
|
public host: string | null;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
2019-04-11 19:03:49 +09:00
|
|
|
length: 512, nullable: true,
|
|
|
|
comment: 'The inbox URL of the User. It will be null if the origin of the user is local.'
|
2019-04-07 21:50:36 +09:00
|
|
|
})
|
|
|
|
public inbox: string | null;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
2019-04-11 19:03:49 +09:00
|
|
|
length: 512, nullable: true,
|
|
|
|
comment: 'The sharedInbox URL of the User. It will be null if the origin of the user is local.'
|
2019-04-07 21:50:36 +09:00
|
|
|
})
|
|
|
|
public sharedInbox: string | null;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
2019-04-11 19:03:49 +09:00
|
|
|
length: 512, nullable: true,
|
|
|
|
comment: 'The featured URL of the User. It will be null if the origin of the user is local.'
|
2019-04-07 21:50:36 +09:00
|
|
|
})
|
|
|
|
public featured: string | null;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column('varchar', {
|
2019-04-11 19:03:49 +09:00
|
|
|
length: 512, nullable: true,
|
2019-04-07 21:50:36 +09:00
|
|
|
comment: 'The URI of the User. It will be null if the origin of the user is local.'
|
|
|
|
})
|
|
|
|
public uri: string | null;
|
|
|
|
|
2021-02-06 11:50:33 +09:00
|
|
|
@Column('varchar', {
|
|
|
|
length: 512, nullable: true,
|
|
|
|
comment: 'The URI of the user Follower Collection. It will be null if the origin of the user is local.'
|
|
|
|
})
|
|
|
|
public followersUri: string | null;
|
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
@Index({ unique: true })
|
2019-04-08 20:29:52 +09:00
|
|
|
@Column('char', {
|
|
|
|
length: 16, nullable: true, unique: true,
|
2019-04-07 21:50:36 +09:00
|
|
|
comment: 'The native access token of the User. It will be null if the origin of the user is local.'
|
|
|
|
})
|
|
|
|
public token: string | null;
|
2019-04-12 01:52:25 +09:00
|
|
|
|
|
|
|
constructor(data: Partial<User>) {
|
|
|
|
if (data == null) return;
|
|
|
|
|
|
|
|
for (const [k, v] of Object.entries(data)) {
|
|
|
|
(this as any)[k] = v;
|
|
|
|
}
|
|
|
|
}
|
2019-04-07 21:50:36 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ILocalUser extends User {
|
|
|
|
host: null;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IRemoteUser extends User {
|
|
|
|
host: string;
|
|
|
|
}
|