Skip to content

Commit

Permalink
Merge pull request #831 from daledah/fix/54630
Browse files Browse the repository at this point in the history
fix: mentions are not shown in invite user or remove user report
  • Loading branch information
nkuoch authored Feb 10, 2025
2 parents 1929732 + 2c9ff4c commit 9d4c74d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
17 changes: 16 additions & 1 deletion __tests__/ExpensiMark-HTMLToText-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ test('Mention user html to text', () => {
testString = '<mention-user accountID="1234" />';
expect(parser.htmlToText(testString, extras)).toBe('@[email protected]');

extras.accountIDToName['1234'] = '[email protected]';
testString = '<mention-user accountID=1234></mention-user>';
expect(parser.htmlToText(testString, extras)).toBe('@[email protected]');

testString = '<mention-user accountID=1234 />';
expect(parser.htmlToText(testString, extras)).toBe('@[email protected]');

extras.accountIDToName['1234'] = '[email protected]';
testString = '<mention-user accountID="1234"/>';
expect(parser.htmlToText(testString, extras)).toBe('@+251924892738');
});
Expand Down Expand Up @@ -193,6 +199,15 @@ test('Mention report html to text', () => {

testString = '<mention-report reportID="1234" />';
expect(parser.htmlToText(testString, extras)).toBe('#room-name');

testString = '<mention-report reportID=1234/>';
expect(parser.htmlToText(testString, extras)).toBe('#room-name');

testString = '<mention-report reportID=1234></mention-report>';
expect(parser.htmlToText(testString, extras)).toBe('#room-name');

testString = '<mention-report reportID="1234"></mention-report>';
expect(parser.htmlToText(testString, extras)).toBe('#room-name');
});

test('Test replacement for attachment tags', () => {
Expand Down
23 changes: 13 additions & 10 deletions lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ export default class ExpensiMark {

{
name: 'reportMentions',
regex: /<mention-report reportID="(\d+)"(?: *\/>|><\/mention-report>)/gi,
regex: /<mention-report reportID="?(\d+)"?(?: *\/>|><\/mention-report>)/gi,
replacement: (extras, _match, g1, _offset, _string) => {
const reportToNameMap = extras.reportIDToName;
if (!reportToNameMap || !reportToNameMap[g1]) {
Expand All @@ -749,7 +749,7 @@ export default class ExpensiMark {
},
{
name: 'userMention',
regex: /(?:<mention-user accountID="(\d+)"(?: *\/>|><\/mention-user>))|(?:<mention-user>(.*?)<\/mention-user>)/gi,
regex: /(?:<mention-user accountID="?(\d+)"?(?: *\/>|><\/mention-user>))|(?:<mention-user>(.*?)<\/mention-user>)/gi,
replacement: (extras, _match, g1, g2, _offset, _string) => {
if (g1) {
const accountToNameMap = extras.accountIDToName;
Expand Down Expand Up @@ -817,7 +817,7 @@ export default class ExpensiMark {
},
{
name: 'reportMentions',
regex: /<mention-report reportID="(\d+)" *\/>/gi,
regex: /<mention-report reportID="?(\d+)"?(?: *\/>|><\/mention-report>)/gi,
replacement: (extras, _match, g1, _offset, _string) => {
const reportToNameMap = extras.reportIDToName;
if (!reportToNameMap || !reportToNameMap[g1]) {
Expand All @@ -830,14 +830,17 @@ export default class ExpensiMark {
},
{
name: 'userMention',
regex: /<mention-user accountID="(\d+)" *\/>/gi,
replacement: (extras, _match, g1, _offset, _string) => {
const accountToNameMap = extras.accountIDToName;
if (!accountToNameMap || !accountToNameMap[g1]) {
ExpensiMark.Log.alert('[ExpensiMark] Missing account name', {accountID: g1});
return '@Hidden';
regex: /(?:<mention-user accountID="?(\d+)"?(?: *\/>|><\/mention-user>))|(?:<mention-user>(.*?)<\/mention-user>)/gi,
replacement: (extras, _match, g1, g2, _offset, _string) => {
if (g1) {
const accountToNameMap = extras.accountIDToName;
if (!accountToNameMap || !accountToNameMap[g1]) {
ExpensiMark.Log.alert('[ExpensiMark] Missing account name', {accountID: g1});
return '@Hidden';
}
return `@${Str.removeSMSDomain(extras.accountIDToName?.[g1] ?? '')}`;
}
return `@${Str.removeSMSDomain(extras.accountIDToName?.[g1] ?? '')}`;
return Str.removeSMSDomain(g2);
},
},
{
Expand Down

0 comments on commit 9d4c74d

Please sign in to comment.