2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-24 01:50:20 -04:00
|
|
|
module Jobs
|
2019-10-02 00:01:53 -04:00
|
|
|
class SendDefaultWelcomeMessage < ::Jobs::Base
|
2017-05-24 01:50:20 -04:00
|
|
|
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)
|
2019-11-13 16:31:49 -05:00
|
|
|
discobot_user = ::DiscourseNarrativeBot::Base.new.discobot_user
|
2017-05-24 01:50:20 -04:00
|
|
|
|
|
|
|
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
|