mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
fix(journey): the digest of a protected link names no entry
A follower keeps getting the daily mail after the owner puts a password on the link or changes it, so the mail named titles, dates and places the password was meant to guard. For a link behind a password the digest now only says there is something new and links to the journey.
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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) },
|
||||
|
||||
Reference in New Issue
Block a user