1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-09-17 10:16:57 +00:00

Improve support for interactive tooltips. Allow chat tokenizers to supply custom delays and interactive flags for their tooltips. Wrap text in <span> elements. Fix bug with stream uptime metadata. Fix bug with fine-router. Add method to EventEmitter that wraps emit in a try/catch. Add lilz to the socket server lineup.

This commit is contained in:
SirStendec 2017-11-14 04:11:43 -05:00
parent c0320dd3ab
commit a081247fdc
14 changed files with 168 additions and 40 deletions

View file

@ -108,6 +108,15 @@ export default class Chat extends Module {
}
});
this.settings.add('tooltip.link-interaction', {
default: true,
ui: {
path: 'Chat > Tooltips >> Links',
title: 'Allow interaction with supported link tooltips.',
component: 'setting-check-box'
}
});
this.settings.add('tooltip.link-images', {
default: true,
requires: ['tooltip.images'],
@ -380,8 +389,13 @@ export default class Chat extends Module {
if ( tokenizer.priority == null )
tokenizer.priority = 0;
if ( tokenizer.tooltip )
this.tooltips.types[type] = tokenizer.tooltip.bind(this);
if ( tokenizer.tooltip ) {
const tt = tokenizer.tooltip;
const tk = this.tooltips.types[type] = tt.bind(this);
for(const i of ['interactive', 'delayShow', 'delayHide'])
tk[i] = typeof tt[i] === 'function' ? tt[i].bind(this) : tt[i];
}
this.__tokenizers.push(tokenizer);
this.__tokenizers.sort((a, b) => {
@ -450,7 +464,9 @@ export default class Chat extends Module {
let res;
if ( type === 'text' )
res = token.text;
res = e('span', {
'data-a-target': 'chat-message-text'
}, token.text);
else if ( tk )
res = tk.render.call(this, token, e);

View file

@ -36,7 +36,10 @@ export default class Room extends EventEmitter {
this.users = [];
this.user_ids = [];
this.load_data();
if ( this.login ) {
this.manager.socket.subscribe(`room.${login}`);
this.load_data();
}
}
destroy() {
@ -44,6 +47,8 @@ export default class Room extends EventEmitter {
this._destroy_timer = null;
this.destroyed = true;
this.manager.socket.unsubscribe(`room.${this.login}`);
this.style.destroy();
if ( this.manager.room_ids[this.id] === this )

View file

@ -140,6 +140,21 @@ export const Links = {
}
}
Links.tooltip.interactive = function(target, tip) {
if ( ! this.context.get('tooltip.rich-links') || ! this.context.get('tooltip.link-interaction') || target.dataset.isMail === 'true' )
return false;
const info = this.get_link_info(target.dataset.url, true);
return info && info.interactive;
};
Links.tooltip.delayHide = function(target, tip) {
if ( ! this.context.get('tooltip.rich-links') || ! this.context.get('tooltip.link-interaction') || target.dataset.isMail === 'true' )
return 0;
return 64;
};
// ============================================================================
// Rich Content

View file

@ -61,11 +61,16 @@ export default class Metadata extends Module {
setup() {
const socket = this.resolve('socket'),
query = this.resolve('site.apollo').getQuery('ChannelPage_ChannelInfoBar_User'),
result = query.lastResult,
created_at = get('data.user.stream.createdAt', result);
result = query && query.lastResult,
created_at = result && get('data.user.stream.createdAt', result);
if ( ! query )
return {};
if ( created_at === undefined && ! query._ffz_refetched ) {
query._ffz_refetched = true;
if ( result )
result.stale = true;
query.refetch();
return {};
}

View file

@ -5,6 +5,7 @@
// ============================================================================
import {createElement as e} from 'utilities/dom';
import {has, maybe_call} from 'utilities/object';
import Tooltip from 'utilities/tooltip';
import Module from 'utilities/module';
@ -65,14 +66,47 @@ export default class TooltipProvider extends Module {
onEnable() {
this.tips = new Tooltip('[data-reactroot]', 'ffz-tooltip', {
html: true,
delayHide: this.checkDelayHide.bind(this),
delayShow: this.checkDelayShow.bind(this),
content: this.process.bind(this),
interactive: this.checkInteractive.bind(this),
popper: {
placement: 'top'
}
});
}
process(target, tip) { //eslint-disable-line class-methods-use-this
checkDelayShow(target, tip) {
const type = target.dataset.tooltipType,
handler = this.types[type];
if ( has(handler, 'delayShow') )
return maybe_call(handler.delayShow, null, target, tip);
return 0;
}
checkDelayHide(target, tip) {
const type = target.dataset.tooltipType,
handler = this.types[type];
if ( has(handler, 'delayHide') )
return maybe_call(handler.delayHide, null, target, tip);
return 0;
}
checkInteractive(target, tip) {
const type = target.dataset.tooltipType,
handler = this.types[type];
if ( has(handler, 'interactive') )
return maybe_call(handler.interactive, null, target, tip);
return false;
}
process(target, tip) {
const type = target.dataset.tooltipType,
handler = this.types[type];