2016-07-01 01:55:44 +08:00
|
|
|
import { ajax } from 'discourse/lib/ajax';
|
2015-11-21 09:27:06 +08:00
|
|
|
import Post from 'discourse/models/post';
|
2017-09-06 22:21:07 +08:00
|
|
|
import computed from 'ember-addons/ember-computed-decorators';
|
2015-11-21 09:27:06 +08:00
|
|
|
|
2017-09-12 04:44:20 +08:00
|
|
|
export default Post.extend({
|
2013-02-22 03:09:28 +08:00
|
|
|
|
2017-09-06 22:21:07 +08:00
|
|
|
@computed
|
|
|
|
summary() {
|
2013-06-17 15:15:56 +08:00
|
|
|
return _(this.post_actions)
|
2014-07-29 01:17:37 +08:00
|
|
|
.groupBy(function (a) { return a.post_action_type_id; })
|
|
|
|
.map(function (v,k) { return I18n.t('admin.flags.summary.action_type_' + k, { count: v.length }); })
|
2013-06-26 14:18:50 +08:00
|
|
|
.join(',');
|
2017-09-06 22:21:07 +08:00
|
|
|
},
|
2014-07-29 01:17:37 +08:00
|
|
|
|
2017-09-06 22:21:07 +08:00
|
|
|
@computed('last_revised_at', 'post_actions.@each.created_at')
|
|
|
|
wasEdited(lastRevisedAt) {
|
2015-08-12 00:27:07 +08:00
|
|
|
if (Ember.isEmpty(this.get("last_revised_at"))) { return false; }
|
2017-09-06 22:21:07 +08:00
|
|
|
lastRevisedAt = Date.parse(lastRevisedAt);
|
2014-08-19 00:56:39 +08:00
|
|
|
return _.some(this.get("post_actions"), function (postAction) {
|
|
|
|
return Date.parse(postAction.created_at) < lastRevisedAt;
|
|
|
|
});
|
2017-09-06 22:21:07 +08:00
|
|
|
},
|
2014-08-19 00:56:39 +08:00
|
|
|
|
2017-09-06 22:21:07 +08:00
|
|
|
@computed('post_actions.@each.name_key')
|
|
|
|
flaggedForSpam() {
|
2017-09-11 22:31:38 +08:00
|
|
|
return this.get('post_actions').every(action => action.name_key === 'spam');
|
2017-09-06 22:21:07 +08:00
|
|
|
},
|
2013-07-27 03:40:08 +08:00
|
|
|
|
2017-09-06 22:21:07 +08:00
|
|
|
@computed('post_actions.@each.targets_topic')
|
|
|
|
topicFlagged() {
|
2014-02-06 06:54:16 +08:00
|
|
|
return _.any(this.get('post_actions'), function(action) { return action.targets_topic; });
|
2017-09-06 22:21:07 +08:00
|
|
|
},
|
2014-02-06 06:54:16 +08:00
|
|
|
|
2017-09-06 22:21:07 +08:00
|
|
|
@computed('post_actions.@each.targets_topic')
|
|
|
|
postAuthorFlagged() {
|
2014-02-06 06:54:16 +08:00
|
|
|
return _.any(this.get('post_actions'), function(action) { return !action.targets_topic; });
|
2017-09-06 22:21:07 +08:00
|
|
|
},
|
2014-02-06 06:54:16 +08:00
|
|
|
|
2017-09-11 22:31:38 +08:00
|
|
|
@computed('flaggedForSpam')
|
2017-09-06 22:21:07 +08:00
|
|
|
canDeleteAsSpammer(flaggedForSpam) {
|
2017-09-11 22:31:38 +08:00
|
|
|
return flaggedForSpam &&
|
|
|
|
this.get('user.can_delete_all_posts') &&
|
|
|
|
this.get('user.can_be_deleted');
|
2017-09-06 22:21:07 +08:00
|
|
|
},
|
2013-07-27 03:40:08 +08:00
|
|
|
|
2017-09-06 22:21:07 +08:00
|
|
|
deletePost() {
|
2013-10-02 22:59:57 +08:00
|
|
|
if (this.get('post_number') === 1) {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax('/t/' + this.topic_id, { type: 'DELETE', cache: false });
|
2013-02-23 04:41:12 +08:00
|
|
|
} else {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax('/posts/' + this.id, { type: 'DELETE', cache: false });
|
2013-02-21 02:15:50 +08:00
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2017-09-06 22:21:07 +08:00
|
|
|
disagreeFlags() {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax('/admin/flags/disagree/' + this.id, { type: 'POST', cache: false });
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2017-09-06 22:21:07 +08:00
|
|
|
deferFlags(deletePost) {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax('/admin/flags/defer/' + this.id, { type: 'POST', cache: false, data: { delete_post: deletePost } });
|
2013-06-20 15:42:15 +08:00
|
|
|
},
|
|
|
|
|
2017-09-06 22:21:07 +08:00
|
|
|
agreeFlags(actionOnPost) {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax('/admin/flags/agree/' + this.id, { type: 'POST', cache: false, data: { action_on_post: actionOnPost } });
|
2013-06-20 15:42:15 +08:00
|
|
|
},
|
|
|
|
|
2017-09-06 22:21:07 +08:00
|
|
|
postHidden: Ember.computed.alias('hidden'),
|
2013-06-20 15:42:15 +08:00
|
|
|
|
2017-09-12 02:01:59 +08:00
|
|
|
deleted: Ember.computed.or('deleted_at', 'topic_deleted_at'),
|
2017-09-15 00:44:49 +08:00
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|