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

Fix tokenization of cheers in chat messages. Also fix cached token invalidation when changing how chat lines should render.

This commit is contained in:
SirStendec 2017-12-01 15:33:06 -05:00
parent 691c09eb18
commit aef58f24af
2 changed files with 52 additions and 43 deletions

View file

@ -328,48 +328,51 @@ export const CheerEmotes = {
return tokens; return tokens;
const actions = bitsConfig.indexedActions, const actions = bitsConfig.indexedActions,
matcher = new RegExp('\\b(' + Object.keys(actions).join('|') + ')(\\d+)\\b', 'ig'); matcher = new RegExp(`^(${Object.keys(actions).join('|')})(\\d+)$`, 'i');
const out = [], const out = [],
collected = {}, collected = {},
collect = this.context.get('chat.bits.stack'); collect = this.context.get('chat.bits.stack');
for(const token of tokens) { for(const token of tokens) {
if ( token.type !== 'text' ) { if ( ! token || token.type !== 'text' ) {
out.push(token); out.push(token);
continue; continue;
} }
matcher.lastIndex = 0; let text = [];
const text = token.text; for(const segment of token.text.split(/ +/)) {
let idx = 0, match; const match = matcher.exec(segment);
if ( match ) {
while((match = matcher.exec(text))) {
const prefix = match[1].toLowerCase(), const prefix = match[1].toLowerCase(),
cheer = actions[prefix]; cheer = actions[prefix];
if ( ! cheer ) if ( ! cheer ) {
text.push(segment);
continue; continue;
}
if ( idx !== match.index )
out.push({type: 'text', text: text.slice(idx, match.index)});
const amount = parseInt(match[2], 10), const amount = parseInt(match[2], 10),
tiers = cheer.orderedTiers; tiers = cheer.orderedTiers;
let tier, token; let tier, token;
for(let i=0, l = tiers.length; i < l; i++) for(let i=0, l = tiers.length; i < l; i++)
if ( amount >= tiers[i].bits ) { if ( amount >= tiers[i].bits ) {
tier = i; tier = i;
break; break;
} }
if ( text.length ) {
// We have pending text. Join it together, with an extra space.
out.push({type: 'text', text: `${text.join(' ')} `});
text = [];
}
out.push(token = { out.push(token = {
type: 'cheer', type: 'cheer',
prefix, prefix,
tier, tier,
amount: parseInt(match[2], 10), amount,
text: match[0] text: match[0]
}); });
@ -382,11 +385,12 @@ export const CheerEmotes = {
token.hidden = true; token.hidden = true;
} }
idx = match.index + match[0].length; } else
text.push(segment);
} }
if ( idx < text.length ) if ( text.length > 1 || (text.length === 1 && text[0] !== '') )
out.push({type: 'text', text: text.slice(idx)}); out.push({type: 'text', text: text.join(' ')});
} }
if ( collect ) { if ( collect ) {

View file

@ -75,7 +75,7 @@ export default class ChatLine extends Module {
if ( ! msg.message && msg.messageParts ) if ( ! msg.message && msg.messageParts )
detokenizeMessage(msg); detokenizeMessage(msg);
const tokens = msg.ffzTokens = msg.ffzTokens || t.chat.tokenizeMessage(msg, {login: this.props.currentUserLogin, display: this.props.currentUserDisplayName}); const tokens = msg.ffz_tokens = msg.ffz_tokens || t.chat.tokenizeMessage(msg, {login: this.props.currentUserLogin, display: this.props.currentUserDisplayName});
let cls = 'chat-line__message', let cls = 'chat-line__message',
out = tokens.length ? [ out = tokens.length ? [
@ -175,9 +175,14 @@ export default class ChatLine extends Module {
updateLines() { updateLines() {
for(const inst of this.ChatLine.instances) for(const inst of this.ChatLine.instances) {
const msg = inst.props.message;
if ( msg )
msg.ffz_tokens = null;
inst.forceUpdate(); inst.forceUpdate();
} }
}
} }