<commit_before>_ = require 'lodash'
kd = require 'kd'
Promise = require 'bluebird'
browserNotifications = require('browser-notifications')(Promise)

###*
 * Makes sure browser notifications are supported.
 *
 * @param {Function} callback
 * @return {Function|undefined} callback
###
supported = (callback) ->
  return callback  if browserNotifications.isSupported()


###*
 * Makes sure that user has given us permissions to send desktop notifications.
 *
 * @param {Function} callback - to be called with err, and args object.
 * @return {Function}
###
permitted = (callback) ->
  return (args...) ->
    browserNotifications
      .requestPermissions()
      .then (isPermitted) ->
        return if isPermitted
        then callback null, args...
        else callback { message: 'Browser notifications are not permitted' }
      .catch (err) -> callback err


module.exports = class DesktopNotificationsController extends kd.Controller

  ###
   * Makes sure browser notifications are supported and permitted by user.
   *
   * NOTE: it curries given options object with the result of err from
   * `permitted` helper.
   *
   * @param {Object} options
   * @param {String} options.title
   * @param {String} options.message
   * @return {Promise} a promise which will resolve if user clicks to notification.
  ###
  notify: supported permitted (err, options) ->

    # return a promise for caller of this method, both errors and the result of
    # `browserNotifications.send` are reachable via that promise.
    new Promise (resolve, reject) ->
      return reject err  if err

      options = _.assign {}, defaultNotificationOptions, options

      return browserNotifications
        .send options.title, options.message, options.iconUrl
        .then resolve
        .catch reject


defaultNotificationOptions =
  iconUrl: '/a/images/logos/share_logo.png'
  title: ''
  message: ''

<commit_msg>client: align equals<commit_after>_                    = require 'lodash'
kd                   = require 'kd'
Promise              = require 'bluebird'
browserNotifications = require('browser-notifications')(Promise)

###*
 * Makes sure browser notifications are supported.
 *
 * @param {Function} callback
 * @return {Function|undefined} callback
###
supported = (callback) ->
  return callback  if browserNotifications.isSupported()


###*
 * Makes sure that user has given us permissions to send desktop notifications.
 *
 * @param {Function} callback - to be called with err, and args object.
 * @return {Function}
###
permitted = (callback) ->
  return (args...) ->
    browserNotifications
      .requestPermissions()
      .then (isPermitted) ->
        return if isPermitted
        then callback null, args...
        else callback { message: 'Browser notifications are not permitted' }
      .catch (err) -> callback err


module.exports = class DesktopNotificationsController extends kd.Controller

  ###
   * Makes sure browser notifications are supported and permitted by user.
   *
   * NOTE: it curries given options object with the result of err from
   * `permitted` helper.
   *
   * @param {Object} options
   * @param {String} options.title
   * @param {String} options.message
   * @return {Promise} a promise which will resolve if user clicks to notification.
  ###
  notify: supported permitted (err, options) ->

    # return a promise for caller of this method, both errors and the result of
    # `browserNotifications.send` are reachable via that promise.
    new Promise (resolve, reject) ->
      return reject err  if err

      options = _.assign {}, defaultNotificationOptions, options

      return browserNotifications
        .send options.title, options.message, options.iconUrl
        .then resolve
        .catch reject


defaultNotificationOptions =
  iconUrl : '/a/images/logos/share_logo.png'
  title   : ''
  message : ''


{'fraction_non_alphanumeric': 0.09689922480620156, 'fraction_numerical': 0.0, 'mean_word_length': 3.1356837606837606, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '6981979', 'n_tokens_mistral': 1026, 'n_tokens_neox': 990, 'n_words': 370}