1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-07-03 17:48:30 +00:00
* Fixed: Clicking an emote in chat not opening an emote information card.
* API Added: Link information can now have a `refresh` value, which will have the client automatically refresh link data after at a certain time.
This commit is contained in:
SirStendec 2020-08-07 01:32:18 -04:00
parent e87c99f206
commit 6c0c421d0a
7 changed files with 80 additions and 26 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "frankerfacez", "name": "frankerfacez",
"author": "Dan Salvato LLC", "author": "Dan Salvato LLC",
"version": "4.20.26", "version": "4.20.27",
"description": "FrankerFaceZ is a Twitch enhancement suite.", "description": "FrankerFaceZ is a Twitch enhancement suite.",
"license": "Apache-2.0", "license": "Apache-2.0",
"scripts": { "scripts": {

View file

@ -40,7 +40,6 @@ export default {
watch: { watch: {
data() { data() {
this.reset(); this.reset();
this.load();
}, },
events() { events() {
@ -57,6 +56,7 @@ export default {
beforeDestroy() { beforeDestroy() {
this.unlisten(); this.unlisten();
this.clearRefresh();
}, },
methods: { methods: {
@ -64,7 +64,7 @@ export default {
if ( tokenizer ) if ( tokenizer )
this.has_tokenizer = true; this.has_tokenizer = true;
else { else {
tokenizer = await import(/* webpack-chunk-name: 'rich_tokens' */ 'utilities/rich_tokens'); tokenizer = await import(/* webpackChunkName: 'rich_tokens' */ 'utilities/rich_tokens');
this.has_tokenizer = true; this.has_tokenizer = true;
} }
}, },
@ -74,25 +74,33 @@ export default {
if ( this.events?.on ) { if ( this.events?.on ) {
this._es = this.events; this._es = this.events;
this._es.on('chat:update-link-resolver', this.checkRefresh, this); this._es.on('chat:update-link-resolver', this.checkReset, this);
} }
}, },
unlisten() { unlisten() {
if ( this._es?.off ) { if ( this._es?.off ) {
this._es.off('chat:update-link-resolver', this.checkRefresh, this); this._es.off('chat:update-link-resolver', this.checkReset, this);
this._es = null; this._es = null;
} }
}, },
checkRefresh(url) { checkReset(url) {
if ( ! url || (url && url === this.url) ) { if ( ! url || (url && url === this.url) ) {
this.reset(); this.reset();
this.load();
} }
}, },
reset() { clearRefresh() {
if ( this._refresh_timer ) {
clearTimeout(this._refresh_timer);
this._refresh_timer = null;
}
},
reset(refresh = false) {
this.clearRefresh();
this.loaded = false; this.loaded = false;
this.error = null; this.error = null;
this.accent = null; this.accent = null;
@ -102,12 +110,15 @@ export default {
this.urls = null; this.urls = null;
this.allow_media = false; this.allow_media = false;
this.allow_unsafe = false; this.allow_unsafe = false;
this.load(refresh);
}, },
async load() { async load(refresh = false) {
this.clearRefresh();
let data; let data;
try { try {
data = this.data.getData(); data = this.data.getData(refresh);
if ( data instanceof Promise ) { if ( data instanceof Promise ) {
const to_wait = has(this.data, 'timeout') ? this.data.timeout : 1000; const to_wait = has(this.data, 'timeout') ? this.data.timeout : 1000;
if ( to_wait ) if ( to_wait )
@ -137,6 +148,21 @@ export default {
} }
} }
if ( data.refresh ) {
try {
this.clearRefresh();
const then = new Date(data.refresh).getTime(),
delta = then - Date.now();
if ( delta > 0 )
this._refresh_timer = setTimeout(() => this.load(true), delta + (100 * Math.floor(Math.random() * 100)));
} catch(err) {
/* no op */
}
}
this.loaded = true; this.loaded = true;
this.error = data.error; this.error = data.error;
this.accent = data.accent; this.accent = data.accent;

View file

@ -400,14 +400,15 @@ export default class Emotes extends Module {
if ( ! fine ) if ( ! fine )
return; return;
const chat = fine.searchParent(target, n => n.props && n.props.onEmoteClick); const line = fine.searchParent(target, n => n.props && n.props.message),
if ( ! chat || ! chat.props || ! chat.props.message ) opener = fine.searchParent(target, n => n.onShowEmoteCard, 200);
if ( ! line || ! opener )
return; return;
const props = chat.props; opener.onShowEmoteCard({
props.onEmoteClick({ channelID: line.props.channelID || '',
channelID: props.channelID || '', channelLogin: line.props.channelLogin || '',
channelLogin: props.channelLogin || '',
emoteID: ds.id, emoteID: ds.id,
emoteCode: target.alt, emoteCode: target.alt,
sourceID: 'chat', sourceID: 'chat',

View file

@ -1560,11 +1560,11 @@ export default class Chat extends Module {
} }
get_link_info(url, no_promises) { get_link_info(url, no_promises, refresh = false) {
let info = this._link_info[url]; let info = this._link_info[url];
const expires = info && info[1]; const expires = info && info[1];
if ( expires && Date.now() > expires ) if ( (info && info[0] && refresh) || (expires && Date.now() > expires) )
info = this._link_info[url] = null; info = this._link_info[url] = null;
if ( info && info[0] ) if ( info && info[0] )

View file

@ -42,10 +42,10 @@ export const Links = {
url: token.url, url: token.url,
timeout: 0, timeout: 0,
getData: async () => { getData: async (refresh = false) => {
let data; let data;
try { try {
data = await this.get_link_info(token.url); data = await this.get_link_info(token.url, false, refresh);
} catch(err) { } catch(err) {
return { return {
url: token.url, url: token.url,

View file

@ -56,7 +56,7 @@ export const Links = {
show_unsafe = datasetBool(target.dataset.forceUnsafe) ?? this.context.get('tooltip.link-nsfw-images'); show_unsafe = datasetBool(target.dataset.forceUnsafe) ?? this.context.get('tooltip.link-nsfw-images');
return Promise.all([ return Promise.all([
import(/* webpack-chunk-name: 'rich_tokens' */ 'utilities/rich_tokens'), import(/* webpackChunkName: 'rich_tokens' */ 'utilities/rich_tokens'),
this.get_link_info(url) this.get_link_info(url)
]).then(([rich_tokens, data]) => { ]).then(([rich_tokens, data]) => {
if ( ! data || (data.v || 1) > TOOLTIP_VERSION ) if ( ! data || (data.v || 1) > TOOLTIP_VERSION )

View file

@ -25,7 +25,7 @@ export default class RichContent extends Module {
if ( this.has_tokenizer ) if ( this.has_tokenizer )
return; return;
this.tokenizer = await import(/* webpack-chunk-name: 'rich_tokens' */ 'utilities/rich_tokens'); this.tokenizer = await import(/* webpackChunkName: 'rich_tokens' */ 'utilities/rich_tokens');
this.has_tokenizer = true; this.has_tokenizer = true;
return this.tokenizer; return this.tokenizer;
} }
@ -52,9 +52,11 @@ export default class RichContent extends Module {
t.loadTokenizer().then(() => this.setState({...this.state, has_tokenizer: true})); t.loadTokenizer().then(() => this.setState({...this.state, has_tokenizer: true}));
} }
async load() { async load(refresh = false) {
this.clearRefresh();
try { try {
let data = this.props.getData(); let data = this.props.getData(refresh);
if ( data instanceof Promise ) { if ( data instanceof Promise ) {
const to_wait = has(this.props, 'timeout') ? this.props.timeout : 1000; const to_wait = has(this.props, 'timeout') ? this.props.timeout : 1000;
if ( to_wait ) if ( to_wait )
@ -78,6 +80,21 @@ export default class RichContent extends Module {
} }
}; };
if ( data.refresh ) {
try {
this.clearRefresh();
const then = new Date(data.refresh).getTime(),
delta = then - Date.now();
if ( delta > 0 )
this._refresh_timer = setTimeout(() => this.load(true), delta + (100 * Math.floor(Math.random() * 100)));
} catch(err) {
/* no op */
}
}
this.setState(Object.assign({ this.setState(Object.assign({
loaded: true, loaded: true,
url: this.props.url, url: this.props.url,
@ -101,17 +118,26 @@ export default class RichContent extends Module {
} }
} }
clearRefresh() {
if ( this._refresh_timer ) {
clearTimeout(this._refresh_timer);
this._refresh_timer = null;
}
}
checkReload(url) { checkReload(url) {
if ( ! url || (url && this.props.url === url) ) if ( ! url || (url && this.props.url === url) )
this.reload(); this.reload();
} }
reload() { reload(refresh = false) {
this.clearRefresh();
this.setState({ this.setState({
loaded: false, loaded: false,
error: false, error: false,
has_tokenizer: t.has_tokenizer has_tokenizer: t.has_tokenizer
}, () => this.load()); }, () => this.load(refresh));
} }
componentDidMount() { componentDidMount() {
@ -122,6 +148,7 @@ export default class RichContent extends Module {
componentWillUnmount() { componentWillUnmount() {
t.off('chat:update-link-resolver', this.checkReload, this); t.off('chat:update-link-resolver', this.checkReload, this);
this.clearRefresh();
} }
renderCard() { renderCard() {