1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-07-01 00:28:30 +00:00

Abandon all hope of useful commit messages, ye who enter here.

This commit is contained in:
SirStendec 2015-07-13 21:52:44 -04:00
parent a7e7f7498d
commit 2bc2b7003b
26 changed files with 3271 additions and 430 deletions

View file

@ -1,16 +1,6 @@
var FFZ = window.FrankerFaceZ,
utils = require('../utils'),
constants = require('../constants'),
format_unread = function(count) {
if ( count < 1 )
return "";
else if ( count >= 99 )
return "99+";
return "" + count;
};
constants = require('../constants');
// --------------------
@ -22,7 +12,7 @@ FFZ.settings_info.swap_sidebars = {
type: "boolean",
value: false,
category: "Miscellaneous",
category: "Appearance",
no_bttv: true,
name: "Swap Sidebar Positions",
@ -39,7 +29,7 @@ FFZ.settings_info.minimal_chat = {
type: "boolean",
value: false,
category: "Chat",
category: "Chat Appearance",
name: "Minimalistic Chat",
help: "Hide all of the chat user interface, only showing messages and an input box.",
@ -52,6 +42,9 @@ FFZ.settings_info.minimal_chat = {
f._roomv && f._roomv.get('stuckToBottom') && f._roomv._scrollToBottom();
},0);
}
if ( this._chatv && this._chatv.get('controller.showList') )
this._chatv.set('controller.showList', false);
}
};
@ -62,7 +55,7 @@ FFZ.settings_info.prevent_clear = {
no_bttv: true,
category: "Chat Moderation",
category: "Chat Filtering",
name: "Show Deleted Messages",
help: "Fade deleted messages instead of replacing them, and prevent chat from being cleared.",
@ -92,7 +85,7 @@ FFZ.settings_info.chat_history = {
value: true,
visible: false,
category: "Chat",
category: "Chat Appearance",
name: "Chat History <span>Alpha</span>",
help: "Load previous chat messages when loading a chat room so you can see what people have been talking about. <b>This currently only works in a handful of channels due to server capacity.</b>",
};
@ -103,7 +96,7 @@ FFZ.settings_info.group_tabs = {
no_bttv: true,
category: "Chat",
category: "Chat Moderation",
name: "Chat Room Tabs <span>Beta</span>",
help: "Enhanced UI for switching the current chat room and noticing new messages.",
@ -121,14 +114,13 @@ FFZ.settings_info.group_tabs = {
FFZ.settings_info.pinned_rooms = {
type: "button",
value: [],
category: "Chat",
visible: false,
};
name: "Pinned Chat Rooms",
help: "Set a list of channels that should always be available in chat."
FFZ.settings_info.visible_rooms = {
value: [],
visible: false,
};
@ -151,8 +143,13 @@ FFZ.prototype.setup_chatview = function() {
if ( Chat ) {
Chat.reopen({
ffzUpdateChannels: function() {
if ( f.settings.group_tabs && f._chatv )
if ( ! f._chatv )
return;
f._chatv.ffzRebuildMenu();
if ( f.settings.group_tabs )
f._chatv.ffzRebuildTabs();
}.observes("currentChannelRoom", "connectedPrivateGroupRooms"),
removeCurrentChannelRoom: function() {
@ -160,14 +157,15 @@ FFZ.prototype.setup_chatview = function() {
return this._super();
var room = this.get("currentChannelRoom"),
room_id = room && room.get('id');
room_id = room && room.get('id'),
user = f.get_user();
if ( ! f.settings.pinned_rooms || f.settings.pinned_rooms.indexOf(room_id) === -1 ) {
// We can actually destroy it.
if ( room === this.get("currentRoom") )
this.blurRoom();
if ( room )
// Don't destroy it if it's the user's room.
if ( room && user && user.login === room_id )
room.destroy();
}
@ -272,8 +270,10 @@ FFZ.prototype._modify_cview = function(view) {
if ( !f.has_bttv && f.settings.group_tabs )
this.ffzEnableTabs();
this.ffzRebuildMenu();
setTimeout(function() {
if ( f.settings.group_tabs && f._chatv._ffz_tabs )
if ( f.settings.group_tabs && f._chatv && f._chatv._ffz_tabs )
f._chatv.$('.chat-room').css('top', f._chatv._ffz_tabs.offsetHeight + "px");
var controller = f._chatv.get('controller');
@ -295,14 +295,28 @@ FFZ.prototype._modify_cview = function(view) {
try {
f.update_ui_link();
if ( !f.has_bttv && f.settings.group_tabs && this._ffz_tabs ) {
var room = this.get('controller.currentRoom');
room && room.resetUnreadCount();
var room = this.get('controller.currentRoom'), rows;
room && room.resetUnreadCount();
if ( this._ffz_chan_table ) {
rows = jQuery(this._ffz_chan_table);
rows.children('.ffz-room-row').removeClass('active');
if ( room )
rows.children('.ffz-room-row[data-room="' + room.get('id') + '"]').addClass('active').children('span').text('');
}
if ( this._ffz_group_table ) {
rows = jQuery(this._ffz_group_table);
rows.children('.ffz-room-row').removeClass('active');
if ( room )
rows.children('.ffz-room-row[data-room="' + room.get('id') + '"]').addClass('active').children('span').text('');
}
if ( !f.has_bttv && f.settings.group_tabs && this._ffz_tabs ) {
var tabs = jQuery(this._ffz_tabs);
tabs.children('.ffz-chat-tab').removeClass('active');
if ( room )
tabs.children('.ffz-chat-tab[data-room="' + room.get('id') + '"]').removeClass('tab-mentioned').addClass('active').children('span').text('');
tabs.children('.ffz-chat-tab[data-room="' + room.get('id') + '"]').removeClass('tab-mentioned').removeClass('hidden').addClass('active').children('span').text('');
// Invite Link
var can_invite = room && room.get('canInvite');
@ -318,6 +332,214 @@ FFZ.prototype._modify_cview = function(view) {
}
}),
// Better Menu
ffzRebuildMenu: function() {
return;
var el = this.get('element'),
room_list = el && el.querySelector('.chat-rooms .tse-content');
if ( ! room_list )
return;
if ( ! room_list.classList.contains('ffz-room-list') ) {
room_list.classList.add('ffz-room-list');
// Find the Pending Invitations
var headers = room_list.querySelectorAll('.list-header'),
hdr = headers.length ? headers[headers.length-1] : undefined;
if ( hdr ) {
hdr.classList.add('ffz');
if ( hdr.nextSibling && hdr.nextSibling.classList )
hdr.nextSibling.classList.add('ffz');
}
}
// Channel Table
var t = this,
chan_table = this._ffz_chan_table || room_list.querySelector('#ffz-channel-table tbody');
if ( ! chan_table ) {
var tbl = document.createElement('table');
tbl.setAttribute('cellspacing', 0);
tbl.id = 'ffz-channel-table';
tbl.className = 'ffz';
tbl.innerHTML = '<thead><tr><th colspan="2">Channels</th><th class="ffz-row-switch">Join</th><th class="ffz-row-switch">Pin</th></tr></thead><tbody></tbody>';
room_list.insertBefore(tbl, room_list.firstChild);
chan_table = this._ffz_chan_table = tbl.querySelector('tbody');
}
chan_table.innerHTML = '';
// Current Channel
var room = this.get('controller.currentChannelRoom'), row;
if ( room ) {
row = this.ffzBuildRow(this, room, true);
row && chan_table.appendChild(row);
}
// Host Target
if ( this._ffz_host_room ) {
row = this.ffzBuildRow(this, this._ffz_host_room, false, true);
row && chan_table.appendChild(row);
}
// Pinned Rooms
for(var i=0; i < f.settings.pinned_rooms.length; i++) {
var room_id = f.settings.pinned_rooms[i];
if ( room && room.get('id') !== room_id && this._ffz_host !== room_id && f.rooms[room_id] && f.rooms[room_id].room ) {
row = this.ffzBuildRow(this, f.rooms[room_id].room);
row && chan_table.appendChild(row);
}
}
// Group Chat Table
var group_table = this._ffz_group_table || room_list.querySelector('#ffz-group-table tbody');
if ( ! group_table ) {
var tbl = document.createElement('table');
tbl.setAttribute('cellspacing', 0);
tbl.id = 'ffz-group-table';
tbl.className = 'ffz';
tbl.innerHTML = '<thead><tr><th colspan="2">Group Chats</th><th class="ffz-row-switch">Pin</th></tr></thead><tbody></tbody>';
var before = room_list.querySelector('#ffz-channel-table');
room_list.insertBefore(tbl, before.nextSibling);
group_table = this._ffz_group_table = tbl.querySelector('tbody');
}
group_table.innerHTML = '';
_.each(this.get('controller.connectedPrivateGroupRooms'), function(room) {
var row = t.ffzBuildRow(t, room);
row && group_table && group_table.appendChild(row);
});
// Change Create Tooltip
var create_btn = el.querySelector('.button.create');
if ( create_btn )
create_btn.title = 'Create a Group Room';
},
ffzBuildRow: function(view, room, current_channel, host_channel) {
var row = document.createElement('tr'),
icon = document.createElement('td'),
name_el = document.createElement('td'),
btn,
toggle_pinned = document.createElement('td'),
toggle_visible = document.createElement('td'),
group = room.get('isGroupRoom'),
current = room === view.get('controller.currentRoom'),
//unread = format_unread(current ? 0 : room.get('unreadCount')),
name = room.get('tmiRoom.displayName') || (group ? room.get('tmiRoom.name') : FFZ.get_capitalization(room.get('id'), function(name) {
f.log("Name for Row: " + name);
//unread = format_unread(current ? 0 : room.get('unreadCount'));
name_el.innerHTML = utils.sanitize(name);
}));
name_el.className = 'ffz-room';
name_el.innerHTML = utils.sanitize(name);
if ( current_channel ) {
icon.innerHTML = constants.CAMERA;
icon.title = name_el.title = "Current Channel";
icon.className = name_el.className = 'tooltip';
} else if ( host_channel ) {
icon.innerHTML = constants.EYE;
icon.title = name_el.title = "Hosted Channel";
icon.className = name_el.className = 'tooltip';
}
toggle_pinned.className = toggle_visible.className = 'ffz-row-switch';
toggle_pinned.innerHTML = '<a class="switch' + (f.settings.pinned_rooms.indexOf(room.get('id')) !== -1 ? ' active' : '') + '"><span></span></a>';
toggle_visible.innerHTML = '<a class="switch' + (f.settings.visible_rooms.indexOf(room.get('id')) !== -1 ? ' active' : '') + '"><span></span></a>';
row.setAttribute('data-room', room.get('id'));
row.className = 'ffz-room-row';
row.classList.toggle('current-channel', current_channel);
row.classList.toggle('host-channel', host_channel);
row.classList.toggle('group-chat', group);
row.classList.toggle('active', current);
row.appendChild(icon);
row.appendChild(name_el);
if ( ! group ) {
row.appendChild(toggle_pinned);
btn = toggle_pinned.querySelector('a.switch');
btn.addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation && e.stopPropagation();
var room_id = room.get('id'),
is_pinned = f.settings.pinned_rooms.indexOf(room_id) !== -1;
if ( is_pinned )
f._leave_room(room_id);
else
f._join_room(room_id);
this.classList.toggle('active', !is_pinned);
});
} else {
btn = document.createElement('a');
btn.className = 'leave-chat tooltip';
btn.innerHTML = constants.CLOSE;
btn.title = 'Leave Group';
name_el.appendChild(btn);
btn.addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation && e.stopPropagation();
if ( ! confirm('Are you sure you want to leave the group room "' + name + '"?') )
return;
room.get('isGroupRoom') && room.del();
});
}
row.appendChild(toggle_visible);
btn = toggle_visible.querySelector('a.switch');
btn.addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation && e.stopPropagation();
var room_id = room.get('id'),
visible_rooms = f.settings.visible_rooms,
is_visible = visible_rooms.indexOf(room_id) !== -1;
if ( is_visible )
visible_rooms.removeObject(room_id);
else
visible_rooms.push(room_id);
f.settings.set('visible_rooms', visible_rooms);
this.classList.toggle('active', !is_visible);
view.ffzRebuildTabs();
});
row.addEventListener('click', function() {
var controller = view.get('controller');
controller.focusRoom(room);
controller.set('showList', false);
});
return row;
},
// Group Tabs~!
ffzEnableTabs: function() {
@ -433,6 +655,8 @@ FFZ.prototype._modify_cview = function(view) {
},
ffzTabUnread: function(room_id) {
// TODO: Update menu.
if ( f.has_bttv || ! f.settings.group_tabs )
return;
@ -446,7 +670,7 @@ FFZ.prototype._modify_cview = function(view) {
room = f.rooms && f.rooms[room_id];
if ( tab && room ) {
var unread = format_unread(room_id === current_id ? 0 : room.room.get('unreadCount'));
var unread = utils.format_unread(room_id === current_id ? 0 : room.room.get('unreadCount'));
tab.querySelector('span').innerHTML = unread;
}
@ -463,7 +687,7 @@ FFZ.prototype._modify_cview = function(view) {
if ( ! room )
continue;
var unread = format_unread(room_id === current_id ? 0 : room.room.get('unreadCount'));
var unread = utils.format_unread(room_id === current_id ? 0 : room.room.get('unreadCount'));
tab.querySelector('span').innerHTML = unread;
}
@ -473,21 +697,24 @@ FFZ.prototype._modify_cview = function(view) {
ffzBuildTab: function(view, room, current_channel, host_channel) {
var tab = document.createElement('span'), name, unread, icon = '',
room_id = room.get('id'),
group = room.get('isGroupRoom'),
current = room === view.get('controller.currentRoom');
current = room === view.get('controller.currentRoom'),
visible = current || f.settings.visible_rooms.indexOf(room_id) !== -1;
tab.setAttribute('data-room', room.id);
tab.className = 'ffz-chat-tab tooltip';
//tab.classList.toggle('hidden', ! visible);
tab.classList.toggle('current-channel', current_channel);
tab.classList.toggle('host-channel', host_channel);
tab.classList.toggle('group-chat', group);
tab.classList.toggle('active', current);
unread = format_unread(current ? 0 : room.get('unreadCount'));
unread = utils.format_unread(current ? 0 : room.get('unreadCount'));
name = room.get('tmiRoom.displayName') || (group ? room.get('tmiRoom.name') : FFZ.get_capitalization(room.get('id'), function(name) {
unread = format_unread(current ? 0 : room.get('unreadCount'));
unread = utils.format_unread(current ? 0 : room.get('unreadCount'));
tab.innerHTML = icon + utils.sanitize(name) + '<span>' + unread + '</span>';
}));
@ -505,7 +732,9 @@ FFZ.prototype._modify_cview = function(view) {
tab.innerHTML = icon + utils.sanitize(name) + '<span>' + unread + '</span>';
tab.addEventListener('click', function() {
view.get('controller').focusRoom(room);
var controller = view.get('controller');
controller.focusRoom(room);
controller.set('showList', false);
});
return tab;
@ -542,14 +771,28 @@ FFZ.prototype._modify_cview = function(view) {
// ----------------------
FFZ.prototype.connect_extra_chat = function() {
var user = this.get_user();
if ( user && user.login ) {
// Make sure we're in the user's room.
if ( ! this.rooms[user.login] || this.rooms[user.login].room ) {
var Room = App.__container__.resolve('model:room'),
r = Room && Room.findOne(user.login);
}
}
if ( this.has_bttv )
return;
for(var i=0; i < this.settings.pinned_rooms.length; i++)
this._join_room(this.settings.pinned_rooms[i], true);
if ( ! this.has_bttv && this._chatv && this.settings.group_tabs )
if ( ! this._chatv )
return;
if ( ! this.has_bttv && this.settings.group_tabs )
this._chatv.ffzRebuildTabs();
this._chatv.ffzRebuildMenu();
}
@ -562,8 +805,11 @@ FFZ.prototype._join_room = function(room_id, no_rebuild) {
}
// Make sure we're not already there.
if ( this.rooms[room_id] && this.rooms[room_id].room )
if ( this.rooms[room_id] && this.rooms[room_id].room ) {
if ( did_join && ! no_rebuild && ! this.has_bttv && this._chatv && this.settings.group_tabs )
this._chatv.ffzRebuildTabs();
return did_join;
}
// Okay, fine. Get it.
var Room = App.__container__.resolve('model:room'),
@ -573,6 +819,9 @@ FFZ.prototype._join_room = function(room_id, no_rebuild) {
if ( ! no_rebuild && ! this.has_bttv && this._chatv && this.settings.group_tabs )
this._chatv.ffzRebuildTabs();
if ( ! no_rebuild && this._chatv )
this._chatv.ffzRebuildMenu();
return did_join;
}
@ -589,7 +838,8 @@ FFZ.prototype._leave_room = function(room_id, no_rebuild) {
return did_leave;
var Chat = App.__container__.lookup('controller:chat'),
r = this.rooms[room_id].room;
r = this.rooms[room_id].room,
user = this.get_user();
if ( ! Chat || Chat.get('currentChannelRoom.id') === room_id || (this._chatv && this._chatv._ffz_host === room_id) )
return did_leave;
@ -597,11 +847,16 @@ FFZ.prototype._leave_room = function(room_id, no_rebuild) {
if ( Chat.get('currentRoom.id') === room_id )
Chat.blurRoom();
r.destroy();
// Don't leave the user's room, but update the UI.
if ( ! user || user.login !== room_id )
r.destroy();
if ( ! no_rebuild && ! this.has_bttv && this._chatv && this.settings.group_tabs )
this._chatv.ffzRebuildTabs();
if ( ! no_rebuild && this._chatv )
this._chatv.ffzRebuildMenu();
return did_leave;
}