From 6b796ffa7401c3c8041e333bcd09dfa4e47b03d3 Mon Sep 17 00:00:00 2001
From: Lordmau5
Date: Sat, 24 Aug 2019 00:02:30 +0200
Subject: [PATCH] Fix hosting menu (#635)
This feature has been broken ever since **JUNE 2018**.
There have been enough changes on Twitch's end to support this more easily now, so that's good.
Also fixed some potentially longer standing bug with the hosts map not being cleared when the query is being re-ran, causing some hosts not to show up
---
.../modules/directory/following.jsx | 103 +++++++-----------
.../modules/directory/index.jsx | 3 +-
2 files changed, 40 insertions(+), 66 deletions(-)
diff --git a/src/sites/twitch-twilight/modules/directory/following.jsx b/src/sites/twitch-twilight/modules/directory/following.jsx
index b58100aa..86832efe 100644
--- a/src/sites/twitch-twilight/modules/directory/following.jsx
+++ b/src/sites/twitch-twilight/modules/directory/following.jsx
@@ -9,6 +9,7 @@ import {createElement} from 'utilities/dom';
import {get} from 'utilities/object';
import Popper from 'popper.js';
+import {makeReference} from 'utilities/tooltip';
import FOLLOWED_INDEX from './followed_index.gql';
import FOLLOWED_HOSTS from './followed_hosts.gql';
@@ -123,8 +124,8 @@ export default class Following extends SiteModule {
if ( ! edges || ! edges.length )
return res;
- const hosts = {},
- out = [];
+ this.hosts = new WeakMap();
+ const out = [];
for(const edge of edges) {
if ( ! edge )
@@ -138,7 +139,7 @@ export default class Following extends SiteModule {
continue;
if ( ! stream.viewersCount ) {
- if ( ! do_grouping || ! hosts[hosted.login] )
+ if ( ! do_grouping || ! this.hosts[hosted.login] )
out.push(edge);
continue;
}
@@ -150,13 +151,13 @@ export default class Following extends SiteModule {
//store.game = stream.game;
if ( do_grouping ) {
- const host_nodes = hosts[hosted.login];
+ const host_nodes = this.hosts[hosted.login];
if ( host_nodes ) {
host_nodes.push(node);
this.hosts.set(store, host_nodes);
} else {
- this.hosts.set(store, hosts[hosted.login] = [node]);
+ this.hosts.set(store, this.hosts[hosted.login] = [node]);
out.push(edge);
}
@@ -224,7 +225,7 @@ export default class Following extends SiteModule {
}
}
- showHostMenu(inst, { channels }, event) {
+ showHostMenu(inst, channels, event) {
if (this.settings.get('directory.following.host-menus') === 0 || this.settings.get('directory.following.host-menus') === 1 && channels.length < 2) return;
event.preventDefault();
@@ -234,7 +235,6 @@ export default class Following extends SiteModule {
this.hostMenu && this.hostMenu.remove();
- const hostData = this.hosts[inst.props.channelName];
const simplebarContentChildren = [];
// Hosted Channel Header
@@ -244,16 +244,16 @@ export default class Following extends SiteModule {
// Hosted Channel Content
simplebarContentChildren.push( this.parent.hijackUserClick(e, hostData.channel, this.destroyHostMenu.bind(this))} // eslint-disable-line react/jsx-no-bind
+ class="tw-block tw-border-radius-small tw-full-width tw-interactable tw-interactable--alpha tw-interactive"
+ href={`/${inst.props.channelLogin}`}
+ onClick={e => this.parent.hijackUserClick(e, inst.props.channelLogin, this.destroyHostMenu.bind(this))} // eslint-disable-line react/jsx-no-bind
>
-

+
- {inst.props.channelName}
+ {inst.props.channelDisplayName}
);
@@ -264,32 +264,27 @@ export default class Following extends SiteModule {
);
// Hosting Channels Content
- for (let i = 0; i < hostData.nodes.length; i++) {
- const node = hostData.nodes[i];
+ for (const channel of channels) {
simplebarContentChildren.push( this.parent.hijackUserClick(e, node.login, this.destroyHostMenu.bind(this))} // eslint-disable-line react/jsx-no-bind
+ class="tw-block tw-border-radius-small tw-full-width tw-interactable tw-interactable--alpha tw-interactive"
+ href={`/${channel.login}`}
+ onClick={e => this.parent.hijackUserClick(e, channel.login, this.destroyHostMenu.bind(this))} // eslint-disable-line react/jsx-no-bind
>
-

+
- {node.displayName}
+ {channel.displayName}
);
}
this.hostMenu = (