mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
Add fetching user statuses
This commit is contained in:
parent
416a7186d1
commit
29f63dfcb7
5 changed files with 132 additions and 47 deletions
73
database/entities/DBStatus.ts
Normal file
73
database/entities/DBStatus.ts
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
import { getConfig } from "@config";
|
||||
import {
|
||||
BaseEntity,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from "typeorm";
|
||||
import { Status } from "~types/entities/status";
|
||||
import { DBUser } from "./DBUser";
|
||||
|
||||
const config = getConfig();
|
||||
|
||||
@Entity({
|
||||
name: "statuses",
|
||||
})
|
||||
export class DBStatus extends BaseEntity {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id!: string;
|
||||
|
||||
@ManyToOne(() => DBUser, (user) => user.id)
|
||||
account!: DBUser;
|
||||
|
||||
@CreateDateColumn()
|
||||
created_at!: Date;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updated_at!: Date;
|
||||
|
||||
@ManyToOne(() => DBStatus, (status) => status.id, {
|
||||
nullable: true,
|
||||
})
|
||||
reblog?: DBStatus;
|
||||
|
||||
@Column("boolean")
|
||||
isReblog!: boolean;
|
||||
|
||||
toAPI(): Status {
|
||||
return {
|
||||
account: this.account.toAPI(),
|
||||
application: null,
|
||||
bookmarked: false,
|
||||
created_at: this.created_at.toISOString(),
|
||||
emojis: [],
|
||||
favourited: false,
|
||||
favourites_count: 0,
|
||||
id: this.id,
|
||||
in_reply_to_account_id: null,
|
||||
in_reply_to_id: null,
|
||||
language: null,
|
||||
media_attachments: [],
|
||||
mentions: [],
|
||||
muted: false,
|
||||
pinned: false,
|
||||
poll: null,
|
||||
reblog: this.isReblog ? this.reblog?.toAPI() ?? null : null,
|
||||
reblogged: false,
|
||||
reblogs_count: 0,
|
||||
replies_count: 0,
|
||||
sensitive: false,
|
||||
spoiler_text: "",
|
||||
tags: [],
|
||||
card: null,
|
||||
content: "",
|
||||
uri: `${config.http.base_url}/@${this.account.username}/${this.id}`,
|
||||
url: `${config.http.base_url}/@${this.account.username}/${this.id}`,
|
||||
visibility: "public",
|
||||
quote: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ const config = getConfig();
|
|||
@Entity({
|
||||
name: "users",
|
||||
})
|
||||
export class User extends BaseEntity {
|
||||
export class DBUser extends BaseEntity {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id!: string;
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ export class User extends BaseEntity {
|
|||
@UpdateDateColumn()
|
||||
updated_at!: Date;
|
||||
|
||||
toAccount(): Account {
|
||||
toAPI(): Account {
|
||||
return {
|
||||
acct: `@${this.username}@${getHost()}`,
|
||||
avatar: "",
|
||||
Loading…
Add table
Add a link
Reference in a new issue