Skip to content

Commit c7e2d84

Browse files
WIP Use flag for comments coming from email reply
A comment flag with source = 'email' should be displayed with whitespace: 'normal';
1 parent 5f1457f commit c7e2d84

File tree

5 files changed

+46
-22
lines changed

5 files changed

+46
-22
lines changed

src/components/HTMLEngineProvider/BaseHTMLEngineProvider.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ const customHTMLElementModels = {
3333
}),
3434
comment: defaultHTMLElementModels.div.extend({
3535
tagName: 'comment',
36+
mixedUAStyles: {whiteSpace: 'pre', backgroundColor: 'blue'},
37+
}),
38+
'email-comment': defaultHTMLElementModels.div.extend({
39+
tagName: 'email-comment',
40+
mixedUAStyles: {whiteSpace: 'normal', backgroundColor: 'green'},
3641
}),
3742
};
3843

src/components/HTMLEngineProvider/htmlEngineUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function computeEmbeddedMaxWidth(tagName, contentWidth) {
2626
function isInsideComment(tnode) {
2727
let currentNode = tnode;
2828
while (currentNode.parent) {
29-
if (currentNode.domNode.name === 'comment') {
29+
if (currentNode.domNode.name === 'comment' || currentNode.domNode.name === 'email-comment') {
3030
return true;
3131
}
3232
currentNode = currentNode.parent;

src/pages/home/report/ReportActionItemFragment.js

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ const propTypes = {
4444
/** Does this fragment belong to a reportAction that has not yet loaded? */
4545
loading: PropTypes.bool,
4646

47+
/** The reportAction's source */
48+
source: PropTypes.string,
49+
4750
/** Should this fragment be contained in a single line? */
4851
isSingleLine: PropTypes.bool,
4952

@@ -64,6 +67,7 @@ const defaultProps = {
6467
loading: false,
6568
isSingleLine: false,
6669
tooltipText: '',
70+
source: '',
6771
};
6872

6973
const ReportActionItemFragment = (props) => {
@@ -86,39 +90,52 @@ const ReportActionItemFragment = (props) => {
8690
)
8791
);
8892
}
93+
let {html, text} = props.fragment;
8994

9095
// If the only difference between fragment.text and fragment.html is <br /> tags
9196
// we replace them with line breaks and render it as text, not as html.
9297
// This is done to render emojis with line breaks between them as text.
93-
const differByLineBreaksOnly = props.fragment.html.replaceAll('<br />', ' ') === props.fragment.text;
98+
const differByLineBreaksOnly = html.replaceAll('<br />', ' ') === text;
9499
if (differByLineBreaksOnly) {
95-
const textWithLineBreaks = props.fragment.html.replaceAll('<br />', '\n');
100+
const textWithLineBreaks = html.replaceAll('<br />', '\n');
96101
// eslint-disable-next-line no-param-reassign
97-
props.fragment = {...props.fragment, text: textWithLineBreaks, html: textWithLineBreaks};
102+
html = textWithLineBreaks;
103+
text = textWithLineBreaks;
98104
}
99105

100106
// Only render HTML if we have html in the fragment
101-
return props.fragment.html !== props.fragment.text
102-
? (
107+
if (html !== text) {
108+
if (props.source === 'email') {
109+
// Messages from email replies usually have complex HTML structure and they don't rely in white-space: pre to preserve spacing,
110+
// instead, the normally use &nbsp;
111+
return (
112+
<RenderHTML
113+
html={`<email-comment>${html + (props.fragment.isEdited ? '<edited></edited>' : '')}</email-comment>`}
114+
/>
115+
);
116+
}
117+
return (
103118
<RenderHTML
104-
html={`<comment>${props.fragment.html + (props.fragment.isEdited ? '<edited></edited>' : '')}</comment>`}
119+
html={`<comment>${html + (props.fragment.isEdited ? '<edited></edited>' : '')}</comment>`}
105120
/>
106-
) : (
107-
<Text
108-
selectable={!canUseTouchScreen() || !props.isSmallScreenWidth}
109-
style={EmojiUtils.containsOnlyEmojis(props.fragment.text) ? styles.onlyEmojisText : undefined}
110-
>
111-
{Str.htmlDecode(props.fragment.text)}
112-
{props.fragment.isEdited && (
113-
<Text
114-
fontSize={variables.fontSizeSmall}
115-
color={themeColors.textSupporting}
116-
>
117-
{` ${props.translate('reportActionCompose.edited')}`}
118-
</Text>
119-
)}
120-
</Text>
121121
);
122+
}
123+
return (
124+
<Text
125+
selectable={!canUseTouchScreen() || !props.isSmallScreenWidth}
126+
style={EmojiUtils.containsOnlyEmojis(text) ? styles.onlyEmojisText : undefined}
127+
>
128+
{Str.htmlDecode(text)}
129+
{props.fragment.isEdited && (
130+
<Text
131+
fontSize={variables.fontSizeSmall}
132+
color={themeColors.textSupporting}
133+
>
134+
{` ${props.translate('reportActionCompose.edited')}`}
135+
</Text>
136+
)}
137+
</Text>
138+
);
122139
}
123140
case 'TEXT':
124141
return (

src/pages/home/report/ReportActionItemMessage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const ReportActionItemMessage = (props) => {
3333
isAttachment={props.action.isAttachment}
3434
attachmentInfo={props.action.attachmentInfo}
3535
loading={props.action.loading}
36+
source={props.action.originalMessage.source}
3637
/>
3738
))}
3839
</View>

src/styles/styles.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ const webViewStyles = {
135135
fontSize: variables.fontSizeNormal,
136136
fontFamily: fontFamily.GTA,
137137
flex: 1,
138+
// whiteSpace: 'pre',
138139
},
139140
};
140141

0 commit comments

Comments
 (0)