Fix timeline rendering

This commit is contained in:
Jesse Wierzbinski 2023-11-28 12:57:48 -10:00
parent 73cb7db6b3
commit 440e994576
No known key found for this signature in database
7 changed files with 359 additions and 20 deletions

View file

@ -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.

View file

@ -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)