From 9331c2a3c858ae8bcf4bf813cef07276dd989dd4 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 25 Jul 2022 11:41:43 -0400 Subject: [PATCH] feat(templating): Include activity id and title for all activities * Include reddit thing id as 'id' * Include 'title' -- for submission this is submission title. For comment this is the first 50 characters of the comment truncated with '...' * Include 'shortTitle' -- same as above but truncated to 15 characters --- src/Utils/SnoowrapUtils.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Utils/SnoowrapUtils.ts b/src/Utils/SnoowrapUtils.ts index 202d984..74abb17 100644 --- a/src/Utils/SnoowrapUtils.ts +++ b/src/Utils/SnoowrapUtils.ts @@ -116,6 +116,9 @@ export const isSubreddit = async (subreddit: Subreddit, stateCriteria: Subreddit })() as boolean; } +const renderContentCommentTruncate = truncateStringToLength(50); +const shortTitleTruncate = truncateStringToLength(15); + export const renderContent = async (template: string, data: (Submission | Comment), ruleResults: RuleResultEntity[] = [], usernotes: UserNotes) => { const conditional: any = {}; if(data.can_mod_post) { @@ -133,11 +136,13 @@ export const renderContent = async (template: string, data: (Submission | Commen } const templateData: any = { kind: data instanceof Submission ? 'submission' : 'comment', - author: await data.author.name, + // @ts-ignore + author: getActivityAuthorName(await data.author), votes: data.score, age: dayjs.duration(dayjs().diff(dayjs.unix(data.created))).humanize(), permalink: `https://reddit.com${data.permalink}`, botLink: BOT_LINK, + id: data.name, ...conditional } if (template.includes('{{item.notes')) { @@ -159,6 +164,10 @@ export const renderContent = async (template: string, data: (Submission | Commen if (data instanceof Submission) { templateData.url = data.url; templateData.title = data.title; + templateData.shortTitle = shortTitleTruncate(data.title); + } else { + templateData.title = renderContentCommentTruncate(data.body); + templateData.shortTitle = shortTitleTruncate(data.body); } // normalize rule names and map context data // NOTE: we are relying on users to use unique names for rules. If they don't only the last rule run of kind X will have its results here