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;
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 = [],
collected = {},
collect = this.context.get('chat.bits.stack');
for(const token of tokens) {
if ( token.type !== 'text' ) {
if ( ! token || token.type !== 'text' ) {
out.push(token);
continue;
}
matcher.lastIndex = 0;
const text = token.text;
let idx = 0, match;
while((match = matcher.exec(text))) {
let text = [];
for(const segment of token.text.split(/ +/)) {
const match = matcher.exec(segment);
if ( match ) {
const prefix = match[1].toLowerCase(),
cheer = actions[prefix];
if ( ! cheer )
if ( ! cheer ) {
text.push(segment);
continue;
if ( idx !== match.index )
out.push({type: 'text', text: text.slice(idx, match.index)});
}
const amount = parseInt(match[2], 10),
tiers = cheer.orderedTiers;
let tier, token;
for(let i=0, l = tiers.length; i < l; i++)
if ( amount >= tiers[i].bits ) {
tier = i;
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 = {
type: 'cheer',
prefix,
tier,
amount: parseInt(match[2], 10),
amount,
text: match[0]
});
@ -382,11 +385,12 @@ export const CheerEmotes = {
token.hidden = true;
}
idx = match.index + match[0].length;
} else
text.push(segment);
}
if ( idx < text.length )
out.push({type: 'text', text: text.slice(idx)});
if ( text.length > 1 || (text.length === 1 && text[0] !== '') )
out.push({type: 'text', text: text.join(' ')});
}
if ( collect ) {

View file

@ -75,7 +75,7 @@ export default class ChatLine extends Module {
if ( ! msg.message && msg.messageParts )
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',
out = tokens.length ? [
@ -175,9 +175,14 @@ export default class ChatLine extends Module {
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();
}
}
}