staged users automatically watches all topics they participates in

This commit is contained in:
Régis Hanol 2015-11-18 22:24:46 +01:00
parent 7f4ca91e06
commit 31a54377be
3 changed files with 27 additions and 2 deletions

View File

@ -48,6 +48,13 @@ class TopicUser < ActiveRecord::Base
end
end
def auto_watch(user_id, topic_id)
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 = notification_reasons[:auto_watch]
topic_user.save
end
# Find the information specific to a user in a forum topic
def lookup_for(user, topics)
# If the user isn't logged in, there's no last read posts

View File

@ -383,8 +383,11 @@ class PostCreator
post_number: @post.post_number,
msecs: 5000)
TopicUser.auto_track(@user.id, @topic.id, TopicUser.notification_reasons[:created_post])
if @user.staged
TopicUser.auto_watch(@user.id, @topic.id)
else
TopicUser.auto_track(@user.id, @topic.id, TopicUser.notification_reasons[:created_post])
end
end
def enqueue_jobs

View File

@ -684,4 +684,19 @@ describe PostCreator do
end
end
context "staged users" do
let(:staged) { Fabricate(:staged) }
it "automatically watches all messages it participates in" do
post = PostCreator.create(staged,
title: "this is the title of a topic created by a staged user",
raw: "this is the content of a topic created by a staged user ;)"
)
topic_user = TopicUser.find_by(user_id: staged.id, topic_id: post.topic_id)
expect(topic_user.notification_level).to eq(TopicUser.notification_levels[:watching])
expect(topic_user.notifications_reason_id).to eq(TopicUser.notification_reasons[:auto_watch])
end
end
end