mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 10:55:54 +08:00
Merge pull request #2491 from techAPJ/system-user-notifications
FEATURE: Send notification by system user for bulk invite
This commit is contained in:
commit
d23c7cdc65
|
@ -112,9 +112,9 @@ module Jobs
|
|||
def notify_user
|
||||
if @current_user
|
||||
if (@sent > 0 && @failed == 0)
|
||||
SystemMessage.create(@current_user, :bulk_invite_succeeded, sent: @sent)
|
||||
SystemMessage.create_from_system_user(@current_user, :bulk_invite_succeeded, sent: @sent)
|
||||
else
|
||||
SystemMessage.create(@current_user, :bulk_invite_failed, sent: @sent, failed: @failed, logs: @logs.join("\n"))
|
||||
SystemMessage.create_from_system_user(@current_user, :bulk_invite_failed, sent: @sent, failed: @failed, logs: @logs.join("\n"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,10 @@ class SystemMessage
|
|||
self.new(recipient).create(type, params)
|
||||
end
|
||||
|
||||
def self.create_from_system_user(recipient, type, params = {})
|
||||
self.new(recipient).create_from_system_user(type, params)
|
||||
end
|
||||
|
||||
def initialize(recipient)
|
||||
@recipient = recipient
|
||||
end
|
||||
|
@ -27,6 +31,20 @@ class SystemMessage
|
|||
subtype: TopicSubtype.system_message)
|
||||
end
|
||||
|
||||
def create_from_system_user(type, params = {})
|
||||
params = defaults.merge(params)
|
||||
|
||||
title = I18n.t("system_messages.#{type}.subject_template", params)
|
||||
raw = I18n.t("system_messages.#{type}.text_body_template", params)
|
||||
|
||||
PostCreator.create(Discourse.system_user,
|
||||
title: title,
|
||||
raw: raw,
|
||||
archetype: Archetype.private_message,
|
||||
target_usernames: @recipient.username,
|
||||
subtype: TopicSubtype.system_message)
|
||||
end
|
||||
|
||||
def defaults
|
||||
{
|
||||
site_name: SiteSetting.title,
|
||||
|
|
Loading…
Reference in New Issue
Block a user