diff --git a/server/src/nest/journey/journey-digest.service.ts b/server/src/nest/journey/journey-digest.service.ts index 93004eb75..7e900f38a 100644 --- a/server/src/nest/journey/journey-digest.service.ts +++ b/server/src/nest/journey/journey-digest.service.ts @@ -49,7 +49,8 @@ function message(err: unknown): string { * - every confirmed follower of its share link gets one mail naming them, when * the link allows following, still works, shows its timeline or its map, * and the instance can send mail; each at most once a day, in the language - * they chose, with the link that stops the mails; + * they chose, with the link that stops the mails (a link behind a password + * only says that there is something new, without naming the entries); * - and the entries are marked as told, so no digest names one twice, also * when it goes back to a draft and comes out again. * @@ -138,9 +139,13 @@ export class JourneyDigestService { if (!link || !link.allow_subscriptions || shareLinkExpired(link.expires_at, now)) return 0; if (!link.share_timeline && !link.share_map) return 0; const due = await this.subscribersRepo.listDue(link.id, dbNow(new Date(now.getTime() - DIGEST_MIN_GAP_MS))); + // A link behind a password names no entry in a mail: a follower keeps the + // mails after the owner changed the password, and a mail is no place for + // what the password guards. They only hear that there is something new. + const named = link.password_hash ? [] : entries; const mailed: number[] = []; for (const follower of due) { - const mail = digestMail(follower.locale, title, entries, { + const mail = digestMail(follower.locale, title, named, { link: link.token, unsubscribe: follower.unsubscribe_token, }); diff --git a/server/src/nest/journey/journey-subscription-mail.ts b/server/src/nest/journey/journey-subscription-mail.ts index b2d88b642..cda74a150 100644 --- a/server/src/nest/journey/journey-subscription-mail.ts +++ b/server/src/nest/journey/journey-subscription-mail.ts @@ -67,7 +67,16 @@ export function digestLine(entry: DigestEntry): string { return detail ? `• ${title} (${detail})` : `• ${title}`; } -/** The daily mail naming what was published on the link since the last one. */ +/** The intro without the colon that leads into a list, for a digest that names no entry. */ +function withoutTrailingColon(text: string): string { + const trimmed = text.trimEnd(); + return trimmed.endsWith(':') || trimmed.endsWith(':') ? trimmed.slice(0, -1).trimEnd() : trimmed; +} + +/** + * The daily mail naming what was published on the link since the last one. + * Given no entries (a link behind a password), it only says there is something new. + */ export function digestMail( lang: string, journey: string, @@ -77,9 +86,10 @@ export function digestMail( const s = stringsFor(lang); const shown = entries.slice(0, DIGEST_MAX_ENTRIES).map(digestLine); const more = entries.length > DIGEST_MAX_ENTRIES ? ['…'] : []; + const intro = withJourney(s.digestIntro, journey); return { subject: withJourney(s.digestSubject, journey), - body: [withJourney(s.digestIntro, journey), '', ...shown, ...more].join('\n'), + body: shown.length > 0 ? [intro, '', ...shown, ...more].join('\n') : withoutTrailingColon(intro), lang, cta: { label: s.digestCta, href: publicJourneyUrl(tokens.link) }, footer: { text: s.footer, linkLabel: s.unsubscribe, href: unsubscribeUrl(tokens.unsubscribe) }, diff --git a/server/tests/e2e/journey-social.e2e.test.ts b/server/tests/e2e/journey-social.e2e.test.ts index 617760598..383d0804d 100644 --- a/server/tests/e2e/journey-social.e2e.test.ts +++ b/server/tests/e2e/journey-social.e2e.test.ts @@ -438,4 +438,26 @@ describe('the daily digest', () => { expect(await digest.run(new Date())).toMatchObject({ journeys: 0, mailed: 0 }); expect(send).not.toHaveBeenCalled(); }); + + it('JSOCIAL-E2E-031: a follower of a link that got a password hears of something new, never what', async () => { + const send = mailWorks(); + const { owner, journey } = await journeyWithPeople(); + const token = await share(journey.id, owner.id, { allow_subscriptions: true }); + await request(server).post(`/api/public/journey/${token}/subscribe`).send({ email: 'locked-out@example.com' }); + const follower = must(await findRow(orm, JourneyShareSubscribers, { email: 'locked-out@example.com' })); + await request(server).post('/api/public/journey-subscriptions/confirm').send({ token: follower.confirm_token }); + await share(journey.id, owner.id, { password: 'a new secret' }); + send.mockClear(); + + await makeJourneyEntry(orm, journey.id, owner.id, { title: 'Behind the password', location_name: 'Furnas' }); + await app.get(JourneyDigestService, { strict: false }).run(new Date()); + await notifications.settled(); + + const mails = send.mock.calls.filter(([to]) => to === 'locked-out@example.com'); + expect(mails).toHaveLength(1); + const [, mail] = must(mails[0]); + expect(mail.body).not.toContain('Behind the password'); + expect(mail.body).not.toContain('Furnas'); + expect(mail.cta.href).toContain(`/public/journey/${token}`); + }); }); diff --git a/server/tests/unit/nest/journey/journey-social.helpers.test.ts b/server/tests/unit/nest/journey/journey-social.helpers.test.ts index 72017c1fd..be1eaf518 100644 --- a/server/tests/unit/nest/journey/journey-social.helpers.test.ts +++ b/server/tests/unit/nest/journey/journey-social.helpers.test.ts @@ -114,6 +114,13 @@ describe('the mails of a follower', () => { ); }); + it('JSOCIAL-HELP-014: a digest without entries only says there is something new, without a dangling colon', () => { + const en = digestMail('en', 'Azores', [], { link: 'tok', unsubscribe: 'u' }); + expect(en.body).toBe('There is something new to read in "Azores"'); + expect(en.cta.href).toMatch(/\/public\/journey\/tok$/); + expect(digestMail('ja', 'Azores', [], { link: 'tok', unsubscribe: 'u' }).body).not.toMatch(/[::]$/); + }); + it('JSOCIAL-HELP-012: a follower language is one the app ships, else English', () => { expect(subscriberLocale('fr')).toBe('fr'); expect(subscriberLocale('klingon')).toBe('en');