mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FIX: insert different message when auto-closing a topic based on the last post
This commit is contained in:
parent
62fa3775f2
commit
7e94f9d6f9
4 changed files with 56 additions and 24 deletions
|
@ -392,7 +392,7 @@ class Topic < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def update_status(status, enabled, user)
|
||||
TopicStatusUpdate.new(self, user).update! status, enabled
|
||||
TopicStatusUpdate.new(self, user).update!(status, enabled)
|
||||
end
|
||||
|
||||
# Atomically creates the next post number
|
||||
|
|
|
@ -15,11 +15,11 @@ TopicStatusUpdate = Struct.new(:topic, :user) do
|
|||
|
||||
def change(status)
|
||||
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?
|
||||
topic.update_column 'closed', status.enabled?
|
||||
topic.update_column('closed', status.enabled?)
|
||||
else
|
||||
topic.update_column status.name, status.enabled?
|
||||
topic.update_column(status.name, status.enabled?)
|
||||
end
|
||||
|
||||
if topic.auto_close_at && (status.reopening_topic? || status.manually_closing_topic?)
|
||||
|
@ -39,26 +39,32 @@ TopicStatusUpdate = Struct.new(:topic, :user) do
|
|||
def update_read_state_for(status, old_highest_read)
|
||||
if status.autoclosed?
|
||||
# let's pretend all the people that read up to the autoclose message
|
||||
# actually read the topic
|
||||
# actually read the topic
|
||||
PostTiming.pretend_read(topic.id, old_highest_read, topic.highest_post_number)
|
||||
end
|
||||
end
|
||||
|
||||
def message_for(status)
|
||||
if status.autoclosed?
|
||||
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
|
||||
I18n.t "#{status.locale_key}_days", count: (num_minutes.minutes / 1.day).round
|
||||
else
|
||||
num_hours = (num_minutes.minutes / 1.hour).round
|
||||
if num_hours >= 2
|
||||
I18n.t "#{status.locale_key}_hours", count: num_hours
|
||||
else
|
||||
I18n.t "#{status.locale_key}_minutes", count: num_minutes
|
||||
end
|
||||
end
|
||||
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
|
||||
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
|
||||
if num_minutes.minutes >= 2.days
|
||||
I18n.t("#{locale_key}_days", count: (num_minutes.minutes / 1.day).round)
|
||||
else
|
||||
num_hours = (num_minutes.minutes / 1.hour).round
|
||||
if num_hours >= 2
|
||||
I18n.t("#{locale_key}_hours", count: num_hours)
|
||||
else
|
||||
I18n.t("#{locale_key}_minutes", count: num_minutes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1080,18 +1080,25 @@ en:
|
|||
closed_enabled: "This topic is now closed. New replies are no longer allowed."
|
||||
closed_disabled: "This topic is now opened. New replies are allowed."
|
||||
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."
|
||||
other: "This topic was automatically closed after %{count} days. New replies are no longer allowed."
|
||||
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."
|
||||
other: "This topic was automatically closed after %{count} hours. New replies are no longer allowed."
|
||||
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."
|
||||
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_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_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."
|
||||
|
|
|
@ -4,18 +4,19 @@ require 'spec_helper'
|
|||
require_dependency 'post_destroyer'
|
||||
|
||||
describe TopicStatusUpdate do
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
it "avoids notifying on automatically closed topics" do
|
||||
# TODO: TopicStatusUpdate should supress message bus updates from the users it "pretends to read"
|
||||
user = Fabricate(:user)
|
||||
post = PostCreator.create(user,
|
||||
raw: "this is a test post 123 this is a test post",
|
||||
title: "hello world title",
|
||||
)
|
||||
# TODO needed so counts sync up,
|
||||
# PostCreator really should not give back out-of-date Topic
|
||||
# TODO needed so counts sync up, PostCreator really should not give back out-of-date Topic
|
||||
post.topic.reload
|
||||
|
||||
admin = Fabricate(:admin)
|
||||
TopicStatusUpdate.new(post.topic, admin).update!("autoclosed", true)
|
||||
|
||||
post.topic.posts.count.should == 2
|
||||
|
@ -23,4 +24,22 @@ describe TopicStatusUpdate do
|
|||
tu = TopicUser.find_by(user_id: user.id)
|
||||
tu.last_read_post_number.should == 2
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue