mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 08:43:25 +08:00
UX: Use smaller messages for moderator actions.
This commit is contained in:
parent
326b2812e4
commit
bb93a345eb
|
@ -0,0 +1,36 @@
|
|||
const icons = {
|
||||
'closed.enabled': 'lock',
|
||||
'closed.disabled': 'unlock-alt',
|
||||
'archived.enabled': 'folder',
|
||||
'archived.disabled': 'folder-open',
|
||||
'pinned.enabled': 'thumb-tack',
|
||||
'pinned.disabled': 'thumb-tack',
|
||||
'visible.enabled': 'eye',
|
||||
'visible.disabled': 'eye-slash'
|
||||
};
|
||||
|
||||
export default Ember.Component.extend({
|
||||
layoutName: 'components/small-action', // needed because `time-gap` inherits from this
|
||||
classNames: ['small-action'],
|
||||
|
||||
description: function() {
|
||||
const actionCode = this.get('actionCode');
|
||||
if (actionCode) {
|
||||
const dt = new Date(this.get('post.created_at'));
|
||||
const when = Discourse.Formatter.relativeAge(dt, {format: 'medium-with-ago'});
|
||||
const result = I18n.t(`action_codes.${actionCode}`, {when});
|
||||
return result + (this.get('post.cooked') || '');
|
||||
}
|
||||
}.property('actionCode', 'post.created_at', 'post.cooked'),
|
||||
|
||||
icon: function() {
|
||||
return icons[this.get('actionCode')] || 'exclamation';
|
||||
}.property('actionCode'),
|
||||
|
||||
actions: {
|
||||
edit: function() {
|
||||
this.sendAction('editPost', this.get('post'));
|
||||
}
|
||||
}
|
||||
|
||||
});
|
|
@ -1,22 +1,19 @@
|
|||
export default Ember.Component.extend({
|
||||
classNameBindings: [':time-gap'],
|
||||
import SmallActionComponent from 'discourse/components/small-action';
|
||||
|
||||
render(buffer) {
|
||||
const gapDays = this.get('gapDays');
|
||||
export default SmallActionComponent.extend({
|
||||
classNames: ['time-gap'],
|
||||
icon: 'clock-o',
|
||||
|
||||
buffer.push("<div class='topic-avatar'><i class='fa fa-clock-o'></i></div>");
|
||||
|
||||
let timeGapWords;
|
||||
description: function() {
|
||||
const gapDays = this.get('daysAgo');
|
||||
if (gapDays < 30) {
|
||||
timeGapWords = I18n.t('dates.later.x_days', {count: gapDays});
|
||||
return I18n.t('dates.later.x_days', {count: gapDays});
|
||||
} else if (gapDays < 365) {
|
||||
const gapMonths = Math.floor(gapDays / 30);
|
||||
timeGapWords = I18n.t('dates.later.x_months', {count: gapMonths});
|
||||
return I18n.t('dates.later.x_months', {count: gapMonths});
|
||||
} else {
|
||||
const gapYears = Math.floor(gapDays / 365);
|
||||
timeGapWords = I18n.t('dates.later.x_years', {count: gapYears});
|
||||
return I18n.t('dates.later.x_years', {count: gapYears});
|
||||
}
|
||||
|
||||
buffer.push("<div class='time-gap-words'>" + timeGapWords + "</div>");
|
||||
}
|
||||
}.property(),
|
||||
});
|
||||
|
|
|
@ -592,6 +592,7 @@ export default ObjectController.extend(SelectedPostsCount, BufferedContent, {
|
|||
|
||||
const self = this;
|
||||
this.messageBus.subscribe("/topic/" + this.get('model.id'), function(data) {
|
||||
console.log(data);
|
||||
const topic = self.get('model');
|
||||
|
||||
if (data.notification_level_change) {
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<div class='topic-avatar'>{{fa-icon icon}}</div>
|
||||
<div class='small-action-desc'>
|
||||
{{#if post}}
|
||||
<button {{action "edit"}} title="{{i18n "post.controls.edit"}}">{{fa-icon "pencil"}}</button>
|
||||
<a href={{post.usernameUrl}} data-user-card={{post.username}}>
|
||||
{{avatar post imageSize="small"}}
|
||||
</a>
|
||||
{{/if}}
|
||||
<p>{{{description}}}</p>
|
||||
</div>
|
|
@ -0,0 +1,3 @@
|
|||
{{post-gap post=this postStream=controller.model.postStream before="true"}}
|
||||
{{small-action actionCode=action_code post=this daysAgo=view.daysAgo editPost="editPost"}}
|
||||
{{post-gap post=this postStream=controller.model.postStream before="false"}}
|
|
@ -1,7 +1,7 @@
|
|||
{{post-gap post=this postStream=controller.model.postStream before="true"}}
|
||||
|
||||
{{#if hasTimeGap}}
|
||||
{{time-gap gapDays=daysSincePrevious}}
|
||||
{{time-gap daysAgo=daysSincePrevious}}
|
||||
{{/if}}
|
||||
|
||||
<div class='row'>
|
||||
|
|
|
@ -2,7 +2,6 @@ const DAY = 60 * 50 * 1000;
|
|||
|
||||
const PostView = Discourse.GroupedView.extend(Ember.Evented, {
|
||||
classNames: ['topic-post', 'clearfix'],
|
||||
templateName: 'post',
|
||||
classNameBindings: ['needsModeratorClass:moderator:regular',
|
||||
'selected',
|
||||
'post.hidden:post-hidden',
|
||||
|
@ -13,6 +12,10 @@ const PostView = Discourse.GroupedView.extend(Ember.Evented, {
|
|||
|
||||
post: Ember.computed.alias('content'),
|
||||
|
||||
templateName: function() {
|
||||
return (this.get('post.post_type') === 3) ? 'post-small-action' : 'post';
|
||||
}.property('post.post_type'),
|
||||
|
||||
historyHeat: function() {
|
||||
const updatedAt = this.get('post.updated_at');
|
||||
if (!updatedAt) { return; }
|
||||
|
|
|
@ -726,35 +726,56 @@ $topic-avatar-width: 45px;
|
|||
width: calc(#{$topic-avatar-width} + #{$topic-body-width} + 2 * #{$topic-body-width-padding});
|
||||
}
|
||||
|
||||
.time-gap {
|
||||
.small-action {
|
||||
width: 755px;
|
||||
border-top: 1px solid dark-light-diff($primary, $secondary, 90%, -60%);
|
||||
|
||||
.topic-avatar {
|
||||
padding: 5px 0;
|
||||
border-top: none;
|
||||
float: left;
|
||||
i {
|
||||
font-size: 35px;
|
||||
width: 45px;
|
||||
text-align: center;
|
||||
color: lighten($primary, 75%);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.time-gap .topic-avatar i {
|
||||
font-size: 35px;
|
||||
width: 45px;
|
||||
text-align: center;
|
||||
color: lighten($primary, 75%);
|
||||
}
|
||||
.time-gap-words {
|
||||
display: inline-block;
|
||||
padding: 0.5em 1em;
|
||||
margin-top: 9px;
|
||||
text-transform: uppercase;
|
||||
font-weight: bold;
|
||||
font-size: 0.9em;
|
||||
color: lighten($primary, 60%);
|
||||
.small-action-desc {
|
||||
display: inline-block;
|
||||
padding: 0.5em 1em;
|
||||
margin-top: 5px;
|
||||
text-transform: uppercase;
|
||||
font-weight: bold;
|
||||
font-size: 0.9em;
|
||||
color: lighten($primary, 60%);
|
||||
width: 680px;
|
||||
|
||||
.avatar {
|
||||
margin-right: 0.8em;
|
||||
float: left;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
padding-top: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
button {
|
||||
background: transparent;
|
||||
border: 0;
|
||||
float: right;
|
||||
}
|
||||
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.posts-wrapper {
|
||||
position: relative;
|
||||
-webkit-font-smoothing: subpixel-antialiased;
|
||||
}
|
||||
}
|
||||
|
||||
.dropdown {
|
||||
position: relative;
|
||||
|
|
|
@ -59,7 +59,7 @@ class DirectoryItem < ActiveRecord::Base
|
|||
AND COALESCE(t.visible, true)
|
||||
AND p.deleted_at IS NULL
|
||||
AND (NOT (COALESCE(p.hidden, false)))
|
||||
AND COALESCE(p.post_type, :regular_post_type) != :moderator_action
|
||||
AND COALESCE(p.post_type, :regular_post_type) = :regular_post_type
|
||||
AND u.id > 0
|
||||
GROUP BY u.id",
|
||||
period_type: period_types[period_type],
|
||||
|
@ -68,8 +68,7 @@ class DirectoryItem < ActiveRecord::Base
|
|||
was_liked_type: UserAction::WAS_LIKED,
|
||||
new_topic_type: UserAction::NEW_TOPIC,
|
||||
reply_type: UserAction::REPLY,
|
||||
regular_post_type: Post.types[:regular],
|
||||
moderator_action: Post.types[:moderator_action]
|
||||
regular_post_type: Post.types[:regular]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -73,7 +73,7 @@ class Post < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.types
|
||||
@types ||= Enum.new(:regular, :moderator_action)
|
||||
@types ||= Enum.new(:regular, :moderator_action, :small_action)
|
||||
end
|
||||
|
||||
def self.cook_methods
|
||||
|
@ -99,10 +99,10 @@ class Post < ActiveRecord::Base
|
|||
# consistency checks should fix, but message
|
||||
# is safe to skip
|
||||
MessageBus.publish("/topic/#{topic_id}", {
|
||||
id: id,
|
||||
post_number: post_number,
|
||||
updated_at: Time.now,
|
||||
type: type
|
||||
id: id,
|
||||
post_number: post_number,
|
||||
updated_at: Time.now,
|
||||
type: type
|
||||
}, group_ids: topic.secure_group_ids) if topic
|
||||
end
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@ SQL
|
|||
end
|
||||
|
||||
def staff_already_replied?(topic)
|
||||
topic.posts.where("user_id IN (SELECT id FROM users WHERE moderator OR admin) OR post_type = :post_type", post_type: Post.types[:moderator_action]).exists?
|
||||
topic.posts.where("user_id IN (SELECT id FROM users WHERE moderator OR admin) OR (post_type != :regular_post_type)", regular_post_type: Post.types[:regular]).exists?
|
||||
end
|
||||
|
||||
def self.create_message_for_post_action(user, post, post_action_type_id, opts)
|
||||
|
|
|
@ -489,15 +489,18 @@ class Topic < ActiveRecord::Base
|
|||
true
|
||||
end
|
||||
|
||||
def add_moderator_post(user, text, opts={})
|
||||
def add_moderator_post(user, text, opts=nil)
|
||||
opts ||= {}
|
||||
new_post = nil
|
||||
Topic.transaction do
|
||||
creator = PostCreator.new(user,
|
||||
raw: text,
|
||||
post_type: Post.types[:moderator_action],
|
||||
post_type: opts[:post_type] || Post.types[:moderator_action],
|
||||
action_code: opts[:action_code],
|
||||
no_bump: opts[:bump].blank?,
|
||||
skip_notifications: opts[:skip_notifications],
|
||||
topic_id: self.id)
|
||||
topic_id: self.id,
|
||||
skip_validations: true)
|
||||
new_post = creator.create
|
||||
increment!(:moderator_posts_count)
|
||||
end
|
||||
|
|
|
@ -49,8 +49,6 @@ TopicStatusUpdate = Struct.new(:topic, :user) do
|
|||
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
|
||||
|
||||
|
@ -69,7 +67,9 @@ TopicStatusUpdate = Struct.new(:topic, :user) do
|
|||
end
|
||||
|
||||
def options_for(status)
|
||||
{ bump: status.reopening_topic? }
|
||||
{ bump: status.reopening_topic?,
|
||||
post_type: Post.types[:small_action],
|
||||
action_code: status.action_code }
|
||||
end
|
||||
|
||||
Status = Struct.new(:name, :enabled) do
|
||||
|
@ -85,8 +85,12 @@ TopicStatusUpdate = Struct.new(:topic, :user) do
|
|||
!enabled?
|
||||
end
|
||||
|
||||
def action_code
|
||||
"#{name}.#{enabled? ? 'enabled' : 'disabled'}"
|
||||
end
|
||||
|
||||
def locale_key
|
||||
"topic_statuses.#{name}_#{enabled? ? 'enabled' : 'disabled'}"
|
||||
"topic_statuses.#{action_code.gsub('.', '_')}"
|
||||
end
|
||||
|
||||
def reopening_topic?
|
||||
|
|
|
@ -46,7 +46,7 @@ class AdminPostSerializer < ApplicationSerializer
|
|||
end
|
||||
|
||||
def moderator_action
|
||||
object.post_type == Post.types[:moderator_action]
|
||||
object.post_type == Post.types[:moderator_action] || object.post_type == Post.types[:small_action]
|
||||
end
|
||||
|
||||
def deleted_by
|
||||
|
|
|
@ -57,7 +57,8 @@ class PostSerializer < BasicPostSerializer
|
|||
:wiki,
|
||||
:user_custom_fields,
|
||||
:static_doc,
|
||||
:via_email
|
||||
:via_email,
|
||||
:action_code
|
||||
|
||||
def initialize(object, opts)
|
||||
super(object, opts)
|
||||
|
@ -281,6 +282,10 @@ class PostSerializer < BasicPostSerializer
|
|||
scope.is_staff? ? object.version : object.public_version
|
||||
end
|
||||
|
||||
def include_action_code?
|
||||
object.action_code.present?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def post_actions
|
||||
|
|
|
@ -68,7 +68,7 @@ class UserActionSerializer < ApplicationSerializer
|
|||
end
|
||||
|
||||
def moderator_action
|
||||
object.post_type == Post.types[:moderator_action]
|
||||
object.post_type == Post.types[:moderator_action] || object.post_type == Post.types[:small_action]
|
||||
end
|
||||
|
||||
def include_reply_to_post_number?
|
||||
|
|
|
@ -24,7 +24,7 @@ class PostAlerter
|
|||
end
|
||||
create_notification(user, Notification.types[:private_message], post)
|
||||
end
|
||||
elsif post.post_type != Post.types[:moderator_action]
|
||||
elsif post.post_type == Post.types[:regular]
|
||||
# If it's not a private message and it's not an automatic post caused by a moderator action, notify the users
|
||||
notify_post_users(post)
|
||||
end
|
||||
|
|
|
@ -119,6 +119,20 @@ en:
|
|||
google+: 'share this link on Google+'
|
||||
email: 'send this link in an email'
|
||||
|
||||
action_codes:
|
||||
closed:
|
||||
enabled: 'closed this topic %{when}'
|
||||
disabled: 'opened this topic %{when}'
|
||||
archived:
|
||||
enabled: 'archived this topic %{when}'
|
||||
disabled: 'unarchived this topic %{when}'
|
||||
pinned:
|
||||
enabled: 'pinned this topic %{when}'
|
||||
disabled: 'unpinned this topic %{when}'
|
||||
visible:
|
||||
enabled: 'unlisted this topic %{when}'
|
||||
disabled: 'listed this topic %{when}'
|
||||
|
||||
topic_admin_menu: "topic admin actions"
|
||||
|
||||
emails_are_disabled: "All outgoing email has been globally disabled by an administrator. No email notifications of any kind will be sent."
|
||||
|
|
5
db/migrate/20150724182342_add_action_code_to_post.rb
Normal file
5
db/migrate/20150724182342_add_action_code_to_post.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddActionCodeToPost < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :posts, :action_code, :string, null: true
|
||||
end
|
||||
end
|
|
@ -139,7 +139,7 @@ module Tilt
|
|||
|
||||
def generate_source(scope)
|
||||
js_source = ::JSON.generate(data, quirks_mode: true)
|
||||
js_source = "babel.transform(#{js_source}, {ast: false, whitelist: ['es6.constants', 'es6.properties.shorthand', 'es6.arrowFunctions', 'es6.blockScoping', 'es6.destructuring']})['code']"
|
||||
js_source = "babel.transform(#{js_source}, {ast: false, whitelist: ['es6.constants', 'es6.properties.shorthand', 'es6.arrowFunctions', 'es6.blockScoping', 'es6.destructuring', 'es6.templateLiterals']})['code']"
|
||||
"new module.exports.Compiler(#{js_source}, '#{module_name(scope.root_path, scope.logical_path)}', #{compiler_options}).#{compiler_method}()"
|
||||
end
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ class PostCreator
|
|||
# :raw_email - Imported from an email
|
||||
# via_email - Mark this post as arriving via email
|
||||
# raw_email - Full text of arriving email (to store)
|
||||
# action_code - Describes a small_action post (optional)
|
||||
#
|
||||
# When replying to a topic:
|
||||
# topic_id - topic we're replying to
|
||||
|
@ -255,7 +256,7 @@ class PostCreator
|
|||
end
|
||||
|
||||
def setup_post
|
||||
@opts[:raw] = TextCleaner.normalize_whitespaces(@opts[:raw]).gsub(/\s+\z/, "")
|
||||
@opts[:raw] = TextCleaner.normalize_whitespaces(@opts[:raw] || '').gsub(/\s+\z/, "")
|
||||
|
||||
post = Post.new(raw: @opts[:raw],
|
||||
topic_id: @topic.try(:id),
|
||||
|
@ -263,7 +264,7 @@ class PostCreator
|
|||
reply_to_post_number: @opts[:reply_to_post_number])
|
||||
|
||||
# Attributes we pass through to the post instance if present
|
||||
[:post_type, :no_bump, :cooking_options, :image_sizes, :acting_user, :invalidate_oneboxes, :cook_method, :via_email, :raw_email].each do |a|
|
||||
[:post_type, :no_bump, :cooking_options, :image_sizes, :acting_user, :invalidate_oneboxes, :cook_method, :via_email, :raw_email, :action_code].each do |a|
|
||||
post.send("#{a}=", @opts[a]) if @opts[a].present?
|
||||
end
|
||||
|
||||
|
|
|
@ -56,6 +56,9 @@ class PostJobsEnqueuer
|
|||
end
|
||||
|
||||
def skip_after_create?
|
||||
@opts[:import_mode] || @topic.private_message? || @post.post_type == Post.types[:moderator_action]
|
||||
@opts[:import_mode] ||
|
||||
@topic.private_message? ||
|
||||
@post.post_type == Post.types[:moderator_action] ||
|
||||
@post.post_type == Post.types[:small_action]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -379,7 +379,7 @@ class TopicView
|
|||
end
|
||||
|
||||
if @best.present?
|
||||
@filtered_posts = @filtered_posts.where('posts.post_type <> ?', Post.types[:moderator_action])
|
||||
@filtered_posts = @filtered_posts.where('posts.post_type = ?', Post.types[:regular])
|
||||
@contains_gaps = true
|
||||
end
|
||||
|
||||
|
|
|
@ -504,7 +504,7 @@ class ImportScripts::Base
|
|||
|
||||
def update_bumped_at
|
||||
puts "", "updating bumped_at on topics"
|
||||
Post.exec_sql("update topics t set bumped_at = COALESCE((select max(created_at) from posts where topic_id = t.id and post_type != #{Post.types[:moderator_action]}), bumped_at)")
|
||||
Post.exec_sql("update topics t set bumped_at = COALESCE((select max(created_at) from posts where topic_id = t.id and post_type = #{Post.types[:regular]}), bumped_at)")
|
||||
end
|
||||
|
||||
def update_last_posted_at
|
||||
|
|
|
@ -30,7 +30,10 @@ describe TopicStatusUpdate do
|
|||
|
||||
TopicStatusUpdate.new(topic, admin).update!("autoclosed", true)
|
||||
|
||||
expect(topic.posts.last.raw).to eq(I18n.t("topic_statuses.autoclosed_enabled_minutes", count: 0))
|
||||
last_post = topic.posts.last
|
||||
expect(last_post.post_type).to eq(Post.types[:small_action])
|
||||
expect(last_post.action_code).to eq('autoclosed.enabled')
|
||||
expect(last_post.raw).to eq(I18n.t("topic_statuses.autoclosed_enabled_minutes", count: 0))
|
||||
end
|
||||
|
||||
it "adds an autoclosed message based on last post" do
|
||||
|
@ -39,7 +42,10 @@ describe TopicStatusUpdate do
|
|||
|
||||
TopicStatusUpdate.new(topic, admin).update!("autoclosed", true)
|
||||
|
||||
expect(topic.posts.last.raw).to eq(I18n.t("topic_statuses.autoclosed_enabled_lastpost_minutes", count: 0))
|
||||
last_post = topic.posts.last
|
||||
expect(last_post.post_type).to eq(Post.types[:small_action])
|
||||
expect(last_post.action_code).to eq('autoclosed.enabled')
|
||||
expect(last_post.raw).to eq(I18n.t("topic_statuses.autoclosed_enabled_lastpost_minutes", count: 0))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user