From 9353c9347b58cb2f587a8d1bbe7b215a0779493b Mon Sep 17 00:00:00 2001 From: Tsaqif Date: Tue, 28 May 2024 09:14:17 +0700 Subject: [PATCH 1/4] Modify mention user and mention report extras field names Signed-off-by: Tsaqif --- lib/ExpensiMark.d.ts | 2 +- lib/ExpensiMark.js | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/ExpensiMark.d.ts b/lib/ExpensiMark.d.ts index f431df7e..fad8f1b6 100644 --- a/lib/ExpensiMark.d.ts +++ b/lib/ExpensiMark.d.ts @@ -35,7 +35,7 @@ declare type Rule = { }; declare type ExtrasObject = { - reportIdToName?: Record; + reportIDToName?: Record; accountIDToName?: Record; }; export default class ExpensiMark { diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index 74e96891..13601667 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -464,7 +464,7 @@ export default class ExpensiMark { name: 'reportMentions', regex: //gi, replacement: (match, g1, offset, string, extras) => { - const reportToNameMap = extras.reportIdToName; + const reportToNameMap = extras.reportIDToName; if (!reportToNameMap || !reportToNameMap[g1]) { Log.alert('[ExpensiMark] Missing report name', {reportID: g1}); return '#Hidden'; @@ -478,13 +478,13 @@ export default class ExpensiMark { regex: /(?:)|(?:(.*?)<\/mention-user>)/gi, replacement: (match, g1, g2, offset, string, extras) => { if (g1) { - const accountToNameMap = extras.accountIdToName; + const accountToNameMap = extras.accountIDToName; if (!accountToNameMap || !accountToNameMap[g1]) { Log.alert('[ExpensiMark] Missing account name', {accountID: g1}); return '@Hidden'; } - return `@${extras.accountIdToName[g1]}`; + return `@${accountToNameMap[g1]}`; } return Str.removeSMSDomain(g2) }, @@ -536,7 +536,7 @@ export default class ExpensiMark { name: 'reportMentions', regex: //gi, replacement: (match, g1, offset, string, extras) => { - const reportToNameMap = extras.reportIdToName; + const reportToNameMap = extras.reportIDToName; if (!reportToNameMap || !reportToNameMap[g1]) { Log.alert('[ExpensiMark] Missing report name', {reportID: g1}); return '#Hidden'; @@ -547,15 +547,18 @@ export default class ExpensiMark { }, { name: 'userMention', - regex: //gi, - replacement: (match, g1, offset, string, extras) => { - const accountToNameMap = extras.accountIdToName; - if (!accountToNameMap || !accountToNameMap[g1]) { - Log.alert('[ExpensiMark] Missing account name', {accountID: g1}); - return '@Hidden'; - } + regex: /(?:)|(?:(.*?)<\/mention-user>)/gi, + replacement: (match, g1, g2, offset, string, extras) => { + if (g1) { + const accountToNameMap = extras.accountIDToName; + if (!accountToNameMap || !accountToNameMap[g1]) { + Log.alert('[ExpensiMark] Missing account name', {accountID: g1}); + return '@Hidden'; + } - return `@${extras.accountIdToName[g1]}`; + return `@${accountToNameMap[g1]}`; + } + return Str.removeSMSDomain(g2) }, }, { From 01bdce7453e6aeb4fb3b97ff5728c0d0a1e58724 Mon Sep 17 00:00:00 2001 From: Tsaqif Date: Tue, 28 May 2024 09:48:21 +0700 Subject: [PATCH 2/4] Retrigger checks Signed-off-by: Tsaqif From 50e7c5d0e3e51122ee11d3b72df128cf350a318b Mon Sep 17 00:00:00 2001 From: Tsaqif Date: Tue, 28 May 2024 20:42:47 +0700 Subject: [PATCH 3/4] Change extras field names in tests Signed-off-by: Tsaqif --- __tests__/ExpensiMark-HTMLToText-test.js | 4 ++-- __tests__/ExpensiMark-Markdown-test.js | 4 ++-- lib/ExpensiMark.js | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/__tests__/ExpensiMark-HTMLToText-test.js b/__tests__/ExpensiMark-HTMLToText-test.js index 39f5bebc..6757803b 100644 --- a/__tests__/ExpensiMark-HTMLToText-test.js +++ b/__tests__/ExpensiMark-HTMLToText-test.js @@ -151,7 +151,7 @@ test('Mention user html to text', () => { expect(parser.htmlToText(testString)).toBe('@Hidden'); const extras = { - accountIdToName: { + accountIDToName: { '1234': 'user@domain.com', }, }; @@ -180,7 +180,7 @@ test('Mention report html to text', () => { expect(parser.htmlToText(testString)).toBe('#Hidden'); const extras = { - reportIdToName: { + reportIDToName: { '1234': '#room-name', }, }; diff --git a/__tests__/ExpensiMark-Markdown-test.js b/__tests__/ExpensiMark-Markdown-test.js index 8f446820..a8bf1769 100644 --- a/__tests__/ExpensiMark-Markdown-test.js +++ b/__tests__/ExpensiMark-Markdown-test.js @@ -765,7 +765,7 @@ test('Mention user html to markdown', () => { expect(parser.htmlToMarkdown(testString)).toBe('@Hidden'); const extras = { - accountIdToName: { + accountIDToName: { '1234': 'user@domain.com', }, }; @@ -794,7 +794,7 @@ test('Mention report html to markdown', () => { expect(parser.htmlToText(testString)).toBe('#Hidden'); const extras = { - reportIdToName: { + reportIDToName: { '1234': '#room-name', }, }; diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index 13601667..ca47ade9 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -483,10 +483,10 @@ export default class ExpensiMark { Log.alert('[ExpensiMark] Missing account name', {accountID: g1}); return '@Hidden'; } - + return `@${accountToNameMap[g1]}`; } - return Str.removeSMSDomain(g2) + return Str.removeSMSDomain(g2); }, }, ]; @@ -558,7 +558,7 @@ export default class ExpensiMark { return `@${accountToNameMap[g1]}`; } - return Str.removeSMSDomain(g2) + return Str.removeSMSDomain(g2); }, }, { From 1137c3f640c41bc72997d4da2c05ac058d60ab6b Mon Sep 17 00:00:00 2001 From: Tsaqif Date: Tue, 28 May 2024 22:30:44 +0700 Subject: [PATCH 4/4] revert some changes Signed-off-by: Tsaqif --- lib/ExpensiMark.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index ca47ade9..b72f2054 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -484,7 +484,7 @@ export default class ExpensiMark { return '@Hidden'; } - return `@${accountToNameMap[g1]}`; + return `@${extras.accountIDToName[g1]}`; } return Str.removeSMSDomain(g2); }, @@ -547,18 +547,14 @@ export default class ExpensiMark { }, { name: 'userMention', - regex: /(?:)|(?:(.*?)<\/mention-user>)/gi, - replacement: (match, g1, g2, offset, string, extras) => { - if (g1) { - const accountToNameMap = extras.accountIDToName; - if (!accountToNameMap || !accountToNameMap[g1]) { - Log.alert('[ExpensiMark] Missing account name', {accountID: g1}); - return '@Hidden'; - } - - return `@${accountToNameMap[g1]}`; + regex: //gi, + replacement: (match, g1, offset, string, extras) => { + const accountToNameMap = extras.accountIDToName; + if (!accountToNameMap || !accountToNameMap[g1]) { + Log.alert('[ExpensiMark] Missing account name', {accountID: g1}); + return '@Hidden'; } - return Str.removeSMSDomain(g2); + return `@${extras.accountIDToName[g1]}`; }, }, {