<commit_before>define([ 
    "backbone", 
    "activity/Activity",
    "activity/Activities"
], function(
    Backbone, 
    Activity,
    Activities
) {
  var ActivityFeed = Backbone.Model.extend(
  /** @lends ActivityFeed.prototype */
  {
    /**
     * @class A model of the Activity Feed. The activity feed is a container for
     *        the Activities collection. It is the primary way to view an
     *        Activities Collection. see <a href =
     *        "http://ui-patterns.com/patterns/ActivityStream">"http://ui-patterns.com/patterns/ActivityStream"</a>
     * 
     * @extends Backbone.Model
     * @constructs
     */
    initialize : function() {
      if(!this.get("activities")) {
//      this.set("activities", window.app.get("currentCorpusTeamActivityFeed").get("activities"));
        this.set("activities", new Activities());
      }
      //TODO remove this, and us the change corpus instead. by keepint htis now, it puts all activity feeds into one.
//      this.pouch = Backbone.sync.pouch(Utils.androidApp() ? Utils.activityFeedTouchUrl
//          : Utils.activityFeedPouchUrl);
      
    },
//    defaults: {
//      activities: Activities
//    },
    // Internal models: used by the parse function
    model : {
      activities: Activities  
    },
    savedcount : 0,
    savedindex : [],
    savefailedcount : 0,
    savefailedindex : [],
    nextsaveactivity : 0,
    
    saveAndInterConnectInApp : function(successcallback, failurecallback){
      if(!successcallback){
        successcallback = function(){
          window.appView.toastUser("Save all activities","alert-success","Saved!");
        };
      }
      var self = this;
      window.hub.unsubscribe("savedActivityToPouch", null, self);
      window.hub.unsubscribe("saveActivityFailedToPouch", null, self);
      
      this.savedcount = 0;
      this.savedindex = [];
      this.savefailedcount = 0;
      this.savefailedindex = [];
      this.nextsaveactivity  = 0;
      
      
      window.hub.subscribe("savedActivityToPouch", function(arg){
        this.savedindex[arg.d] = true;
        this.savedcount++;
        if( arg.d <= 0 ){
          /*
           * If we are at the final index in the activity feed
           */
          Utils.debug("Activity feed saved.");
          if(typeof successcallback == "function"){
            successcallback();
          }
        }else{
          /*
           * Save another activity when the previous succeeds
           */
          var next = parseInt(arg.d) - 1;
          this.saveAnActivityAndLoop(next);
        }
      }, self);
      
      window.hub.subscribe("saveActivityFailedToPouch",function(arg){
        this.savefailedindex[arg.d] = false; 
        this.savefailedcount++;
        window.appView.toastUser("Save activity failed "+arg.d+" : "+arg.message,"alert-danger","Failure:");
        
        if( arg.d <= 0 ){
          /*
           * If we are at the final index in the activity feed
           */            
          Utils.debug("Activity feed saved.");
          if(typeof successcallback == "function"){
            successcallback();
          }
        }else{
          /*
           * Save another activity when the previous fails
           */
          var next = parseInt(arg.d) - 1;
          this.saveAnActivityAndLoop(next);
        }
        
      }, self);
      
      /*
       * Begin the activity saving loop with the last activity 
       */
      if(self.get("activities").length > 0){
        self.saveAnActivityAndLoop(self.get("activities").length - 1);
      }else{
        Utils.debug("Activity feed didnt need to be saved.");
        if(typeof successcallback == "function"){
          successcallback();
        }
      }
      
    },
   
    saveAnActivityAndLoop : function(d){
      var thatactivity = this.get("activities").models[d];
      console.log(JSON.stringify(thatactivity.toJSON()));
          
      thatactivity.saveAndInterConnectInApp(function(){
        hub.publish("savedActivityToPouch",{d: d, message: " activity "+thatactivity.id});
      },function(){
        //The e error should be from the error callback
        if(!e){
          e = {};
        }
        hub.publish("saveActivityFailedToPouch",{d: d, message: " activity "+ JSON.stringify(e) });
      });
    },<commit_msg>Getting an error on a new user. the ajax erorr catching isnt working, will hav ot redo it. or figure out why there seems to be two search fireing, is it the two views?<commit_after>define([ 
    "backbone", 
    "activity/Activity",
    "activity/Activities"
], function(
    Backbone, 
    Activity,
    Activities
) {
  var ActivityFeed = Backbone.Model.extend(
  /** @lends ActivityFeed.prototype */
  {
    /**
     * @class A model of the Activity Feed. The activity feed is a container for
     *        the Activities collection. It is the primary way to view an
     *        Activities Collection. see <a href =
     *        "http://ui-patterns.com/patterns/ActivityStream">"http://ui-patterns.com/patterns/ActivityStream"</a>
     * 
     * @extends Backbone.Model
     * @constructs
     */
    initialize : function() {
      if(!this.get("activities")) {
//      this.set("activities", window.app.get("currentCorpusTeamActivityFeed").get("activities"));
        this.set("activities", new Activities());
      }
      //TODO remove this, and us the change corpus instead. by keepint htis now, it puts all activity feeds into one.
//      this.pouch = Backbone.sync.pouch(Utils.androidApp() ? Utils.activityFeedTouchUrl
//          : Utils.activityFeedPouchUrl);
      
    },
//    defaults: {
//      activities: Activities
//    },
    // Internal models: used by the parse function
    model : {
      activities: Activities  
    },
    savedcount : 0,
    savedindex : [],
    savefailedcount : 0,
    savefailedindex : [],
    nextsaveactivity : 0,
    
    saveAndInterConnectInApp : function(successcallback, failurecallback){
      if(!successcallback){
        successcallback = function(){
          window.appView.toastUser("Save all activities","alert-success","Saved!");
        };
      }
      var self = this;
      window.hub.unsubscribe("savedActivityToPouch", null, self);
      window.hub.unsubscribe("saveActivityFailedToPouch", null, self);
      
      this.savedcount = 0;
      this.savedindex = [];
      this.savefailedcount = 0;
      this.savefailedindex = [];
      this.nextsaveactivity  = 0;
      
      
      window.hub.subscribe("savedActivityToPouch", function(arg){
        this.savedindex[arg.d] = true;
        this.savedcount++;
        if( arg.d <= 0 ){
          /*
           * If we are at the final index in the activity feed
           */
          Utils.debug("Activity feed saved.");
          if(typeof successcallback == "function"){
            successcallback();
          }
        }else{
          /*
           * Save another activity when the previous succeeds
           */
          var next = parseInt(arg.d) - 1;
          this.saveAnActivityAndLoop(next);
        }
      }, self);
      
      window.hub.subscribe("saveActivityFailedToPouch",function(arg){
        this.savefailedindex[arg.d] = false; 
        this.savefailedcount++;
        window.appView.toastUser("Save activity failed "+arg.d+" : "+arg.message,"alert-danger","Failure:");
        
        if( arg.d <= 0 ){
          /*
           * If we are at the final index in the activity feed
           */            
          Utils.debug("Activity feed saved.");
          if(typeof successcallback == "function"){
            successcallback();
          }
        }else{
          /*
           * Save another activity when the previous fails
           */
          var next = parseInt(arg.d) - 1;
          this.saveAnActivityAndLoop(next);
        }
        
      }, self);
      
      /*
       * Begin the activity saving loop with the last activity 
       */
      if(self.get("activities").length > 0){
        self.saveAnActivityAndLoop(self.get("activities").length - 1);
      }else{
        Utils.debug("Activity feed didnt need to be saved.");
        if(typeof successcallback == "function"){
          successcallback();
        }
      }
      
    },
   
    saveAnActivityAndLoop : function(d){
      var thatactivity = this.get("activities").models[d];
      if(thatactivity){
        console.log(JSON.stringify(thatactivity.toJSON()));
      }
          
      thatactivity.saveAndInterConnectInApp(function(){
        hub.publish("savedActivityToPouch",{d: d, message: " activity "+thatactivity.id});
      },function(){
        //The e error should be from the error callback
        if(!e){
          e = {};
        }
        hub.publish("saveActivityFailedToPouch",{d: d, message: " activity "+ JSON.stringify(e) });
      });
    },
{'fraction_non_alphanumeric': 0.12454669084315503, 'fraction_numerical': 0.0027198549410698096, 'mean_word_length': 2.0389118457300275, 'pattern_counts': {'":': 0, '<': 11, '<?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': '6589892', 'n_tokens_mistral': 2481, 'n_tokens_neox': 2402, 'n_words': 562}