mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
Fix timeline rendering
This commit is contained in:
parent
73cb7db6b3
commit
440e994576
7 changed files with 359 additions and 20 deletions
|
|
@ -37,6 +37,33 @@ export const createNewRelationship = async (
|
|||
});
|
||||
};
|
||||
|
||||
export const checkForBidirectionalRelationships = async (
|
||||
user1: User,
|
||||
user2: User,
|
||||
createIfNotExists = true
|
||||
): Promise<boolean> => {
|
||||
const relationship1 = await client.relationship.findFirst({
|
||||
where: {
|
||||
ownerId: user1.id,
|
||||
subjectId: user2.id,
|
||||
},
|
||||
});
|
||||
|
||||
const relationship2 = await client.relationship.findFirst({
|
||||
where: {
|
||||
ownerId: user2.id,
|
||||
subjectId: user1.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!relationship1 && !relationship2 && createIfNotExists) {
|
||||
await createNewRelationship(user1, user2);
|
||||
await createNewRelationship(user2, user1);
|
||||
}
|
||||
|
||||
return !!relationship1 && !!relationship2;
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts the relationship to an API-friendly format.
|
||||
* @returns The API-friendly relationship.
|
||||
|
|
|
|||
|
|
@ -55,7 +55,9 @@ export const statusAndUserRelations: Prisma.StatusInclude = {
|
|||
},
|
||||
attachments: true,
|
||||
instance: true,
|
||||
mentions: true,
|
||||
mentions: {
|
||||
include: userRelations,
|
||||
},
|
||||
pinnedBy: true,
|
||||
_count: {
|
||||
select: {
|
||||
|
|
@ -307,12 +309,9 @@ export const createNewStatus = async (data: {
|
|||
};
|
||||
quote?: Status;
|
||||
}) => {
|
||||
// Get people mentioned in the content
|
||||
const mentionedPeople = [...data.content.matchAll(/@([a-zA-Z0-9_]+)/g)].map(
|
||||
match => {
|
||||
return `${config.http.base_url}/users/${match[1]}`;
|
||||
}
|
||||
);
|
||||
// Get people mentioned in the content (match @username or @username@domain.com mentions)
|
||||
const mentionedPeople =
|
||||
data.content.match(/@[a-zA-Z0-9_]+(@[a-zA-Z0-9_]+)?/g) ?? [];
|
||||
|
||||
let mentions = data.mentions || [];
|
||||
|
||||
|
|
@ -438,7 +437,8 @@ export const statusToAPI = async (
|
|||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
favourites_count: (status.likes ?? []).length,
|
||||
media_attachments: [],
|
||||
mentions: [],
|
||||
// @ts-expect-error Prisma TypeScript types dont include relations
|
||||
mentions: status.mentions.map(mention => userToAPI(mention)),
|
||||
language: null,
|
||||
muted: user
|
||||
? user.relationships.find(r => r.subjectId == status.authorId)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue