* window.ForemMobile namespaced functions * Fix broken Buildkite * Wait for data-loaded before using Runtime in pack * Bring back sprockets base * Better error handling * Smal fixes to ConsumerApp to support Android platform * Fix typo * utilities/waitForDataLoaded.js * Update app/javascript/utilities/waitForDataLoaded.js Co-authored-by: Nick Taylor <nick@forem.com> * Review feedback * Fix failing spec * Cleanup promise * Remove old utility file * Add Cypress check for namespaced availability * More specs * Refactor to rely on ForemMobile for native bridge messaging * Fix spec/requests/api/v0/instances_spec.rb * Fix devices spec * Remove changes to /api/instance * Refactor to dynamic import * Fix typo * Fixed custom event detail payload for tests. * mock ForemMobile function instead of webkit call directly * failing jest test debug * Another attempt * Fixed broken test that was missing an onMainImageUrlChange prop on the component. * Fixed mobile bridging E2E tests. * Move Cypress tests to mobileFlows * Add JSDocs + cypress spec for injectJSMessage when logged out * Cleanup + Disable native image upload until AppStore approval Co-authored-by: Nick Taylor <nick@forem.com> Co-authored-by: Nick Taylor <nick@dev.to>
62 lines
1.9 KiB
Ruby
62 lines
1.9 KiB
Ruby
class ConsumerApp < ApplicationRecord
|
|
resourcify
|
|
|
|
FOREM_BUNDLE = "com.forem.app".freeze
|
|
FOREM_APP_PLATFORMS = %w[ios android].freeze
|
|
FOREM_TEAM_ID = "R9SWHSQNV8".freeze
|
|
|
|
enum platform: { android: Device::ANDROID, ios: Device::IOS }
|
|
|
|
validates :app_bundle, presence: true, uniqueness: { scope: :platform }
|
|
validates :platform, inclusion: { in: platforms.keys }
|
|
|
|
has_many :devices, dependent: :destroy
|
|
|
|
# Clear Redis-backed model to ensure it will be recreated with updated values
|
|
after_update :clear_rpush_app
|
|
|
|
def forem_app?
|
|
app_bundle == FOREM_BUNDLE && FOREM_APP_PLATFORMS.include?(platform)
|
|
end
|
|
|
|
def creator_app?
|
|
!forem_app?
|
|
end
|
|
|
|
# When an error is raised during an attempt to deliver PNs we should catch
|
|
# them, mark the app as active=false and the error logged into `last_error`
|
|
# If the app is marked as active and credentials are available it's likely
|
|
# the ConsumerApp is operational.
|
|
def operational?
|
|
active && auth_credentials.present?
|
|
end
|
|
|
|
# The Forem apps will get their credentials from an ENV variable, whereas
|
|
# custom PN targets will get their credentials from the auth_key stored in
|
|
# the DB (configured by the Forem creator).
|
|
def auth_credentials
|
|
if forem_app? && ios?
|
|
ApplicationConfig["RPUSH_IOS_PEM"]
|
|
elsif forem_app? && android?
|
|
ApplicationConfig["RPUSH_FCM_KEY"]
|
|
else
|
|
auth_key
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
# [@forem/backend] `.where().first` is necessary because we use Redis data storage
|
|
# https://github.com/rpush/rpush/wiki/Using-Redis#find_by_name-cannot-be-used-in-rpush-redis
|
|
def clear_rpush_app
|
|
case ConsumerApp.platforms[platform_was]
|
|
when Device::IOS
|
|
Rpush::Apns2::App.where(name: app_bundle_was).first&.destroy
|
|
when Device::ANDROID
|
|
Rpush::Gcm::App.where(name: app_bundle_was).first&.destroy
|
|
end
|
|
|
|
# This prevents the `destroy` method to return true or false in a callback
|
|
true
|
|
end
|
|
end
|