<commit_before>import Ember from "ember";
import AjaxPromise from './../utils/ajax-promise';

export default Ember.ArrayController.extend({
  sortProperties: ["date"],
  sortAscending: true,
  messagesUtil: Ember.inject.service("messages"),

  nextNotification: function() {
    //retrieveNotification is not implemented here because it needs to call itself
    return this.retrieveNotification();
  }.property("[]"),

  retrieveNotification: function(index) {
    // not sure why but model.firstObject is undefined when there's one notification
    var notification = this.get("model")[index || 0];
    if (!notification) {
      return null;
    }

    this.setRoute(notification);

    // if current url matches notification view action url then dismiss notification
    var router = this.get("target");
    var currentUrl = router.get("url");
    var actionUrl = router.generate.apply(router, notification.route);

    if (currentUrl === actionUrl) {
      this.removeObject(notification);
      return this.retrieveNotification(index);
    }

    return notification;
  },

  itemImageUrl: function() {
    var itemId = this.get("nextNotification.item_id");
    return itemId ? this.store.getById("item", itemId).get("displayImageUrl") : null;
  }.property("nextNotification"),

  showItemImage: Ember.computed.notEmpty("itemImageUrl"),

  senderImageUrl: function() {
    var notification = this.get("nextNotification");
    if (!notification) { return null; }
    return this.store.getById("user", notification.author_id).get("displayImageUrl");
  }.property("nextNotification"),

  setRoute: function(notification) {
    switch (notification.category) {
      case "message":
        notification.route = this.get("messagesUtil").getRoute(notification);
        break;

      case "new_offer":
      case "incoming_call":
        var routeName = this.get("session.isDonorApp") ? "offer" : "review_offer";
        notification.route = [routeName, notification.offer_id];
        break;

      case "call_answered":
        notification.route = ["offer.donor_messages", notification.offer_id];
        break;
    }
  },

  acceptCall: function(notification) {
    new AjaxPromise("/twilio/accept_call", "GET", this.get('session.authToken'), { donor_id: notification.author_id })
  },

  actions: {
    view: function() {
      var notification = this.get("nextNotification");
      this.removeObject(notification);
      if (notification.category === "incoming_call") {
        this.acceptCall(notification);
      }
      this.transitionToRoute.apply(this, notification.route);
    }
  }
});<commit_msg>update twilio-call accept notification path<commit_after>import Ember from "ember";
import AjaxPromise from './../utils/ajax-promise';

export default Ember.ArrayController.extend({
  sortProperties: ["date"],
  sortAscending: true,
  messagesUtil: Ember.inject.service("messages"),

  nextNotification: function() {
    //retrieveNotification is not implemented here because it needs to call itself
    return this.retrieveNotification();
  }.property("[]"),

  retrieveNotification: function(index) {
    // not sure why but model.firstObject is undefined when there's one notification
    var notification = this.get("model")[index || 0];
    if (!notification) {
      return null;
    }

    this.setRoute(notification);

    // if current url matches notification view action url then dismiss notification
    var router = this.get("target");
    var currentUrl = router.get("url");
    var actionUrl = router.generate.apply(router, notification.route);

    if (currentUrl === actionUrl) {
      this.removeObject(notification);
      return this.retrieveNotification(index);
    }

    return notification;
  },

  itemImageUrl: function() {
    var itemId = this.get("nextNotification.item_id");
    return itemId ? this.store.getById("item", itemId).get("displayImageUrl") : null;
  }.property("nextNotification"),

  showItemImage: Ember.computed.notEmpty("itemImageUrl"),

  senderImageUrl: function() {
    var notification = this.get("nextNotification");
    if (!notification) { return null; }
    return this.store.getById("user", notification.author_id).get("displayImageUrl");
  }.property("nextNotification"),

  setRoute: function(notification) {
    switch (notification.category) {
      case "message":
        notification.route = this.get("messagesUtil").getRoute(notification);
        break;

      case "new_offer":
      case "incoming_call":
        var routeName = this.get("session.isDonorApp") ? "offer" : "review_offer";
        notification.route = [routeName, notification.offer_id];
        break;

      case "call_answered":
        notification.route = ["offer.donor_messages", notification.offer_id];
        break;
    }
  },

  acceptCall: function(notification) {
    new AjaxPromise("/twilio_inbound/accept_call", "GET", this.get('session.authToken'), { donor_id: notification.author_id })
  },

  actions: {
    view: function() {
      var notification = this.get("nextNotification");
      this.removeObject(notification);
      if (notification.category === "incoming_call") {
        this.acceptCall(notification);
      }
      this.transitionToRoute.apply(this, notification.route);
    }
  }
});
{'fraction_non_alphanumeric': 0.1310384176492963, 'fraction_numerical': 0.0003803727653100038, 'mean_word_length': 3.7293165467625897, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '3288030', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1416, 'n_words': 322}