<commit_before># this class will register itself just before application starts loading, right after framework is ready
KD.extend
  impersonate : (username)->
    KD.remote.api.JAccount.impersonate username, (err)->
      if err then new KDNotificationView title: err.message
      else location.reload()

  notifyError_:(message)->
    console.log message
    new KDNotificationView
      type     : 'mini'
      cssClass : 'error'
      title    : message
      duration : 3500

  requireMembership:(options={})->

    {callback, onFailMsg, onFail, silence, tryAgain, groupName} = options
    unless KD.isLoggedIn()
      # if there is fail message, display it
      if onFailMsg
        @notifyError_ onFailMsg

      # if there is fail method, call it
      onFail?()

      # if it's not a silent operation redirect
      unless silence
        @getSingleton('router').handleRoute "/Login", KD.config.entryPoint

      # if there is callback and we want to try again
      if callback? and tryAgain
        unless KD.lastFuncCall
          {mainController} = KD.singletons
          mainController.once "accountChanged.to.loggedIn", =>
            if groupName and KD.isLoggedIn()
              @joinGroup_ groupName, (res)=>
                unless res then return @notifyError_ "Joining to #{groupName} group failed"
                KD.lastFuncCall?()
                KD.lastFuncCall = null
        KD.lastFuncCall = callback
    else
      if groupName
        @joinGroup_ groupName, (res)=>
          if res then callback?()
          else @notifyError_ "Joining to #{groupName} group failed 2"
      else callback?()

  joinGroup_:(groupName, callback)->
    unless groupName then return callback true
    user = @whoami()
    user.fetchGroups (err, groups)=>
      if err or !groups then return callback false
      @remote.api.JGroup.one { slug: groupName }, (err, currentGroup)=>
        if err then return @notifyError_ err.message
        for group in groups
          if groupName is group.group.slug
            return callback true
        currentGroup.join (err)=>
          if err then return callback false
          @notifyError_ "Joined to #{groupName} group!"
          return callback true

  jsonhTest:->
    method    = 'fetchQuestionTeasers'
    testData  = {
      foo: 10
      bar: 11<commit_msg>[client][app][mainapp] added notification to show user joins a group when they are in any interaction with that group<commit_after># this class will register itself just before application starts loading, right after framework is ready
KD.extend
  impersonate : (username)->
    KD.remote.api.JAccount.impersonate username, (err)->
      if err then new KDNotificationView title: err.message
      else location.reload()

  notify_:(message, type)->
    console.log message
    new KDNotificationView
      cssClass : "#{type}"
      title    : message
      duration : 3500

  requireMembership:(options={})->

    {callback, onFailMsg, onFail, silence, tryAgain, groupName} = options
    unless KD.isLoggedIn()
      # if there is fail message, display it
      if onFailMsg
        @notify_ onFailMsg, "error"

      # if there is fail method, call it
      onFail?()

      # if it's not a silent operation redirect
      unless silence
        @getSingleton('router').handleRoute "/Login", KD.config.entryPoint

      # if there is callback and we want to try again
      if callback? and tryAgain
        unless KD.lastFuncCall
          {mainController} = KD.singletons
          mainController.once "accountChanged.to.loggedIn", =>
            if groupName and KD.isLoggedIn()
              @joinGroup_ groupName, (res)=>
                unless res then return @notify_ "Joining to #{groupName} group failed", "error"
                KD.lastFuncCall?()
                KD.lastFuncCall = null
        KD.lastFuncCall = callback
    else
      if groupName
        @joinGroup_ groupName, (res)=>
          if res

            callback?()
          else @notify_ "Joining to #{groupName} group failed", "error"
      else callback?()

  joinGroup_:(groupName, callback)->
    unless groupName then return callback true
    user = @whoami()
    user.fetchGroups (err, groups)=>
      if err or !groups then return callback false
      @remote.api.JGroup.one { slug: groupName }, (err, currentGroup)=>
        if err then return @notify_ err.message, "error"
        for group in groups
          if groupName is group.group.slug
            return callback true
        currentGroup.join (err)=>
          if err then return callback false
          @notify_ "Joined to #{groupName} group!", "success"
          return callback true

  jsonhTest:->
    method    = 'fetchQuestionTeasers'
    testData  = {
      foo: 10
      bar: 11
{'fraction_non_alphanumeric': 0.08524039470921688, 'fraction_numerical': 0.003569179088809574, 'mean_word_length': 2.388335704125178, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '1073486', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1262, 'n_words': 446}