<commit_before>/**
 * Material Design GMail.
 **/

Object_forEach({
  ARCHIVE:       'archive',
  TRASH:         'delete',
  REPLY:         'reply',
  REPLY_ALL:     'reply_all',
  SPAM:          'report',
  FORWARD:       'forward',
  STAR:          'star',
  MOVE_TO_INBOX: 'inbox',
  SEND:          'send',
  MARK_UNREAD:   'markunread'
}, function(image, name) {
  EMail[name].copyFrom({iconUrl: 'icons/ic_' + image + '_black_24dp.png', label: ''});
});


/** Modify the default QueryParser so that label ids are looked up in the EMailLabels DAO. **/
var queryParser = {
  __proto__: QueryParserFactory(EMail),

  id: sym('string'),

  labelMatch: seq(alt('label','l'), alt(':', '='), sym('valueList'))
}.addActions({
  id: function(v) {
     return OR(
        CONTAINS_IC(EMail.TO, v),
        CONTAINS_IC(EMail.FROM, v),
        CONTAINS_IC(EMail.SUBJECT, v),
        CONTAINS_IC(EMail.BODY, v));
  },

  labelMatch: function(v) {
    var or = OR();
    var values = v[2];
    for ( var i = 0 ; i < values.length ; i++ ) {
      or.args.push(EQ(EMail.LABELS, values[i]))
    }
    return or;
  }
});

queryParser.expr = alt(
  sym('labelMatch'),
  queryParser.export('expr')
);


CLASS({
  name: 'MGmail',
  description: 'Mobile Gmail',
  traits: ['PositionedDOMViewTrait'],

  extendsModel: 'View',

  requires: [
    'GMailUserInfo'
  ],

  properties: [
    {
      name: 'controller',
      subType: 'AppController',
      postSet: function(_, controller) {
        var view = controller.X.DetailView.create({data: controller});
        this.stack.setTopView(FloatingView.create({ view: view }));
      }
    },
    { name: 'oauth' },
    {
      name: 'emailDao',
      type: 'DAO',
      factory: function() {
        var dao = this.X.LimitedLiveCachingDAO.create({
          cacheLimit: 100,
          src: this.X.GMailToEMailDAO.create({
            delegate: this.X.GMailMessageDAO.create({})
//            delegate: this.X.StoreAndForwardDAO.create({
//              delegate: this.X.GMailMessageDAO.create({})
//            })
          }),
          cache: this.X.CachingDAO.create({
              src: this.X.IDBDAO.create({
                  model: this.X.EMail
              }),
              cache: this.X.MDAO.create({ model: this.X.EMail })
          })
        });
        dao.src
          .limit(100)
          .where(EQ(this.X.EMail.LABELS, "INBOX"))
          .select(dao.cache);
        return dao;
      }
    },
    {
      name: 'labelDao',
      type: 'DAO',
      factory: function() {
        return this.X.CachingDAO.create({
          src: this.X.GMailRestDAO.create({ model: FOAMGMailLabel, modelName: 'labels' }),
          cache: this.X.MDAO.create({ model: FOAMGMailLabel }),
        });
      }
    },
    {
      name: 'stack',
      subType: 'StackView',
      factory: function() { return this.X.StackView.create(); },
      postSet: function(old, v) {
        if ( old ) {
          Events.unfollow(this.width$, old.width$);
          Events.unfollow(this.height$, old.height$);
        }
        Events.follow(this.width$, v.width$);
        Events.follow(this.height$, v.height$);
      }
    },
    {
      // TODO: Populate this somehow
      name: 'profile',
      description: 'Profile information of current user.',
      factory: function() {
        var xhr = this.X.XHR.create({ responseType: 'json' });
        aseq(
          function(ret) {
            xhr.asend(ret, 'https://www.googleapis.com/oauth2/v1/userinfo');
          }
        )(function(resp) {
          var user = this.GMailUserInfo.create();
          user.fromJSON(resp);
          this.profile = user;
        }.bind(this));
        return '';
      }
    }
  ],

  methods: {
    init: function() {
      this.X = this.X.sub({
        touchManager: this.X.TouchManager.create({})
      }, 'MGMAIL CONTEXT');
      this.X.gestureManager = this.X.GestureManager.create({});

      this.oauth = this.X.EasyOAuth2.create({
        clientId: "945476427475-oaso9hq95r8lnbp2rruo888rl3hmfuf8.apps.googleusercontent.com",
        clientSecret: "GTkp929u268_SXAiHitESs-1",
        scopes: [
          "https://www.googleapis.com/auth/userinfo.profile",
          "https://www.googleapis.com/auth/userinfo.email",
          "https://mail.google.com/"
        ]
      });

      this.X.registerModel(XHR.xbind({
        authAgent: this.oauth,
        retries: 3,
        delay: 10
      }), 'XHR');

      this.SUPER();
    },

    toHTML: function() { return this.stack.toHTML(); },
<commit_msg>Fix GMail app broken by new init system.<commit_after>/**
 * Material Design GMail.
 **/

Object_forEach({
  ARCHIVE:       'archive',
  TRASH:         'delete',
  REPLY:         'reply',
  REPLY_ALL:     'reply_all',
  SPAM:          'report',
  FORWARD:       'forward',
  STAR:          'star',
  MOVE_TO_INBOX: 'inbox',
  SEND:          'send',
  MARK_UNREAD:   'markunread'
}, function(image, name) {
  EMail[name].copyFrom({iconUrl: 'icons/ic_' + image + '_black_24dp.png', label: ''});
});


/** Modify the default QueryParser so that label ids are looked up in the EMailLabels DAO. **/
var queryParser = {
  __proto__: QueryParserFactory(EMail),

  id: sym('string'),

  labelMatch: seq(alt('label','l'), alt(':', '='), sym('valueList'))
}.addActions({
  id: function(v) {
     return OR(
        CONTAINS_IC(EMail.TO, v),
        CONTAINS_IC(EMail.FROM, v),
        CONTAINS_IC(EMail.SUBJECT, v),
        CONTAINS_IC(EMail.BODY, v));
  },

  labelMatch: function(v) {
    var or = OR();
    var values = v[2];
    for ( var i = 0 ; i < values.length ; i++ ) {
      or.args.push(EQ(EMail.LABELS, values[i]))
    }
    return or;
  }
});

queryParser.expr = alt(
  sym('labelMatch'),
  queryParser.export('expr')
);


CLASS({
  name: 'MGmail',
  description: 'Mobile Gmail',
  traits: ['PositionedDOMViewTrait'],

  extendsModel: 'View',

  requires: [
    'GMailUserInfo',
    'TouchManager',
    'GestureManager',
    'EasyOAuth2'
  ],

  exports: [
    'XHR',
    'touchManager',
    'gestureManager'
  ],

  properties: [
    {
      name: 'XHR',
      factory: function() {
        return XHR.xbind({
          authAgent: this.oauth,
          retries: 3,
          delay: 10
        });
      }
    },
    {
      name: 'touchManager',
      factory: function()  { return this.TouchManager.create(); }
    },
    {
      name: 'gestureManager',
      factory: function() { return this.GestureManager.create(); }
    },
    {
      name: 'oauth',
      factory: function() {
        return this.EasyOAuth2.create({
          clientId: "945476427475-oaso9hq95r8lnbp2rruo888rl3hmfuf8.apps.googleusercontent.com",
          clientSecret: "GTkp929u268_SXAiHitESs-1",
          scopes: [
            "https://www.googleapis.com/auth/userinfo.profile",
            "https://www.googleapis.com/auth/userinfo.email",
            "https://mail.google.com/"
          ]
        });        
      }
    },
    {
      name: 'controller',
      subType: 'AppController',
      postSet: function(_, controller) {
        var view = controller.X.DetailView.create({data: controller});
        this.stack.setTopView(FloatingView.create({ view: view }));
      }
    },
    {
      name: 'emailDao',
      type: 'DAO',
      factory: function() {
        var dao = this.X.LimitedLiveCachingDAO.create({
          cacheLimit: 100,
          src: this.X.GMailToEMailDAO.create({
            delegate: this.X.GMailMessageDAO.create({})
//            delegate: this.X.StoreAndForwardDAO.create({
//              delegate: this.X.GMailMessageDAO.create({})
//            })
          }),
          cache: this.X.CachingDAO.create({
              src: this.X.IDBDAO.create({
                  model: this.X.EMail
              }),
              cache: this.X.MDAO.create({ model: this.X.EMail })
          })
        });
        dao.src
          .limit(100)
          .where(EQ(this.X.EMail.LABELS, "INBOX"))
          .select(dao.cache);
        return dao;
      }
    },
    {
      name: 'labelDao',
      type: 'DAO',
      factory: function() {
        return this.X.CachingDAO.create({
          src: this.X.GMailRestDAO.create({ model: FOAMGMailLabel, modelName: 'labels' }),
          cache: this.X.MDAO.create({ model: FOAMGMailLabel }),
        });
      }
    },
    {
      name: 'stack',
      subType: 'StackView',
      factory: function() { return this.X.StackView.create(); },
      postSet: function(old, v) {
        if ( old ) {
          Events.unfollow(this.width$, old.width$);
          Events.unfollow(this.height$, old.height$);
        }
        Events.follow(this.width$, v.width$);
        Events.follow(this.height$, v.height$);
      }
    },
    {
      // TODO: Populate this somehow
      name: 'profile',
      description: 'Profile information of current user.',
      factory: function() {
        var xhr = this.X.XHR.create({ responseType: 'json' });
        aseq(
          function(ret) {
            xhr.asend(ret, 'https://www.googleapis.com/oauth2/v1/userinfo');
          }
        )(function(resp) {
          var user = this.GMailUserInfo.create();
          user.fromJSON(resp);
          this.profile = user;
        }.bind(this));
        return '';
      }
    }
  ],

  methods: {
    toHTML: function() { return this.stack.toHTML(); },

{'fraction_non_alphanumeric': 0.15890263582571276, 'fraction_numerical': 0.009790209790209791, 'mean_word_length': 2.0093881515053416, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 6, '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': '1831878', 'n_tokens_mistral': 3204, 'n_tokens_neox': 3131, 'n_words': 547}