import { ASSETS, getAssetPath } from "../assetUtils"; import { clipCommunityInviteDescription, communityInviteInitials, communityPossessive, inviteRuleCountsLabel, } from "../create/ruleInviteCardMeta"; export const RULE_STAKEHOLDER_INVITE_LOGO_PATH = getAssetPath(ASSETS.LOGO_MARK); const PREVIEW_TEXT = "It covers how they talk, who belongs, how they decide and what happens when they disagree."; function escapeHtml(value: string): string { return value .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """); } export function ruleStakeholderInviteCopyUrl(verifyUrl: string): string { return `${verifyUrl}${verifyUrl.includes("?") ? "&" : "?"}copy=1`; } export type RuleStakeholderInviteMailInput = { to: string; verifyUrl: string; origin: string; communityName: string; inviterEmail: string; summary?: string | null; document?: unknown; }; export type RuleStakeholderInviteMailContent = { subject: string; previewText: string; text: string; html: string; }; export function buildRuleStakeholderInviteMail( input: RuleStakeholderInviteMailInput, ): RuleStakeholderInviteMailContent { const communityName = input.communityName.trim() || "A community"; const inviterEmail = input.inviterEmail.trim().toLowerCase(); const origin = input.origin.replace(/\/$/, ""); const verifyUrl = input.verifyUrl; const copyUrl = ruleStakeholderInviteCopyUrl(verifyUrl); const possessive = communityPossessive(communityName); const description = clipCommunityInviteDescription(input.summary); const initials = communityInviteInitials(communityName); const countsLabel = inviteRuleCountsLabel(input.document); const subject = `${communityName} invited you to read their Rule`; const intro = `${inviterEmail} sent the invitation. Their Rule sets out how they talk, who belongs, how they decide and what happens when they disagree.`; const privacy = `Every Rule starts private. Only the people ${communityName} invites can read it until the person who holds the pen turns on a link. A Rule is public and featured only when a community asks us in writing.`; const ownLink = "Your own link. Forwarding this email shares it. Ask the community to invite anyone else who should read the Rule."; const copyLead = "Writing a Rule for another community? Make a copy of this one and change what does not fit."; const why = `You got this email because ${inviterEmail} added your address to ${possessive} Rule on CommunityRule. If you do not know the community, you can ignore this email.`; const madeBy = "CommunityRule is made by the Media Economies Design Lab at the University of Colorado Boulder."; const privacyUrl = `${origin}/privacy`; const aboutUrl = `${origin}/about`; const logoUrl = `${origin}${RULE_STAKEHOLDER_INVITE_LOGO_PATH}`; const text = [ subject, "", intro, "", "Read the Rule", verifyUrl, "", privacy, "", ownLink, "", copyLead, copyUrl, "", why, "", madeBy, `Privacy ${privacyUrl}`, ].join("\n"); const html = inviteHtml({ subject, intro, verifyUrl, copyUrl, communityName, description, initials, countsLabel, privacy, ownLink, copyLead, why, madeBy, privacyUrl, aboutUrl, logoUrl, }); return { subject, previewText: PREVIEW_TEXT, text, html }; } function inviteHtml(opts: { subject: string; intro: string; verifyUrl: string; copyUrl: string; communityName: string; description: string; initials: string; countsLabel: string; privacy: string; ownLink: string; copyLead: string; why: string; madeBy: string; privacyUrl: string; aboutUrl: string; logoUrl: string; }): string { const heading = escapeHtml(opts.subject); const intro = escapeHtml(opts.intro); const verifyHref = escapeHtml(opts.verifyUrl); const copyHref = escapeHtml(opts.copyUrl); const name = escapeHtml(opts.communityName); const description = escapeHtml(opts.description); const initials = escapeHtml(opts.initials); const counts = escapeHtml(opts.countsLabel); const privacyHtml = privacyHtmlWithLead(opts.privacy); const ownLinkHtml = leadInHtml("Your own link.", opts.ownLink); const copyHtml = `Writing a Rule for another community?` + ` Make a copy` + ` of this one and change what does not fit.`; const why = escapeHtml(opts.why); const madeBy = escapeHtml(opts.madeBy); const privacyUrl = escapeHtml(opts.privacyUrl); const aboutUrl = escapeHtml(opts.aboutUrl); const logoUrl = escapeHtml(opts.logoUrl); const cardBody = description ? `
${description}
` : ""; return `
|