<commit_before>goog.provide('KeepMeContributing.Worker.ContributionStatusNotifier');

goog.require('KeepMeContributing.Worker.TimeOfDay');

goog.require('KeepMeContributing.ContributionStatus');
goog.require('KeepMeContributing.Github');

goog.require('goog.Promise');

KeepMeContributing.Worker.ContributionStatusNotifier = class {
  /**
   * @param {string} username
   * @param {KeepMeContributing.ContributionStatus} status
   */
  constructor(username, status){
    /**
     * @private
     * @type {string}
     */
    this.username_ = username;

    /**
     * @private
     * @type {KeepMeContributing.ContributionStatus}
     */
    this.status_ = status;
  }

  /**
   * Simple wrapper for Notification#constructor.
   * Checks if  Notification.permission is 'granted' in advance.
   * @param {string} title passed to new Notification().
   * @param {!NotificationOptions} options passed to new Notification().
   */
  notify(title, options){
    if (this.getPermission() === 'granted'){
      this.showNotification(title, options);
    } else {
      console.warn(`Denied to show notification. Current Notification.permission is ${Notification.permission}`);
    }
  }

  /**
   * Fetch contibution status from GitHub, then notify the result.
   * @param {KeepMeContributing.Worker.TimeOfDay} time
   * @param {Date} actualCurrentTime
   * @return {goog.Promise<undefined, ?>}
   */
  askToNotifyAt(time, actualCurrentTime = new Date()){
    return this.status_.queryHasContributedAt(actualCurrentTime).then(
      (/** boolean */ contributed) => {
        if (contributed){
          this.notify(
            `Congratulations! ${this.username_} has already contributed today!`,
            {
              tag: KeepMeContributing.Worker.ContributionStatusNotifier.TAG,
              icon: '/img/icon.png'
            }
          );
        } else {
          this.notify(
            `Oh my... ${this.username_} has NOT contributed yet today!`,
            {
              tag: KeepMeContributing.Worker.ContributionStatusNotifier.TAG,
              icon: '/img/icon-not_yet.png'
            }
          );
        }
      }, (error) => {
        let /** string */ message = error.toString();
        console.error(message);
        this.notify(
          'An error occurred while asking if contributed',
          {
            tag: KeepMeContributing.Worker.ContributionStatusNotifier.TAG,
            icon: '/img/icon-error.png'
          }<commit_msg>:shirt: fix error by eslint<commit_after>goog.provide('KeepMeContributing.Worker.ContributionStatusNotifier');

goog.require('KeepMeContributing.Worker.TimeOfDay');

goog.require('KeepMeContributing.ContributionStatus');
goog.require('KeepMeContributing.Github');

goog.require('goog.Promise');

KeepMeContributing.Worker.ContributionStatusNotifier = class {
  /**
   * @param {string} username
   * @param {KeepMeContributing.ContributionStatus} status
   */
  constructor(username, status){
    /**
     * @private
     * @type {string}
     */
    this.username_ = username;

    /**
     * @private
     * @type {KeepMeContributing.ContributionStatus}
     */
    this.status_ = status;
  }

  /**
   * Simple wrapper for Notification#constructor.
   * Checks if  Notification.permission is 'granted' in advance.
   * @param {string} title passed to new Notification().
   * @param {!NotificationOptions} options passed to new Notification().
   */
  notify(title, options){
    if (this.getPermission() === 'granted'){
      this.showNotification(title, options);
    } else {
      console.warn(`Denied to show notification. Current Notification.permission is ${Notification.permission}`);
    }
  }

  /**
   * Fetch contibution status from GitHub, then notify the result.
   * @param {KeepMeContributing.Worker.TimeOfDay} time
   * @param {Date} actualCurrentTime
   * @return {goog.Promise<undefined, ?>}
   */
  askToNotifyAt(time, actualCurrentTime = new Date()){
    return this.status_.queryHasContributedAt(actualCurrentTime).then(
      (/** boolean */ contributed) => {
        if (contributed){
          this.notify(
            `Congratulations! ${this.username_} has already contributed today!`,
            {
              tag: KeepMeContributing.Worker.ContributionStatusNotifier.TAG,
              icon: '/img/icon.png'
            }
          );
        } else {
          this.notify(
            `Oh my... ${this.username_} has NOT contributed yet today!`,
            {
              tag: KeepMeContributing.Worker.ContributionStatusNotifier.TAG,
              icon: '/img/icon-not_yet.png'
            }
          );
        }
      },
      (error) => {
        let /** string */ message = error.toString();
        console.error(message);
        this.notify(
          'An error occurred while asking if contributed',
          {
            tag: KeepMeContributing.Worker.ContributionStatusNotifier.TAG,
            icon: '/img/icon-error.png'
          }
{'fraction_non_alphanumeric': 0.124343964473153, 'fraction_numerical': 0.0, 'mean_word_length': 2.5570710696338836, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3138653', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1381, 'n_words': 276}