* Bump rubocop from 1.15.0 to 1.16.0 Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.15.0 to 1.16.0. - [Release notes](https://github.com/rubocop/rubocop/releases) - [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop/rubocop/compare/v1.15.0...v1.16.0) --- updated-dependencies: - dependency-name: rubocop dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Enable new cops and fix violations Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: rhymes <github@rhymes.dev>
58 lines
1.5 KiB
Ruby
58 lines
1.5 KiB
Ruby
class Device < ApplicationRecord
|
|
# @fdoxyz to remove app_bundle from Device soon
|
|
self.ignored_columns = ["app_bundle"]
|
|
|
|
belongs_to :consumer_app
|
|
belongs_to :user
|
|
|
|
IOS = "iOS".freeze
|
|
ANDROID = "Android".freeze
|
|
|
|
enum platform: { android: ANDROID, ios: IOS }
|
|
|
|
validates :platform, inclusion: { in: platforms.keys }
|
|
validates :token, presence: true
|
|
validates :token, uniqueness: { scope: %i[user_id platform consumer_app_id] }
|
|
|
|
def create_notification(title, body, payload)
|
|
if android?
|
|
android_notification(title, body, payload)
|
|
elsif ios?
|
|
ios_notification(title, body, payload)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def ios_notification(title, body, payload)
|
|
n = Rpush::Apns2::Notification.new
|
|
n.device_token = token
|
|
n.app = ConsumerApps::RpushAppQuery.call(
|
|
app_bundle: consumer_app.app_bundle,
|
|
platform: platform,
|
|
)
|
|
n.data = {
|
|
aps: {
|
|
alert: {
|
|
title: Settings::Community.community_name,
|
|
subtitle: title,
|
|
body: body
|
|
},
|
|
"thread-id": Settings::Community.community_name
|
|
},
|
|
data: payload
|
|
}
|
|
n.save!
|
|
end
|
|
|
|
def android_notification(title, body, payload)
|
|
n = Rpush::Gcm::Notification.new
|
|
n.app = ConsumerApp.rpush_app(app_bundle: app_bundle, platform: platform)
|
|
n.registration_ids = [token]
|
|
n.priority = "high"
|
|
n.content_available = true
|
|
n.notification = { title: title, body: body }
|
|
n.data = { data: payload }
|
|
n.save!
|
|
end
|
|
end
|