summaryrefslogtreecommitdiff
path: root/src/models/entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/models/entities')
-rw-r--r--src/models/entities/messaging-message.ts24
-rw-r--r--src/models/entities/user-group-joining.ts41
-rw-r--r--src/models/entities/user-group.ts46
3 files changed, 109 insertions, 2 deletions
diff --git a/src/models/entities/messaging-message.ts b/src/models/entities/messaging-message.ts
index d3c3eab3a2..c18897a37d 100644
--- a/src/models/entities/messaging-message.ts
+++ b/src/models/entities/messaging-message.ts
@@ -2,6 +2,7 @@ import { PrimaryColumn, Entity, Index, JoinColumn, Column, ManyToOne } from 'typ
import { User } from './user';
import { DriveFile } from './drive-file';
import { id } from '../id';
+import { UserGroup } from './user-group';
@Entity()
export class MessagingMessage {
@@ -29,10 +30,10 @@ export class MessagingMessage {
@Index()
@Column({
- ...id(),
+ ...id(), nullable: true,
comment: 'The recipient user ID.'
})
- public recipientId: User['id'];
+ public recipientId: User['id'] | null;
@ManyToOne(type => User, {
onDelete: 'CASCADE'
@@ -40,6 +41,19 @@ export class MessagingMessage {
@JoinColumn()
public recipient: User | null;
+ @Index()
+ @Column({
+ ...id(), nullable: true,
+ comment: 'The recipient group ID.'
+ })
+ public groupId: UserGroup['id'] | null;
+
+ @ManyToOne(type => UserGroup, {
+ onDelete: 'CASCADE'
+ })
+ @JoinColumn()
+ public group: UserGroup | null;
+
@Column('varchar', {
length: 4096, nullable: true
})
@@ -52,6 +66,12 @@ export class MessagingMessage {
@Column({
...id(),
+ array: true, default: '{}'
+ })
+ public reads: User['id'][];
+
+ @Column({
+ ...id(),
nullable: true,
})
public fileId: DriveFile['id'] | null;
diff --git a/src/models/entities/user-group-joining.ts b/src/models/entities/user-group-joining.ts
new file mode 100644
index 0000000000..17b534f42f
--- /dev/null
+++ b/src/models/entities/user-group-joining.ts
@@ -0,0 +1,41 @@
+import { PrimaryColumn, Entity, Index, JoinColumn, Column, ManyToOne } from 'typeorm';
+import { User } from './user';
+import { UserGroup } from './user-group';
+import { id } from '../id';
+
+@Entity()
+export class UserGroupJoining {
+ @PrimaryColumn(id())
+ public id: string;
+
+ @Column('timestamp with time zone', {
+ comment: 'The created date of the UserGroupJoining.'
+ })
+ public createdAt: Date;
+
+ @Index()
+ @Column({
+ ...id(),
+ comment: 'The user ID.'
+ })
+ public userId: User['id'];
+
+ @ManyToOne(type => User, {
+ onDelete: 'CASCADE'
+ })
+ @JoinColumn()
+ public user: User | null;
+
+ @Index()
+ @Column({
+ ...id(),
+ comment: 'The group ID.'
+ })
+ public userGroupId: UserGroup['id'];
+
+ @ManyToOne(type => UserGroup, {
+ onDelete: 'CASCADE'
+ })
+ @JoinColumn()
+ public userGroup: UserGroup | null;
+}
diff --git a/src/models/entities/user-group.ts b/src/models/entities/user-group.ts
new file mode 100644
index 0000000000..f4bac03223
--- /dev/null
+++ b/src/models/entities/user-group.ts
@@ -0,0 +1,46 @@
+import { Entity, Index, JoinColumn, Column, PrimaryColumn, ManyToOne } from 'typeorm';
+import { User } from './user';
+import { id } from '../id';
+
+@Entity()
+export class UserGroup {
+ @PrimaryColumn(id())
+ public id: string;
+
+ @Index()
+ @Column('timestamp with time zone', {
+ comment: 'The created date of the UserGroup.'
+ })
+ public createdAt: Date;
+
+ @Column('varchar', {
+ length: 256,
+ })
+ public name: string;
+
+ @Index()
+ @Column({
+ ...id(),
+ comment: 'The ID of owner.'
+ })
+ public userId: User['id'];
+
+ @ManyToOne(type => User, {
+ onDelete: 'CASCADE'
+ })
+ @JoinColumn()
+ public user: User | null;
+
+ @Column('boolean', {
+ default: false,
+ })
+ public isPrivate: boolean;
+
+ constructor(data: Partial<UserGroup>) {
+ if (data == null) return;
+
+ for (const [k, v] of Object.entries(data)) {
+ (this as any)[k] = v;
+ }
+ }
+}