1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-08-02 07:58:31 +00:00

Basic badge stuff. Rendering of extension badges is still disabled for now, but SOON(tm). Fix emotes in locally echoed messages when emoji are present. Cache tokens in chat lines. Include the intl-login element within the username link in chat so it all underlines together.

This commit is contained in:
SirStendec 2017-11-28 02:03:59 -05:00
parent f66069798d
commit cbbe6f3e20
12 changed files with 517 additions and 155 deletions

View file

@ -4,9 +4,6 @@
// Chat
// ============================================================================
import {IS_WEBKIT} from 'utilities/constants';
const WEBKIT = IS_WEBKIT ? '-webkit-' : '';
import Module from 'utilities/module';
import {createElement, ManagedStyle} from 'utilities/dom';
import {timeout, has} from 'utilities/object';
@ -242,13 +239,13 @@ export default class Chat extends Module {
this.context.on('changed:theme.is-dark', () => {
for(const key in this.rooms)
if ( this.rooms[key] )
this.rooms[key].updateBitsCSS();
this.rooms[key].buildBitsCSS();
});
this.context.on('changed:chat.bits.animated', () => {
for(const key in this.rooms)
if ( this.rooms[key] )
this.rooms[key].updateBitsCSS();
this.rooms[key].buildBitsCSS();
});
}
@ -260,53 +257,6 @@ export default class Chat extends Module {
}
getBadge(badge, version, room) {
let b;
if ( this.room_ids[room] ) {
const versions = this.room_ids[room].badges.get(badge);
b = versions && versions.get(version);
}
if ( ! b ) {
const versions = this.badges.get(badge);
b = versions && versions.get(version);
}
return b;
}
updateBadges(badges) {
this.badges = badges;
this.updateBadgeCSS();
}
updateBadgeCSS() {
if ( ! this.badges )
this.style.delete('badges');
const out = [];
for(const [key, versions] of this.badges)
for(const [version, data] of versions) {
out.push(`.ffz-badge.badge--${key}.version--${version} {
background-color: transparent;
filter: none;
${WEBKIT}mask-image: none;
background-image: url("${data.image1x}");
background-image: ${WEBKIT}image-set(
url("${data.image1x}") 1x,
url("${data.image2x}") 2x,
url("${data.image4x}") 4x
);
}`)
}
this.style.set('badges', out.join('\n'));
}
getUser(id, login, no_create, no_login) {
let user;
if ( id && typeof id === 'number' )
@ -404,6 +354,27 @@ export default class Chat extends Module {
}
* iterateRooms() {
const visited = new Set;
for(const id in this.room_ids)
if ( has(this.room_ids, id) ) {
const room = this.room_ids[id];
if ( room ) {
visited.add(room);
yield room;
}
}
for(const login in this.rooms)
if ( has(this.rooms, login) ) {
const room = this.rooms[login];
if ( room && ! visited.has(room) )
yield room;
}
}
formatTime(time) {
if (!( time instanceof Date ))
time = new Date(time);
@ -467,25 +438,6 @@ export default class Chat extends Module {
}
renderBadges(msg, e) { // eslint-disable-line class-methods-use-this
const out = [],
badges = msg.badges || {};
for(const key in badges)
if ( has(badges, key) ) {
const version = badges[key];
out.push(e('span', {
className: `ffz-tooltip ffz-badge badge--${key} version--${version}`,
'data-tooltip-type': 'badge',
'data-badge': key,
'data-version': version
}))
}
return out;
}
renderTokens(tokens, e) {
if ( ! e )
e = createElement;