2015-10-24 22:44:00 -04:00
var FFZ = window . FrankerFaceZ ,
2016-10-25 14:44:22 -04:00
utils = require ( '../utils' ) ;
2015-10-24 22:44:00 -04:00
2016-08-09 20:45:28 -04:00
// ---------------------
// Badware Check
// ---------------------
FFZ . prototype . check _badware = function ( ) {
if ( this . embed _in _dash || ! window . jQuery || ! window . jQuery . noty )
return ;
// Check for the stolen version of BTTV4FFZ.
if ( FFZ . settings _info . bttv _global _emotes && FFZ . settings _info . bttv _global _emotes . category === "BetterTTV" ) {
var shown = localStorage . ffz _warning _bttv4ffz _clone ;
if ( shown !== "true" ) {
localStorage . ffz _warning _bttv4ffz _clone = "true" ;
this . show _message ( "You appear to be using an unofficial version of BTTV4FFZ that was copied without the developer's permission. Please use the official version available at <a href=\"https://lordmau5.com/bttv4ffz/\">https://lordmau5.com/bttv4ffz/</a>" ) ;
}
}
}
2015-10-24 22:44:00 -04:00
// ---------------------
// API Constructor
// ---------------------
2016-08-09 20:45:28 -04:00
var API = FFZ . API = function ( instance , name , icon , version , name _key ) {
2015-10-24 22:44:00 -04:00
this . ffz = instance || FFZ . get ( ) ;
// Check for a known API!
if ( name ) {
for ( var id in this . ffz . _known _apis ) {
if ( this . ffz . _known _apis [ id ] === name ) {
this . id = id ;
break ;
}
}
}
if ( ! this . id ) {
var i = 0 ;
while ( ! this . id ) {
if ( ! this . ffz . _known _apis . hasOwnProperty ( i ) ) {
this . id = i ;
break ;
}
i ++ ;
}
if ( name ) {
this . ffz . _known _apis [ this . id ] = name ;
localStorage . ffz _known _apis = JSON . stringify ( this . ffz . _known _apis ) ;
}
}
2016-10-20 02:34:55 -04:00
this . _events = { } ;
2015-10-24 22:44:00 -04:00
this . ffz . _apis [ this . id ] = this ;
this . emote _sets = { } ;
this . global _sets = [ ] ;
this . default _sets = [ ] ;
2016-07-13 02:06:50 -04:00
this . badges = { } ;
2016-05-06 02:23:12 -04:00
this . users = { } ;
2015-10-24 22:44:00 -04:00
this . name = name || ( "Extension#" + this . id ) ;
2016-08-09 20:45:28 -04:00
this . name _key = name _key || this . name . replace ( /[^A-Z0-9_\-]/g , '' ) . toLowerCase ( ) ;
2016-07-13 02:06:50 -04:00
2016-11-23 16:41:49 -05:00
// We can't start name key with a number.
if ( /^[0-9]/ . test ( this . name _key ) )
this . name _key = '_' + this . name _key ;
2015-10-24 22:44:00 -04:00
this . icon = icon || null ;
2016-07-13 02:31:26 -04:00
this . version = version || null ;
2015-10-24 22:44:00 -04:00
2016-11-23 16:41:49 -05:00
this . ffz . log ( 'Registered New Extension #' + this . id + ' (' + this . name _key + '): ' + this . name ) ;
2015-10-24 22:44:00 -04:00
} ;
2016-11-23 16:41:49 -05:00
FFZ . prototype . api = function ( name , icon , version , name _key ) {
2015-10-24 22:44:00 -04:00
// Load the known APIs list.
if ( ! this . _known _apis ) {
this . _known _apis = { } ;
if ( localStorage . hasOwnProperty ( 'ffz_known_apis' ) )
try {
this . _known _apis = JSON . parse ( localStorage . ffz _known _apis ) ;
} catch ( err ) {
2016-09-30 13:09:03 -04:00
this . error ( "Error loading Known APIs" , err ) ;
2015-10-24 22:44:00 -04:00
}
}
2016-11-23 16:41:49 -05:00
return new API ( this , name , icon , version , name _key ) ;
2015-10-24 22:44:00 -04:00
}
API . prototype . log = function ( msg , data , to _json , log _json ) {
2016-11-23 16:41:49 -05:00
this . ffz . log ( 'Ext #' + this . id + ' (' + this . name _key + '): ' + msg , data , to _json , log _json ) ;
2015-10-24 22:44:00 -04:00
}
2016-09-30 13:09:03 -04:00
API . prototype . error = function ( msg , error , to _json , log _json ) {
2016-11-23 16:41:49 -05:00
this . ffz . error ( 'Ext #' + this . id + ' (' + this . name _key + '): ' + msg , data , to _json , log _json ) ;
2016-09-30 13:09:03 -04:00
}
2016-10-20 02:34:55 -04:00
// ---------------------
// Events
// ---------------------
API . prototype . on = function ( event , func ) {
var e = this . _events [ event ] = this . _events [ event ] || [ ] ;
if ( e . indexOf ( func ) === - 1 )
e . push ( func ) ;
}
API . prototype . off = function ( event , func ) {
if ( func === undefined )
this . _events [ event ] = [ ] ;
else {
var e = this . _events [ event ] = this . _events [ event ] || [ ] ,
ind = e . indexOf ( func ) ;
if ( ind !== - 1 )
e . splice ( ind , 1 ) ;
}
}
var slice = Array . prototype . slice ;
API . prototype . trigger = function ( event /*, args... */ ) {
var e = this . _events [ event ] ;
if ( e && e . length )
for ( var i = 0 ; i < e . length ; i ++ )
e [ i ] . apply ( this , slice . call ( arguments , 1 ) ) ;
}
FFZ . prototype . api _trigger = function ( /*event, args...*/ ) {
for ( var api _id in this . _apis ) {
var api = this . _apis [ api _id ] ;
api . trigger . apply ( api , arguments ) ;
}
}
2015-10-24 22:44:00 -04:00
// ---------------------
// Set Loading
// ---------------------
API . prototype . _load _set = function ( real _id , set _id , data ) {
if ( ! data )
2015-12-12 13:28:35 -05:00
return null ;
2015-10-24 22:44:00 -04:00
// Check for an existing set to copy the users.
var users = [ ] ;
2016-09-30 13:09:03 -04:00
if ( this . emote _sets [ set _id ] && this . emote _sets [ set _id ] . users )
users = this . emote _sets [ set _id ] . users ;
2015-10-24 22:44:00 -04:00
2016-11-19 01:59:03 -05:00
var emote _set = _ . extend ( {
source : this . name ,
icon : this . icon || null ,
title : "Global Emoticons" ,
_type : 0
} , data , {
source _ext : this . id ,
source _id : set _id ,
id : real _id ,
users : users ,
count : 0 ,
emoticons : { } ,
} ) ;
2015-10-24 22:44:00 -04:00
2016-09-30 13:09:03 -04:00
this . emote _sets [ set _id ] = emote _set ;
2015-10-24 22:44:00 -04:00
2016-09-30 13:09:03 -04:00
// Use the real ID for FFZ's own tracking.
2015-10-24 22:44:00 -04:00
if ( this . ffz . emote _sets )
2015-12-12 13:28:35 -05:00
this . ffz . emote _sets [ real _id ] = emote _set ;
2015-10-24 22:44:00 -04:00
var output _css = "" ,
ems = data . emoticons ,
2015-12-12 13:28:35 -05:00
emoticons = emote _set . emoticons ;
2015-10-24 22:44:00 -04:00
for ( var i = 0 ; i < ems . length ; i ++ ) {
var emote = ems [ i ] ,
id = emote . id || ( this . name + '-' + set _id + '-' + i ) ;
if ( ! emote . name )
continue ;
2016-11-19 01:59:03 -05:00
var new _emote = _ . extend ( { } , emote , {
id : id ,
set _id : real _id ,
srcSet : emote . urls [ 1 ] + ' 1x'
} ) ;
2015-10-24 22:44:00 -04:00
2016-11-19 01:59:03 -05:00
if ( emote . urls [ 2 ] )
2015-10-24 22:44:00 -04:00
new _emote . srcSet += ', ' + emote . urls [ 2 ] + ' 2x' ;
2016-11-19 01:59:03 -05:00
if ( emote . urls [ 3 ] )
2015-10-24 22:44:00 -04:00
new _emote . srcSet += ', ' + emote . urls [ 3 ] + ' 3x' ;
2016-11-19 01:59:03 -05:00
if ( emote . urls [ 4 ] )
new _emote . srcSet += ', ' + emote . urls [ 4 ] + ' 4x' ;
2015-10-24 22:44:00 -04:00
2016-07-13 02:31:26 -04:00
new _emote . token = {
type : "emoticon" ,
srcSet : new _emote . srcSet ,
imgSrc : new _emote . urls [ 1 ] ,
ffzEmote : id ,
ffzEmoteSet : real _id ,
altText : new _emote . hidden ? '???' : new _emote . name
} ;
2016-03-23 19:28:22 -04:00
2016-10-25 14:44:22 -04:00
output _css += utils . emote _css ( new _emote ) ;
2015-12-12 13:28:35 -05:00
emote _set . count ++ ;
2015-10-24 22:44:00 -04:00
emoticons [ id ] = new _emote ;
}
2016-09-30 13:09:03 -04:00
// Use the real ID for building CSS.
2016-10-20 02:34:55 -04:00
if ( this . ffz . _emote _style )
utils . update _css ( this . ffz . _emote _style , real _id , output _css + ( emote _set . css || "" ) ) ;
else
emote _set . pending _css = output _css ;
2015-10-24 22:44:00 -04:00
if ( this . ffz . _cindex )
this . ffz . _cindex . ffzFixTitle ( ) ;
try {
this . ffz . update _ui _link ( ) ;
} catch ( err ) { }
2015-12-12 13:28:35 -05:00
return emote _set ;
2015-10-24 22:44:00 -04:00
}
2015-10-27 14:25:13 -04:00
// -------------------------
// Loading / Unloading Sets
// -------------------------
API . prototype . load _set = function ( id , emote _set ) {
var exact _id = this . id + '-' + id ;
emote _set . title = emote _set . title || "Global Emoticons" ;
emote _set . _type = emote _set . _type || 0 ;
emote _set = this . _load _set ( exact _id , id , emote _set ) ;
this . log ( "Loaded Emoticon Set #" + id + ": " + emote _set . title + " (" + emote _set . count + " emotes)" , emote _set ) ;
return emote _set ;
}
2016-09-30 13:09:03 -04:00
API . prototype . unload _set = function ( set _id ) {
var exact _id = this . id + '-' + set _id ,
emote _set = this . emote _sets [ set _id ] ;
2015-10-27 14:25:13 -04:00
if ( ! emote _set )
return ;
// First, let's unregister it as a global.
2016-09-30 13:09:03 -04:00
this . unregister _global _set ( set _id ) ;
2015-10-27 14:25:13 -04:00
// Now, remove the set data.
2016-10-20 02:34:55 -04:00
if ( this . ffz . _emote _style )
utils . update _css ( this . ffz . _emote _style , exact _id , null ) ;
2015-10-27 14:25:13 -04:00
2016-09-30 13:09:03 -04:00
this . emote _sets [ set _id ] = undefined ;
2015-10-27 14:25:13 -04:00
if ( this . ffz . emote _sets )
this . ffz . emote _sets [ exact _id ] = undefined ;
// Remove from all its Rooms
if ( emote _set . users ) {
for ( var i = 0 ; i < emote _set . users . length ; i ++ ) {
var room _id = emote _set . users [ i ] ,
room = this . ffz . rooms && this . ffz . rooms [ room _id ] ;
if ( ! room )
continue ;
2016-03-25 18:32:35 -04:00
var ind = room . ext _sets ? room . ext _sets . indexOf ( exact _id ) : - 1 ;
2015-10-27 14:25:13 -04:00
if ( ind !== - 1 )
room . ext _sets . splice ( ind , 1 ) ;
}
emote _set . users = [ ] ;
}
2015-12-12 13:28:35 -05:00
return emote _set ;
2015-10-27 14:25:13 -04:00
}
2016-09-30 13:09:03 -04:00
API . prototype . get _set = function ( set _id ) {
return this . emote _sets [ set _id ] ;
2015-10-27 14:25:13 -04:00
}
2015-10-24 22:44:00 -04:00
// ---------------------
// Global Emote Sets
// ---------------------
2016-09-30 13:09:03 -04:00
API . prototype . register _global _set = function ( set _id , emote _set ) {
var exact _id = this . id + '-' + set _id ;
2015-10-24 22:44:00 -04:00
2015-10-27 14:25:13 -04:00
if ( emote _set ) {
// If a set was provided, load it.
2016-09-30 13:09:03 -04:00
emote _set = this . load _set ( set _id , emote _set ) ;
2015-10-27 14:25:13 -04:00
} else
2016-09-30 13:09:03 -04:00
emote _set = this . emote _sets [ set _id ] ;
2015-10-24 22:44:00 -04:00
2015-10-27 14:25:13 -04:00
if ( ! emote _set )
throw new Error ( "Invalid set ID" ) ;
2015-10-24 22:44:00 -04:00
2015-10-27 14:25:13 -04:00
2015-10-27 21:22:54 -04:00
// Make sure the set is still available with FFZ.
2016-10-20 02:34:55 -04:00
if ( this . ffz . emote _sets && ! this . ffz . emote _sets [ exact _id ] )
2015-10-27 21:22:54 -04:00
this . ffz . emote _sets [ exact _id ] = emote _set ;
2015-10-27 14:25:13 -04:00
// It's a valid set if we get here, so make it global.
2016-09-30 13:09:03 -04:00
if ( this . global _sets . indexOf ( set _id ) === - 1 )
this . global _sets . push ( set _id ) ;
2015-10-24 22:44:00 -04:00
2016-09-30 13:09:03 -04:00
if ( this . default _sets . indexOf ( set _id ) === - 1 )
this . default _sets . push ( set _id ) ;
2015-10-24 22:44:00 -04:00
if ( this . ffz . global _sets && this . ffz . global _sets . indexOf ( exact _id ) === - 1 )
this . ffz . global _sets . push ( exact _id ) ;
if ( this . ffz . default _sets && this . ffz . default _sets . indexOf ( exact _id ) === - 1 )
this . ffz . default _sets . push ( exact _id ) ;
2016-03-26 16:09:36 -04:00
2016-07-13 02:31:26 -04:00
// Update tab completion.
if ( this . ffz . _inputv )
Ember . propertyDidChange ( this . ffz . _inputv , 'ffz_emoticons' ) ;
2015-10-24 22:44:00 -04:00
} ;
2016-09-30 13:09:03 -04:00
API . prototype . unregister _global _set = function ( set _id ) {
var exact _id = this . id + '-' + set _id ,
emote _set = this . emote _sets [ set _id ] ;
2015-10-24 22:44:00 -04:00
2015-10-27 14:25:13 -04:00
if ( ! emote _set )
2015-10-24 22:44:00 -04:00
return ;
2015-10-27 14:25:13 -04:00
// Remove the set from global sets.
2016-09-30 13:09:03 -04:00
var ind = this . global _sets . indexOf ( set _id ) ;
2015-10-24 22:44:00 -04:00
if ( ind !== - 1 )
this . global _sets . splice ( ind , 1 ) ;
2016-09-30 13:09:03 -04:00
ind = this . default _sets . indexOf ( set _id ) ;
2015-10-24 22:44:00 -04:00
if ( ind !== - 1 )
this . default _sets . splice ( ind , 1 ) ;
ind = this . ffz . global _sets ? this . ffz . global _sets . indexOf ( exact _id ) : - 1 ;
if ( ind !== - 1 )
this . ffz . global _sets . splice ( ind , 1 ) ;
ind = this . ffz . default _sets ? this . ffz . default _sets . indexOf ( exact _id ) : - 1 ;
if ( ind !== - 1 )
this . ffz . default _sets . splice ( ind , 1 ) ;
2016-03-26 16:09:36 -04:00
2016-07-13 02:31:26 -04:00
// Update tab completion.
if ( this . ffz . _inputv )
Ember . propertyDidChange ( this . ffz . _inputv , 'ffz_emoticons' ) ;
2015-10-24 22:44:00 -04:00
} ;
// -----------------------
// Per-Channel Emote Sets
// -----------------------
2016-09-30 13:09:03 -04:00
API . prototype . register _room _set = function ( room _id , set _id , emote _set ) {
var exact _id = this . id + '-' + set _id ,
2015-10-27 14:25:13 -04:00
room = this . ffz . rooms && this . ffz . rooms [ room _id ] ;
2015-10-24 22:44:00 -04:00
2015-10-27 14:25:13 -04:00
if ( ! room )
throw new Error ( "Room not loaded" ) ;
2015-10-24 22:44:00 -04:00
2015-10-27 14:25:13 -04:00
if ( emote _set ) {
// If a set was provided, load it.
emote _set . title = emote _set . title || "Channel: " + ( room . display _name || room _id ) ;
emote _set . _type = emote _set . _type || 1 ;
2015-10-24 22:44:00 -04:00
2016-09-30 13:09:03 -04:00
emote _set = this . load _set ( set _id , emote _set ) ;
2015-10-27 14:25:13 -04:00
} else
2016-09-30 13:09:03 -04:00
emote _set = this . emote _sets [ set _id ] ;
2015-10-24 22:44:00 -04:00
2015-10-27 14:25:13 -04:00
if ( ! emote _set )
throw new Error ( "Invalid set ID" ) ;
2015-10-27 21:22:54 -04:00
// Make sure the set is still available with FFZ.
if ( ! this . ffz . emote _sets [ exact _id ] )
this . ffz . emote _sets [ exact _id ] = emote _set ;
2015-10-27 14:25:13 -04:00
// Register it on the room.
2016-10-20 16:41:04 -04:00
if ( room . ext _sets && room . ext _sets . indexOf ( exact _id ) === - 1 )
room . ext _sets . push ( exact _id ) ;
if ( emote _set . users . indexOf ( room _id ) === - 1 )
emote _set . users . push ( room _id ) ;
2016-03-26 16:09:36 -04:00
2016-07-13 02:31:26 -04:00
// Update tab completion.
if ( this . ffz . _inputv )
Ember . propertyDidChange ( this . ffz . _inputv , 'ffz_emoticons' ) ;
2015-10-27 14:25:13 -04:00
}
2016-09-30 13:09:03 -04:00
API . prototype . unregister _room _set = function ( room _id , set _id ) {
var exact _id = this . id + '-' + set _id ,
emote _set = this . emote _sets [ set _id ] ,
2015-10-27 14:25:13 -04:00
room = this . ffz . rooms && this . ffz . rooms [ room _id ] ;
if ( ! emote _set || ! room )
return ;
2016-03-25 18:32:35 -04:00
var ind = room . ext _sets ? room . ext _sets . indexOf ( exact _id ) : - 1 ;
2015-10-27 14:25:13 -04:00
if ( ind !== - 1 )
room . ext _sets . splice ( ind , 1 ) ;
ind = emote _set . users . indexOf ( room _id ) ;
if ( ind !== - 1 )
emote _set . users . splice ( ind , 1 ) ;
2016-03-26 16:09:36 -04:00
2016-07-13 02:31:26 -04:00
// Update tab completion.
if ( this . ffz . _inputv )
Ember . propertyDidChange ( this . ffz . _inputv , 'ffz_emoticons' ) ;
2015-10-27 14:25:13 -04:00
}
2016-07-13 02:06:50 -04:00
// -----------------------
// Badge APIs
// -----------------------
API . prototype . add _badge = function ( badge _id , badge ) {
2016-11-23 16:41:49 -05:00
var exact _id = this . name _key + '-' + badge _id , // this.id + '-' + badge_id,
2016-07-13 02:06:50 -04:00
2016-11-19 01:59:03 -05:00
real _badge = _ . extend ( { } , badge , {
2016-07-13 02:06:50 -04:00
id : exact _id ,
source _ext : this . id ,
2016-11-19 01:59:03 -05:00
source _id : badge _id
} ) ;
if ( ! real _badge . color )
real _badge . color = "transparent" ;
2016-07-13 02:06:50 -04:00
2016-10-20 02:34:55 -04:00
this . badges [ badge _id ] = real _badge ;
if ( this . ffz . badges )
this . ffz . badges [ exact _id ] = real _badge ;
if ( this . ffz . _badge _style )
utils . update _css ( this . ffz . _badge _style , exact _id , utils . badge _css ( real _badge ) ) ;
2016-07-13 02:06:50 -04:00
}
API . prototype . remove _badge = function ( badge _id ) {
2016-11-23 16:41:49 -05:00
var exact _id = this . name _key + '-' + badge _id ;
2016-10-20 02:34:55 -04:00
this . badges [ badge _id ] = undefined ;
if ( this . ffz . badges )
this . ffz . badges [ exact _id ] = undefined ;
if ( this . ffz . _badge _style )
utils . update _css ( this . ffz . _badge _style , exact _id ) ;
2016-07-13 02:06:50 -04:00
}
2016-05-06 02:23:12 -04:00
// -----------------------
// User Modifications
// -----------------------
2016-07-13 02:06:50 -04:00
API . prototype . user _add _badge = function ( username , slot , badge _id ) {
var user = this . users [ username ] = this . users [ username ] || { } ,
ffz _user = this . ffz . users [ username ] = this . ffz . users [ username ] || { } ,
badges = user . badges = user . badges || { } ,
ffz _badges = ffz _user . badges = ffz _user . badges || { } ,
2016-11-23 16:41:49 -05:00
exact _id = this . name _key + '-' + badge _id ,
2016-07-13 02:06:50 -04:00
badge = { id : exact _id } ;
badges [ slot ] = ffz _badges [ slot ] = badge ;
}
API . prototype . user _remove _badge = function ( username , slot ) {
var user = this . users [ username ] = this . users [ username ] || { } ,
ffz _user = this . ffz . users [ username ] = this . ffz . users [ username ] || { } ,
badges = user . badges = user . badges || { } ,
ffz _badges = ffz _user . badges = ffz _user . badges || { } ;
badges [ slot ] = ffz _badges [ slot ] = null ;
}
2016-12-07 17:58:05 -05:00
API . prototype . room _add _user _badge = function ( room _name , username , slot , badge _id ) {
var ffz _room _users = this . ffz . rooms [ room _name ] && this . ffz . rooms [ room _name ] . users ;
if ( ! ffz _room _users )
return ;
var ffz _user = ffz _room _users [ username ] = ffz _room _users [ username ] || { badges : { } , sets : [ ] } ,
ffz _badges = ffz _user && ffz _user . badges ,
exact _id = this . name _key + '-' + badge _id ,
badge = { id : exact _id } ;
ffz _badges [ slot ] = badge ;
}
API . prototype . room _remove _user _badge = function ( room _name , username , slot ) {
var ffz _room _users = this . ffz . rooms [ room _name ] && this . ffz . rooms [ room _name ] . users ,
ffz _user = ffz _room _users && ffz _room _users [ username ] ,
ffz _badges = ffz _user && ffz _user . badges ;
if ( ffz _badges )
ffz _badges [ slot ] = null ;
}
2016-07-13 02:06:50 -04:00
API . prototype . user _add _set = function ( username , set _id ) {
var user = this . users [ username ] = this . users [ username ] || { } ,
ffz _user = this . ffz . users [ username ] = this . ffz . users [ username ] || { } ,
2016-05-06 02:23:12 -04:00
emote _sets = user . sets = user . sets || [ ] ,
ffz _sets = ffz _user . sets = ffz _user . sets || [ ] ,
exact _id = this . id + '-' + set _id ;
2016-09-30 13:09:03 -04:00
if ( emote _sets . indexOf ( set _id ) === - 1 )
emote _sets . push ( set _id ) ;
2016-05-06 02:23:12 -04:00
if ( ffz _sets . indexOf ( exact _id ) === - 1 )
ffz _sets . push ( exact _id ) ;
// Update tab completion.
var user = this . ffz . get _user ( ) ;
2016-07-13 02:06:50 -04:00
if ( this . ffz . _inputv && user && user . login === username )
2016-07-13 02:31:26 -04:00
Ember . propertyDidChange ( this . ffz . _inputv , 'ffz_emoticons' ) ;
2016-05-06 02:23:12 -04:00
}
2016-07-13 02:06:50 -04:00
API . prototype . user _remove _set = function ( username , set _id ) {
var user = this . users [ username ] ,
ffz _user = this . ffz . users [ username ] ,
2016-05-06 02:23:12 -04:00
emote _sets = user && user . sets ,
ffz _sets = ffz _user && ffz _user . sets ,
exact _id = this . id + '-' + set _id ;
2016-09-30 13:09:03 -04:00
var ind = emote _sets ? emote _sets . indexOf ( set _id ) : - 1 ;
2016-05-06 02:23:12 -04:00
if ( ind !== - 1 )
emote _sets . splice ( ind , 1 ) ;
ind = ffz _sets ? ffz _sets . indexOf ( exact _id ) : - 1 ;
if ( ind !== - 1 )
ffz _sets . splice ( ind , 1 ) ;
// Update tab completion.
var user = this . ffz . get _user ( ) ;
2016-07-13 02:06:50 -04:00
if ( this . ffz . _inputv && user && user . login === username )
2016-07-13 02:31:26 -04:00
Ember . propertyDidChange ( this . ffz . _inputv , 'ffz_emoticons' ) ;
2016-05-06 02:23:12 -04:00
}
// -----------------------
// Chat Callback
// -----------------------
API . prototype . register _chat _filter = function ( filter ) {
2016-10-20 02:34:55 -04:00
this . on ( 'room-message' , filter ) ;
2016-05-06 02:23:12 -04:00
}
API . prototype . unregister _chat _filter = function ( filter ) {
2016-10-20 02:34:55 -04:00
this . off ( 'room-message' , filter ) ;
2016-05-06 02:23:12 -04:00
}
2015-10-27 14:25:13 -04:00
// -----------------------
// Channel Callbacks
// -----------------------
2016-11-20 13:43:12 -05:00
API . prototype . iterate _chat _views = function ( func ) {
if ( func === undefined )
func = this . trigger . bind ( this , 'chat-view-init' ) ;
if ( this . ffz . _chatv ) {
var view = this . ffz . _chatv ;
func ( view . get ( 'element' ) , view ) ;
}
}
2016-10-20 02:34:55 -04:00
API . prototype . iterate _rooms = function ( func ) {
if ( func === undefined )
func = this . trigger . bind ( this , 'room-add' ) ;
for ( var room _id in this . ffz . rooms )
func ( room _id ) ;
}
2015-10-27 14:25:13 -04:00
API . prototype . register _on _room _callback = function ( callback , dont _iterate ) {
2016-10-20 16:41:04 -04:00
var cb = this . register _room _set . bind ( this , room _id ) ,
2016-10-20 02:34:55 -04:00
thing = function ( room _id ) {
2016-10-20 16:41:04 -04:00
return callback ( room _id , cb ) ;
2016-10-20 02:34:55 -04:00
} ;
2015-10-24 22:44:00 -04:00
2016-10-20 02:34:55 -04:00
thing . original _func = callback ;
this . on ( 'room-add' , thing ) ;
2015-10-24 22:44:00 -04:00
2016-10-20 02:34:55 -04:00
if ( ! dont _iterate )
this . iterate _rooms ( thing ) ;
}
2015-10-24 22:44:00 -04:00
API . prototype . unregister _on _room _callback = function ( callback ) {
2016-10-20 02:34:55 -04:00
var e = this . _events [ 'room-add' ] || [ ] ;
for ( var i = e . length ; i -- ; ) {
var cb = e [ i ] ;
if ( cb && cb . original _func === callback )
e . splice ( i , 1 ) ;
}
2015-10-24 22:44:00 -04:00
}