namespace Models { export abstract class Channel { channelId : number ; channelType : Models . ChannelType ; owners : string [ ] = [ ] ; users : string [ ] = [ ] ; chats : Models . Chat [ ] = [ ] ; name : string ; constructor ( channelId , channelType ) { this . channelId = channelId ; this . channelType = channelType ; this . name = "Channel #" + channelId . toString ( ) ; } public static createChannel ( channelId , channelType ) { switch ( channelType ) { case ChannelType . Room : return new RoomChannel ( channelId ) ; case ChannelType . Game : return new GameChannel ( channelId ) ; } throw "Unknown or unsupported channel type: " + channelType . toString ( ) ; } public syncOwners ( owners ) { let ownerNames = new Array ( owners . length ) ; for ( let i = 0 ; i < owners . length ; ++ i ) { ownerNames [ i ] = owners [ i ] . name ; } return Utils . setSync ( this . owners , ownerNames ) ; } public mergeUsers ( users ) { let touch = false ; for ( let i = 0 ; i < users . length ; ++ i ) { if ( Utils . setAdd ( this . users , users [ i ] . name ) ) touch = true ; } return touch ; } public appendChat ( message , importance , timestamp ) { this . chats . push ( { sender : message . user . name , text : message . text , importance : importance , received : timestamp } ) ; return true ; } } }