UNPKG

@cocalc/server

Version:

CoCalc server functionality: functions used by either the hub and the next.js server

60 lines (58 loc) 2.6 kB
"use strict"; /* * This file is part of CoCalc: Copyright © 2021 Sagemath, Inc. * License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const get_name_1 = __importDefault(require("@cocalc/server/accounts/get-name")); const get_email_address_1 = __importDefault(require("@cocalc/server/accounts/get-email-address")); const get_title_1 = __importDefault(require("@cocalc/server/projects/get-title")); const misc_1 = require("@cocalc/util/misc"); const site_url_1 = __importDefault(require("@cocalc/server/settings/site-url")); const settings_1 = require("@cocalc/server/settings"); const send_email_1 = __importDefault(require("@cocalc/server/email/send-email")); async function sendNotificationIfPossible(key, source, description) { const to = await (0, get_email_address_1.default)(key.target); if (!to) { // Email is the only notification method at present. // Nothing more to do -- target user has no known email address. // They will see notification when they sign in. return "nothing"; } const sourceName = (0, misc_1.trunc)((await (0, get_name_1.default)(source)) ?? "Unknown User", 60); const projectTitle = await (0, get_title_1.default)(key.project_id); const context = description.length > 0 ? `<br/><blockquote>${description}</blockquote>` : ""; const subject = `[${(0, misc_1.trunc)(projectTitle, 40)}] ${key.path}`; const url = `${await (0, site_url_1.default)()}/projects/${key.project_id}/files/${key.path}${key.fragment_id ? (key.fragment_id.startsWith("#") ? "" : "#") + key.fragment_id : ""}`; const html = ` ${sourceName} mentioned you in <a href="${url}">a chat at ${key.path} in ${projectTitle}</a>. ${context} `; const text = ` ${sourceName} mentioned you in a chat at ${key.path} in ${projectTitle}. ${url} ${description ? "> " : ""}${description} `; const { help_email } = await (0, settings_1.getServerSettings)(); const from = `${sourceName} <${help_email}>`; await (0, send_email_1.default)({ from, to, subject, text, html, categories: ["notification"], asm_group: 148185, // see https://app.sendgrid.com/suppressions/advanced_suppression_manager }, source); return "email"; } exports.default = sendNotificationIfPossible; //# sourceMappingURL=notify.js.map