REFACTOR: Use `Topic#private_message?` to reduce duplication.

This commit is contained in:
Guo Xiang Tan 2018-03-05 15:38:05 +08:00
parent 07f1d90b88
commit 2f65393706
7 changed files with 8 additions and 8 deletions

View File

@ -164,7 +164,7 @@ class Post < ActiveRecord::Base
}.merge(options)
if Topic.visible_post_types.include?(post_type)
if topic.archetype == Archetype.private_message
if topic.private_message?
user_ids = User.where('admin or moderator').pluck(:id)
user_ids |= topic.allowed_users.pluck(:id)
MessageBus.publish(channel, msg, user_ids: user_ids)

View File

@ -265,7 +265,7 @@ class Topic < ActiveRecord::Base
end
def advance_draft_sequence
if archetype == Archetype.private_message
if self.private_message?
DraftSequence.next!(user, Draft::NEW_PRIVATE_MESSAGE)
else
DraftSequence.next!(user, Draft::NEW_TOPIC)

View File

@ -85,7 +85,7 @@ class UserActionCreator
return unless model.user_id
row = {
action_type: model.archetype == Archetype.private_message ? UserAction::NEW_PRIVATE_MESSAGE : UserAction::NEW_TOPIC,
action_type: model.private_message? ? UserAction::NEW_PRIVATE_MESSAGE : UserAction::NEW_TOPIC,
user_id: model.user_id,
acting_user_id: model.user_id,
target_topic_id: model.id,
@ -94,7 +94,7 @@ class UserActionCreator
}
UserAction.remove_action!(row.merge(
action_type: model.archetype == Archetype.private_message ? UserAction::NEW_TOPIC : UserAction::NEW_PRIVATE_MESSAGE
action_type: model.private_message? ? UserAction::NEW_TOPIC : UserAction::NEW_PRIVATE_MESSAGE
))
rows = [row]

View File

@ -20,7 +20,7 @@ class ComposerMessagesFinder
# Determines whether to show the user education text
def check_education_message
return if @topic && @topic.archetype == Archetype.private_message
return if @topic&.private_message?
if creating_topic?
count = @user.created_topic_count

View File

@ -176,7 +176,7 @@ module DiscourseNarrativeBot
}
if @post &&
@post.archetype == Archetype.private_message &&
@post.topic.private_message? &&
@post.topic.topic_allowed_users.pluck(:user_id).include?(@user.id)
opts = opts.merge(topic_id: @post.topic_id)

View File

@ -190,7 +190,7 @@ module DiscourseNarrativeBot
}
if @post &&
@post.archetype == Archetype.private_message &&
@post.topic.private_message? &&
@post.topic.topic_allowed_users.pluck(:user_id).include?(@user.id)
opts = opts.merge(topic_id: @post.topic_id)

View File

@ -58,7 +58,7 @@ after_initialize do
topic = type == 'post' ? Post.find_by(id: id).topic : Topic.find_by(id: id)
if topic.archetype == Archetype.private_message
if topic.private_message?
user_ids = User.where('admin OR moderator').pluck(:id) + topic.allowed_users.pluck(:id)
group_ids = topic.allowed_groups.pluck(:id)