Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Jun 8, 2023
1 parent 0b3bf28 commit 089c16f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/react-components/chat-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@ const messageBodyDom = (body, from, fromSessionId, onViewProfile, emojiClassName

const bubbleColorRegEx = /^.*\s?(-color=)(#?[0-9a-fA-Z]{6}|[0-9a-fA-Z]{3})\s?.*$/;
function renderChatMessage(body, from, allowEmojiRender) {
const matches = body.match(bubbleColorRegEx);
const { content, emoji, multiline } = messageBodyDom(body, from, null, null, styles.emoji);
const isEmoji = allowEmojiRender && emoji;
const el = document.createElement("div");
el.setAttribute("class", `${styles.presenceLog} ${styles.presenceLogSpawn}`);
document.body.appendChild(el);

let bubbleColor;
const matches = body.match(bubbleColorRegEx);
if (matches) {
matches.shift();
bubbleColor = matches[1];
body = matches.reduce((acc, cur) => acc.replace(cur, ""), body);
}

const { content, emoji, multiline } = messageBodyDom(body, from, null, null, styles.emoji);
const isEmoji = allowEmojiRender && emoji;
const el = document.createElement("div");
el.setAttribute("class", `${styles.presenceLog} ${styles.presenceLogSpawn}`);
document.body.appendChild(el);

const entryDom = (
<div
className={classNames({
[styles.presenceLogEntry]: !isEmoji,
[styles.presenceLogEntryOneLine]: !isEmoji && !multiline,
[styles.presenceLogEmoji]: isEmoji
})}
style={{ backgroundColor: `${bubbleColor}` }}
style={bubbleColor && { backgroundColor: `${bubbleColor}` }}
>
{content}
</div>
Expand Down

0 comments on commit 089c16f

Please sign in to comment.