mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
28 lines
780 B
Ruby
28 lines
780 B
Ruby
module Jobs
|
|
class PushNotification < Jobs::Base
|
|
def execute(args)
|
|
notification = args["payload"]
|
|
notification["url"] = UrlHelper.absolute_without_cdn(notification["post_url"])
|
|
notification.delete("post_url")
|
|
|
|
payload = {
|
|
secret_key: SiteSetting.push_api_secret_key,
|
|
url: Discourse.base_url,
|
|
title: SiteSetting.title,
|
|
description: SiteSetting.site_description,
|
|
}
|
|
|
|
clients = args["clients"]
|
|
clients.group_by{|r| r[1]}.each do |push_url, group|
|
|
notifications = group.map do |client_id, _|
|
|
notification.merge({
|
|
client_id: client_id
|
|
})
|
|
end
|
|
|
|
RestClient.send :post, push_url, payload.merge({notifications: notifications})
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|