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

The Last Ever v3 Commit (Hopefully)

This commit is contained in:
SirStendec 2017-11-13 01:13:52 -05:00
parent e0bad1dc10
commit c2688646af
16 changed files with 396 additions and 121 deletions

View file

@ -26,12 +26,26 @@ FFZ.prototype.setup_dashboard = function() {
if ( location.search === '?standalone' )
utils.toggle_cls('ffz-minimal-dashboard')(true);
this.update_views('component:dashboards/live-widget', this.modify_dashboard_widget);
this.try_modify_dashboard();
//this.update_views('component:dashboards/live/stream-stats', this.modify_dashboard_stats);
//this.update_views('component:dashboards/live/stream-health', this.modify_dashboard_health);
}
FFZ.prototype.try_modify_dashboard = function() {
if ( this._dashboard_modified )
return;
var loaded = window.features && window.features.includes('dashboard');
if ( ! loaded )
return this.log('Dashboard still not loaded.');
this._dashboard_modified = true;
this.update_views('component:dashboards/live-widget', this.modify_dashboard_widget);
}
FFZ.prototype.modify_dashboard_widget = function(component) {
var f = this;
utils.ember_reopen_view(component, {

View file

@ -659,8 +659,16 @@ FFZ.settings_info.chat_font_family = {
FFZ.settings_info.recent_highlights = {
type: "boolean",
value: false,
type: "select",
options: {
0: "Disabled",
1: "Moderator Promoted",
2: "Mentioned",
3: "Both"
},
value: 0,
process_value: utils.process_int(0, 0, 3),
category: "Chat Appearance",
no_bttv: true,
@ -1183,11 +1191,33 @@ FFZ.prototype._modify_chat_line = function(component, is_vod) {
}
else if ( msg_type === 'raid' || msg_type === 'unraid' )
// TODO: This.
return '';
else if ( msg_type === 'raid' || msg_type === 'unraid' ) {
var Intl = utils.ember_lookup('service:intl');
else
if ( Intl ) {
if ( msg_type === 'raid' ) {
var channel = this.ffzGetChannel(),
data = channel.loaded ? channel.data : {display_name: tags['msg-param-login']};
out = '<span class="flex align-items-center">' +
(data.logo ? '<div class="square-3">' +
'<img src="' + utils.quote_attr(data.logo) + '" alt="' + utils.quote_san(data.display_name) + '">' +
'</div>' : '') +
'<div class="mg-l-1">' +
Intl.t('chat.raids.incomingRaid', {
displayName: data.display_name,
viewerCount: tags['msg-param-viewerCount'],
htmlSafe: true
}) +
'</div>' +
'</span>';
} else
out = Intl.t('chat.raids.cancelRaid');
} else
out = utils.sanitize(this.get('systemMsg'));
} else
out = utils.sanitize(this.get('systemMsg'));
return out ? '<div class="system-msg">' + out + '</div>' : '';
@ -1210,11 +1240,51 @@ FFZ.prototype._modify_chat_line = function(component, is_vod) {
return out;
},
ffzUpdateSystemMessage: function() {
var msg = this.buildSystemMessageHTML(),
el = this.$('.system-msg')[0];
if ( el )
el.outerHTML = msg;
else if ( msg ) {
el = this.$('.indicator')[0];
el.outerHTML = '<div class="indicator"></div>' + msg;
}
},
ffzUpdateRichContent: function() {
if ( this.get('msgObject.tags.content') )
this.$(".ffz-rich-content").html(this.buildRichContentHTML());
},
ffzGetChannel: function() {
var login = this.get('msgObject.tags.msg-param-login');
if ( ! login )
return {
loaded: true,
errored: true
};
var t = this,
channel_info = this._channel_info = this._channel_info || {};
if ( ! channel_info._started ) {
channel_info._started = true;
utils.api.get('channels/' + login, {}, {version: 3})
.done(function(data) {
channel_info.data = data;
channel_info.loaded = true;
t.isDestroyed || t.ffzUpdateSystemMessage();
}).fail(function(data) {
channel_info.loaded = true;
channel_info.errored = true;
t.isDestroyed || t.ffzUpdateSystemMessage();
});
}
return channel_info;
},
ffzGetContent: function(provider_key, info) {
info = info || this.get('msgObject.tags.content.' + provider_key + '.firstObject')
if ( ! info || ! info.data )

View file

@ -283,7 +283,7 @@ FFZ.prototype.modify_twitch_player = function(player) {
// Add an option to the menu to recreate the player.
var t = this,
el = this.$('.player-buttons-right #js-settings')[0],
el = this.$('.player-buttons-right .pl-flex')[0],
container = el && el.parentElement;
if ( el && ! container.querySelector('.ffz-player-reset') ) {

View file

@ -682,7 +682,7 @@ FFZ.prototype.modify_room_component = function(component) {
actions.accommodatePinnedMessage = function(e) {
var el = t.get('element'),
chat = el.querySelector('.js-chat-messages');
chat = el && el.querySelector('.js-chat-messages');
if ( chat )
chat.dataset.pinned_height = e;
@ -2069,41 +2069,121 @@ FFZ.prototype._modify_room = function(room) {
if ( highlight_unread ) {
// API Stuff
f.api_trigger('room-recent-highlights', highlight_messages);
if ( f.settings.recent_highlights && highlight_messages.length ) {
var old_highlights = this.get('ffz_recent_highlights') || [],
raw_remove = old_highlights.length + highlight_messages.length > f.settings.recent_highlight_count ?
Math.max(0, old_highlights.length - f.settings.recent_highlight_count) + highlight_messages.length : 0,
if ( f.settings.recent_highlights > 1 )
this.ffzAddHighlights(highlight_messages);
}
},
to_remove = raw_remove % 2,
trimmed = old_highlights.slice(to_remove, old_highlights.length).concat(highlight_messages),
el = f._roomv && f._roomv.get('ffz_recent_el');
this.set('ffz_recent_highlights', trimmed);
this.incrementProperty('ffz_recent_highlights_unread', highlight_messages.length);
ffzAddHighlights: function(messages) {
if ( f.settings.recent_highlights && messages.length ) {
var old_highlights = this.get('ffz_recent_highlights') || [],
raw_remove = old_highlights.length + messages.length > f.settings.recent_highlight_count ?
Math.max(0, old_highlights.length - f.settings.recent_highlight_count) + messages.length : 0,
if ( el && f._roomv.get('room') === this ) {
var was_at_bottom = el.scrollTop >= (el.scrollHeight - el.clientHeight);
to_remove = raw_remove % 2,
trimmed = old_highlights.slice(to_remove, old_highlights.length).concat(messages),
el = f._roomv && f._roomv.get('ffz_recent_el');
while( el.childElementCount && to_remove-- )
el.removeChild(el.firstElementChild);
this.set('ffz_recent_highlights', trimmed);
this.incrementProperty('ffz_recent_highlights_unread', messages.length);
for(var i=0; i < highlight_messages.length; i++)
el.appendChild(f._build_mod_card_history(highlight_messages[i], null, true));
if ( el && f._roomv.get('room') === this ) {
var was_at_bottom = el.scrollTop >= (el.scrollHeight - el.clientHeight);
if ( was_at_bottom )
el.scrollTop = el.scrollHeight;
while( el.childElementCount && to_remove-- )
el.removeChild(el.firstElementChild);
if ( el.dataset.docked ) {
el = f._roomv.get('ffz_recent_count_el');
if ( el )
el.textContent = utils.format_unread(this.get('ffz_recent_highlights_unread'));
}
for(var i=0; i < messages.length; i++)
el.appendChild(f._build_mod_card_history(messages[i], null, true));
if ( was_at_bottom )
el.scrollTop = el.scrollHeight;
if ( el.dataset.docked ) {
el = f._roomv.get('ffz_recent_count_el');
if ( el )
el.textContent = utils.format_unread(this.get('ffz_recent_highlights_unread'));
}
}
}
},
ffzHighlightMessage: function(msg_id) {
var message = this.ffz_ids && this.ffz_ids[msg_id];
if ( ! f.settings.recent_highlights || ! message )
return;
var highlights = this.get('ffz_recent_highlights') || [],
high_len = highlights.length,
posted = message.date,
insert_before = -1;
for(var i=0; i < high_len; i++) {
var msg = highlights[i];
if ( msg.tags && msg.tags.id === msg_id )
return;
if ( insert_before === -1 && posted <= msg.date )
insert_before = i;
}
var raw_remove = high_len + 1 > f.settings.recent_highlight_count ?
Math.max(0, high_len - f.settings.recent_highlight_count) + 1 : 0,
to_remove = raw_remove % 2,
el = f._roomv && f._roomv.get('ffz_recent_el');
console.log('msg', message);
console.log('count', high_len);
console.log('to_remove', to_remove);
console.log('insert_before', insert_before);
console.log('msgs', highlights.slice(0));
// If we're going to add the element only to remove it, leave.
if ( to_remove && insert_before === 0 )
return;
if ( to_remove ) {
highlights.splice(0, to_remove);
insert_before -= to_remove;
high_len = highlights.length;
}
if ( insert_before === -1 )
highlights.push(message);
else
highlights.splice(insert_before, 0, message);
this.set('ffz_recent_highlights', highlights);
this.incrementProperty('ffz_recent_highlights_unread', 1);
if ( ! el || f._roomv.get('room') !== this )
return;
var was_at_bottom = el.scrollTop >= (el.scrollHeight - el.clientHeight);
while ( el.childElementCount && to_remove-- )
el.removeChild(el.firstElementChild);
var msg_line = f._build_mod_card_history(message, null, true)
if ( insert_before === -1 )
el.appendChild(msg_line);
else
el.insertBefore(msg_line, el.children[insert_before]);
if ( was_at_bottom )
el.scrollTop = el.scrollHeight;
if ( el.dataset.docked ) {
el = f._roomv.get('ffz_recent_count_el');
if ( el )
el.textContent = utils.format_unread(this.get('ffz_recent_highlights_unread'));
}
},
ffzSchedulePendingFlush: function(now) {
// Instead of just blindly looping every x seconds, we want to calculate the time until
// the next message should be displayed, and then set the timeout for that. We'll
@ -2786,4 +2866,22 @@ FFZ.prototype._modify_room = function(room) {
this.updateWait(0);
}.observes('slowMode')
});
}
// ---------------
// Socket Stuff
// ---------------
FFZ.ws_commands.promote_message = function(data) {
var channel = data[0],
user = data[1],
msg_id = data[2],
ffz_room = this.rooms && this.rooms[channel],
room = ffz_room && ffz_room.room,
setting = this.settings.recent_highlights;
if ( room && (setting === 1 || setting === 3) )
room.ffzHighlightMessage(msg_id, user);
}

View file

@ -26,6 +26,7 @@ FFZ.prototype.setup_router = function() {
// If we're coming from a page without app-main, make sure we install the
// scroll listener.
f.fix_scroll();
f.try_modify_dashboard();
try {
document.body.setAttribute('data-current-path', App.get('currentPath'));