2016-07-01 01:55:44 +08:00
|
|
|
import { ajax } from 'discourse/lib/ajax';
|
2015-11-21 09:27:06 +08:00
|
|
|
const EmailPreview = Discourse.Model.extend({});
|
2013-06-04 04:12:24 +08:00
|
|
|
|
2015-11-21 09:27:06 +08:00
|
|
|
EmailPreview.reopenClass({
|
2015-10-31 02:05:54 +08:00
|
|
|
findDigest: function(lastSeenAt, username) {
|
2014-01-06 23:18:20 +08:00
|
|
|
|
|
|
|
if (Em.isEmpty(lastSeenAt)) {
|
2014-08-21 04:22:58 +08:00
|
|
|
lastSeenAt = moment().subtract(7, 'days').format('YYYY-MM-DD');
|
2014-01-06 23:18:20 +08:00
|
|
|
}
|
|
|
|
|
2015-10-31 02:05:54 +08:00
|
|
|
if (Em.isEmpty(username)) {
|
|
|
|
username = Discourse.User.current().username;
|
|
|
|
}
|
|
|
|
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/email/preview-digest.json", {
|
2015-10-31 02:05:54 +08:00
|
|
|
data: { last_seen_at: lastSeenAt, username: username }
|
2013-06-04 04:12:24 +08:00
|
|
|
}).then(function (result) {
|
2015-11-21 09:27:06 +08:00
|
|
|
return EmailPreview.create(result);
|
2013-06-04 04:12:24 +08:00
|
|
|
});
|
2016-11-24 06:46:57 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
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 }
|
|
|
|
});
|
2013-06-04 04:12:24 +08:00
|
|
|
}
|
|
|
|
});
|
2015-11-21 09:27:06 +08:00
|
|
|
|
|
|
|
export default EmailPreview;
|