<commit_before>'use strict'

###
The JoinCtrl is responsible for collecting the username and calling the PubNub.init() method
when the "Join" button is clicked.
###
angular.module('PubNubAngularApp')
  .controller 'JoinCtrl', ($rootScope, $scope, $location, PubNub) ->
    $scope.data = {username:'Anonymous ' + Math.floor(Math.random() * 1000)}

    $scope.join = ->
      $rootScope.data ||= {}
      $rootScope.data.username = $scope.data?.username
      $rootScope.data.super    = $scope.data?.super

      #
      # NOTE! We include the secret & auth keys here only for demo purposes!
      #
      # In a real app, the secret key should be protected by server-only access, and
      # different/separate auth keys should be distributed by the server and used
      # for user authentication.
      #
      $rootScope.secretKey = if $scope.data.super then '<KEY>' else null
      $rootScope.authKey   = if $scope.data.super then 'ChooseABetterSecret' else null

      PubNub.init({
        subscribe_key : 'sub-c-d66562f0-62b0-11e3-b12d-02ee2ddab7fe'
        publish_key   : '<KEY>'
        # WARNING: DEMO purposes only, never provide secret key in a real web application!
        secret_key    : $rootScope.secretKey
        auth_key      : $rootScope.authKey
        uuid          : Math.floor(Math.random() * 1000000) + '__' + $scope.data.username
        ssl           : true
      })
      
      if $scope.data.super
        ### Grant access to the SuperHeroes room for supers only! ###
        PubNub.ngGrant({channel:'SuperHeroes',auth_key:$rootScope.authKey,read:true,write:true,callback:->console.log('SuperHeroes! all set', arguments)})
        PubNub.ngGrant({channel:"SuperHeroes-pnpres",auth_key:$rootScope.authKey,read:true,write:true,callback:->console.log('SuperHeroes! presence all set', arguments)})
        # Let everyone see the control channel so they can retrieve the rooms list
        PubNub.ngGrant({channel:'__controlchannel',read:true,write:true,callback:->console.log('control channel all set', arguments)})
        PubNub.ngGrant({channel:'__controlchannel-pnpres',read:true,write:true,callback:->console.log('control channel presence all set', arguments)})

      $location.path '/chat'
      
    $(".prettyprint")


###
The ChatCtrl is responsible for creating, displaying, subscribing to, and
chatting in channels
###
angular.module('PubNubAngularApp')
  .controller 'ChatCtrl', ($rootScope, $scope, $location, PubNub) ->
    $location.path '/join' unless PubNub.initialized()
    
    ### Use a "control channel" to collect channel creation messages ###
    $scope.controlChannel = '__controlchannel'
    $scope.channels = []

    ### Publish a chat message ###
    $scope.publish = ->
      console.log 'publish', $scope
      return unless $scope.selectedChannel
      PubNub.ngPublish { channel: $scope.selectedChannel, message: {text:$scope.newMessage, user:$scope.data.username} }
      $scope.newMessage = ''

    ### Create a new channel ###
    $scope.createChannel = ->
      console.log 'createChannel', $scope
      return unless $scope.data.super && $scope.newChannel
      channel = $scope.newChannel
      $scope.newChannel = ''

      # grant anonymous access to channel and presence
      PubNub.ngGrant({channel:channel,read:true,write:true,callback:->console.log("#{channel} all set", arguments)})
      PubNub.ngGrant({channel:"#{channel}-pnpres",read:true,write:true,callback:->console.log("#{channel} presence all set", arguments)})

      # publish the channel creation message to the control channel
      PubNub.ngPublish { channel: $scope.controlChannel, message: channel }

      # wait a tiny bit before selecting the channel to allow time for the presence
      # handlers to register
      setTimeout ->
        $scope.subscribe channel
        $scope.showCreate = false
      , 100
<commit_msg>try to fixup -pnpres authorization<commit_after>'use strict'

###
The JoinCtrl is responsible for collecting the username and calling the PubNub.init() method
when the "Join" button is clicked.
###
angular.module('PubNubAngularApp')
  .controller 'JoinCtrl', ($rootScope, $scope, $location, PubNub) ->
    $scope.data = {username:'Anonymous ' + Math.floor(Math.random() * 1000)}

    $scope.join = ->
      $rootScope.data ||= {}
      $rootScope.data.username = $scope.data?.username
      $rootScope.data.super    = $scope.data?.super

      #
      # NOTE! We include the secret & auth keys here only for demo purposes!
      #
      # In a real app, the secret key should be protected by server-only access, and
      # different/separate auth keys should be distributed by the server and used
      # for user authentication.
      #
      $rootScope.secretKey = if $scope.data.super then '<KEY>' else null
      $rootScope.authKey   = if $scope.data.super then 'ChooseABetterSecret' else null

      PubNub.init({
        subscribe_key : 'sub-c-d66562f0-62b0-11e3-b12d-02ee2ddab7fe'
        publish_key   : '<KEY>'
        # WARNING: DEMO purposes only, never provide secret key in a real web application!
        secret_key    : $rootScope.secretKey
        auth_key      : $rootScope.authKey
        uuid          : Math.floor(Math.random() * 1000000) + '__' + $scope.data.username
        ssl           : true
      })
      
      if $scope.data.super
        ### Grant access to the SuperHeroes room for supers only! ###
        PubNub.ngGrant({channel:'SuperHeroes',auth_key:$rootScope.authKey,read:true,write:true,callback:->console.log('SuperHeroes! all set', arguments)})
        PubNub.ngGrant({channel:"SuperHeroes-pnpres",auth_key:$rootScope.authKey,read:true,write:false,callback:->console.log('SuperHeroes! presence all set', arguments)})
        # Let everyone see the control channel so they can retrieve the rooms list
        PubNub.ngGrant({channel:'__controlchannel',read:true,write:true,callback:->console.log('control channel all set', arguments)})
        PubNub.ngGrant({channel:'__controlchannel-pnpres',read:true,write:false,callback:->console.log('control channel presence all set', arguments)})

      $location.path '/chat'
      
    $(".prettyprint")


###
The ChatCtrl is responsible for creating, displaying, subscribing to, and
chatting in channels
###
angular.module('PubNubAngularApp')
  .controller 'ChatCtrl', ($rootScope, $scope, $location, PubNub) ->
    $location.path '/join' unless PubNub.initialized()
    
    ### Use a "control channel" to collect channel creation messages ###
    $scope.controlChannel = '__controlchannel'
    $scope.channels = []

    ### Publish a chat message ###
    $scope.publish = ->
      console.log 'publish', $scope
      return unless $scope.selectedChannel
      PubNub.ngPublish { channel: $scope.selectedChannel, message: {text:$scope.newMessage, user:$scope.data.username} }
      $scope.newMessage = ''

    ### Create a new channel ###
    $scope.createChannel = ->
      console.log 'createChannel', $scope
      return unless $scope.data.super && $scope.newChannel
      channel = $scope.newChannel
      $scope.newChannel = ''

      # grant anonymous access to channel and presence
      PubNub.ngGrant({channel:channel,read:true,write:true,callback:->console.log("#{channel} all set", arguments)})
      PubNub.ngGrant({channel:"#{channel}-pnpres",read:true,write:false,callback:->console.log("#{channel} presence all set", arguments)})

      # publish the channel creation message to the control channel
      PubNub.ngPublish { channel: $scope.controlChannel, message: channel }

      # wait a tiny bit before selecting the channel to allow time for the presence
      # handlers to register
      setTimeout ->
        $scope.subscribe channel
        $scope.showCreate = false
      , 100

{'fraction_non_alphanumeric': 0.12342017023471756, 'fraction_numerical': 0.008253804488006191, 'mean_word_length': 3.337248322147651, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6326178', 'n_tokens_mistral': 2302, 'n_tokens_neox': 2197, 'n_words': 582}