2024-09-30 12:14:00 -04:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
2024-09-29 21:27:38 -04:00
|
|
|
import { PrimaryColumn, Entity, JoinColumn, Column, ManyToOne } from 'typeorm';
|
|
|
|
|
import { MiUser } from '@/models/User.js';
|
|
|
|
|
import { MiNote } from '@/models/Note.js';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Maps a user to the most recent post by that user.
|
|
|
|
|
* Public, home-only, and followers-only posts are included.
|
|
|
|
|
* DMs are not counted.
|
|
|
|
|
*/
|
|
|
|
|
@Entity('latest_note')
|
2024-10-08 16:37:44 -04:00
|
|
|
export class SkLatestNote {
|
2024-09-29 21:27:38 -04:00
|
|
|
@PrimaryColumn({
|
|
|
|
|
name: 'user_id',
|
|
|
|
|
type: 'varchar' as const,
|
|
|
|
|
length: 32,
|
|
|
|
|
})
|
|
|
|
|
public userId: string;
|
|
|
|
|
|
|
|
|
|
@ManyToOne(() => MiUser, {
|
|
|
|
|
onDelete: 'CASCADE',
|
|
|
|
|
})
|
2024-09-29 22:51:24 -04:00
|
|
|
@JoinColumn({
|
|
|
|
|
name: 'user_id',
|
|
|
|
|
})
|
2024-09-29 21:27:38 -04:00
|
|
|
public user: MiUser | null;
|
|
|
|
|
|
|
|
|
|
@Column({
|
|
|
|
|
name: 'note_id',
|
|
|
|
|
type: 'varchar' as const,
|
|
|
|
|
length: 32,
|
|
|
|
|
})
|
|
|
|
|
public noteId: string;
|
|
|
|
|
|
|
|
|
|
@ManyToOne(() => MiNote, {
|
|
|
|
|
onDelete: 'CASCADE',
|
|
|
|
|
})
|
2024-09-29 22:51:24 -04:00
|
|
|
@JoinColumn({
|
|
|
|
|
name: 'note_id',
|
|
|
|
|
})
|
2024-09-29 21:27:38 -04:00
|
|
|
public note: MiNote | null;
|
2024-09-29 21:52:57 -04:00
|
|
|
|
2024-10-08 16:37:44 -04:00
|
|
|
constructor(data?: Partial<SkLatestNote>) {
|
2024-09-29 23:22:58 -04:00
|
|
|
if (!data) return;
|
|
|
|
|
|
2024-09-29 21:52:57 -04:00
|
|
|
for (const [k, v] of Object.entries(data)) {
|
2024-09-29 22:50:39 -04:00
|
|
|
(this as Record<string, unknown>)[k] = v;
|
2024-09-29 21:52:57 -04:00
|
|
|
}
|
|
|
|
|
}
|
2024-09-29 21:27:38 -04:00
|
|
|
}
|