<commit_before>import { Component, OnInit, ViewChild } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { WASAlertComponent, UserService, User, UserParams } from 'wickeyappstore';
import { Howl } from 'howler';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent implements OnInit {
  @ViewChild(WASAlertComponent) wasalert: WASAlertComponent;
  public busy: Subscription;
  title = 'WAS Tutorial';
  private test_alert = 0;
  public userMessage = '';
  public verifiedUser = false;
  private oneSignal: any;
  private sound = new Howl({
    src: ['assets/sounds/airhorn.mp3']
  });

  constructor(
    public userService: UserService
  ) {
    // Wait for user service to load
    this.userService.user.subscribe((usr: User) => {
      console.log('USER LOADED: usr.user_id', usr.user_id);
      // This initiate the Push Service, and asks to enable push on load
      this.loadOneSignal();
    });
  }


  public tutorial_config: Object = {
    pagination: '.swiper-pagination',
    paginationClickable: true,
    slidesPerView: 'auto',
    centeredSlides: true,
    spaceBetween: 20,
    initialSlide: 1, // slide number which you want to show-- 0 by default
  };

  playHorn(horn: number) {
    console.log('playHorn', horn);
    if (horn === 1) {
      this.sound.play();
    } else {
      // check if locked
      console.log('this horn is locked');
      this.wasalert.open(
        { title: 'Locked', text: 'This sound is locked' } // Login error
      );
    }
  }
  closealert(action: any) {
    console.log('close alert');
  }

  // PUSH NOTIFICATIONS
  // STEP 1: Create an account https://onesignal.com
  // STEP 2: https://documentation.onesignal.com/docs/web-push-sdk-setup-https
  // OneSignal API: https://documentation.onesignal.com/docs/web-push-sdk
  // https://documentation.onesignal.com/v3.0/docs/customize-permission-messages
  doOneSignal() {
    // INIT PUSH serviceWorkerUpdaterPath: 'was-tutorial',
    this.oneSignal.push(['init', {
      appId: '5198c0dc-616c-46df-9357-15830b47ffbc',
      safari_web_id: 'web.onesignal.auto.48d27e8c-5bf0-4f8f-a083-e09c208eb2cb',
      path: 'was-tutorial/',
      autoRegister: false,
      allowLocalhostAsSecureOrigin: true,
      notifyButton: {
        enable: false
      },
      promptOptions: {
        /* Change bold title, limited to 30 characters */
        siteName: 'AirHorner',
        /* Subtitle, limited to 90 characters */
        actionMessage: `We'd like to show you push notifications for new app content and important news.`,
        /* Example notification title */
        exampleNotificationTitle: 'New App Content!',
        /* Example notification message */
        exampleNotificationMessage: 'New horn sounds are here, honk honk!',
        /* Text below example notification, limited to 50 characters */
        exampleNotificationCaption: 'You can unsubscribe anytime',
        /* Accept button text, limited to 15 characters */
        acceptButtonText: 'ALLOW',
        /* Cancel button text, limited to 15 characters */
        cancelButtonText: 'NO THANKS'
    }
    }]);
    // REGISTER FOR PUSH
    this.oneSignal.push(() => {
      console.log('OneSignal: Register For Push');
      // CHECK IF PUSH IS ENABLED
      this.oneSignal.isPushNotificationsEnabled().then((isEnabled) => {
        if (isEnabled) {
          console.log('Push notifications are enabled!');
        } else {
          // SHOW PUSH REGISTRATION POPUP
          // this.oneSignal.push(['registerForPushNotifications', {modalPrompt: true}]);
          this.oneSignal.registerForPushNotifications({
            modalPrompt: true
          });
        }
      });
    });
    // // CHECK IF PUSH SUPPORTED
    // this.oneSignal.push(() => {
    //   const isPushSupported = this.oneSignal.isPushNotificationsSupported();
    //   if (isPushSupported) {
    //     console.log('=======\nPUSH ALLOWED\n=======');
    //     // Push notifications are supported
    //   } else {
    //     // Push notifications are not supported
    //     console.log('=======\nOH NO, NO PUSH\n=======');
    //   }
    // });
    // ADD LISTENER ON SUBSCRIPTION CHANGE
    this.oneSignal.push(() => {
      // Occurs when the user's subscription changes to a new value.
      this.oneSignal.on('subscriptionChange', (isSubscribed) => {
        console.log(`OneSignal: The user's subscription state is now:`, isSubscribed);
        this.oneSignal.getUserId().then((userId) => {
          console.log('OneSignal: User ID is', userId);
          this.updateUserPushId(userId);
        });
      });
    });
    // // GET USER ID
    // this.oneSignal.push(() => {
    //   this.oneSignal.getUserId().then((userId) => {
    //     console.log('OneSignal User ID is', userId);
    //     this.updateUserPushId(userId);
    //   });
    // });
  }

  loadOneSignal() {
    console.log('loadOneSignal');
    // Wait till window has OneSignal, else don't do push stuff<commit_msg>UPDATE: Wait to ask for push till after first horn press<commit_after>import { Component, OnInit, ViewChild } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { WASAlertComponent, UserService, User, UserParams } from 'wickeyappstore';
import { Howl } from 'howler';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent implements OnInit {
  @ViewChild(WASAlertComponent) wasalert: WASAlertComponent;
  public busy: Subscription;
  title = 'WAS Tutorial';
  private test_alert = 0;
  public userMessage = '';
  public verifiedUser = false;
  private oneSignal: any;
  private sound = new Howl({
    src: ['assets/sounds/airhorn.mp3']
  });

  constructor(
    public userService: UserService
  ) {
    // Wait for user service to load
    this.userService.user.subscribe((usr: User) => {
      console.log('USER LOADED: usr.user_id', usr.user_id);
      // This initiate the Push Service, and asks to enable push on load
      this.loadOneSignal();
    });
  }


  public tutorial_config: Object = {
    pagination: '.swiper-pagination',
    paginationClickable: true,
    slidesPerView: 'auto',
    centeredSlides: true,
    spaceBetween: 20,
    initialSlide: 1, // slide number which you want to show-- 0 by default
  };

  playHorn(horn: number) {
    console.log('playHorn', horn);
    if (horn === 1) {
      this.sound.play();
      this.askForPush();
    } else {
      // check if locked
      console.log('this horn is locked');
      this.wasalert.open(
        { title: 'Locked', text: 'This sound is locked' } // Login error
      );
    }
  }
  closealert(action: any) {
    console.log('close alert');
  }

  // PUSH NOTIFICATIONS
  // STEP 1: Create an account https://onesignal.com
  // STEP 2: https://documentation.onesignal.com/docs/web-push-sdk-setup-https
  // OneSignal API: https://documentation.onesignal.com/docs/web-push-sdk
  // https://documentation.onesignal.com/v3.0/docs/customize-permission-messages
  doOneSignal() {
    // INIT PUSH serviceWorkerUpdaterPath: 'was-tutorial',
    this.oneSignal.push(['init', {
      appId: '5198c0dc-616c-46df-9357-15830b47ffbc',
      safari_web_id: 'web.onesignal.auto.48d27e8c-5bf0-4f8f-a083-e09c208eb2cb',
      path: 'was-tutorial/',
      autoRegister: false,
      allowLocalhostAsSecureOrigin: true,
      notifyButton: {
        enable: false
      },
      promptOptions: {
        /* Change bold title, limited to 30 characters */
        siteName: 'AirHorner',
        /* Subtitle, limited to 90 characters */
        actionMessage: `We'd like to show you push notifications for new app content and important news.`,
        /* Example notification title */
        exampleNotificationTitle: 'New App Content!',
        /* Example notification message */
        exampleNotificationMessage: 'New horn sounds are here, honk honk!',
        /* Text below example notification, limited to 50 characters */
        exampleNotificationCaption: 'You can unsubscribe anytime',
        /* Accept button text, limited to 15 characters */
        acceptButtonText: 'ALLOW',
        /* Cancel button text, limited to 15 characters */
        cancelButtonText: 'NO THANKS'
    }
    }]);
    // // CHECK IF PUSH SUPPORTED
    // this.oneSignal.push(() => {
    //   const isPushSupported = this.oneSignal.isPushNotificationsSupported();
    //   if (isPushSupported) {
    //     console.log('=======\nPUSH ALLOWED\n=======');
    //     // Push notifications are supported
    //   } else {
    //     // Push notifications are not supported
    //     console.log('=======\nOH NO, NO PUSH\n=======');
    //   }
    // });
    // ADD LISTENER ON SUBSCRIPTION CHANGE
    this.oneSignal.push(() => {
      // Occurs when the user's subscription changes to a new value.
      this.oneSignal.on('subscriptionChange', (isSubscribed) => {
        console.log(`OneSignal: The user's subscription state is now:`, isSubscribed);
        this.oneSignal.getUserId().then((userId) => {
          console.log('OneSignal: User ID is', userId);
          this.updateUserPushId(userId);
        });
      });
    });
    // // GET USER ID
    // this.oneSignal.push(() => {
    //   this.oneSignal.getUserId().then((userId) => {
    //     console.log('OneSignal User ID is', userId);
    //     this.updateUserPushId(userId);
    //   });
    // });
    // NOTE: To immediately ask for push, uncomment following line
    // this.askForPush();
  }

  askForPush() {
    try {
      // REGISTER FOR PUSH
      this.oneSignal.push(() => {
        console.log('OneSignal: Register For Push');
        // CHECK IF PUSH IS ENABLED
        this.oneSignal.isPushNotificationsEnabled().then((isEnabled) => {
          if (isEnabled) {
            console.log('Push notifications are enabled!');
          } else {
            // SHOW PUSH REGISTRATION POPUP
            this.oneSignal.registerForPushNotifications({modalPrompt: true});
          }
        });
      });
    } catch (pusherror) {
      console.error('askForPush', pusherror);
    }
  }

  loadOneSignal() {
    console.log('loadOneSignal');
    // Wait till window has OneSignal, else don't do push stuff
{'fraction_non_alphanumeric': 0.13676127527216175, 'fraction_numerical': 0.01166407465007776, 'mean_word_length': 2.595038434661076, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4193794', 'n_tokens_mistral': 3190, 'n_tokens_neox': 3073, 'n_words': 762}