FIX: insert different message when auto-closing a topic based on the last post
This commit is contained in:
parent
62fa3775f2
commit
7e94f9d6f9
|
@ -392,7 +392,7 @@ class Topic < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_status(status, enabled, user)
|
def update_status(status, enabled, user)
|
||||||
TopicStatusUpdate.new(self, user).update! status, enabled
|
TopicStatusUpdate.new(self, user).update!(status, enabled)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Atomically creates the next post number
|
# Atomically creates the next post number
|
||||||
|
|
|
@ -15,11 +15,11 @@ TopicStatusUpdate = Struct.new(:topic, :user) do
|
||||||
|
|
||||||
def change(status)
|
def change(status)
|
||||||
if status.pinned? || status.pinned_globally?
|
if status.pinned? || status.pinned_globally?
|
||||||
topic.update_pinned status.enabled?, status.pinned_globally?
|
topic.update_pinned(status.enabled?, status.pinned_globally?)
|
||||||
elsif status.autoclosed?
|
elsif status.autoclosed?
|
||||||
topic.update_column 'closed', status.enabled?
|
topic.update_column('closed', status.enabled?)
|
||||||
else
|
else
|
||||||
topic.update_column status.name, status.enabled?
|
topic.update_column(status.name, status.enabled?)
|
||||||
end
|
end
|
||||||
|
|
||||||
if topic.auto_close_at && (status.reopening_topic? || status.manually_closing_topic?)
|
if topic.auto_close_at && (status.reopening_topic? || status.manually_closing_topic?)
|
||||||
|
@ -46,20 +46,26 @@ TopicStatusUpdate = Struct.new(:topic, :user) do
|
||||||
|
|
||||||
def message_for(status)
|
def message_for(status)
|
||||||
if status.autoclosed?
|
if status.autoclosed?
|
||||||
|
locale_key = status.locale_key
|
||||||
|
locale_key << "_lastpost" if topic.auto_close_based_on_last_post
|
||||||
|
message_for_autoclosed(locale_key)
|
||||||
|
else
|
||||||
|
I18n.t(status.locale_key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_for_autoclosed(locale_key)
|
||||||
num_minutes = topic.auto_close_started_at ? ((Time.zone.now - topic.auto_close_started_at) / 1.minute).round : topic.age_in_minutes
|
num_minutes = topic.auto_close_started_at ? ((Time.zone.now - topic.auto_close_started_at) / 1.minute).round : topic.age_in_minutes
|
||||||
if num_minutes.minutes >= 2.days
|
if num_minutes.minutes >= 2.days
|
||||||
I18n.t "#{status.locale_key}_days", count: (num_minutes.minutes / 1.day).round
|
I18n.t("#{locale_key}_days", count: (num_minutes.minutes / 1.day).round)
|
||||||
else
|
else
|
||||||
num_hours = (num_minutes.minutes / 1.hour).round
|
num_hours = (num_minutes.minutes / 1.hour).round
|
||||||
if num_hours >= 2
|
if num_hours >= 2
|
||||||
I18n.t "#{status.locale_key}_hours", count: num_hours
|
I18n.t("#{locale_key}_hours", count: num_hours)
|
||||||
else
|
else
|
||||||
I18n.t "#{status.locale_key}_minutes", count: num_minutes
|
I18n.t("#{locale_key}_minutes", count: num_minutes)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
I18n.t status.locale_key
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def options_for(status)
|
def options_for(status)
|
||||||
|
|
|
@ -1080,18 +1080,25 @@ en:
|
||||||
closed_enabled: "This topic is now closed. New replies are no longer allowed."
|
closed_enabled: "This topic is now closed. New replies are no longer allowed."
|
||||||
closed_disabled: "This topic is now opened. New replies are allowed."
|
closed_disabled: "This topic is now opened. New replies are allowed."
|
||||||
autoclosed_enabled_days:
|
autoclosed_enabled_days:
|
||||||
zero: "This topic was automatically closed after 1 day. New replies are no longer allowed."
|
|
||||||
one: "This topic was automatically closed after 1 day. New replies are no longer allowed."
|
one: "This topic was automatically closed after 1 day. New replies are no longer allowed."
|
||||||
other: "This topic was automatically closed after %{count} days. New replies are no longer allowed."
|
other: "This topic was automatically closed after %{count} days. New replies are no longer allowed."
|
||||||
autoclosed_enabled_hours:
|
autoclosed_enabled_hours:
|
||||||
zero: "This topic was automatically closed after 1 hour. New replies are no longer allowed."
|
|
||||||
one: "This topic was automatically closed after 1 hour. New replies are no longer allowed."
|
one: "This topic was automatically closed after 1 hour. New replies are no longer allowed."
|
||||||
other: "This topic was automatically closed after %{count} hours. New replies are no longer allowed."
|
other: "This topic was automatically closed after %{count} hours. New replies are no longer allowed."
|
||||||
autoclosed_enabled_minutes:
|
autoclosed_enabled_minutes:
|
||||||
zero: "This topic was automatically closed after 1 minute. New replies are no longer allowed."
|
|
||||||
one: "This topic was automatically closed after 1 minute. New replies are no longer allowed."
|
one: "This topic was automatically closed after 1 minute. New replies are no longer allowed."
|
||||||
other: "This topic was automatically closed after %{count} minutes. New replies are no longer allowed."
|
other: "This topic was automatically closed after %{count} minutes. New replies are no longer allowed."
|
||||||
|
autoclosed_enabled_lastpost_days:
|
||||||
|
one: "This topic was automatically closed 1 day after the last reply. New replies are no longer allowed."
|
||||||
|
other: "This topic was automatically closed %{count} days after the last reply. New replies are no longer allowed."
|
||||||
|
autoclosed_enabled_lastpost_hours:
|
||||||
|
one: "This topic was automatically closed 1 hour after the last reply. New replies are no longer allowed."
|
||||||
|
other: "This topic was automatically closed count} hours after the last reply. New replies are no longer allowed."
|
||||||
|
autoclosed_enabled_lastpost_minutes:
|
||||||
|
one: "This topic was automatically closed 1 minute after the last reply. New replies are no longer allowed."
|
||||||
|
other: "This topic was automatically closed %{count} minutes after the last reply. New replies are no longer allowed."
|
||||||
autoclosed_disabled: "This topic is now opened. New replies are allowed."
|
autoclosed_disabled: "This topic is now opened. New replies are allowed."
|
||||||
|
autoclosed_disabled_lastpost: "This topic is now opened. New replies are allowed."
|
||||||
pinned_enabled: "This topic is now pinned. It will appear at the top of its category until it is unpinned by staff for everyone, or by individual users for themselves."
|
pinned_enabled: "This topic is now pinned. It will appear at the top of its category until it is unpinned by staff for everyone, or by individual users for themselves."
|
||||||
pinned_disabled: "This topic is now unpinned. It will no longer appear at the top of its category."
|
pinned_disabled: "This topic is now unpinned. It will no longer appear at the top of its category."
|
||||||
pinned_globally_enabled: "This topic is now pinned globally. It will appear at the top of its category and all topic lists until it is unpinned by staff for everyone, or by individual users for themselves."
|
pinned_globally_enabled: "This topic is now pinned globally. It will appear at the top of its category and all topic lists until it is unpinned by staff for everyone, or by individual users for themselves."
|
||||||
|
|
|
@ -4,18 +4,19 @@ require 'spec_helper'
|
||||||
require_dependency 'post_destroyer'
|
require_dependency 'post_destroyer'
|
||||||
|
|
||||||
describe TopicStatusUpdate do
|
describe TopicStatusUpdate do
|
||||||
|
|
||||||
|
let(:user) { Fabricate(:user) }
|
||||||
|
let(:admin) { Fabricate(:admin) }
|
||||||
|
|
||||||
it "avoids notifying on automatically closed topics" do
|
it "avoids notifying on automatically closed topics" do
|
||||||
# TODO: TopicStatusUpdate should supress message bus updates from the users it "pretends to read"
|
# TODO: TopicStatusUpdate should supress message bus updates from the users it "pretends to read"
|
||||||
user = Fabricate(:user)
|
|
||||||
post = PostCreator.create(user,
|
post = PostCreator.create(user,
|
||||||
raw: "this is a test post 123 this is a test post",
|
raw: "this is a test post 123 this is a test post",
|
||||||
title: "hello world title",
|
title: "hello world title",
|
||||||
)
|
)
|
||||||
# TODO needed so counts sync up,
|
# TODO needed so counts sync up, PostCreator really should not give back out-of-date Topic
|
||||||
# PostCreator really should not give back out-of-date Topic
|
|
||||||
post.topic.reload
|
post.topic.reload
|
||||||
|
|
||||||
admin = Fabricate(:admin)
|
|
||||||
TopicStatusUpdate.new(post.topic, admin).update!("autoclosed", true)
|
TopicStatusUpdate.new(post.topic, admin).update!("autoclosed", true)
|
||||||
|
|
||||||
post.topic.posts.count.should == 2
|
post.topic.posts.count.should == 2
|
||||||
|
@ -23,4 +24,22 @@ describe TopicStatusUpdate do
|
||||||
tu = TopicUser.find_by(user_id: user.id)
|
tu = TopicUser.find_by(user_id: user.id)
|
||||||
tu.last_read_post_number.should == 2
|
tu.last_read_post_number.should == 2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "adds an autoclosed message" do
|
||||||
|
topic = create_topic
|
||||||
|
|
||||||
|
TopicStatusUpdate.new(topic, admin).update!("autoclosed", true)
|
||||||
|
|
||||||
|
topic.posts.last.raw.should == I18n.t("topic_statuses.autoclosed_enabled_minutes", count: 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "adds an autoclosed message based on last post" do
|
||||||
|
topic = create_topic
|
||||||
|
topic.auto_close_based_on_last_post = true
|
||||||
|
|
||||||
|
TopicStatusUpdate.new(topic, admin).update!("autoclosed", true)
|
||||||
|
|
||||||
|
topic.posts.last.raw.should == I18n.t("topic_statuses.autoclosed_enabled_lastpost_minutes", count: 0)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue