FIX: invited staged users would sometimes not get notified of replies
This commit is contained in:
parent
1477a0e910
commit
3bdd8f57c1
|
@ -38,26 +38,19 @@ class TopicUser < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def auto_notification(user_id, topic_id, reason, notification_level)
|
||||
if TopicUser.where("user_id = :user_id AND topic_id = :topic_id AND (notifications_reason_id IS NULL OR
|
||||
(notification_level < :notification_level AND notification_level > :normal_notification_level))",
|
||||
user_id: user_id, topic_id: topic_id, notification_level: notification_level,
|
||||
normal_notification_level: notification_levels[:regular]).exists?
|
||||
change(user_id, topic_id,
|
||||
notification_level: notification_level,
|
||||
notifications_reason_id: reason
|
||||
)
|
||||
end
|
||||
should_change = TopicUser
|
||||
.where(user_id: user_id, topic_id: topic_id)
|
||||
.where("notifications_reason_id IS NULL OR (notification_level < :min AND notification_level > :max)", min: notification_level, max: notification_levels[:regular])
|
||||
.exists?
|
||||
|
||||
change(user_id, topic_id, notification_level: notification_level, notifications_reason_id: reason) if should_change
|
||||
end
|
||||
|
||||
def auto_notification_for_staging(user_id, topic_id, reason)
|
||||
topic_user = TopicUser.find_or_initialize_by(user_id: user_id, topic_id: topic_id)
|
||||
topic_user.notification_level = notification_levels[:watching]
|
||||
topic_user.notifications_reason_id = reason
|
||||
topic_user.save
|
||||
def auto_notification_for_staging(user_id, topic_id, reason, notification_level=notification_levels[:watching])
|
||||
change(user_id, topic_id, notification_level: notification_level, notifications_reason_id: reason)
|
||||
end
|
||||
|
||||
def unwatch_categories!(user, category_ids)
|
||||
|
||||
track_threshold = user.user_option.auto_track_topics_after_msecs
|
||||
|
||||
sql = <<SQL
|
||||
|
|
|
@ -93,7 +93,7 @@ class PostAlerter
|
|||
DiscourseEvent.trigger(:before_create_notifications_for_users, users, post)
|
||||
users.each do |user|
|
||||
notification_level = TopicUser.get(post.topic, user).try(:notification_level)
|
||||
if notified.include?(user) || notification_level == TopicUser.notification_levels[:watching]
|
||||
if notified.include?(user) || notification_level == TopicUser.notification_levels[:watching] || user.staged?
|
||||
create_notification(user, Notification.types[:private_message], post)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -692,7 +692,7 @@ module Email
|
|||
if result.post
|
||||
@incoming_email.update_columns(topic_id: result.post.topic_id, post_id: result.post.id)
|
||||
if result.post.topic && result.post.topic.private_message?
|
||||
add_other_addresses(result.post.topic, user)
|
||||
add_other_addresses(result.post, user)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -707,7 +707,7 @@ module Email
|
|||
html
|
||||
end
|
||||
|
||||
def add_other_addresses(topic, sender)
|
||||
def add_other_addresses(post, sender)
|
||||
%i(to cc bcc).each do |d|
|
||||
if @mail[d] && @mail[d].address_list && @mail[d].address_list.addresses
|
||||
@mail[d].address_list.addresses.each do |address_field|
|
||||
|
@ -718,13 +718,14 @@ module Email
|
|||
next unless email["@"]
|
||||
if should_invite?(email)
|
||||
user = find_or_create_user(email, display_name)
|
||||
if user && can_invite?(topic, user)
|
||||
topic.topic_allowed_users.create!(user_id: user.id)
|
||||
topic.add_small_action(sender, "invited_user", user.username)
|
||||
if user && can_invite?(post.topic, user)
|
||||
post.topic.topic_allowed_users.create!(user_id: user.id)
|
||||
TopicUser.auto_notification_for_staging(user.id, post.topic_id, TopicUser.notification_reasons[:auto_watch])
|
||||
post.topic.add_small_action(sender, "invited_user", user.username)
|
||||
end
|
||||
# cap number of staged users created per email
|
||||
if @staged_users.count > SiteSetting.maximum_staged_users_per_email
|
||||
topic.add_moderator_post(sender, I18n.t("emails.incoming.maximum_staged_user_per_email_reached"))
|
||||
post.topic.add_moderator_post(sender, I18n.t("emails.incoming.maximum_staged_user_per_email_reached"))
|
||||
return
|
||||
end
|
||||
end
|
||||
|
|
|
@ -508,12 +508,9 @@ class PostCreator
|
|||
|
||||
if @user.staged
|
||||
TopicUser.auto_notification_for_staging(@user.id, @topic.id, TopicUser.notification_reasons[:auto_watch])
|
||||
elsif @user.user_option.notification_level_when_replying === NotificationLevels.topic_levels[:watching]
|
||||
TopicUser.auto_notification(@user.id, @topic.id, TopicUser.notification_reasons[:created_post], NotificationLevels.topic_levels[:watching])
|
||||
elsif @user.user_option.notification_level_when_replying === NotificationLevels.topic_levels[:regular]
|
||||
TopicUser.auto_notification(@user.id, @topic.id, TopicUser.notification_reasons[:created_post], NotificationLevels.topic_levels[:regular])
|
||||
else
|
||||
TopicUser.auto_notification(@user.id, @topic.id, TopicUser.notification_reasons[:created_post], NotificationLevels.topic_levels[:tracking])
|
||||
notification_level = @user.user_option.notification_level_when_replying || NotificationLevels.topic_levels[:tracking]
|
||||
TopicUser.auto_notification(@user.id, @topic.id, TopicUser.notification_reasons[:created_post], notification_level)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -419,9 +419,13 @@ describe Email::Receiver do
|
|||
|
||||
it "invites everyone in the chain but emails configured as 'incoming' (via reply, group or category)" do
|
||||
expect { process(:cc) }.to change(Topic, :count)
|
||||
emails = Topic.last.allowed_users.joins(:user_emails).pluck(:"user_emails.email")
|
||||
expect(emails.size).to eq(3)
|
||||
expect(emails).to include("someone@else.com", "discourse@bar.com", "wat@bar.com")
|
||||
|
||||
topic = Topic.last
|
||||
|
||||
emails = topic.allowed_users.joins(:user_emails).pluck(:"user_emails.email")
|
||||
expect(emails).to contain_exactly("someone@else.com", "discourse@bar.com", "wat@bar.com")
|
||||
|
||||
expect(topic.topic_users.count).to eq(3)
|
||||
end
|
||||
|
||||
it "cap the number of staged users created per email" do
|
||||
|
|
Loading…
Reference in New Issue