2018-06-15 23:03:24 +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
|
|
|
|
2017-06-29 03:36:34 +08:00
|
|
|
export function oneWeekAgo() {
|
2018-06-15 23:03:24 +08:00
|
|
|
return moment()
|
|
|
|
.locale("en")
|
|
|
|
.subtract(7, "days")
|
|
|
|
.format("YYYY-MM-DD");
|
2017-06-29 03:36:34 +08:00
|
|
|
}
|
2014-01-06 23:18:20 +08:00
|
|
|
|
2017-06-29 03:36:34 +08:00
|
|
|
EmailPreview.reopenClass({
|
|
|
|
findDigest(username, lastSeenAt) {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/email/preview-digest.json", {
|
2017-06-29 03:36:34 +08:00
|
|
|
data: { last_seen_at: lastSeenAt || oneWeekAgo(), username }
|
|
|
|
}).then(result => EmailPreview.create(result));
|
2016-11-24 06:46:57 +08:00
|
|
|
},
|
|
|
|
|
2017-06-29 03:36:34 +08:00
|
|
|
sendDigest(username, lastSeenAt, email) {
|
2016-11-24 06:46:57 +08:00
|
|
|
return ajax("/admin/email/send-digest.json", {
|
2017-06-29 03:36:34 +08:00
|
|
|
data: { last_seen_at: lastSeenAt || oneWeekAgo(), username, email }
|
2016-11-24 06:46:57 +08:00
|
|
|
});
|
2018-06-15 23:03:24 +08:00
|
|
|
}
|
2013-06-04 04:12:24 +08:00
|
|
|
});
|
2015-11-21 09:27:06 +08:00
|
|
|
|
|
|
|
export default EmailPreview;
|