fix: retirer la mention initiale des commentaires importés
This commit is contained in:
@@ -87,6 +87,21 @@ describe('importBokanteComments', () => {
|
|||||||
expect(result.imported).toBe(1);
|
expect(result.imported).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('retire la mention initiale du compte cité (déjà visible via l\'auteur)', async () => {
|
||||||
|
bokanteMastodon.getStatusContext = vi.fn(async () => ({
|
||||||
|
descendants: [buildStatus({content: '<p><span class="h-card"><a href="x">@<span>pawol_nu</span></a></span> Trè bèl !</p>'})]
|
||||||
|
}));
|
||||||
|
const paroles = [{id: 7, documentId: 'doc-7', slug: 'mon-titre', bokanteStatusId: '112233'}];
|
||||||
|
const strapi = buildStrapi({paroles});
|
||||||
|
|
||||||
|
await importBokanteComments({strapi});
|
||||||
|
|
||||||
|
expect(strapi.documents('api::commentaire.commentaire').create).toHaveBeenCalledWith({
|
||||||
|
status: 'published',
|
||||||
|
data: expect.objectContaining({contenu: 'Trè bèl !'})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('n\'importe pas un commentaire déjà présent (déduplication par remoteId)', async () => {
|
it('n\'importe pas un commentaire déjà présent (déduplication par remoteId)', async () => {
|
||||||
bokanteMastodon.getStatusContext = vi.fn(async () => ({descendants: [buildStatus({id: 'deja-la'})]}));
|
bokanteMastodon.getStatusContext = vi.fn(async () => ({descendants: [buildStatus({id: 'deja-la'})]}));
|
||||||
const paroles = [{id: 7, documentId: 'doc-7', slug: 'mon-titre', bokanteStatusId: '112233'}];
|
const paroles = [{id: 7, documentId: 'doc-7', slug: 'mon-titre', bokanteStatusId: '112233'}];
|
||||||
|
|||||||
@@ -6,6 +6,12 @@ function stripHtml(html) {
|
|||||||
return (html || '').replace(/<[^>]*>/g, '').trim();
|
return (html || '').replace(/<[^>]*>/g, '').trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mastodon préfixe toujours une réponse par la mention du compte cité,
|
||||||
|
// déjà visible via l'avatar/le nom : redondant à l'affichage.
|
||||||
|
function stripMentionsInisyal(texte) {
|
||||||
|
return texte.replace(/^(@\S+\s*)+/, '').trim();
|
||||||
|
}
|
||||||
|
|
||||||
async function importBokanteComments({strapi}) {
|
async function importBokanteComments({strapi}) {
|
||||||
const paroles = await strapi.db.query('api::parole.parole').findMany({
|
const paroles = await strapi.db.query('api::parole.parole').findMany({
|
||||||
where: {bokanteStatusId: {$notNull: true}}
|
where: {bokanteStatusId: {$notNull: true}}
|
||||||
@@ -39,7 +45,7 @@ async function importBokanteComments({strapi}) {
|
|||||||
const commentaire = await strapi.documents('api::commentaire.commentaire').create({
|
const commentaire = await strapi.documents('api::commentaire.commentaire').create({
|
||||||
status: 'published',
|
status: 'published',
|
||||||
data: {
|
data: {
|
||||||
contenu: stripHtml(status.content),
|
contenu: stripMentionsInisyal(stripHtml(status.content)),
|
||||||
datePublication: status.created_at,
|
datePublication: status.created_at,
|
||||||
origine: 'activitypub',
|
origine: 'activitypub',
|
||||||
auteurNom: status.account?.display_name,
|
auteurNom: status.account?.display_name,
|
||||||
|
|||||||
Reference in New Issue
Block a user