<commit_before>class RealtimeController extends KDController

  constructor: (options = {}, data) ->

    # when we remove broker completely, we no longer need to
    # make another caching here
    @channels = {}

    super options, data

    {subscribekey} = KD.config.pubnub

    @pubnub = PUBNUB.init subscribe_key : subscribekey

  # subscriptionData =
  #   serviceType: 'socialapi'
  #   group      : group.slug
  #   channelType: socialApiChannel.typeConstant
  #   channelName: socialApiChannel.name
  authenticate: (options = {}, callback = noop) ->

    { channelName, typeConstant, group } = options
    return callback { message: "channel name is not defined" }  unless channelName

    endPoint = '/api/gatekeeper/channel/authenticate'
    data = {name: channelName, typeConstant, group}
    KD.utils.doXhrRequest {endPoint, data}, callback

  subscribe: (options = {}) ->

    pubnubChannelName = prepareChannelName options

    # return channel if it already exists
    return @channels[pubnubChannelName]  if @channels[pubnubChannelName]

    channelInstance = new PubnubChannel name: pubnubChannelName
    @channels[pubnubChannelName] = channelInstance

    @pubnub.subscribe
      channel : pubnubChannelName
      message : (message, env, channel) =>
        return  unless message
        {eventName, body} = message

        # no need to emit any events when not subscribed
        return  unless @channels[channel]

        @channels[channel].emit eventName, body

    return channelInstance

  prepareChannelName = (options) ->
    { eventType } = options
    switch eventType
      when 'channel'
        { channelName, typeConstant, group, token } = options
        return "channel-#{token}-#{group}-#{typeConstant}-#{channelName}"<commit_msg>pubnub: set restore flag as true while subscribing to channel<commit_after>class RealtimeController extends KDController

  constructor: (options = {}, data) ->

    # when we remove broker completely, we no longer need to
    # make another caching here
    @channels = {}

    super options, data

    {subscribekey} = KD.config.pubnub

    @pubnub = PUBNUB.init subscribe_key : subscribekey

  # subscriptionData =
  #   serviceType: 'socialapi'
  #   group      : group.slug
  #   channelType: socialApiChannel.typeConstant
  #   channelName: socialApiChannel.name
  authenticate: (options = {}, callback = noop) ->

    { channelName, typeConstant, group } = options
    return callback { message: "channel name is not defined" }  unless channelName

    endPoint = '/api/gatekeeper/channel/authenticate'
    data = {name: channelName, typeConstant, group}
    KD.utils.doXhrRequest {endPoint, data}, callback

  subscribe: (options = {}) ->

    pubnubChannelName = prepareChannelName options

    # return channel if it already exists
    return @channels[pubnubChannelName]  if @channels[pubnubChannelName]

    channelInstance = new PubnubChannel name: pubnubChannelName
    @channels[pubnubChannelName] = channelInstance

    @pubnub.subscribe
      channel : pubnubChannelName
      message : (message, env, channel) =>
        return  unless message
        console.log 'mesaj mi var', env
        {eventName, body} = message

        # no need to emit any events when not subscribed
        return  unless @channels[channel]

        @channels[channel].emit eventName, body
      restore : yes

    return channelInstance

  prepareChannelName = (options) ->
    { eventType } = options
    switch eventType
      when 'channel'
        { channelName, typeConstant, group, token } = options
        return "channel-#{token}-#{group}-#{typeConstant}-#{channelName}"
{'fraction_non_alphanumeric': 0.09051014810751508, 'fraction_numerical': 0.0, 'mean_word_length': 3.265497076023392, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '5509605', 'n_tokens_mistral': 1028, 'n_tokens_neox': 986, 'n_words': 287}