summary refs log tree commit diff
path: root/src/util/entities/ReadState.ts
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-22 22:18:59 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-22 22:18:59 +1000
commit0cd9a46eea260c299db2e2983f7214ab8b119d29 (patch)
tree5fbb98e7adcfeab81594732089474afdde5893f9 /src/util/entities/ReadState.ts
parentMerge branch 'master' into feat/captchaVerify (diff)
parentMerge remote-tracking branch 'Puyodead1/patch/prettier-config' into staging (diff)
downloadserver-0cd9a46eea260c299db2e2983f7214ab8b119d29.tar.xz
Merge remote-tracking branch 'upstream/staging' into feat/captchaVerify
Diffstat (limited to 'src/util/entities/ReadState.ts')
-rw-r--r--src/util/entities/ReadState.ts55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/util/entities/ReadState.ts b/src/util/entities/ReadState.ts
new file mode 100644

index 00000000..b915573b --- /dev/null +++ b/src/util/entities/ReadState.ts
@@ -0,0 +1,55 @@ +import { Column, Entity, Index, JoinColumn, ManyToOne, RelationId } from "typeorm"; +import { BaseClass } from "./BaseClass"; +import { Channel } from "./Channel"; +import { Message } from "./Message"; +import { User } from "./User"; + +// for read receipts +// notification cursor and public read receipt need to be forwards-only (the former to prevent re-pinging when marked as unread, and the latter to be acceptable as a legal acknowledgement in criminal proceedings), and private read marker needs to be advance-rewind capable +// public read receipt ≥ notification cursor ≥ private fully read marker + +@Entity("read_states") +@Index(["channel_id", "user_id"], { unique: true }) +export class ReadState extends BaseClass { + @Column() + @RelationId((read_state: ReadState) => read_state.channel) + channel_id: string; + + @JoinColumn({ name: "channel_id" }) + @ManyToOne(() => Channel, { + onDelete: "CASCADE", + }) + channel: Channel; + + @Column() + @RelationId((read_state: ReadState) => read_state.user) + user_id: string; + + @JoinColumn({ name: "user_id" }) + @ManyToOne(() => User, { + onDelete: "CASCADE", + }) + user: User; + + // fully read marker + @Column({ nullable: true }) + last_message_id: string; + + // public read receipt + @Column({ nullable: true }) + public_ack: string; + + // notification cursor / private read receipt + @Column({ nullable: true }) + notifications_cursor: string; + + @Column({ nullable: true }) + last_pin_timestamp?: Date; + + @Column({ nullable: true }) + mention_count: number; + + // @Column({ nullable: true }) + // TODO: derive this from (last_message_id=notifications_cursor=public_ack)=true + manual: boolean; +}