discourse/plugins/discourse-narrative-bot/autoload/jobs/send_default_welcome_message.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

28 lines
800 B
Ruby

# frozen_string_literal: true
module Jobs
class SendDefaultWelcomeMessage < Jobs::Base
def execute(args)
if user = User.find_by(id: args[:user_id])
type = user.invited_by ? 'welcome_invite' : 'welcome_user'
params = SystemMessage.new(user).defaults
title = I18n.t("system_messages.#{type}.subject_template", params)
raw = I18n.t("system_messages.#{type}.text_body_template", params)
discobot_user = User.find(-2)
post = PostCreator.create!(
discobot_user,
title: title,
raw: raw,
archetype: Archetype.private_message,
target_usernames: user.username,
skip_validations: true
)
post.topic.update_status('closed', true, discobot_user)
end
end
end
end