mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
Add status pinning and unpinning, fix bugs
This commit is contained in:
parent
0a74bbfe93
commit
f51476e810
14 changed files with 322 additions and 116 deletions
|
|
@ -11,14 +11,13 @@ import { client } from "~database/datasource";
|
|||
import type { LysandPublication, Note } from "~types/lysand/Object";
|
||||
import { htmlToText } from "html-to-text";
|
||||
import { getBestContentType } from "@content_types";
|
||||
import type {
|
||||
Application,
|
||||
Emoji,
|
||||
Instance,
|
||||
Like,
|
||||
Relationship,
|
||||
Status,
|
||||
User,
|
||||
import {
|
||||
Prisma,
|
||||
type Application,
|
||||
type Emoji,
|
||||
type Relationship,
|
||||
type Status,
|
||||
type User,
|
||||
} from "@prisma/client";
|
||||
import { emojiToAPI, emojiToLysand, parseEmojis } from "./Emoji";
|
||||
import type { APIStatus } from "~types/entities/status";
|
||||
|
|
@ -26,7 +25,7 @@ import { applicationToAPI } from "./Application";
|
|||
|
||||
const config = getConfig();
|
||||
|
||||
export const statusAndUserRelations = {
|
||||
export const statusAndUserRelations: Prisma.StatusInclude = {
|
||||
author: {
|
||||
include: userRelations,
|
||||
},
|
||||
|
|
@ -54,6 +53,7 @@ export const statusAndUserRelations = {
|
|||
},
|
||||
},
|
||||
},
|
||||
attachments: true,
|
||||
instance: true,
|
||||
mentions: true,
|
||||
pinnedBy: true,
|
||||
|
|
@ -115,64 +115,13 @@ export const statusAndUserRelations = {
|
|||
},
|
||||
};
|
||||
|
||||
export type StatusWithRelations = Status & {
|
||||
author: UserWithRelations;
|
||||
application: Application | null;
|
||||
emojis: Emoji[];
|
||||
inReplyToPost:
|
||||
| (Status & {
|
||||
author: UserWithRelations;
|
||||
application: Application | null;
|
||||
emojis: Emoji[];
|
||||
inReplyToPost: Status | null;
|
||||
instance: Instance | null;
|
||||
mentions: User[];
|
||||
pinnedBy: User[];
|
||||
_count: {
|
||||
replies: number;
|
||||
};
|
||||
})
|
||||
| null;
|
||||
instance: Instance | null;
|
||||
mentions: User[];
|
||||
pinnedBy: User[];
|
||||
_count: {
|
||||
replies: number;
|
||||
likes: number;
|
||||
reblogs: number;
|
||||
};
|
||||
reblog:
|
||||
| (Status & {
|
||||
author: UserWithRelations;
|
||||
application: Application | null;
|
||||
emojis: Emoji[];
|
||||
inReplyToPost: Status | null;
|
||||
instance: Instance | null;
|
||||
mentions: User[];
|
||||
pinnedBy: User[];
|
||||
_count: {
|
||||
replies: number;
|
||||
};
|
||||
})
|
||||
| null;
|
||||
quotingPost:
|
||||
| (Status & {
|
||||
author: UserWithRelations;
|
||||
application: Application | null;
|
||||
emojis: Emoji[];
|
||||
inReplyToPost: Status | null;
|
||||
instance: Instance | null;
|
||||
mentions: User[];
|
||||
pinnedBy: User[];
|
||||
_count: {
|
||||
replies: number;
|
||||
};
|
||||
})
|
||||
| null;
|
||||
likes: (Like & {
|
||||
liker: User;
|
||||
})[];
|
||||
};
|
||||
const statusRelations = Prisma.validator<Prisma.StatusDefaultArgs>()({
|
||||
include: statusAndUserRelations,
|
||||
});
|
||||
|
||||
export type StatusWithRelations = Prisma.StatusGetPayload<
|
||||
typeof statusRelations
|
||||
>;
|
||||
|
||||
/**
|
||||
* Represents a status (i.e. a post)
|
||||
|
|
@ -494,7 +443,7 @@ export const statusToAPI = async (
|
|||
? user.relationships.find(r => r.subjectId == status.authorId)
|
||||
?.muting || false
|
||||
: false,
|
||||
pinned: status.author.pinnedNotes.some(note => note.id === status.id),
|
||||
pinned: status.pinnedBy.find(u => u.id === user?.id) ? true : false,
|
||||
// TODO: Add pols
|
||||
poll: null,
|
||||
reblog: status.reblog
|
||||
|
|
|
|||
|
|
@ -3,14 +3,8 @@ import { getConfig } from "@config";
|
|||
import type { APIAccount } from "~types/entities/account";
|
||||
import type { User as LysandUser } from "~types/lysand/Object";
|
||||
import { htmlToText } from "html-to-text";
|
||||
import type {
|
||||
Emoji,
|
||||
Instance,
|
||||
Like,
|
||||
Relationship,
|
||||
Status,
|
||||
User,
|
||||
} from "@prisma/client";
|
||||
import type { User } from "@prisma/client";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { client } from "~database/datasource";
|
||||
import { addEmojiIfNotExists, emojiToAPI, emojiToLysand } from "./Emoji";
|
||||
import { addInstanceIfNotExists } from "./Instance";
|
||||
|
|
@ -26,7 +20,7 @@ export interface AuthData {
|
|||
* Stores local and remote users
|
||||
*/
|
||||
|
||||
export const userRelations = {
|
||||
export const userRelations: Prisma.UserInclude = {
|
||||
emojis: true,
|
||||
instance: true,
|
||||
likes: true,
|
||||
|
|
@ -41,18 +35,11 @@ export const userRelations = {
|
|||
},
|
||||
};
|
||||
|
||||
export type UserWithRelations = User & {
|
||||
emojis: Emoji[];
|
||||
instance: Instance | null;
|
||||
likes: Like[];
|
||||
relationships: Relationship[];
|
||||
relationshipSubjects: Relationship[];
|
||||
pinnedNotes: Status[];
|
||||
_count: {
|
||||
statuses: number;
|
||||
likes: number;
|
||||
};
|
||||
};
|
||||
const userRelations2 = Prisma.validator<Prisma.UserDefaultArgs>()({
|
||||
include: userRelations,
|
||||
});
|
||||
|
||||
export type UserWithRelations = Prisma.UserGetPayload<typeof userRelations2>;
|
||||
|
||||
/**
|
||||
* Get the user's avatar in raw URL format
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue