2013-02-23 04:41:12 +08:00
|
|
|
/**
|
|
|
|
Our data model for interacting with flagged posts.
|
2013-02-21 02:15:50 +08:00
|
|
|
|
2013-03-06 04:39:21 +08:00
|
|
|
@class FlaggedPost
|
2013-02-23 04:41:12 +08:00
|
|
|
@extends Discourse.Post
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
2013-03-06 04:39:21 +08:00
|
|
|
**/
|
2013-02-23 04:41:12 +08:00
|
|
|
Discourse.FlaggedPost = Discourse.Post.extend({
|
2013-02-22 03:09:28 +08:00
|
|
|
|
2014-07-29 01:17:37 +08:00
|
|
|
summary: function () {
|
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(',');
|
2013-06-17 15:15:56 +08:00
|
|
|
}.property(),
|
|
|
|
|
2014-07-29 01:17:37 +08:00
|
|
|
flaggers: function () {
|
|
|
|
var self = this;
|
|
|
|
var flaggers = [];
|
|
|
|
|
|
|
|
_.each(this.post_actions, function (postAction) {
|
|
|
|
flaggers.push({
|
|
|
|
user: self.userLookup[postAction.user_id],
|
|
|
|
topic: self.topicLookup[postAction.topic_id],
|
|
|
|
flagType: I18n.t('admin.flags.summary.action_type_' + postAction.post_action_type_id, { count: 1 }),
|
|
|
|
flaggedAt: postAction.created_at,
|
|
|
|
disposedBy: postAction.disposed_by_id ? self.userLookup[postAction.disposed_by_id] : null,
|
|
|
|
disposedAt: postAction.disposed_at,
|
2014-08-12 00:21:34 +08:00
|
|
|
dispositionIcon: self.dispositionIcon(postAction.disposition),
|
2014-07-29 01:17:37 +08:00
|
|
|
tookAction: postAction.staff_took_action
|
2014-06-24 11:20:57 +08:00
|
|
|
});
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|
2014-07-29 01:17:37 +08:00
|
|
|
|
|
|
|
return flaggers;
|
2013-05-21 03:27:58 +08:00
|
|
|
}.property(),
|
2013-02-22 03:09:28 +08:00
|
|
|
|
2014-08-12 00:21:34 +08:00
|
|
|
dispositionIcon: function (disposition) {
|
|
|
|
if (!disposition) { return null; }
|
|
|
|
var icon, title = I18n.t('admin.flags.dispositions.' + disposition);
|
|
|
|
switch (disposition) {
|
|
|
|
case "deferred": { icon = "fa-external-link"; break; }
|
|
|
|
case "agreed": { icon = "fa-thumbs-o-up"; break; }
|
|
|
|
case "disagreed": { icon = "fa-thumbs-o-down"; break; }
|
|
|
|
}
|
|
|
|
return "<i class='fa " + icon + "' title='" + title + "'></i>";
|
|
|
|
},
|
|
|
|
|
2014-08-19 00:56:39 +08:00
|
|
|
wasEdited: function () {
|
|
|
|
if (this.blank("last_revised_at")) { return false; }
|
|
|
|
var lastRevisedAt = Date.parse(this.get("last_revised_at"));
|
|
|
|
return _.some(this.get("post_actions"), function (postAction) {
|
|
|
|
return Date.parse(postAction.created_at) < lastRevisedAt;
|
|
|
|
});
|
|
|
|
}.property("last_revised_at", "post_actions.@each.created_at"),
|
|
|
|
|
2014-07-29 01:17:37 +08:00
|
|
|
conversations: function () {
|
|
|
|
var self = this;
|
|
|
|
var conversations = [];
|
|
|
|
|
|
|
|
_.each(this.post_actions, function (postAction) {
|
|
|
|
if (postAction.conversation) {
|
|
|
|
var conversation = {
|
|
|
|
permalink: postAction.permalink,
|
|
|
|
hasMore: postAction.conversation.has_more,
|
|
|
|
response: {
|
|
|
|
excerpt: postAction.conversation.response.excerpt,
|
|
|
|
user: self.userLookup[postAction.conversation.response.user_id]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (postAction.conversation.reply) {
|
|
|
|
conversation["reply"] = {
|
|
|
|
excerpt: postAction.conversation.reply.excerpt,
|
|
|
|
user: self.userLookup[postAction.conversation.reply.user_id]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
conversations.push(conversation);
|
2013-02-23 04:41:12 +08:00
|
|
|
}
|
|
|
|
});
|
2013-02-22 03:09:28 +08:00
|
|
|
|
2014-07-29 01:17:37 +08:00
|
|
|
return conversations;
|
2013-04-04 04:06:55 +08:00
|
|
|
}.property(),
|
2013-02-22 03:09:28 +08:00
|
|
|
|
2013-04-04 04:06:55 +08:00
|
|
|
user: function() {
|
2013-02-23 04:41:12 +08:00
|
|
|
return this.userLookup[this.user_id];
|
2013-04-04 04:06:55 +08:00
|
|
|
}.property(),
|
2013-02-22 03:09:28 +08:00
|
|
|
|
2014-07-29 01:17:37 +08:00
|
|
|
topic: function () {
|
|
|
|
return this.topicLookup[this.topic_id];
|
|
|
|
}.property(),
|
2013-02-22 03:09:28 +08:00
|
|
|
|
2013-07-27 03:40:08 +08:00
|
|
|
flaggedForSpam: function() {
|
|
|
|
return !_.every(this.get('post_actions'), function(action) { return action.name_key !== 'spam'; });
|
|
|
|
}.property('post_actions.@each.name_key'),
|
|
|
|
|
2014-02-06 06:54:16 +08:00
|
|
|
topicFlagged: function() {
|
|
|
|
return _.any(this.get('post_actions'), function(action) { return action.targets_topic; });
|
|
|
|
}.property('post_actions.@each.targets_topic'),
|
|
|
|
|
|
|
|
postAuthorFlagged: function() {
|
|
|
|
return _.any(this.get('post_actions'), function(action) { return !action.targets_topic; });
|
|
|
|
}.property('post_actions.@each.targets_topic'),
|
|
|
|
|
2013-07-27 03:40:08 +08:00
|
|
|
canDeleteAsSpammer: function() {
|
2014-07-29 01:17:37 +08:00
|
|
|
return Discourse.User.currentProp('staff') && this.get('flaggedForSpam') && this.get('user.can_delete_all_posts') && this.get('user.can_be_deleted');
|
2013-07-27 03:40:08 +08:00
|
|
|
}.property('flaggedForSpam'),
|
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
deletePost: function() {
|
2013-10-02 22:59:57 +08:00
|
|
|
if (this.get('post_number') === 1) {
|
2013-06-26 14:18:50 +08:00
|
|
|
return Discourse.ajax('/t/' + this.topic_id, { type: 'DELETE', cache: false });
|
2013-02-23 04:41:12 +08:00
|
|
|
} else {
|
2013-06-26 14:18:50 +08:00
|
|
|
return Discourse.ajax('/posts/' + this.id, { type: 'DELETE', cache: false });
|
2013-02-21 02:15:50 +08:00
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2014-07-29 01:17:37 +08:00
|
|
|
disagreeFlags: function () {
|
2013-06-26 14:18:50 +08:00
|
|
|
return Discourse.ajax('/admin/flags/disagree/' + this.id, { type: 'POST', cache: false });
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2014-07-29 01:17:37 +08:00
|
|
|
deferFlags: function (deletePost) {
|
|
|
|
return Discourse.ajax('/admin/flags/defer/' + this.id, { type: 'POST', cache: false, data: { delete_post: deletePost } });
|
2013-06-20 15:42:15 +08:00
|
|
|
},
|
|
|
|
|
2014-08-05 04:48:04 +08:00
|
|
|
agreeFlags: function (actionOnPost) {
|
|
|
|
return Discourse.ajax('/admin/flags/agree/' + this.id, { type: 'POST', cache: false, data: { action_on_post: actionOnPost } });
|
2013-06-20 15:42:15 +08:00
|
|
|
},
|
|
|
|
|
2013-07-10 03:20:18 +08:00
|
|
|
postHidden: Em.computed.alias('hidden'),
|
2013-06-20 15:42:15 +08:00
|
|
|
|
2013-06-26 14:18:50 +08:00
|
|
|
extraClasses: function() {
|
|
|
|
var classes = [];
|
2014-07-29 01:17:37 +08:00
|
|
|
if (this.get('hidden')) { classes.push('hidden-post'); }
|
|
|
|
if (this.get('deleted')) { classes.push('deleted'); }
|
2013-06-26 14:18:50 +08:00
|
|
|
return classes.join(' ');
|
|
|
|
}.property(),
|
|
|
|
|
2013-07-10 03:20:18 +08:00
|
|
|
deleted: Em.computed.or('deleted_at', 'topic_deleted_at')
|
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
Discourse.FlaggedPost.reopenClass({
|
2014-07-29 01:17:37 +08:00
|
|
|
findAll: function (filter, offset) {
|
2013-08-19 19:14:26 +08:00
|
|
|
offset = offset || 0;
|
|
|
|
|
2013-04-04 04:06:55 +08:00
|
|
|
var result = Em.A();
|
2013-06-05 22:24:50 +08:00
|
|
|
result.set('loading', true);
|
2014-07-29 01:17:37 +08:00
|
|
|
|
|
|
|
return Discourse.ajax('/admin/flags/' + filter + '.json?offset=' + offset).then(function (data) {
|
|
|
|
// users
|
2013-04-04 04:06:55 +08:00
|
|
|
var userLookup = {};
|
2014-08-19 00:56:39 +08:00
|
|
|
_.each(data.users, function (user) {
|
2013-06-27 14:32:03 +08:00
|
|
|
userLookup[user.id] = Discourse.AdminUser.create(user);
|
2013-04-04 04:06:55 +08:00
|
|
|
});
|
2014-07-29 01:17:37 +08:00
|
|
|
|
|
|
|
// topics
|
|
|
|
var topicLookup = {};
|
|
|
|
_.each(data.topics, function (topic) {
|
|
|
|
topicLookup[topic.id] = Discourse.Topic.create(topic);
|
|
|
|
});
|
|
|
|
|
|
|
|
// posts
|
2014-08-19 00:56:39 +08:00
|
|
|
_.each(data.posts, function (post) {
|
2013-06-11 04:48:50 +08:00
|
|
|
var f = Discourse.FlaggedPost.create(post);
|
2013-04-04 04:06:55 +08:00
|
|
|
f.userLookup = userLookup;
|
2014-07-29 01:17:37 +08:00
|
|
|
f.topicLookup = topicLookup;
|
2013-04-04 04:06:55 +08:00
|
|
|
result.pushObject(f);
|
|
|
|
});
|
2014-07-29 01:17:37 +08:00
|
|
|
|
2013-06-05 22:24:50 +08:00
|
|
|
result.set('loading', false);
|
2014-07-29 01:17:37 +08:00
|
|
|
|
2013-08-19 19:14:26 +08:00
|
|
|
return result;
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|