mirror of
https://github.com/versia-pub/server.git
synced 2025-12-07 16:58:20 +01:00
Few bugfixes
This commit is contained in:
parent
35438860c2
commit
1c8847ac6d
|
|
@ -236,6 +236,32 @@ export const parseTextMentions = async (text: string) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const replaceTextMentions = async (
|
||||||
|
text: string,
|
||||||
|
mentions: UserWithRelations[],
|
||||||
|
) => {
|
||||||
|
let finalText = text;
|
||||||
|
for (const mention of mentions) {
|
||||||
|
// Replace @username and @username@domain
|
||||||
|
if (mention.instanceId) {
|
||||||
|
finalText = finalText.replace(
|
||||||
|
new RegExp(
|
||||||
|
`@${mention.username}@${mention.instance?.base_url}`,
|
||||||
|
"g",
|
||||||
|
),
|
||||||
|
`<a class="u-url mention" rel="nofollow noopener noreferrer" target="_blank" href="${mention.uri}">@${mention.username}@${mention.instance?.base_url}</a>`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
finalText = finalText.replace(
|
||||||
|
new RegExp(`@${mention.username}`, "g"),
|
||||||
|
`<a class="u-url mention" rel="nofollow noopener noreferrer" target="_blank" href="${mention.uri}">@${mention.username}</a>`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return finalText;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new status and saves it to the database.
|
* Creates a new status and saves it to the database.
|
||||||
* @returns A promise that resolves with the new status.
|
* @returns A promise that resolves with the new status.
|
||||||
|
|
@ -274,6 +300,9 @@ export const createNewStatus = async (
|
||||||
htmlContent = "";
|
htmlContent = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replace mentions text
|
||||||
|
htmlContent = await replaceTextMentions(htmlContent, mentions ?? []);
|
||||||
|
|
||||||
// Parse emojis and fuse with existing emojis
|
// Parse emojis and fuse with existing emojis
|
||||||
let foundEmojis = emojis;
|
let foundEmojis = emojis;
|
||||||
|
|
||||||
|
|
@ -298,7 +327,6 @@ export const createNewStatus = async (
|
||||||
visibility: visibility,
|
visibility: visibility,
|
||||||
sensitive: is_sensitive,
|
sensitive: is_sensitive,
|
||||||
spoilerText: spoiler_text,
|
spoilerText: spoiler_text,
|
||||||
isReblog: false, // DEPRECATED FIELD
|
|
||||||
emojis: {
|
emojis: {
|
||||||
connect: foundEmojis.map((emoji) => {
|
connect: foundEmojis.map((emoji) => {
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ export default apiRoute<{
|
||||||
{
|
{
|
||||||
where: {
|
where: {
|
||||||
authorId: id,
|
authorId: id,
|
||||||
isReblog: false,
|
reblogId: null,
|
||||||
pinnedBy: {
|
pinnedBy: {
|
||||||
some: {
|
some: {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
|
|
@ -104,7 +104,7 @@ export default apiRoute<{
|
||||||
{
|
{
|
||||||
where: {
|
where: {
|
||||||
authorId: id,
|
authorId: id,
|
||||||
isReblog: exclude_reblogs ? true : undefined,
|
reblogId: exclude_reblogs ? null : undefined,
|
||||||
id: {
|
id: {
|
||||||
lt: max_id,
|
lt: max_id,
|
||||||
gt: min_id,
|
gt: min_id,
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ export default apiRoute<{
|
||||||
visibility: "public" | "unlisted" | "private";
|
visibility: "public" | "unlisted" | "private";
|
||||||
}>(async (req, matchedRoute, extraData) => {
|
}>(async (req, matchedRoute, extraData) => {
|
||||||
const id = matchedRoute.params.id;
|
const id = matchedRoute.params.id;
|
||||||
const config = await extraData.configManager.getConfig();
|
|
||||||
|
|
||||||
const { user } = extraData.auth;
|
const { user } = extraData.auth;
|
||||||
|
|
||||||
|
|
@ -56,30 +55,14 @@ export default apiRoute<{
|
||||||
data: {
|
data: {
|
||||||
authorId: user.id,
|
authorId: user.id,
|
||||||
reblogId: status.id,
|
reblogId: status.id,
|
||||||
isReblog: true,
|
|
||||||
uri: new URL(
|
|
||||||
`/statuses/FAKE-${crypto.randomUUID()}`,
|
|
||||||
config.http.base_url,
|
|
||||||
).toString(),
|
|
||||||
visibility,
|
visibility,
|
||||||
sensitive: false,
|
sensitive: false,
|
||||||
},
|
},
|
||||||
include: statusAndUserRelations,
|
include: statusAndUserRelations,
|
||||||
});
|
});
|
||||||
|
|
||||||
await client.status.update({
|
|
||||||
where: { id: newReblog.id },
|
|
||||||
data: {
|
|
||||||
uri: new URL(
|
|
||||||
`/statuses/${newReblog.id}`,
|
|
||||||
config.http.base_url,
|
|
||||||
).toString(),
|
|
||||||
},
|
|
||||||
include: statusAndUserRelations,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create notification for reblog if reblogged user is on the same instance
|
// Create notification for reblog if reblogged user is on the same instance
|
||||||
if ((status.author as UserWithRelations).instanceId === user.instanceId) {
|
if (status.author.instanceId === user.instanceId) {
|
||||||
await client.notification.create({
|
await client.notification.create({
|
||||||
data: {
|
data: {
|
||||||
accountId: user.id,
|
accountId: user.id,
|
||||||
|
|
@ -90,16 +73,5 @@ export default apiRoute<{
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonResponse(
|
return jsonResponse(await statusToAPI(newReblog, user));
|
||||||
await statusToAPI(
|
|
||||||
{
|
|
||||||
...newReblog,
|
|
||||||
uri: new URL(
|
|
||||||
`/statuses/${newReblog.id}`,
|
|
||||||
config.http.base_url,
|
|
||||||
).toString(),
|
|
||||||
},
|
|
||||||
user,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import type { StatusWithRelations } from "~database/entities/Status";
|
||||||
import {
|
import {
|
||||||
createNewStatus,
|
createNewStatus,
|
||||||
federateStatus,
|
federateStatus,
|
||||||
|
parseTextMentions,
|
||||||
statusToAPI,
|
statusToAPI,
|
||||||
} from "~database/entities/Status";
|
} from "~database/entities/Status";
|
||||||
import type { UserWithRelations } from "~database/entities/User";
|
import type { UserWithRelations } from "~database/entities/User";
|
||||||
|
|
@ -169,7 +170,6 @@ export default apiRoute<{
|
||||||
|
|
||||||
// Get reply account and status if exists
|
// Get reply account and status if exists
|
||||||
let replyStatus: StatusWithRelations | null = null;
|
let replyStatus: StatusWithRelations | null = null;
|
||||||
let replyUser: UserWithRelations | null = null;
|
|
||||||
let quote: StatusWithRelations | null = null;
|
let quote: StatusWithRelations | null = null;
|
||||||
|
|
||||||
if (in_reply_to_id) {
|
if (in_reply_to_id) {
|
||||||
|
|
@ -181,9 +181,6 @@ export default apiRoute<{
|
||||||
if (!replyStatus) {
|
if (!replyStatus) {
|
||||||
return errorResponse("Reply status not found", 404);
|
return errorResponse("Reply status not found", 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-expect-error Prisma Typescript doesn't include relations
|
|
||||||
replyUser = replyStatus.author;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quote_id) {
|
if (quote_id) {
|
||||||
|
|
@ -216,14 +213,13 @@ export default apiRoute<{
|
||||||
return errorResponse("Invalid media IDs", 422);
|
return errorResponse("Invalid media IDs", 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mentions = await parseTextMentions(sanitizedStatus);
|
||||||
|
|
||||||
const newStatus = await createNewStatus(
|
const newStatus = await createNewStatus(
|
||||||
user,
|
user,
|
||||||
{
|
{
|
||||||
"text/html": {
|
|
||||||
content: sanitizedStatus,
|
|
||||||
},
|
|
||||||
[content_type ?? "text/plain"]: {
|
[content_type ?? "text/plain"]: {
|
||||||
content: status ?? "",
|
content: sanitizedStatus ?? "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
visibility as APIStatus["visibility"],
|
visibility as APIStatus["visibility"],
|
||||||
|
|
@ -231,7 +227,7 @@ export default apiRoute<{
|
||||||
spoiler_text ?? "",
|
spoiler_text ?? "",
|
||||||
[],
|
[],
|
||||||
undefined,
|
undefined,
|
||||||
[],
|
mentions,
|
||||||
media_ids,
|
media_ids,
|
||||||
replyStatus ?? undefined,
|
replyStatus ?? undefined,
|
||||||
quote ?? undefined,
|
quote ?? undefined,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue