Unverified Commit 30b3b8b0 authored by Rafael Kellermann Streit's avatar Rafael Kellermann Streit Committed by GitHub

Merge pull request #1014 from RocketChat/fix/missing-play-services

[FIX] Don't crash on missing Play Services.
parents 3ac4578e 376c74ac
...@@ -144,7 +144,8 @@ class MainPresenter @Inject constructor( ...@@ -144,7 +144,8 @@ class MainPresenter @Inject constructor(
suspend fun refreshToken(token: String?) { suspend fun refreshToken(token: String?) {
token?.let { token?.let {
client.registerPushToken(it, getAccountsInteractor.get(), factory) localRepository.save(LocalRepository.KEY_PUSH_TOKEN, token)
client.registerPushToken(token, getAccountsInteractor.get(), factory)
} }
} }
} }
\ No newline at end of file
...@@ -49,9 +49,13 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, HasSupp ...@@ -49,9 +49,13 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, HasSupp
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
launch(CommonPool) { launch(CommonPool) {
val token = InstanceID.getInstance(this@MainActivity).getToken(getString(R.string.gcm_sender_id), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null) try {
Timber.d("GCM token: $token") val token = InstanceID.getInstance(this@MainActivity).getToken(getString(R.string.gcm_sender_id), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null)
presenter.refreshToken(token) Timber.d("GCM token: $token")
presenter.refreshToken(token)
} catch (ex: Exception) {
Timber.d(ex, "Missing play services...")
}
} }
presenter.connect() presenter.connect()
......
...@@ -35,17 +35,19 @@ class FirebaseTokenService : FirebaseInstanceIdService() { ...@@ -35,17 +35,19 @@ class FirebaseTokenService : FirebaseInstanceIdService() {
// default push gateway. We should register this project's own project sender id into it. // default push gateway. We should register this project's own project sender id into it.
val gcmToken = InstanceID.getInstance(this) val gcmToken = InstanceID.getInstance(this)
.getToken(getString(R.string.gcm_sender_id), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null) .getToken(getString(R.string.gcm_sender_id), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null)
val currentServer = getCurrentServerInteractor.get()!! val currentServer = getCurrentServerInteractor.get()
val client = factory.create(currentServer) val client = currentServer?.let { factory.create(currentServer) }
gcmToken?.let { gcmToken?.let {
localRepository.save(LocalRepository.KEY_PUSH_TOKEN, gcmToken) localRepository.save(LocalRepository.KEY_PUSH_TOKEN, gcmToken)
launch { client?.let {
try { launch {
Timber.d("Registering push token: $gcmToken for ${client.url}") try {
client.registerPushToken(gcmToken) Timber.d("Registering push token: $gcmToken for ${client.url}")
} catch (ex: RocketChatException) { client.registerPushToken(gcmToken)
Timber.e(ex) } catch (ex: RocketChatException) {
Timber.e(ex)
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment