1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-09-16 01:56:55 +00:00

Fix tab-complete not sorting favored emotes from add-ons (#639)

Additionally, there's no early return in the `getMatchedEmotes` method anymore, since it could be that the results we get from Twitch could exceed 25 emotes and thus would cause potential favored FFZ Emotes / Add-On Emotes / Emoji to not show up at the top of the list
This commit is contained in:
Lordmau5 2019-08-13 10:42:37 +08:00 committed by Mike
parent 60e8fad4fa
commit f32b2efd1a

View file

@ -339,8 +339,6 @@ export default class Input extends Module {
inst.getMatchedEmotes = function(input) { inst.getMatchedEmotes = function(input) {
const limitResults = t.chat.context.get('chat.tab-complete.limit-results'); const limitResults = t.chat.context.get('chat.tab-complete.limit-results');
let results = t.getTwitchEmoteSuggestions(input, this); let results = t.getTwitchEmoteSuggestions(input, this);
if ( limitResults && results.length >= 25 )
return t.sortFavorites(results).slice(0, 25);
if ( t.chat.context.get('chat.tab-complete.ffz-emotes') ) { if ( t.chat.context.get('chat.tab-complete.ffz-emotes') ) {
const ffz_emotes = t.getEmoteSuggestions(input, this); const ffz_emotes = t.getEmoteSuggestions(input, this);
@ -348,15 +346,11 @@ export default class Input extends Module {
results = results.concat(ffz_emotes); results = results.concat(ffz_emotes);
} }
if ( limitResults && results.length >= 25 ) if ( t.chat.context.get('chat.tab-complete.emoji') ) {
return t.sortFavorites(results).slice(0, 25);
if ( ! t.chat.context.get('chat.tab-complete.emoji') )
return results;
const emoji = t.getEmojiSuggestions(input, this); const emoji = t.getEmojiSuggestions(input, this);
if ( Array.isArray(emoji) && emoji.length ) if ( Array.isArray(emoji) && emoji.length )
results = Array.isArray(results) ? results.concat(emoji) : emoji; results = Array.isArray(results) ? results.concat(emoji) : emoji;
}
results = t.sortFavorites(results); results = t.sortFavorites(results);
return limitResults && results.length > 25 ? results.slice(0, 25) : results; return limitResults && results.length > 25 ? results.slice(0, 25) : results;
@ -405,12 +399,10 @@ export default class Input extends Module {
} }
return results.sort((a, b) => { return results.sort((a, b) => {
const a_fav = a.favorite; if (a.favorite) {
const b_fav = b.favorite; return b.favorite ? a.replacement.localeCompare(b.replacement) : -1;
if (a_fav) {
return b_fav ? a.replacement.localeCompare(b.replacement) : -1;
} }
else if (b_fav) { else if (b.favorite) {
return 1; return 1;
} }
else { else {
@ -528,22 +520,23 @@ export default class Input extends Module {
const search = input.startsWith(':') ? input.slice(1) : input, const search = input.startsWith(':') ? input.slice(1) : input,
results = [], results = [],
emotes = this.emotes.getEmotes( sets = this.emotes.getSets(
user && user.id, user && user.id,
user && user.login, user && user.login,
channel_id, channel_id,
channel_login channel_login
); );
for(const emote of Object.values(emotes)) for(const set of sets)
for(const emote of Object.values(set.emotes))
if ( inst.doesEmoteMatchTerm(emote, search) ) { if ( inst.doesEmoteMatchTerm(emote, search) ) {
const favorite = this.emotes.isFavorite(emote.token.provider, emote.id); const favorite = this.emotes.isFavorite(set.source || 'ffz', emote.id);
results.push({ results.push({
current: input, current: input,
replacement: emote.name, replacement: emote.name,
element: inst.renderEmoteSuggestion({ element: inst.renderEmoteSuggestion({
token: emote.name, token: emote.name,
id: `${emote.token.provider}-${emote.id}`, id: `${set.source}-${emote.id}`,
srcSet: emote.srcSet, srcSet: emote.srcSet,
favorite favorite
}), }),