Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mentions are not shown in invite user or remove user report #831

Merged
merged 5 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add more test cases here

<mention-report reportID=1234></mention-report>
<mention-report reportID="1234"></mention-report>


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
Loading