<commit_before>import { ajax } from 'discourse/lib/ajax';
const EmailPreview = Discourse.Model.extend({});

EmailPreview.reopenClass({
  findDigest: function(lastSeenAt, username) {

    if (Em.isEmpty(lastSeenAt)) {
      lastSeenAt = moment().subtract(7, 'days').format('YYYY-MM-DD');
    }

    if (Em.isEmpty(username)) {
      username = Discourse.User.current().username;
    }

    return ajax("/admin/email/preview-digest.json", {
      data: { last_seen_at: lastSeenAt, username: username }
    }).then(function (result) {
      return EmailPreview.create(result);
    });
  },

  sendDigest: function(lastSeenAt, username, email) {
    if (Em.isEmpty(lastSeenAt)) {
      lastSeenAt = moment().subtract(7, 'days').format('YYYY-MM-DD');
    }

    if (Em.isEmpty(username)) {
      username = Discourse.User.current().username;
    }

    return ajax("/admin/email/send-digest.json", {
      data: { last_seen_at: lastSeenAt, username: username, email: email }
    });
  }
});

export default EmailPreview;<commit_msg>FIX: digest email preview error in Persian and other languages<commit_after>import { ajax } from 'discourse/lib/ajax';
const EmailPreview = Discourse.Model.extend({});

EmailPreview.reopenClass({
  findDigest: function(lastSeenAt, username) {

    if (Em.isEmpty(lastSeenAt)) {
      lastSeenAt = this.oneWeekAgo();
    }

    if (Em.isEmpty(username)) {
      username = Discourse.User.current().username;
    }

    return ajax("/admin/email/preview-digest.json", {
      data: { last_seen_at: lastSeenAt, username: username }
    }).then(function (result) {
      return EmailPreview.create(result);
    });
  },

  sendDigest: function(lastSeenAt, username, email) {
    if (Em.isEmpty(lastSeenAt)) {
      lastSeenAt = this.oneWeekAgo();
    }

    if (Em.isEmpty(username)) {
      username = Discourse.User.current().username;
    }

    return ajax("/admin/email/send-digest.json", {
      data: { last_seen_at: lastSeenAt, username: username, email: email }
    });
  },

  oneWeekAgo() {
    const en = moment().locale('en');
    return en.subtract(7, 'days').format('YYYY-MM-DD');
  }
});

export default EmailPreview;
{'fraction_non_alphanumeric': 0.15630797773654917, 'fraction_numerical': 0.0013914656771799629, 'mean_word_length': 3.4200819672131146, 'pattern_counts': {'":': 0, '<': 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': '5104004', 'n_tokens_mistral': 723, 'n_tokens_neox': 697, 'n_words': 125}