don't treat notify user as a flag

This commit is contained in:
Sam 2013-04-15 13:09:52 +10:00
parent 034513f0fa
commit 2bdb53261b
4 changed files with 25 additions and 15 deletions

View file

@ -43,7 +43,12 @@ Discourse.ActionSummary = Discourse.Model.extend({
this.set('acted', true);
this.set('count', this.get('count') + 1);
this.set('can_act', false);
this.set('can_undo', action !== 'notify_moderators' && action !== 'notify_user');
this.set('can_undo', true);
if(action === 'notify_moderators' || action=='notify_user') {
this.set('can_undo',false);
this.set('can_clear_flags',false);
}
// Add ourselves to the users who liked it if present
if (this.present('users')) {

View file

@ -21,7 +21,7 @@ join (
limit 100
"
sql.where2 "post_action_type_id in (:flag_types)", flag_types: PostActionType.flag_types.values
sql.where2 "post_action_type_id in (:flag_types)", flag_types: PostActionType.notify_flag_types.values
# it may make sense to add a view that shows flags on deleted posts,
@ -62,7 +62,7 @@ limit 100
from post_actions a
/*where*/
"
sql.where("post_action_type_id in (:flag_types)", flag_types: PostActionType.flag_types.values)
sql.where("post_action_type_id in (:flag_types)", flag_types: PostActionType.notify_flag_types.values)
sql.where("post_id in (:posts)", posts: posts.map{|p| p["id"].to_i})
if params[:filter] == 'old'

View file

@ -20,7 +20,7 @@ class PostAction < ActiveRecord::Base
def self.update_flagged_posts_count
posts_flagged_count = PostAction.joins(post: :topic)
.where('post_actions.post_action_type_id' => PostActionType.flag_types.values,
.where('post_actions.post_action_type_id' => PostActionType.notify_flag_types.values,
'posts.deleted_at' => nil,
'topics.deleted_at' => nil).count('DISTINCT posts.id')
@ -74,23 +74,23 @@ class PostAction < ActiveRecord::Base
def self.act(user, post, post_action_type_id, message = nil)
begin
title, target_usernames,body = nil
if message
[:notify_moderators, :notify_user].each do |k|
if post_action_type_id == PostActionType.types[k]
target_usernames = k == :notify_moderators ? target_moderators(user) : post.user.username
title = I18n.t("post_action_types.#{k}.email_title",
title: post.topic.title)
body = I18n.t("post_action_types.#{k}.email_body",
message: message,
target_usernames = k == :notify_moderators ? target_moderators(user) : post.user.username
title = I18n.t("post_action_types.#{k}.email_title",
title: post.topic.title)
body = I18n.t("post_action_types.#{k}.email_body",
message: message,
link: "#{Discourse.base_url}#{post.url}")
end
end
end
if target_usernames.present?
PostCreator.new(user,
target_usernames: target_usernames,
PostCreator.new(user,
target_usernames: target_usernames,
archetype: Archetype.private_message,
title: title,
raw: body
@ -169,11 +169,11 @@ class PostAction < ActiveRecord::Base
Topic.update_all ["#{column} = #{column} + ?", delta], id: post.topic_id
if PostActionType.flag_types.values.include?(post_action_type_id)
if PostActionType.notify_flag_types.values.include?(post_action_type_id)
PostAction.update_flagged_posts_count
end
if SiteSetting.flags_required_to_hide_post > 0
if PostActionType.auto_action_flag_types.include?(post_action_type) && SiteSetting.flags_required_to_hide_post > 0
# automatic hiding of posts
flag_counts = exec_sql("SELECT SUM(CASE WHEN deleted_at IS NULL THEN 1 ELSE 0 END) AS new_flags,
SUM(CASE WHEN deleted_at IS NOT NULL THEN 1 ELSE 0 END) AS old_flags
@ -197,7 +197,7 @@ class PostAction < ActiveRecord::Base
end
end
protected
protected
def self.target_moderators(me)
User

View file

@ -21,6 +21,11 @@ class PostActionType < ActiveRecord::Base
@flag_types ||= types.only(:off_topic, :spam, :inappropriate, :notify_user, :notify_moderators)
end
# flags resulting in mod notifications
def notify_flag_types
@notify_flag_types ||= types.only(:off_topic, :spam, :inappropriate, :notify_moderators)
end
def is_flag?(sym)
flag_types.valid?(sym)
end