Big emojis in chats, too
This commit is contained in:
parent
60872c9f67
commit
c856e9df55
|
@ -9,18 +9,10 @@ import classnames from 'classnames';
|
||||||
import Icon from 'soapbox/components/icon';
|
import Icon from 'soapbox/components/icon';
|
||||||
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
import { addGreentext } from 'soapbox/utils/greentext';
|
import { addGreentext } from 'soapbox/utils/greentext';
|
||||||
|
import { justEmojis } from 'soapbox/utils/rich_content';
|
||||||
|
|
||||||
const MAX_HEIGHT = 642; // 20px * 32 (+ 2px padding at the top)
|
const MAX_HEIGHT = 642; // 20px * 32 (+ 2px padding at the top)
|
||||||
|
const BIG_EMOJI_LIMIT = 10;
|
||||||
const justEmojis = (node, limit = 10) => {
|
|
||||||
if (!node) return false;
|
|
||||||
if (node.textContent.replaceAll(' ', '') !== '') return false;
|
|
||||||
const emojis = [...node.querySelectorAll('img.emojione')];
|
|
||||||
if (emojis.length > limit) return false;
|
|
||||||
const images = [...node.querySelectorAll('img')];
|
|
||||||
if (images.length > emojis.length) return false;
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
greentext: getSoapboxConfig(state).get('greentext'),
|
greentext: getSoapboxConfig(state).get('greentext'),
|
||||||
|
@ -98,10 +90,16 @@ class StatusContent extends React.PureComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setJustEmojis = () => {
|
||||||
|
if (this.node && this.state.justEmojis === undefined) {
|
||||||
|
this.setState({ justEmojis: justEmojis(this.node, BIG_EMOJI_LIMIT) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
refresh = () => {
|
refresh = () => {
|
||||||
this.setCollapse();
|
this.setCollapse();
|
||||||
this._updateStatusLinks();
|
this._updateStatusLinks();
|
||||||
this.setState({ justEmojis: justEmojis(this.node) });
|
this.setJustEmojis();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
|
|
@ -15,6 +15,9 @@ import Bundle from 'soapbox/features/ui/components/bundle';
|
||||||
import DropdownMenuContainer from 'soapbox/containers/dropdown_menu_container';
|
import DropdownMenuContainer from 'soapbox/containers/dropdown_menu_container';
|
||||||
import { initReportById } from 'soapbox/actions/reports';
|
import { initReportById } from 'soapbox/actions/reports';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
|
import { justEmojis } from 'soapbox/utils/rich_content';
|
||||||
|
|
||||||
|
const BIG_EMOJI_LIMIT = 1;
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
today: { id: 'chats.dividers.today', defaultMessage: 'Today' },
|
today: { id: 'chats.dividers.today', defaultMessage: 'Today' },
|
||||||
|
@ -120,6 +123,10 @@ class ChatMessageList extends ImmutablePureComponent {
|
||||||
link.setAttribute('rel', 'ugc nofollow noopener');
|
link.setAttribute('rel', 'ugc nofollow noopener');
|
||||||
link.setAttribute('target', '_blank');
|
link.setAttribute('target', '_blank');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (justEmojis(c, BIG_EMOJI_LIMIT)) {
|
||||||
|
c.classList.add('chat-message__bubble--onlyEmoji');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isNearBottom = () => {
|
isNearBottom = () => {
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
// Returns `true` if the node contains only emojis, up to a limit
|
||||||
|
export const justEmojis = (node, limit = 1) => {
|
||||||
|
if (!node) return false;
|
||||||
|
if (node.textContent.replaceAll(' ', '') !== '') return false;
|
||||||
|
const emojis = [...node.querySelectorAll('img.emojione')];
|
||||||
|
if (emojis.length > limit) return false;
|
||||||
|
const images = [...node.querySelectorAll('img')];
|
||||||
|
if (images.length > emojis.length) return false;
|
||||||
|
return true;
|
||||||
|
};
|
|
@ -163,6 +163,15 @@
|
||||||
pointer-events: all;
|
pointer-events: all;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--onlyEmoji {
|
||||||
|
background: transparent;
|
||||||
|
|
||||||
|
img.emojione {
|
||||||
|
width: 36px !important;
|
||||||
|
height: 36px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&--me .chat-message__bubble {
|
&--me .chat-message__bubble {
|
||||||
|
|
Loading…
Reference in New Issue