2015-06-05 03:59:28 -04:00
var FFZ = window . FrankerFaceZ ,
utils = require ( '../utils' ) ,
2015-07-13 21:52:44 -04:00
constants = require ( '../constants' ) ;
2015-06-05 03:59:28 -04:00
// --------------------
// Settings
// --------------------
2015-08-14 13:21:57 -04:00
FFZ . basic _settings . delayed _chat = {
type : "select" ,
options : {
0 : "No Delay" ,
300 : "Minor (Bot Moderation; 0.3s)" ,
1200 : "Normal (Human Moderation; 1.2s)" ,
2016-03-23 19:28:22 -04:00
5000 : "Large (Spoiler Removal / Really Slow Mods; 5s)" ,
10000 : "Extra Large (10s)" ,
15000 : "Extremely Large (15s)" ,
20000 : "Mods Asleep; Delay Chat (20s)" ,
30000 : "Half a Minute (30s)" ,
60000 : "Why??? (1m)"
2015-08-14 13:21:57 -04:00
} ,
2015-08-09 23:32:29 -07:00
category : "Chat" ,
2015-08-21 19:00:48 -04:00
no _bttv : true ,
2015-08-09 23:32:29 -07:00
2015-08-21 19:00:48 -04:00
name : "Delay and Filter Chat" ,
2015-08-14 13:21:57 -04:00
help : "Delay the appearance of chat messages to allow time for moderation and completely hide removed messages." ,
2015-08-09 23:32:29 -07:00
get : function ( ) {
2015-08-14 13:21:57 -04:00
if ( ! this . settings . remove _deleted || ! this . settings . remove _bot _ban _notices )
return 0 ;
return this . settings . chat _delay ;
2015-08-09 23:32:29 -07:00
} ,
set : function ( val ) {
2015-08-14 13:21:57 -04:00
val = + val ;
this . settings . set ( 'remove_deleted' , val !== 0 ) ;
this . settings . set ( 'remove_bot_ban_notices' , val !== 0 ) ;
this . settings . set ( 'chat_delay' , val ) ;
2015-08-09 23:32:29 -07:00
}
} ;
2015-07-06 00:09:21 -04:00
FFZ . settings _info . minimal _chat = {
2015-10-17 18:05:44 -04:00
type : "select" ,
options : {
0 : "Disabled" ,
1 : "No Heading" ,
2 : "Minimalistic Input" ,
3 : "All"
} ,
value : 0 ,
2015-07-04 17:06:36 -04:00
2015-07-13 21:52:44 -04:00
category : "Chat Appearance" ,
2015-08-04 01:43:08 -04:00
2015-07-04 17:06:36 -04:00
name : "Minimalistic Chat" ,
help : "Hide all of the chat user interface, only showing messages and an input box." ,
2015-10-17 18:05:44 -04:00
process _value : function ( val ) {
if ( val === false )
return 0 ;
else if ( val === true )
return 3 ;
else if ( typeof val === "string" )
return parseInt ( val ) || 0 ;
return val ;
} ,
2015-07-04 17:06:36 -04:00
on _update : function ( val ) {
2015-10-17 18:05:44 -04:00
document . body . classList . toggle ( "ffz-minimal-chat-head" , val === 1 || val === 3 ) ;
document . body . classList . toggle ( "ffz-minimal-chat-input" , val > 1 ) ;
2015-07-04 17:06:36 -04:00
if ( this . settings . group _tabs && this . _chatv && this . _chatv . _ffz _tabs ) {
var f = this ;
setTimeout ( function ( ) {
f . _chatv && f . _chatv . $ ( '.chat-room' ) . css ( 'top' , f . _chatv . _ffz _tabs . offsetHeight + "px" ) ;
2015-07-06 00:09:21 -04:00
f . _roomv && f . _roomv . get ( 'stuckToBottom' ) && f . _roomv . _scrollToBottom ( ) ;
2015-07-04 17:06:36 -04:00
} , 0 ) ;
}
2015-08-04 01:43:08 -04:00
2015-10-17 18:05:44 -04:00
if ( ( val === 1 || val === 3 ) && this . _chatv && this . _chatv . get ( 'controller.showList' ) )
2015-07-13 21:52:44 -04:00
this . _chatv . set ( 'controller.showList' , false ) ;
2015-08-04 01:43:08 -04:00
2015-07-29 01:03:10 -04:00
// Remove the style if we have it.
2015-10-17 18:05:44 -04:00
if ( ! ( val > 1 ) && this . _chat _style ) {
2015-07-29 01:03:10 -04:00
if ( this . _inputv ) {
if ( this . _inputv . _ffz _minimal _style )
this . _inputv . _ffz _minimal _style . innerHTML = '' ;
2015-08-04 01:43:08 -04:00
2015-07-29 01:03:10 -04:00
this . _inputv . _ffz _last _height = undefined ;
}
2015-08-04 01:43:08 -04:00
2015-07-29 01:03:10 -04:00
utils . update _css ( this . _chat _style , "input_height" , '' ) ;
this . _roomv && this . _roomv . get ( 'stuckToBottom' ) && this . _roomv . _scrollToBottom ( ) ;
2015-08-04 01:43:08 -04:00
2015-10-17 18:05:44 -04:00
} else if ( val > 1 && this . _inputv )
2015-07-29 01:03:10 -04:00
this . _inputv . ffzResizeInput ( ) ;
}
} ;
2015-11-01 17:28:19 -05:00
FFZ . settings _info . chat _batching = {
type : "select" ,
options : {
0 : "No Batching" ,
250 : "Minor (0.25s)" ,
500 : "Normal (0.5s)" ,
750 : "Large (0.75s)" ,
1000 : "Extreme (1s)"
} ,
value : 0 ,
category : "Chat Appearance" ,
no _bttv : true ,
name : "Chat Message Batching" ,
help : "Display chat messages in batches to improve performance in <em>extremely</em> fast chats." ,
process _value : function ( val ) {
if ( typeof val === "string" )
return parseInt ( val ) || 0 ;
return val ;
} ,
on _update : function ( val ) {
if ( this . _roomv )
this . _roomv . ffzUpdateStatus ( ) ;
}
} ;
2015-08-09 23:32:29 -07:00
FFZ . settings _info . chat _delay = {
type : "select" ,
options : {
0 : "No Delay" ,
2015-08-14 13:21:57 -04:00
300 : "Minor (Bot Moderation; 0.3s)" ,
1200 : "Normal (Human Moderation; 1.2s)" ,
2016-03-23 19:28:22 -04:00
5000 : "Large (Spoiler Removal / Really Slow Mods; 5s)" ,
10000 : "Extra Large (10s)" ,
15000 : "Extremely Large (15s)" ,
20000 : "Mods Asleep; Delay Chat (20s)" ,
30000 : "Half a Minute (30s)" ,
60000 : "Why??? (1m)"
2015-08-09 23:32:29 -07:00
} ,
value : 0 ,
category : "Chat Appearance" ,
2015-08-21 19:00:48 -04:00
no _bttv : true ,
2015-08-09 23:32:29 -07:00
name : "Artificial Chat Delay" ,
2015-08-14 13:21:57 -04:00
help : "Delay the appearance of chat messages to allow for moderation before you see them." ,
process _value : function ( val ) {
if ( typeof val === "string" )
return parseInt ( val || "0" ) ;
return val ;
} ,
2015-08-09 23:32:29 -07:00
on _update : function ( val ) {
2015-08-14 13:21:57 -04:00
if ( this . _roomv )
this . _roomv . ffzUpdateStatus ( ) ;
2015-08-09 23:32:29 -07:00
}
} ;
2015-07-29 01:03:10 -04:00
FFZ . settings _info . remove _deleted = {
type : "boolean" ,
value : false ,
no _bttv : true ,
category : "Chat Filtering" ,
name : "Remove Deleted Messages" ,
help : "Remove deleted messages from chat entirely rather than leaving behind a clickable <deleted message>." ,
on _update : function ( val ) {
if ( this . has _bttv || ! this . rooms || ! val )
return ;
for ( var room _id in this . rooms ) {
var ffz _room = this . rooms [ room _id ] ,
room = ffz _room && ffz _room . room ;
if ( ! room )
continue ;
var msgs = room . get ( 'messages' ) ,
total = msgs . get ( 'length' ) ,
i = total ,
alternate ;
2015-08-04 01:43:08 -04:00
2015-07-29 01:03:10 -04:00
while ( i -- ) {
var msg = msgs . get ( i ) ;
if ( msg . ffz _deleted || msg . deleted ) {
if ( alternate === undefined )
alternate = msg . ffz _alternate ;
2015-07-31 17:44:20 -04:00
msgs . removeAt ( i ) ;
2015-07-29 01:03:10 -04:00
continue ;
}
2015-08-04 01:43:08 -04:00
2015-07-29 01:03:10 -04:00
if ( alternate === undefined )
alternate = msg . ffz _alternate ;
else {
alternate = ! alternate ;
room . set ( 'messages.' + i + '.ffz_alternate' , alternate ) ;
}
}
}
2015-07-04 17:06:36 -04:00
}
} ;
2015-08-09 23:32:29 -07:00
FFZ . settings _info . remove _bot _ban _notices = {
type : "boolean" ,
value : false ,
2015-08-21 19:00:48 -04:00
no _bttv : true ,
2015-08-09 23:32:29 -07:00
category : "Chat Filtering" ,
name : "Remove Bot Ban Notices" ,
help : "Remove messages from bots announcing who was banned for what reason and for how long." ,
} ;
2015-06-10 18:46:04 -04:00
FFZ . settings _info . prevent _clear = {
type : "boolean" ,
value : false ,
no _bttv : true ,
2015-07-13 21:52:44 -04:00
category : "Chat Filtering" ,
2015-06-10 18:46:04 -04:00
name : "Show Deleted Messages" ,
help : "Fade deleted messages instead of replacing them, and prevent chat from being cleared." ,
on _update : function ( val ) {
if ( this . has _bttv || ! this . rooms )
return ;
for ( var room _id in this . rooms ) {
var ffz _room = this . rooms [ room _id ] ,
room = ffz _room && ffz _room . room ;
if ( ! room )
continue ;
room . get ( "messages" ) . forEach ( function ( s , n ) {
if ( val && ! s . ffz _deleted && s . deleted )
room . set ( "messages." + n + ".deleted" , false ) ;
else if ( s . ffz _deleted && ! val && ! s . deleted )
room . set ( "messages." + n + ".deleted" , true ) ;
} ) ;
}
}
} ;
FFZ . settings _info . chat _history = {
type : "boolean" ,
value : true ,
visible : false ,
2015-07-13 21:52:44 -04:00
category : "Chat Appearance" ,
2015-06-10 18:46:04 -04:00
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>" ,
} ;
2015-06-05 03:59:28 -04:00
FFZ . settings _info . group _tabs = {
2015-12-12 13:28:35 -05:00
type : "select" ,
options : {
0 : "Disabled" ,
1 : "Rooms with Recent Activity" ,
2 : "Rooms with Recent Mentions" ,
3 : "All Rooms"
} ,
value : 0 ,
process _value : function ( val ) {
if ( val === false )
return 0 ;
else if ( val === true )
return 3 ;
else if ( typeof val === "string" )
return parseInt ( val ) || 0 ;
return val ;
} ,
2015-06-05 03:59:28 -04:00
no _bttv : true ,
2015-12-12 13:28:35 -05:00
category : "Chat Appearance" ,
name : "Chat Room Tabs" ,
help : "Display tabs for chat rooms with recent activity at the top of the chat window for more convenient chatting." ,
2015-06-05 03:59:28 -04:00
on _update : function ( val ) {
2015-12-12 13:28:35 -05:00
if ( this . has _bttv || ! this . _chatv )
2015-06-05 03:59:28 -04:00
return ;
2015-12-12 13:28:35 -05:00
if ( val )
if ( this . _chatv . _ffz _tabs )
this . _chatv . ffzRebuildTabs ( ) ;
else
this . _chatv . ffzEnableTabs ( ) ;
2015-06-05 03:59:28 -04:00
else
this . _chatv . ffzDisableTabs ( ) ;
2015-12-12 13:28:35 -05:00
this . _chatv . ffzUpdateMenuUnread ( ) ;
2015-06-05 03:59:28 -04:00
}
} ;
FFZ . settings _info . pinned _rooms = {
value : [ ] ,
visible : false ,
2015-07-13 21:52:44 -04:00
} ;
2015-06-05 03:59:28 -04:00
2015-07-13 21:52:44 -04:00
FFZ . settings _info . visible _rooms = {
value : [ ] ,
visible : false ,
2015-06-05 03:59:28 -04:00
} ;
2015-01-20 01:53:18 -05:00
// --------------------
// Initialization
// --------------------
2016-03-23 19:28:22 -04:00
FFZ . prototype . refresh _chat = function ( ) {
var parents , lines = jQuery ( 'ul.chat-lines' ) ;
if ( this . has _bttv || ! lines || ! lines . length )
return ;
parents = lines . parents ( '.chatReplay' ) ;
if ( parents && parents . length )
return ;
// There are chat-lines in the DOM and they aren't chat replay.
2016-03-23 20:23:04 -04:00
var controller = utils . ember _lookup ( 'controller:chat' ) ;
2016-03-23 19:28:22 -04:00
if ( ! controller )
return ;
var current _room = controller . get ( "currentRoom" ) ;
controller . blurRoom ( ) ;
controller . focusRoom ( current _room ) ;
}
2015-01-20 01:53:18 -05:00
FFZ . prototype . setup _chatview = function ( ) {
2015-10-17 18:05:44 -04:00
document . body . classList . toggle ( "ffz-minimal-chat-head" , this . settings . minimal _chat === 1 || this . settings . minimal _chat === 3 ) ;
document . body . classList . toggle ( "ffz-minimal-chat-input" , this . settings . minimal _chat === 2 || this . settings . minimal _chat === 3 ) ;
2015-07-04 17:06:36 -04:00
2015-06-05 03:59:28 -04:00
this . log ( "Hooking the Ember Chat controller." ) ;
2016-03-23 20:23:04 -04:00
var Chat = utils . ember _lookup ( 'controller:chat' ) ,
2015-06-05 03:59:28 -04:00
f = this ;
if ( Chat ) {
Chat . reopen ( {
ffzUpdateChannels : function ( ) {
2015-12-12 13:28:35 -05:00
if ( ! f . _chatv || f . has _bttv )
2015-07-13 21:52:44 -04:00
return ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
f . _chatv . ffzRebuildMenu ( ) ;
if ( f . settings . group _tabs )
2015-06-05 03:59:28 -04:00
f . _chatv . ffzRebuildTabs ( ) ;
2015-08-04 01:43:08 -04:00
2015-07-04 17:06:36 -04:00
} . observes ( "currentChannelRoom" , "connectedPrivateGroupRooms" ) ,
2015-12-12 13:28:35 -05:00
ffzUpdateInvites : function ( ) {
if ( ! f . _chatv || f . has _bttv )
return ;
f . _chatv . ffzUpdateMenuUnread ( ) ;
} . observes ( "invitedPrivateGroupRooms" ) ,
2016-03-26 16:09:36 -04:00
ffzChangedRoom : function ( ) {
if ( f . _inputv )
Ember . propertyDidChange ( f . _inputv , 'ffz_emoticons' ) ;
} . observes ( 'currentRoom' ) ,
2015-12-12 13:28:35 -05:00
notificationsCount : function ( ) {
if ( ! f . _chatv || f . has _bttv )
return this . _super ( ) ;
var total = this . get ( 'invitedPrivateGroupRooms.length' ) || 0 ;
2016-03-24 14:48:53 -04:00
if ( ! f . _chatv . _ffz _tabs && f . _chatv . ffz _unread )
2015-12-12 13:28:35 -05:00
for ( var room _id in f . _chatv . ffz _unread )
if ( f . _chatv . ffz _unread [ room _id ] )
total ++ ;
return total ;
} . property ( "currentRoom" , "currentChannelRoom" , "currentChannelRoom.unreadCount" , "invitedPrivateGroupRooms.length" , "connectedPrivateGroupRooms.@each.unreadCount" ) ,
_kickUserFromRoomNoLongerInList : function ( ) {
// Remove an unread notice for any missing channels.
2016-03-24 14:48:53 -04:00
if ( f . _chatv && f . _chatv . ffz _unread ) {
2015-12-12 13:28:35 -05:00
var updated = false ;
for ( var room _id in f . _chatv . ffz _unread )
if ( f . _chatv . ffz _unread [ room _id ] && ( ! f . rooms [ room _id ] || ! f . rooms [ room _id ] . room ) ) {
f . _chatv . ffz _unread [ room _id ] = false ;
updated = true ;
}
if ( updated )
f . _chatv . ffzUpdateMenuUnread ( ) ;
}
var room = this . get ( "currentRoom" ) ,
room _id = room && room . get ( 'id' ) ,
channel _room = this . get ( "currentChannelRoom" ) ,
is _group = room && _ . contains ( this . get ( "privateGroupRooms.content" ) || [ ] , room ) ;
if ( room === channel _room || is _group || ( f . _chatv && f . _chatv . _ffz _host === room _id ) || ( f . settings . pinned _rooms && f . settings . pinned _rooms . indexOf ( room _id ) !== - 1 ) )
return ;
this . blurRoom ( ) ;
if ( ! this . get ( "showList" ) )
this . send ( "toggleMode" ) ;
} . observes ( "privateGroupRooms.@each" ) ,
2015-07-04 17:06:36 -04:00
removeCurrentChannelRoom : function ( ) {
2015-12-12 13:28:35 -05:00
if ( f . has _bttv )
2015-07-04 17:06:36 -04:00
return this . _super ( ) ;
var room = this . get ( "currentChannelRoom" ) ,
2015-07-13 21:52:44 -04:00
room _id = room && room . get ( 'id' ) ,
user = f . get _user ( ) ;
2015-07-04 17:06:36 -04:00
2015-12-12 13:28:35 -05:00
// Don't clean up pinned rooms or the current host target.
if ( ! ( ( f . _chatv && f . _chatv . _ffz _host === room _id ) || ( f . settings . pinned _rooms && f . settings . pinned _rooms . indexOf ( room _id ) !== - 1 ) ) ) {
2015-07-04 17:06:36 -04:00
if ( room === this . get ( "currentRoom" ) )
this . blurRoom ( ) ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
// Don't destroy it if it's the user's room.
2015-10-27 14:25:13 -04:00
if ( room && user && user . login !== room _id )
2015-12-12 13:28:35 -05:00
room . ffzScheduleDestroy ( ) ;
2015-07-04 17:06:36 -04:00
}
this . set ( "currentChannelRoom" , void 0 ) ;
}
2015-06-05 03:59:28 -04:00
} ) ;
}
2015-01-20 01:53:18 -05:00
this . log ( "Hooking the Ember Chat view." ) ;
2016-03-23 20:23:04 -04:00
var Chat = utils . ember _resolve ( 'view:chat' ) ;
2015-01-20 01:53:18 -05:00
this . _modify _cview ( Chat ) ;
// For some reason, this doesn't work unless we create an instance of the
// chat view and then destroy it immediately.
2015-02-24 00:33:29 -05:00
try {
Chat . create ( ) . destroy ( ) ;
} catch ( err ) { }
2016-03-27 02:15:32 -04:00
2015-01-20 01:53:18 -05:00
// Modify all existing Chat views.
2016-03-23 20:23:04 -04:00
var views = utils . ember _views ( ) ;
2015-12-12 13:28:35 -05:00
for ( var key in views ) {
if ( ! views . hasOwnProperty ( key ) )
2015-01-20 01:53:18 -05:00
continue ;
2015-12-12 13:28:35 -05:00
var view = views [ key ] ;
2015-01-20 01:53:18 -05:00
if ( ! ( view instanceof Chat ) )
continue ;
2015-06-05 03:59:28 -04:00
this . log ( "Manually updating existing Chat view." , view ) ;
2015-02-10 01:34:23 -05:00
try {
2016-03-23 19:28:22 -04:00
if ( ! view . ffzInit )
this . _modify _cview ( view ) ;
2015-06-05 03:59:28 -04:00
view . ffzInit ( ) ;
2015-02-10 01:34:23 -05:00
} catch ( err ) {
this . error ( "setup: build_ui_link: " + err ) ;
}
2015-01-20 01:53:18 -05:00
}
}
// --------------------
// Modify Chat View
// --------------------
FFZ . prototype . _modify _cview = function ( view ) {
var f = this ;
view . reopen ( {
didInsertElement : function ( ) {
2016-03-23 19:28:22 -04:00
this . _super ( ) ;
2015-06-05 03:59:28 -04:00
2015-02-10 01:34:23 -05:00
try {
2015-06-05 03:59:28 -04:00
this . ffzInit ( ) ;
2015-02-10 01:34:23 -05:00
} catch ( err ) {
2016-03-24 14:48:53 -04:00
f . error ( "view:chat ffzInit error: " + err ) ;
2015-02-10 01:34:23 -05:00
}
2015-01-20 01:53:18 -05:00
} ,
2016-03-24 14:48:53 -04:00
didUpdate : function ( ) {
this . _super ( ) ;
f . log ( "view:chat didUpdate" , this )
} ,
2015-01-20 01:53:18 -05:00
willClearRender : function ( ) {
2015-02-10 01:34:23 -05:00
try {
2015-06-05 03:59:28 -04:00
this . ffzTeardown ( ) ;
2015-02-10 01:34:23 -05:00
} catch ( err ) {
2016-03-24 14:48:53 -04:00
f . error ( "view:chat ffzTeardown error: " + err ) ;
2015-02-10 01:34:23 -05:00
}
2015-06-05 03:59:28 -04:00
this . _super ( ) ;
2015-01-20 01:53:18 -05:00
} ,
2015-06-05 03:59:28 -04:00
ffzInit : function ( ) {
2016-03-24 14:48:53 -04:00
f . _chatv = this ;
2016-03-23 19:28:22 -04:00
2016-03-31 19:47:17 -04:00
var room _id = this . get ( 'controller.currentRoom.id' ) ,
el = this . get ( 'element' ) ;
el && el . setAttribute ( 'data-room' , room _id || "" ) ;
2015-06-05 03:59:28 -04:00
this . $ ( '.textarea-contain' ) . append ( f . build _ui _link ( this ) ) ;
2015-11-14 23:52:49 -05:00
this . $ ( '.chat-messages' ) . find ( '.html-tooltip' ) . tipsy ( { live : true , html : true , gravity : utils . tooltip _placement ( 2 * constants . TOOLTIP _DISTANCE , 'n' ) } ) ;
2016-03-23 19:28:22 -04:00
this . $ ( '.chat-messages' ) . find ( '.ffz-tooltip' ) . tipsy ( { live : true , html : true , title : f . render _tooltip ( ) , gravity : utils . tooltip _placement ( 2 * constants . TOOLTIP _DISTANCE , 'n' ) } ) ;
2015-12-12 13:28:35 -05:00
if ( ! f . has _bttv ) {
if ( f . settings . group _tabs )
this . ffzEnableTabs ( ) ;
this . ffzRebuildMenu ( ) ;
}
2015-06-05 03:59:28 -04:00
2015-12-12 13:28:35 -05:00
this . ffz _pruner = setInterval ( this . ffzPruneTabs . bind ( this ) , 10000 ) ;
2015-07-13 21:52:44 -04:00
2015-06-05 03:59:28 -04:00
setTimeout ( function ( ) {
2015-07-13 21:52:44 -04:00
if ( f . settings . group _tabs && f . _chatv && f . _chatv . _ffz _tabs )
2015-06-05 03:59:28 -04:00
f . _chatv . $ ( '.chat-room' ) . css ( 'top' , f . _chatv . _ffz _tabs . offsetHeight + "px" ) ;
2015-11-19 02:45:56 -05:00
var controller = f . _chatv && f . _chatv . get ( 'controller' ) ;
2015-06-05 03:59:28 -04:00
controller && controller . set ( 'showList' , false ) ;
} , 1000 ) ;
} ,
ffzTeardown : function ( ) {
if ( f . _chatv === this )
f . _chatv = null ;
2015-12-12 13:28:35 -05:00
if ( this . ffz _pruner ) {
clearInterval ( this . ffz _pruner ) ;
this . ffz _pruner = null ;
}
2015-06-05 03:59:28 -04:00
this . $ ( '.textarea-contain .ffz-ui-toggle' ) . remove ( ) ;
if ( f . settings . group _tabs )
this . ffzDisableTabs ( ) ;
2015-12-12 13:28:35 -05:00
this . ffzTeardownMenu ( ) ;
this . ffzUnloadHost ( ) ;
} ,
ffzPruneTabs : function ( ) {
if ( ! this . _ffz _tabs )
return ;
var elements = this . _ffz _tabs . querySelectorAll ( '.ffz-chat-tab:not(.hidden):not(.active)' ) ,
update _height = false ;
for ( var i = 0 ; i < elements . length ; i ++ ) {
var el = elements [ i ] ,
room _id = el . getAttribute ( 'data-room' ) ,
was _hidden = el . classList . contains ( 'hidden' ) ,
is _hidden = ! this . ffzTabVisible ( room _id ) ;
if ( was _hidden !== is _hidden ) {
el . classList . toggle ( 'hidden' , is _hidden ) ;
update _height = true ;
}
}
if ( update _height )
this . $ ( '.chat-room' ) . css ( 'top' , this . _ffz _tabs . offsetHeight + "px" ) ;
2015-06-05 03:59:28 -04:00
} ,
2015-12-12 13:28:35 -05:00
2015-06-05 03:59:28 -04:00
ffzChangeRoom : Ember . observer ( 'controller.currentRoom' , function ( ) {
2015-07-29 01:03:10 -04:00
f . update _ui _link ( ) ;
2016-03-23 19:28:22 -04:00
this . ffz _unread = this . ffz _unread || { } ;
2015-11-19 02:45:56 -05:00
// Close mod cards when changing to a new room.
if ( f . _mod _card )
f . _mod _card . send ( 'close' ) ;
2015-12-12 13:28:35 -05:00
var room = this . get ( 'controller.currentRoom' ) ,
room _id = room && room . get ( 'id' ) ,
2016-03-31 19:47:17 -04:00
el = this . get ( 'element' ) ,
2016-03-24 14:48:53 -04:00
was _unread = room _id && this . ffz _unread [ room _id ] ,
2015-12-12 13:28:35 -05:00
update _height = false ;
if ( room ) {
room . resetUnreadCount ( ) ;
room . ffz _last _view = Date . now ( ) ;
}
2015-06-05 03:59:28 -04:00
2016-03-31 19:47:17 -04:00
el && el . setAttribute ( 'data-room' , room _id || "" ) ;
2015-11-11 02:06:02 -05:00
2015-12-12 13:28:35 -05:00
if ( room && room . _ffz _tab ) {
var was _hidden = room . _ffz _tab . classList . contains ( 'hidden' ) ,
is _hidden = ! this . ffzTabVisible ( room _id ) ;
2015-11-11 02:06:02 -05:00
2015-12-12 13:28:35 -05:00
if ( was _hidden !== is _hidden ) {
room . _ffz _tab . classList . toggle ( 'hidden' , is _hidden ) ;
update _height = true ;
}
}
if ( was _unread && room _id ) {
this . ffz _unread [ room _id ] = false ;
this . ffzUpdateMenuUnread ( ) ;
2015-11-11 02:06:02 -05:00
}
2015-12-12 13:28:35 -05:00
if ( this . _ffz _chan _table )
jQuery ( '.ffz-room-row.active' , this . _ffz _chan _table ) . removeClass ( 'active' ) ;
if ( this . _ffz _group _table )
jQuery ( '.ffz-room-row.active' , this . _ffz _group _table ) . removeClass ( 'active' ) ;
if ( this . _ffz _tabs ) {
jQuery ( '.ffz-chat-tab.active' , this . _ffz _tabs ) . removeClass ( 'active' ) ;
// Invite Link
var can _invite = room && room . get ( 'canInvite' ) ;
if ( this . _ffz _invite )
this . _ffz _invite . classList . toggle ( 'hidden' , ! can _invite ) ;
this . set ( 'controller.showInviteUser' , can _invite && this . get ( 'controller.showInviteUser' ) ) ;
update _height = true ;
2015-07-29 01:03:10 -04:00
}
2015-08-04 01:43:08 -04:00
2015-12-12 13:28:35 -05:00
if ( room && room . _ffz _tab ) {
room . _ffz _tab . classList . remove ( 'tab-mentioned' ) ;
room . _ffz _tab . classList . add ( 'active' ) ;
var sp = room . _ffz _tab . querySelector ( 'span' ) ;
if ( sp )
sp . innerHTML = '' ;
2015-07-29 01:03:10 -04:00
}
2015-06-05 03:59:28 -04:00
2015-12-12 13:28:35 -05:00
if ( room && room . _ffz _row ) {
room . _ffz _row . classList . remove ( 'row-mentioned' ) ;
room . _ffz _row . classList . add ( 'active' ) ;
var sp = room . _ffz _row . querySelector ( 'span' ) ;
if ( sp )
sp . innerHTML = '' ;
}
2015-11-11 02:06:02 -05:00
2015-12-12 13:28:35 -05:00
if ( update _height )
this . $ ( '.chat-room' ) . css ( 'top' , this . _ffz _tabs . offsetHeight + "px" ) ;
} ) ,
// Hosted Channel Chat
ffzUnloadHost : function ( ) {
if ( ! this . _ffz _host )
return ;
if ( f . settings . pinned _rooms . indexOf ( this . _ffz _host ) === - 1 ) {
if ( this . get ( 'controller.currentRoom' ) === this . _ffz _host _room )
this . get ( 'controller' ) . blurRoom ( ) ;
// Schedule the room to be destroyed. This is after a short
// delay to make sure we aren't just loading the room in a
// new way.
this . _ffz _host _room . ffzScheduleDestroy ( ) ;
}
this . _ffz _host = null ;
this . _ffz _host _room = null ;
} ,
ffzUpdateHost : function ( ) {
2016-03-23 20:23:04 -04:00
var Channel = utils . ember _lookup ( 'controller:channel' ) ,
Room = utils . ember _resolve ( 'model:room' ) ,
2015-12-12 13:28:35 -05:00
target = Room && Channel && Channel . get ( 'hostModeTarget' ) ,
updated = false ;
if ( f . has _bttv )
return ;
if ( target ) {
var target _id = target . get ( 'id' ) ;
if ( this . _ffz _host !== target _id ) {
this . ffzUnloadHost ( ) ;
this . _ffz _host = target _id ;
this . _ffz _host _room = Room . findOne ( target _id ) ;
updated = true ;
}
} else if ( this . _ffz _host ) {
this . ffzUnloadHost ( ) ;
updated = true ;
}
if ( updated ) {
this . ffzRebuildMenu ( ) ;
this . ffzRebuildTabs ( ) ;
}
} ,
// Unread Handling
ffzUpdateMenuUnread : function ( ) {
var el = this . get ( 'element' ) ,
controller = this . get ( 'controller' ) ,
unread _display = el && el . querySelector ( '#ffz-group-tabs .button .notifications' ) ;
Ember . propertyDidChange ( controller , 'notificationsCount' ) ;
if ( unread _display )
unread _display . innerHTML = utils . format _unread ( controller . get ( 'notificationsCount' ) ) ;
} ,
ffzUpdateUnread : function ( target _id ) {
var current _id = this . get ( 'controller.currentRoom.id' ) ;
2016-03-24 14:48:53 -04:00
this . ffz _unread = this . ffz _unread || { } ;
2015-12-12 13:28:35 -05:00
if ( target _id === current _id )
// We don't care about updates to the current room.
return ;
var to _update ,
update _unread = false ,
update _height = false ;
// If we DO have a room ID, only update that room.
if ( target _id )
to _update = [ target _id ] ;
else
to _update = Object . keys ( f . rooms ) ;
for ( var i = 0 ; i < to _update . length ; i ++ ) {
var room _id = to _update [ i ] ,
room = f . rooms [ room _id ] && f . rooms [ room _id ] . room ,
row = room && room . _ffz _row ,
tab = room && room . _ffz _tab ,
unread _count = room _id === current _id ? 0 : room . get ( 'unreadCount' ) ,
is _unread = unread _count > 0 ,
unread = utils . format _unread ( unread _count ) ;
if ( this . ffz _unread [ room _id ] !== is _unread ) {
this . ffz _unread [ room _id ] = is _unread ;
update _unread = true ;
2015-06-05 03:59:28 -04:00
}
2015-12-12 13:28:35 -05:00
if ( row ) {
var sp = row . querySelector ( 'span' ) ;
2015-11-11 02:06:02 -05:00
if ( sp )
2015-12-12 13:28:35 -05:00
sp . innerHTML = unread ;
2015-11-11 02:06:02 -05:00
}
2015-12-12 13:28:35 -05:00
if ( tab ) {
var was _hidden = tab . classList . contains ( 'hidden' ) ,
is _hidden = ! this . ffzTabVisible ( room _id ) ,
sp = tab . querySelector ( 'span' ) ;
if ( was _hidden !== is _hidden ) {
tab . classList . toggle ( 'hidden' , is _hidden ) ;
update _height = true ;
}
2015-07-29 01:03:10 -04:00
2015-12-12 13:28:35 -05:00
if ( sp )
sp . innerHTML = unread ;
}
}
if ( update _height )
2015-07-29 01:03:10 -04:00
this . $ ( '.chat-room' ) . css ( 'top' , this . _ffz _tabs . offsetHeight + "px" ) ;
2015-12-12 13:28:35 -05:00
if ( update _unread )
this . ffzUpdateMenuUnread ( ) ;
} ,
// Menu Rendering
ffzTeardownMenu : function ( ) {
var el = this . get ( 'element' ) ,
room _list = el && el . querySelector ( '.chat-rooms .tse-content' ) ,
chan _table = room _list && room _list . querySelector ( '#ffz-channel-table' ) ,
group _table = room _list && room _list . querySelector ( '#ffz-group-table' ) ;
if ( chan _table )
chan _table . parentElement . removeChild ( chan _table ) ;
if ( group _table )
group _table . parentElement . removeChild ( group _table ) ;
this . _ffz _chan _table = null ;
this . _ffz _group _table = null ;
if ( room _list && room _list . classList . contains ( 'ffz-room-list' ) ) {
room _list . classList . remove ( 'ffz-room-list' ) ;
jQuery ( '.ffz' , room _list ) . removeClass ( 'ffz' ) ;
2015-06-05 03:59:28 -04:00
}
2015-12-12 13:28:35 -05:00
for ( var room _id in f . rooms )
if ( f . rooms [ room _id ] && f . rooms [ room _id ] . room && f . rooms [ room _id ] . room . _ffz _row )
f . rooms [ room _id ] . room . _ffz _row = null ;
} ,
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
ffzRebuildMenu : function ( ) {
2015-12-12 13:28:35 -05:00
var el = this . get ( 'element' ) ,
2015-07-13 21:52:44 -04:00
room _list = el && el . querySelector ( '.chat-rooms .tse-content' ) ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
if ( ! room _list )
return ;
if ( ! room _list . classList . contains ( 'ffz-room-list' ) ) {
room _list . classList . add ( 'ffz-room-list' ) ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
// Find the Pending Invitations
var headers = room _list . querySelectorAll ( '.list-header' ) ,
hdr = headers . length ? headers [ headers . length - 1 ] : undefined ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
if ( hdr ) {
hdr . classList . add ( 'ffz' ) ;
if ( hdr . nextSibling && hdr . nextSibling . classList )
hdr . nextSibling . classList . add ( 'ffz' ) ;
}
}
// Channel Table
2015-12-12 13:28:35 -05:00
var view = this ,
2015-07-13 21:52:44 -04:00
chan _table = this . _ffz _chan _table || room _list . querySelector ( '#ffz-channel-table tbody' ) ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
if ( ! chan _table ) {
var tbl = document . createElement ( 'table' ) ;
2015-12-12 13:28:35 -05:00
tbl . setAttribute ( 'cellspacing' , '0' ) ;
2015-07-13 21:52:44 -04:00
tbl . id = 'ffz-channel-table' ;
tbl . className = 'ffz' ;
2015-12-12 13:28:35 -05:00
tbl . innerHTML = '<thead><tr><th colspan="2">Channels</th><th class="ffz-row-switch" title="Pinning a channel makes it so you always join that channel\'s chat, no matter where you are on Twitch.">Pin</th></tr></thead><tbody></tbody>' ;
2015-07-13 21:52:44 -04:00
room _list . insertBefore ( tbl , room _list . firstChild ) ;
2015-12-12 13:28:35 -05:00
jQuery ( '.ffz-row-switch' , tbl ) . tipsy ( { gravity : utils . tooltip _placement ( constants . TOOLTIP _DISTANCE , 'se' ) } ) ;
2015-07-13 21:52:44 -04:00
chan _table = this . _ffz _chan _table = tbl . querySelector ( 'tbody' ) ;
2015-12-12 13:28:35 -05:00
} else
chan _table . innerHTML = '' ;
2015-07-13 21:52:44 -04:00
// Current Channel
2015-12-12 13:28:35 -05:00
var room = this . get ( 'controller.currentChannelRoom' ) ,
room _id = room && room . get ( 'id' ) ,
row ;
2015-07-13 21:52:44 -04:00
if ( room ) {
2015-12-12 13:28:35 -05:00
row = this . ffzBuildRow ( room , true ) ;
2015-07-13 21:52:44 -04:00
row && chan _table . appendChild ( row ) ;
}
2015-08-04 01:43:08 -04:00
2015-12-12 13:28:35 -05:00
2015-07-13 21:52:44 -04:00
// Host Target
if ( this . _ffz _host _room ) {
2015-12-12 13:28:35 -05:00
row = this . ffzBuildRow ( this . _ffz _host _room , false , true ) ;
2015-07-13 21:52:44 -04:00
row && chan _table . appendChild ( row ) ;
}
2015-08-04 01:43:08 -04:00
2015-12-12 13:28:35 -05:00
2015-07-13 21:52:44 -04:00
// Pinned Rooms
for ( var i = 0 ; i < f . settings . pinned _rooms . length ; i ++ ) {
2015-12-12 13:28:35 -05:00
var pinned _id = f . settings . pinned _rooms [ i ] ;
if ( room _id !== pinned _id && this . _ffz _host !== pinned _id && f . rooms [ pinned _id ] && f . rooms [ pinned _id ] . room ) {
row = this . ffzBuildRow ( f . rooms [ pinned _id ] . room ) ;
2015-07-13 21:52:44 -04:00
row && chan _table . appendChild ( row ) ;
}
}
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
// 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' ) ;
2015-12-12 13:28:35 -05:00
tbl . setAttribute ( 'cellspacing' , '0' ) ;
2015-07-13 21:52:44 -04:00
tbl . id = 'ffz-group-table' ;
tbl . className = 'ffz' ;
2015-11-11 02:06:02 -05:00
tbl . innerHTML = '<thead><tr><th colspan="2">Group Chats</th></tr></thead><tbody></tbody>' ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
var before = room _list . querySelector ( '#ffz-channel-table' ) ;
room _list . insertBefore ( tbl , before . nextSibling ) ;
group _table = this . _ffz _group _table = tbl . querySelector ( 'tbody' ) ;
2015-08-04 01:43:08 -04:00
2015-12-12 13:28:35 -05:00
} else
group _table . innerHTML = '' ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
_ . each ( this . get ( 'controller.connectedPrivateGroupRooms' ) , function ( room ) {
2015-12-12 13:28:35 -05:00
var row = view . ffzBuildRow ( room ) ;
2015-07-13 21:52:44 -04:00
row && group _table && group _table . appendChild ( row ) ;
} ) ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
// Change Create Tooltip
var create _btn = el . querySelector ( '.button.create' ) ;
if ( create _btn )
2015-12-12 13:28:35 -05:00
create _btn . title = 'Create a Group Room' ;
2015-07-13 21:52:44 -04:00
} ,
2015-08-04 01:43:08 -04:00
2015-12-12 13:28:35 -05:00
ffzBuildRow : function ( room , current _channel , host _channel ) {
var view = this ,
row = document . createElement ( 'tr' ) ,
2015-07-13 21:52:44 -04:00
icon = document . createElement ( 'td' ) ,
name _el = document . createElement ( 'td' ) ,
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
btn ,
toggle _pinned = document . createElement ( 'td' ) ,
2015-08-04 01:43:08 -04:00
2015-12-12 13:28:35 -05:00
room _id = room . get ( 'id' ) ,
2015-07-13 21:52:44 -04:00
group = room . get ( 'isGroupRoom' ) ,
2015-12-12 13:28:35 -05:00
active _channel = room === this . get ( 'controller.currentRoom' ) ,
unread = utils . format _unread ( active _channel ? 0 : room . get ( 'unreadCount' ) ) ,
2015-08-04 01:43:08 -04:00
2015-12-12 13:28:35 -05:00
name = room . get ( 'tmiRoom.displayName' ) || ( group ? room . get ( 'tmiRoom.name' ) : FFZ . get _capitalization ( room _id , function ( name ) {
var active _channel = room === view . get ( 'controller.currentRoom' ) ;
unread = utils . format _unread ( active _channel ? 0 : room . get ( 'unreadCount' ) ) ;
2015-11-11 02:06:02 -05:00
name _el . innerHTML = utils . sanitize ( name ) + ' <span>' + unread + '</span>' ;
2015-07-13 21:52:44 -04:00
} ) ) ;
2015-08-04 01:43:08 -04:00
2015-12-12 13:28:35 -05:00
row . setAttribute ( 'data-room' , room _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' , active _channel ) ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
if ( current _channel ) {
icon . innerHTML = constants . CAMERA ;
2015-12-12 13:28:35 -05:00
row . title = "Current Channel" ;
row . classList . add ( 'tooltip' ) ;
2015-07-13 21:52:44 -04:00
} else if ( host _channel ) {
icon . innerHTML = constants . EYE ;
2015-12-12 13:28:35 -05:00
row . title = "Hosted Channel" ;
row . classList . add ( 'tooltip' ) ;
2015-07-13 21:52:44 -04:00
}
2015-08-04 01:43:08 -04:00
2015-12-12 13:28:35 -05:00
name _el . className = 'ffz-room' ;
name _el . innerHTML = utils . sanitize ( name ) + ' <span>' + unread + '</span>' ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
row . appendChild ( icon ) ;
row . appendChild ( name _el ) ;
2015-08-04 01:43:08 -04:00
2015-12-12 13:28:35 -05:00
toggle _pinned . className = 'ffz-row-switch' ;
2015-07-13 21:52:44 -04:00
if ( ! group ) {
2015-12-12 13:28:35 -05:00
toggle _pinned . innerHTML = '<a class="switch' + ( f . settings . pinned _rooms . indexOf ( room _id ) !== - 1 ? ' active' : '' ) + '"><span></span></a>' ;
2015-07-13 21:52:44 -04:00
btn = toggle _pinned . querySelector ( 'a.switch' ) ;
btn . addEventListener ( 'click' , function ( e ) {
e . preventDefault ( ) ;
e . stopPropagation && e . stopPropagation ( ) ;
2015-08-04 01:43:08 -04:00
2015-12-12 13:28:35 -05:00
var is _pinned = f . settings . pinned _rooms . indexOf ( room _id ) !== - 1 ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
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' ;
2015-12-12 13:28:35 -05:00
toggle _pinned . innerHTML = '' ;
toggle _pinned . appendChild ( btn ) ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
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 ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
room . get ( 'isGroupRoom' ) && room . del ( ) ;
} ) ;
}
2015-12-12 13:28:35 -05:00
row . appendChild ( toggle _pinned ) ;
2015-07-13 21:52:44 -04:00
row . addEventListener ( 'click' , function ( ) {
var controller = view . get ( 'controller' ) ;
controller . focusRoom ( room ) ;
controller . set ( 'showList' , false ) ;
} ) ;
2015-08-04 01:43:08 -04:00
2015-11-11 02:06:02 -05:00
room . _ffz _row = row ;
2015-07-13 21:52:44 -04:00
return row ;
2015-12-12 13:28:35 -05:00
} ,
2015-07-13 21:52:44 -04:00
2015-12-12 13:28:35 -05:00
// Group Tabs
2015-06-05 03:59:28 -04:00
ffzEnableTabs : function ( ) {
2015-12-12 13:28:35 -05:00
if ( f . has _bttv || ! f . settings . group _tabs || this . _ffz _tabs )
2015-06-05 03:59:28 -04:00
return ;
// Hide the existing chat UI.
this . $ ( ".chat-header" ) . addClass ( "hidden" ) ;
// Create our own UI.
var tabs = this . _ffz _tabs = document . createElement ( "div" ) ;
tabs . id = "ffz-group-tabs" ;
this . $ ( ".chat-header" ) . after ( tabs ) ;
// List the Rooms
this . ffzRebuildTabs ( ) ;
} ,
2015-12-12 13:28:35 -05:00
ffzDisableTabs : function ( ) {
if ( this . _ffz _tabs ) {
this . _ffz _tabs . parentElement . removeChild ( this . _ffz _tabs ) ;
this . _ffz _tabs = null ;
this . _ffz _invite = null ;
for ( var room _id in f . rooms )
if ( f . rooms [ room _id ] && f . rooms [ room _id ] . room && f . rooms [ room _id ] . room . _ffz _tab )
f . rooms [ room _id ] . room . _ffz _tab = null ;
}
// Show the old chat UI.
this . $ ( '.chat-room' ) . css ( 'top' , '' ) ;
this . $ ( ".chat-header" ) . removeClass ( "hidden" ) ;
} ,
2015-06-05 03:59:28 -04:00
2015-12-12 13:28:35 -05:00
ffzRebuildTabs : function ( ) {
2015-06-05 03:59:28 -04:00
var tabs = this . _ffz _tabs || this . get ( 'element' ) . querySelector ( '#ffz-group-tabs' ) ;
if ( ! tabs )
return ;
tabs . innerHTML = "" ;
2015-12-12 13:28:35 -05:00
if ( f . has _bttv || ! f . settings . group _tabs )
return ;
2015-06-05 03:59:28 -04:00
var link = document . createElement ( 'a' ) ,
2015-11-11 16:03:27 -05:00
view = this ;
2015-11-11 02:06:02 -05:00
2015-06-05 03:59:28 -04:00
2015-12-12 13:28:35 -05:00
// Chat Room Management Button
2016-03-24 14:48:53 -04:00
link . className = 'button glyph-only' ;
2015-06-05 03:59:28 -04:00
link . title = "Chat Room Management" ;
2015-12-12 13:28:35 -05:00
link . innerHTML = constants . ROOMS + '<span class="notifications"></span>' ;
2015-06-05 03:59:28 -04:00
2016-03-24 14:48:53 -04:00
jQuery ( link ) . tipsy ( { gravity : "n" , offset : 5 } ) ;
2015-06-05 03:59:28 -04:00
link . addEventListener ( 'click' , function ( ) {
var controller = view . get ( 'controller' ) ;
controller && controller . set ( 'showList' , ! controller . get ( 'showList' ) ) ;
} ) ;
tabs . appendChild ( link ) ;
2015-12-12 13:28:35 -05:00
// Invite Button
2015-06-05 03:59:28 -04:00
link = document . createElement ( 'a' ) ,
link . className = 'button glyph-only tooltip invite' ;
link . title = "Invite a User" ;
link . innerHTML = constants . INVITE ;
link . addEventListener ( 'click' , function ( ) {
var controller = view . get ( 'controller' ) ;
controller && controller . set ( 'showInviteUser' , controller . get ( 'currentRoom.canInvite' ) && ! controller . get ( 'showInviteUser' ) ) ;
} ) ;
link . classList . toggle ( 'hidden' , ! this . get ( "controller.currentRoom.canInvite" ) ) ;
view . _ffz _invite = link ;
tabs . appendChild ( link ) ;
2015-12-12 13:28:35 -05:00
// Current Room
var room = this . get ( 'controller.currentChannelRoom' ) ,
room _id = room && room . get ( 'id' ) ,
tab ;
2015-06-05 03:59:28 -04:00
if ( room ) {
2015-12-12 13:28:35 -05:00
tab = this . ffzBuildTab ( room , true ) ;
2015-06-05 03:59:28 -04:00
tab && tabs . appendChild ( tab ) ;
2015-02-10 01:34:23 -05:00
}
2015-06-05 03:59:28 -04:00
2015-12-12 13:28:35 -05:00
// Host Target
2015-06-05 03:59:28 -04:00
if ( this . _ffz _host _room ) {
2015-12-12 13:28:35 -05:00
tab = view . ffzBuildTab ( this . _ffz _host _room , false , true ) ;
2015-06-05 03:59:28 -04:00
tab && tabs . appendChild ( tab ) ;
}
2015-12-12 13:28:35 -05:00
2015-06-05 03:59:28 -04:00
// Pinned Rooms
for ( var i = 0 ; i < f . settings . pinned _rooms . length ; i ++ ) {
2015-12-12 13:28:35 -05:00
var pinned _id = f . settings . pinned _rooms [ i ] ;
if ( room _id !== pinned _id && this . _ffz _host !== pinned _id && f . rooms [ pinned _id ] && f . rooms [ pinned _id ] . room ) {
tab = view . ffzBuildTab ( f . rooms [ pinned _id ] . room , false , false ) ;
2015-06-05 03:59:28 -04:00
tab && tabs . appendChild ( tab ) ;
}
}
2015-12-12 13:28:35 -05:00
// Group Chat
2015-06-05 03:59:28 -04:00
_ . each ( this . get ( 'controller.connectedPrivateGroupRooms' ) , function ( room ) {
2015-12-12 13:28:35 -05:00
var tab = view . ffzBuildTab ( room ) ;
2015-06-05 03:59:28 -04:00
tab && tabs . appendChild ( tab ) ;
} ) ;
2015-12-12 13:28:35 -05:00
// Adjust the height of the chat room to account for the height of the numerous tabs.
2015-06-05 03:59:28 -04:00
this . $ ( '.chat-room' ) . css ( 'top' , tabs . offsetHeight + "px" ) ;
2015-12-12 13:28:35 -05:00
this . ffzUpdateMenuUnread ( ) ;
2015-06-05 03:59:28 -04:00
} ,
2015-12-12 13:28:35 -05:00
ffzBuildTab : function ( room , current _channel , host _channel ) {
var view = this ,
2015-08-04 01:43:08 -04:00
2015-12-12 13:28:35 -05:00
tab = document . createElement ( 'span' ) , name , unread , icon = '' ,
2015-07-13 21:52:44 -04:00
room _id = room . get ( 'id' ) ,
2015-06-05 03:59:28 -04:00
group = room . get ( 'isGroupRoom' ) ,
2015-12-12 13:28:35 -05:00
active _channel = room === this . get ( 'controller.currentRoom' ) ;
2015-06-05 03:59:28 -04:00
2015-12-12 13:28:35 -05:00
tab . setAttribute ( 'data-room' , room _id ) ;
2015-06-05 03:59:28 -04:00
tab . className = 'ffz-chat-tab tooltip' ;
tab . classList . toggle ( 'current-channel' , current _channel ) ;
tab . classList . toggle ( 'host-channel' , host _channel ) ;
tab . classList . toggle ( 'group-chat' , group ) ;
2015-12-12 13:28:35 -05:00
tab . classList . toggle ( 'active' , active _channel ) ;
2015-06-05 03:59:28 -04:00
2015-12-12 13:28:35 -05:00
tab . classList . toggle ( 'hidden' , ! this . ffzTabVisible ( room _id ) ) ;
2015-06-05 03:59:28 -04:00
2015-12-12 13:28:35 -05:00
unread = utils . format _unread ( active _channel ? 0 : room . get ( 'unreadCount' ) ) ;
name = room . get ( 'tmiRoom.displayName' ) || ( group ? room . get ( 'tmiRoom.name' ) : FFZ . get _capitalization ( room _id , function ( name ) {
var active _channel = room === view . get ( 'controller.currentRoom' ) ;
unread = utils . format _unread ( active _channel ? 0 : room . get ( 'unreadCount' ) ) ;
2015-07-04 17:06:36 -04:00
tab . innerHTML = icon + utils . sanitize ( name ) + '<span>' + unread + '</span>' ;
} ) ) ;
2015-06-05 03:59:28 -04:00
if ( current _channel ) {
2015-07-04 17:06:36 -04:00
icon = constants . CAMERA ;
2015-06-05 03:59:28 -04:00
tab . title = "Current Channel" ;
} else if ( host _channel ) {
2015-07-04 17:06:36 -04:00
icon = constants . EYE ;
2015-06-05 03:59:28 -04:00
tab . title = "Hosted Channel" ;
} else if ( group )
tab . title = "Group Chat" ;
else
tab . title = "Pinned Channel" ;
2015-07-04 17:06:36 -04:00
tab . innerHTML = icon + utils . sanitize ( name ) + '<span>' + unread + '</span>' ;
2015-06-05 03:59:28 -04:00
tab . addEventListener ( 'click' , function ( ) {
2015-07-13 21:52:44 -04:00
var controller = view . get ( 'controller' ) ;
controller . focusRoom ( room ) ;
controller . set ( 'showList' , false ) ;
2015-06-05 03:59:28 -04:00
} ) ;
2015-07-29 01:03:10 -04:00
room . _ffz _tab = tab ;
2015-06-05 03:59:28 -04:00
return tab ;
} ,
2015-12-12 13:28:35 -05:00
ffzTabVisible : function ( room _id ) {
var room = f . rooms [ room _id ] && f . rooms [ room _id ] . room ,
is _current = room === this . get ( 'controller.currentRoom' ) ,
is _channel = room === this . get ( 'controller.currentChannelRoom' ) ,
2015-06-05 03:59:28 -04:00
2015-12-12 13:28:35 -05:00
now = Date . now ( ) ;
2015-06-05 03:59:28 -04:00
2015-12-12 13:28:35 -05:00
if ( is _current || is _channel || room _id === this . _ffz _host || f . settings . group _tabs === 3 )
// Important Tabs
return true ;
2015-06-05 03:59:28 -04:00
2015-12-12 13:28:35 -05:00
else if ( now - room . ffz _last _view < 60000 || now - room . ffz _last _input < 2700000 )
// Recent Self Input or View
return true ;
else if ( f . settings . group _tabs === 1 && now - ( room . ffz _last _activity || 0 ) < 2700000 )
// Any Recent Activity
return true ;
else if ( f . settings . group _tabs === 2 && now - ( room . ffz _last _mention || 0 ) < 2700000 )
// Recent Mentions
return true ;
return false ;
}
2015-01-20 01:53:18 -05:00
} ) ;
2015-06-05 03:59:28 -04:00
}
// ----------------------
// Chat Room Connections
// ----------------------
FFZ . prototype . connect _extra _chat = function ( ) {
2015-07-13 21:52:44 -04:00
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 ) {
2016-03-23 20:23:04 -04:00
var Room = utils . ember _resolve ( 'model:room' ) ;
2015-12-12 13:28:35 -05:00
Room && Room . findOne ( user . login ) ;
2015-07-13 21:52:44 -04:00
}
}
2015-08-04 01:43:08 -04:00
2015-12-12 13:28:35 -05:00
// We don't join extra rooms with BTTV.
2015-06-05 03:59:28 -04:00
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 ) ;
2015-07-13 21:52:44 -04:00
if ( ! this . _chatv )
return ;
2015-12-12 13:28:35 -05:00
// Rebuild the chat UI.
if ( this . settings . group _tabs )
2015-06-05 03:59:28 -04:00
this . _chatv . ffzRebuildTabs ( ) ;
2015-07-13 21:52:44 -04:00
this . _chatv . ffzRebuildMenu ( ) ;
2015-06-05 03:59:28 -04:00
}
2015-12-12 13:28:35 -05:00
FFZ . prototype . disconnect _extra _chat = function ( ) {
2016-03-23 20:23:04 -04:00
var Chat = utils . ember _lookup ( 'controller:chat' ) ,
2015-12-12 13:28:35 -05:00
current _channel _id = Chat && Chat . get ( 'currentChannelRoom.id' ) ,
current _id = Chat && Chat . get ( 'currentRoom.id' ) ,
user = this . get _user ( ) ;
if ( ! Chat )
return ;
for ( var i = 0 ; i < this . settings . pinned _rooms . length ; i ++ ) {
var room _id = this . settings . pinned _rooms [ i ] ;
if ( room _id === current _channel _id || ( user && room _id === user . login ) )
continue ;
if ( this . rooms [ room _id ] && this . rooms [ room _id ] . room ) {
if ( current _id === room _id )
Chat . blurRoom ( ) ;
this . rooms [ room _id ] . room . destroy ( ) ;
}
}
}
2015-06-05 03:59:28 -04:00
FFZ . prototype . _join _room = function ( room _id , no _rebuild ) {
var did _join = false ;
if ( this . settings . pinned _rooms . indexOf ( room _id ) === - 1 ) {
this . settings . pinned _rooms . push ( room _id ) ;
this . settings . set ( "pinned_rooms" , this . settings . pinned _rooms ) ;
did _join = true ;
}
2015-12-12 13:28:35 -05:00
2015-06-05 03:59:28 -04:00
// Make sure we're not already there.
2015-12-12 13:28:35 -05:00
if ( ! this . rooms [ room _id ] || ! this . rooms [ room _id ] . room ) {
// Okay, fine. Get it.
2016-03-23 20:23:04 -04:00
var Room = utils . ember _resolve ( 'model:room' ) ;
2015-12-12 13:28:35 -05:00
Room && Room . findOne ( room _id ) ;
2015-07-13 21:52:44 -04:00
}
2015-06-05 03:59:28 -04:00
2015-12-12 13:28:35 -05:00
// Rebuild the chat UI.
if ( ! no _rebuild && ! this . has _bttv && this . _chatv ) {
if ( this . settings . group _tabs )
this . _chatv . ffzRebuildTabs ( ) ;
2015-06-05 03:59:28 -04:00
2015-07-13 21:52:44 -04:00
this . _chatv . ffzRebuildMenu ( ) ;
2015-12-12 13:28:35 -05:00
}
2015-07-13 21:52:44 -04:00
2015-06-05 03:59:28 -04:00
return did _join ;
}
FFZ . prototype . _leave _room = function ( room _id , no _rebuild ) {
var did _leave = false ;
if ( this . settings . pinned _rooms . indexOf ( room _id ) !== - 1 ) {
this . settings . pinned _rooms . removeObject ( room _id ) ;
this . settings . set ( "pinned_rooms" , this . settings . pinned _rooms ) ;
did _leave = true ;
}
if ( ! this . rooms [ room _id ] || ! this . rooms [ room _id ] . room )
return did _leave ;
2016-03-23 20:23:04 -04:00
var Chat = utils . ember _lookup ( 'controller:chat' ) ,
2015-07-13 21:52:44 -04:00
r = this . rooms [ room _id ] . room ,
user = this . get _user ( ) ;
2015-06-05 03:59:28 -04:00
if ( ! Chat || Chat . get ( 'currentChannelRoom.id' ) === room _id || ( this . _chatv && this . _chatv . _ffz _host === room _id ) )
return did _leave ;
if ( Chat . get ( 'currentRoom.id' ) === room _id )
Chat . blurRoom ( ) ;
2015-07-13 21:52:44 -04:00
// Don't leave the user's room, but update the UI.
if ( ! user || user . login !== room _id )
r . destroy ( ) ;
2015-06-05 03:59:28 -04:00
2015-12-12 13:28:35 -05:00
// Rebuild the chat UI.
if ( ! no _rebuild && ! this . has _bttv && this . _chatv ) {
if ( this . settings . group _tabs )
this . _chatv . ffzRebuildTabs ( ) ;
2015-07-13 21:52:44 -04:00
this . _chatv . ffzRebuildMenu ( ) ;
2015-12-12 13:28:35 -05:00
}
2015-07-13 21:52:44 -04:00
2015-06-05 03:59:28 -04:00
return did _leave ;
}
// ----------------------
// Commands
// ----------------------
FFZ . chat _commands . join = function ( room , args ) {
2015-12-12 13:28:35 -05:00
if ( this . has _bttv )
return "Pinned Rooms are not available with BetterTTV installed." ;
2015-06-05 03:59:28 -04:00
if ( ! args || ! args . length || args . length > 1 )
return "Join Usage: /join <channel>" ;
var room _id = args [ 0 ] . toLowerCase ( ) ;
if ( room _id . charAt ( 0 ) === "#" )
room _id = room _id . substr ( 1 ) ;
if ( this . _join _room ( room _id ) )
return "Joining " + room _id + ". You will always connect to this channel's chat unless you later /part from it." ;
else
return "You have already joined " + room _id + ". Please use \"/part " + room _id + "\" to leave it." ;
}
FFZ . chat _commands . part = function ( room , args ) {
2015-12-12 13:28:35 -05:00
if ( this . has _bttv )
return "Pinned Rooms are not available with BetterTTV installed." ;
2015-06-05 03:59:28 -04:00
if ( ! args || ! args . length || args . length > 1 )
return "Part Usage: /part <channel>" ;
var room _id = args [ 0 ] . toLowerCase ( ) ;
if ( room _id . charAt ( 0 ) === "#" )
room _id = room _id . substr ( 1 ) ;
if ( this . _leave _room ( room _id ) )
return "Leaving " + room _id + "." ;
else if ( this . rooms [ room _id ] )
return "You do not have " + room _id + " pinned and you cannot leave the current channel or hosted channels via /part." ;
else
return "You are not in " + room _id + "." ;
2015-01-12 17:58:07 -05:00
}