2019-11-09 03:13:35 +08:00
|
|
|
import EmberObject from "@ember/object";
|
2016-07-01 01:55:44 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2023-10-11 02:38:59 +08:00
|
|
|
import AdminUser from "admin/models/admin-user";
|
2016-01-19 07:57:55 +08:00
|
|
|
|
2023-03-17 18:18:42 +08:00
|
|
|
export default class IncomingEmail extends EmberObject {
|
|
|
|
static create(attrs) {
|
2016-01-19 07:57:55 +08:00
|
|
|
attrs = attrs || {};
|
|
|
|
|
|
|
|
if (attrs.user) {
|
|
|
|
attrs.user = AdminUser.create(attrs.user);
|
|
|
|
}
|
|
|
|
|
2023-03-20 18:49:01 +08:00
|
|
|
return super.create(attrs);
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2016-01-19 07:57:55 +08:00
|
|
|
|
2023-03-17 18:18:42 +08:00
|
|
|
static find(id) {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax(`/admin/email/incoming/${id}.json`);
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2016-02-11 05:00:27 +08:00
|
|
|
|
2023-03-17 18:18:42 +08:00
|
|
|
static findByBounced(id) {
|
2017-02-23 01:51:33 +08:00
|
|
|
return ajax(`/admin/email/incoming_from_bounced/${id}.json`);
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2017-02-23 01:51:33 +08:00
|
|
|
|
2023-03-17 18:18:42 +08:00
|
|
|
static findAll(filter, offset) {
|
2016-01-19 07:57:55 +08:00
|
|
|
filter = filter || {};
|
|
|
|
offset = offset || 0;
|
|
|
|
|
|
|
|
const status = filter.status || "received";
|
2020-09-02 01:38:57 +08:00
|
|
|
delete filter.status;
|
2016-01-19 07:57:55 +08:00
|
|
|
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax(`/admin/email/${status}.json?offset=${offset}`, {
|
|
|
|
data: filter,
|
2016-01-19 07:57:55 +08:00
|
|
|
}).then((incomings) =>
|
2018-11-19 17:46:46 +08:00
|
|
|
incomings.map((incoming) => IncomingEmail.create(incoming))
|
2016-01-19 07:57:55 +08:00
|
|
|
);
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
|
|
|
}
|