mirror of
https://github.com/versia-pub/server.git
synced 2026-01-26 12:16:01 +01:00
fix(api): 🐛 Fix duplicated mentions, general refactorings
This commit is contained in:
parent
84a0a07ea6
commit
e293bd280d
|
|
@ -143,7 +143,7 @@ describe(meta.route, () => {
|
||||||
|
|
||||||
const objects = (await response.json()) as ApiNotification[];
|
const objects = (await response.json()) as ApiNotification[];
|
||||||
|
|
||||||
expect(objects.length).toBe(2);
|
expect(objects.length).toBe(3);
|
||||||
// There should be no element with a status with id of timeline[0].id
|
// There should be no element with a status with id of timeline[0].id
|
||||||
expect(objects).not.toContainEqual(
|
expect(objects).not.toContainEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,7 @@ export default apiRoute((app) =>
|
||||||
),
|
),
|
||||||
limit,
|
limit,
|
||||||
context.req.url,
|
context.req.url,
|
||||||
user?.id,
|
user.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
return context.json(
|
return context.json(
|
||||||
|
|
|
||||||
|
|
@ -310,6 +310,9 @@ describe(meta.route, () => {
|
||||||
|
|
||||||
const object = (await response.json()) as ApiStatus;
|
const object = (await response.json()) as ApiStatus;
|
||||||
|
|
||||||
|
expect(object.content).toBe(
|
||||||
|
`<p>Hello, <a class="u-url mention" rel="nofollow noopener noreferrer" target="_blank" href="${users[1].getUri()}">@${users[1].data.username}</a>!</p>`,
|
||||||
|
);
|
||||||
expect(object.mentions).toBeArrayOfSize(1);
|
expect(object.mentions).toBeArrayOfSize(1);
|
||||||
expect(object.mentions[0]).toMatchObject({
|
expect(object.mentions[0]).toMatchObject({
|
||||||
id: users[1].id,
|
id: users[1].id,
|
||||||
|
|
|
||||||
|
|
@ -298,19 +298,16 @@ export const replaceTextMentions = (text: string, mentions: User[]): string => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return finalText
|
return finalText.replace(
|
||||||
.replace(
|
|
||||||
createRegExp(
|
createRegExp(
|
||||||
|
exactly(
|
||||||
exactly(`@${username}`)
|
exactly(`@${username}`)
|
||||||
.notBefore(anyOf(letter, digit, charIn("@")))
|
.notBefore(anyOf(letter, digit, charIn("@")))
|
||||||
.notAfter(anyOf(letter, digit, charIn("@"))),
|
.notAfter(anyOf(letter, digit, charIn("@"))),
|
||||||
|
).or(exactly(`@${username}@${baseHost}`)),
|
||||||
[global],
|
[global],
|
||||||
),
|
),
|
||||||
linkTemplate(`@${username}@${baseHost}`),
|
linkTemplate(`@${username}@${baseHost}`),
|
||||||
)
|
|
||||||
.replaceAll(
|
|
||||||
`@${username}@${baseHost}`,
|
|
||||||
linkTemplate(`@${username}@${baseHost}`),
|
|
||||||
);
|
);
|
||||||
}, text);
|
}, text);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ mock.module("@versia/kit/db", () => ({
|
||||||
},
|
},
|
||||||
Notification: {
|
Notification: {
|
||||||
fromSql: jest.fn(),
|
fromSql: jest.fn(),
|
||||||
insert: jest.fn(),
|
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
@ -242,6 +241,7 @@ describe("InboxProcessor", () => {
|
||||||
id: "followee-id",
|
id: "followee-id",
|
||||||
data: { isLocked: false },
|
data: { isLocked: false },
|
||||||
sendFollowAccept: jest.fn(),
|
sendFollowAccept: jest.fn(),
|
||||||
|
notify: jest.fn(),
|
||||||
};
|
};
|
||||||
const mockRelationship = {
|
const mockRelationship = {
|
||||||
data: { following: false },
|
data: { following: false },
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue