| 6 | "": "//lib.notifications\\\\nfunction extractMentions(text) {\\\\n const mentionRegex =\\\\n /@((?:(?:[a-z\\\\\\\\d]+[-_])*[a-z\\\\\\\\d]+\\\\\\\\.)*(?:[a-z\\\\\\\\d]+[-_])*[a-z\\\\\\\\d]+)/gi;\\\\n mentionRegex.lastIndex = 0;\\\\n const accountIds = new Set();\\\\n for (const match of text.matchAll(mentionRegex)) {\\\\n if (\\\\n !/[\\\\\\\\w`]/.test(match.input.charAt(match.index - 1)) &&\\\\n !/[/\\\\\\\\w`]/.test(match.input.charAt(match.index + match[0].length)) &&\\\\n match[1].length >= 2 &&\\\\n match[1].length <= 64\\\\n ) {\\\\n accountIds.add(match[1].toLowerCase());\\\\n }\\\\n }\\\\n return [...accountIds];\\\\n}\\\\n\\\\nfunction joinPeoplesName(usersToNotify) {\\\\n if (usersToNotify.length === 1) return `@${usersToNotify[0]}`;\\\\n\\\\n return usersToNotify.reduce((acc, user, index) => {\\\\n if(index === usersToNotify.length - 1) {\\\\n acc += ` and `;\\\\n } else if(index !== 0) {\\\\n acc += `, `;\\\\n }\\\\n\\\\n return `${acc}@${user}`\\\\n }, \\\\\\\"\\\\\\\");\\\\n}\\\\n\\\\nfunction getNotificationData(config, notificationType, usersToNotify, metadata, extraParams) {\\\\n const { author } = extraParams;\\\\n\\\\n const baseURL = `https://near.org/${config.forumURL}?${config.isTest ? \\\\\\\"isTest=true\\\\\\\" : \\\\\\\"\\\\\\\"}`\\\\n\\\\n const notificationTypeText = {\\\\n mention: {\\\\n text: `I have mentioned ${joinPeoplesName(usersToNotify)} in this post: `,\\\\n url: `${baseURL}&said=${metadata.id}`\\\\n },\\\\n mentionOnComment: {\\\\n text: `I have mentioned ${joinPeoplesName(usersToNotify)} on my comment on this post: `,\\\\n url: `${baseURL}&said=${metadata.articleId}&scid=${metadata.id}`\\\\n },\\\\n upVote: {\\\\n text: \\\\\\\"I have upVoted this post: \\\\\\\",\\\\n url: `${baseURL}said=${metadata.articleId}`\\\\n },\\\\n // emoji: {\\\\n // text: \\\\\\\"I have reacted to this post: \\\\\\\",\\\\n // url: ``},\\\\n comment: {\\\\n text: \\\\\\\"I have commented this post: \\\\\\\",\\\\n url: `${baseURL}said=${metadata.articleId}&scid=${metadata.id}`\\\\n },\\\\n };\\\\n\\\\n if(author && !usersToNotify.includes(author)) {\\\\n usersToNotify.push(author);\\\\n }\\\\n\\\\n const dataToAdd = {\\\\n post: {\\\\n main: JSON.stringify({\\\\n type: \\\\\\\"md\\\\\\\",\\\\n text: `${notificationTypeText[notificationType].text} ${notificationTypeText[notificationType].url}`,\\\\n }),\\\\n },\\\\n index: {\\\\n notify: JSON.stringify(\\\\n usersToNotify.map((user) => {\\\\n return {\\\\n key: user,\\\\n value: {\\\\n type: \\\\\\\"mention\\\\\\\",\\\\n item: {\\\\n type: \\\\\\\"social\\\\\\\",\\\\n path: `${metadata.author}/post/main`,\\\\n },\\\\n },\\\\n };\\\\n })\\\\n ),\\\\n },\\\\n };\\\\n\\\\n return dataToAdd;\\\\n}\\\\n\\\\nreturn {\\\\n extractMentions,\\\\n getNotificationData,\\\\n functionsToTest: {joinPeoplesName},\\\\n};\\\\n" |