mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 15:28:30 +08:00
DEV: Create post actions without creating a notification and store custom data. (#15397)
I plan to use this in an upcoming discourse-reactions PR, where I want to like a post without notifying the user, so I can instead create a reaction notification. Additionally, we decouple the a11y attributes from the icon itself, which will let us extend the widget's icon without losing them.
This commit is contained in:
@ -7,20 +7,21 @@ class PostActionCreator
|
||||
|
||||
# Shortcut methods for easier invocation
|
||||
class << self
|
||||
def create(created_by, post, action_key, message: nil, created_at: nil, reason: nil)
|
||||
def create(created_by, post, action_key, message: nil, created_at: nil, reason: nil, silent: false)
|
||||
new(
|
||||
created_by,
|
||||
post,
|
||||
PostActionType.types[action_key],
|
||||
message: message,
|
||||
created_at: created_at,
|
||||
reason: reason
|
||||
reason: reason,
|
||||
silent: silent
|
||||
).perform
|
||||
end
|
||||
|
||||
[:like, :off_topic, :spam, :inappropriate, :bookmark].each do |action|
|
||||
define_method(action) do |created_by, post|
|
||||
create(created_by, post, action)
|
||||
define_method(action) do |created_by, post, silent = false|
|
||||
create(created_by, post, action, silent: silent)
|
||||
end
|
||||
end
|
||||
[:notify_moderators, :notify_user].each do |action|
|
||||
@ -40,7 +41,8 @@ class PostActionCreator
|
||||
flag_topic: false,
|
||||
created_at: nil,
|
||||
queue_for_review: false,
|
||||
reason: nil
|
||||
reason: nil,
|
||||
silent: false
|
||||
)
|
||||
@created_by = created_by
|
||||
@created_at = created_at || Time.zone.now
|
||||
@ -62,6 +64,8 @@ class PostActionCreator
|
||||
if reason.nil? && @queue_for_review
|
||||
@reason = 'queued_by_staff'
|
||||
end
|
||||
|
||||
@silent = silent
|
||||
end
|
||||
|
||||
def post_can_act?
|
||||
@ -113,7 +117,7 @@ class PostActionCreator
|
||||
create_reviewable(result)
|
||||
enforce_rules
|
||||
UserActionManager.post_action_created(post_action)
|
||||
PostActionNotifier.post_action_created(post_action)
|
||||
PostActionNotifier.post_action_created(post_action) if !@silent
|
||||
notify_subscribers
|
||||
|
||||
# agree with other flags
|
||||
|
Reference in New Issue
Block a user