[Glitch] Fix custom emoji animation on hover in conversations view

Port 66f85e540c to glitch-soc

Signed-off-by: Thibaut Girka <thib@sitedethib.com>
lolsob-rspec
ThibG 2019-10-01 17:11:14 +02:00 committed by Thibaut Girka
parent de2a936748
commit 3c90dcf546
1 changed files with 43 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import Permalink from 'flavours/glitch/components/permalink';
import IconButton from 'flavours/glitch/components/icon_button'; import IconButton from 'flavours/glitch/components/icon_button';
import RelativeTimestamp from 'flavours/glitch/components/relative_timestamp'; import RelativeTimestamp from 'flavours/glitch/components/relative_timestamp';
import { HotKeys } from 'react-hotkeys'; import { HotKeys } from 'react-hotkeys';
import { autoPlayGif } from 'flavours/glitch/util/initial_state';
const messages = defineMessages({ const messages = defineMessages({
more: { id: 'status.more', defaultMessage: 'More' }, more: { id: 'status.more', defaultMessage: 'More' },
@ -64,6 +65,43 @@ class Conversation extends ImmutablePureComponent {
} }
} }
_updateEmojis () {
const node = this.namesNode;
if (!node || autoPlayGif) {
return;
}
const emojis = node.querySelectorAll('.custom-emoji');
for (var i = 0; i < emojis.length; i++) {
let emoji = emojis[i];
if (emoji.classList.contains('status-emoji')) {
continue;
}
emoji.classList.add('status-emoji');
emoji.addEventListener('mouseenter', this.handleEmojiMouseEnter, false);
emoji.addEventListener('mouseleave', this.handleEmojiMouseLeave, false);
}
}
componentDidMount () {
this._updateEmojis();
}
componentDidUpdate () {
this._updateEmojis();
}
handleEmojiMouseEnter = ({ target }) => {
target.src = target.getAttribute('data-original');
}
handleEmojiMouseLeave = ({ target }) => {
target.src = target.getAttribute('data-static');
}
handleClick = () => { handleClick = () => {
if (!this.context.router) { if (!this.context.router) {
return; return;
@ -112,6 +150,10 @@ class Conversation extends ImmutablePureComponent {
this.setState({ isExpanded: value }); this.setState({ isExpanded: value });
} }
setNamesRef = (c) => {
this.namesNode = c;
}
render () { render () {
const { accounts, lastStatus, unread, intl } = this.props; const { accounts, lastStatus, unread, intl } = this.props;
const { isExpanded } = this.state; const { isExpanded } = this.state;
@ -162,7 +204,7 @@ class Conversation extends ImmutablePureComponent {
<RelativeTimestamp timestamp={lastStatus.get('created_at')} /> <RelativeTimestamp timestamp={lastStatus.get('created_at')} />
</div> </div>
<div className='conversation__content__names'> <div className='conversation__content__names' ref={this.setNamesRef}>
<FormattedMessage id='conversation.with' defaultMessage='With {names}' values={{ names: <span>{names}</span> }} /> <FormattedMessage id='conversation.with' defaultMessage='With {names}' values={{ names: <span>{names}</span> }} />
</div> </div>
</div> </div>