Add basic support for displaying emotes (#161)
This commit is contained in:
parent
b5c5cd9586
commit
14cd84dab7
3 changed files with 46 additions and 3 deletions
|
@ -106,10 +106,17 @@ MessageReply.propTypes = {
|
||||||
content: PropTypes.string.isRequired,
|
content: PropTypes.string.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
function MessageContent({ content, isMarkdown, isEdited }) {
|
function MessageContent({
|
||||||
|
senderName,
|
||||||
|
content,
|
||||||
|
isMarkdown,
|
||||||
|
isEdited,
|
||||||
|
msgType,
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className="message__content">
|
<div className="message__content">
|
||||||
<div className="text text-b1">
|
<div className="text text-b1">
|
||||||
|
{ msgType === 'm.emote' && `* ${senderName} ` }
|
||||||
{ isMarkdown ? genMarkdown(content) : linkifyContent(content) }
|
{ isMarkdown ? genMarkdown(content) : linkifyContent(content) }
|
||||||
</div>
|
</div>
|
||||||
{ isEdited && <Text className="message__content-edited" variant="b3">(edited)</Text>}
|
{ isEdited && <Text className="message__content-edited" variant="b3">(edited)</Text>}
|
||||||
|
@ -121,9 +128,11 @@ MessageContent.defaultProps = {
|
||||||
isEdited: false,
|
isEdited: false,
|
||||||
};
|
};
|
||||||
MessageContent.propTypes = {
|
MessageContent.propTypes = {
|
||||||
|
senderName: PropTypes.string.isRequired,
|
||||||
content: PropTypes.node.isRequired,
|
content: PropTypes.node.isRequired,
|
||||||
isMarkdown: PropTypes.bool,
|
isMarkdown: PropTypes.bool,
|
||||||
isEdited: PropTypes.bool,
|
isEdited: PropTypes.bool,
|
||||||
|
msgType: PropTypes.string.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
function MessageEdit({ content, onSave, onCancel }) {
|
function MessageEdit({ content, onSave, onCancel }) {
|
||||||
|
@ -228,10 +237,27 @@ MessageOptions.propTypes = {
|
||||||
|
|
||||||
function Message({
|
function Message({
|
||||||
avatar, header, reply, content, editContent, reactions, options,
|
avatar, header, reply, content, editContent, reactions, options,
|
||||||
|
msgType,
|
||||||
}) {
|
}) {
|
||||||
const msgClass = header === null ? ' message--content-only' : ' message--full';
|
const className = [
|
||||||
|
'message',
|
||||||
|
header === null ? ' message--content-only' : ' message--full',
|
||||||
|
];
|
||||||
|
switch (msgType) {
|
||||||
|
case 'm.text':
|
||||||
|
className.push('message--type-text');
|
||||||
|
break;
|
||||||
|
case 'm.emote':
|
||||||
|
className.push('message--type-emote');
|
||||||
|
break;
|
||||||
|
case 'm.notice':
|
||||||
|
className.push('message--type-notice');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`message${msgClass}`}>
|
<div className={className.join(' ')}>
|
||||||
<div className="message__avatar-container">
|
<div className="message__avatar-container">
|
||||||
{avatar !== null && avatar}
|
{avatar !== null && avatar}
|
||||||
</div>
|
</div>
|
||||||
|
@ -254,6 +280,7 @@ Message.defaultProps = {
|
||||||
editContent: null,
|
editContent: null,
|
||||||
reactions: null,
|
reactions: null,
|
||||||
options: null,
|
options: null,
|
||||||
|
msgType: 'm.text',
|
||||||
};
|
};
|
||||||
Message.propTypes = {
|
Message.propTypes = {
|
||||||
avatar: PropTypes.node,
|
avatar: PropTypes.node,
|
||||||
|
@ -263,6 +290,7 @@ Message.propTypes = {
|
||||||
editContent: PropTypes.node,
|
editContent: PropTypes.node,
|
||||||
reactions: PropTypes.node,
|
reactions: PropTypes.node,
|
||||||
options: PropTypes.node,
|
options: PropTypes.node,
|
||||||
|
msgType: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
|
@ -410,3 +410,14 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.message.message--type-emote {
|
||||||
|
.message__content {
|
||||||
|
font-style: italic;
|
||||||
|
|
||||||
|
// Remove blockness of first `<p>` so that markdown emotes stay on one line.
|
||||||
|
p:first-of-type {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -282,6 +282,7 @@ function RoomViewContent({
|
||||||
|
|
||||||
let content = mEvent.getContent().body;
|
let content = mEvent.getContent().body;
|
||||||
if (typeof content === 'undefined') return null;
|
if (typeof content === 'undefined') return null;
|
||||||
|
const msgType = mEvent.getContent()?.msgtype;
|
||||||
let reply = null;
|
let reply = null;
|
||||||
let reactions = null;
|
let reactions = null;
|
||||||
let isMarkdown = mEvent.getContent().format === 'org.matrix.custom.html';
|
let isMarkdown = mEvent.getContent().format === 'org.matrix.custom.html';
|
||||||
|
@ -379,8 +380,10 @@ function RoomViewContent({
|
||||||
);
|
);
|
||||||
const userContent = (
|
const userContent = (
|
||||||
<MessageContent
|
<MessageContent
|
||||||
|
senderName={getUsernameOfRoomMember(mEvent.sender)}
|
||||||
isMarkdown={isMarkdown}
|
isMarkdown={isMarkdown}
|
||||||
content={isMedia(mEvent) ? genMediaContent(mEvent) : content}
|
content={isMedia(mEvent) ? genMediaContent(mEvent) : content}
|
||||||
|
msgType={msgType}
|
||||||
isEdited={isEdited}
|
isEdited={isEdited}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -496,6 +499,7 @@ function RoomViewContent({
|
||||||
header={userHeader}
|
header={userHeader}
|
||||||
reply={userReply}
|
reply={userReply}
|
||||||
content={editEvent !== null && isEditingEvent ? null : userContent}
|
content={editEvent !== null && isEditingEvent ? null : userContent}
|
||||||
|
msgType={msgType}
|
||||||
editContent={editEvent !== null && isEditingEvent ? (
|
editContent={editEvent !== null && isEditingEvent ? (
|
||||||
<MessageEdit
|
<MessageEdit
|
||||||
content={content}
|
content={content}
|
||||||
|
|
Loading…
Reference in a new issue