Unverified Commit 2a645d78 authored by Leonardo Aramaki's avatar Leonardo Aramaki Committed by GitHub

Merge pull request #1313 from RocketChat/revert-1300-fix/push-better-multiserver-support

Revert "[FIX] Better multi-server support for push notifications"
parents e4d1724a abe613c1
...@@ -382,7 +382,7 @@ class LoginPresenter @Inject constructor( ...@@ -382,7 +382,7 @@ class LoginPresenter @Inject constructor(
} }
private suspend fun registerPushToken() { private suspend fun registerPushToken() {
localRepository.getPushToken(currentServer)?.let { localRepository.get(LocalRepository.KEY_PUSH_TOKEN)?.let {
client.registerPushToken(it, getAccountsInteractor.get(), factory) client.registerPushToken(it, getAccountsInteractor.get(), factory)
} }
// TODO: When the push token is null, at some point we should receive it with // TODO: When the push token is null, at some point we should receive it with
......
...@@ -65,7 +65,7 @@ class RegisterUsernamePresenter @Inject constructor( ...@@ -65,7 +65,7 @@ class RegisterUsernamePresenter @Inject constructor(
} }
private suspend fun registerPushToken() { private suspend fun registerPushToken() {
localRepository.getPushToken(currentServer)?.let { localRepository.get(LocalRepository.KEY_PUSH_TOKEN)?.let {
client.registerPushToken(it, getAccountsInteractor.get(), factory) client.registerPushToken(it, getAccountsInteractor.get(), factory)
} }
// TODO: When the push token is null, at some point we should receive it with // TODO: When the push token is null, at some point we should receive it with
......
...@@ -95,7 +95,7 @@ class SignupPresenter @Inject constructor(private val view: SignupView, ...@@ -95,7 +95,7 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
} }
private suspend fun registerPushToken() { private suspend fun registerPushToken() {
localRepository.getPushToken(currentServer)?.let { localRepository.get(LocalRepository.KEY_PUSH_TOKEN)?.let {
client.registerPushToken(it, getAccountsInteractor.get(), factory) client.registerPushToken(it, getAccountsInteractor.get(), factory)
} }
// TODO: When the push token is null, at some point we should receive it with // TODO: When the push token is null, at some point we should receive it with
......
...@@ -79,7 +79,7 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView, ...@@ -79,7 +79,7 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
fun signup() = navigator.toSignUp() fun signup() = navigator.toSignUp()
private suspend fun registerPushToken() { private suspend fun registerPushToken() {
localRepository.getPushToken(currentServer)?.let { localRepository.get(LocalRepository.KEY_PUSH_TOKEN)?.let {
client.registerPushToken(it, getAccountsInteractor.get(), factory) client.registerPushToken(it, getAccountsInteractor.get(), factory)
} }
// TODO: When the push token is null, at some point we should receive it with // TODO: When the push token is null, at some point we should receive it with
......
...@@ -18,11 +18,9 @@ interface LocalRepository { ...@@ -18,11 +18,9 @@ interface LocalRepository {
fun clearAllFromServer(server: String) fun clearAllFromServer(server: String)
fun getCurrentUser(url: String): User? fun getCurrentUser(url: String): User?
fun saveCurrentUser(url: String, user: User) fun saveCurrentUser(url: String, user: User)
fun savePushToken(url: String, token: String)
fun getPushToken(url: String): String?
companion object { companion object {
const val PUSH_TOKEN_KEY = "push_token_" const val KEY_PUSH_TOKEN = "KEY_PUSH_TOKEN"
const val MIGRATION_FINISHED_KEY = "MIGRATION_FINISHED_KEY" const val MIGRATION_FINISHED_KEY = "MIGRATION_FINISHED_KEY"
const val TOKEN_KEY = "token_" const val TOKEN_KEY = "token_"
const val SETTINGS_KEY = "settings_" const val SETTINGS_KEY = "settings_"
......
...@@ -2,7 +2,6 @@ package chat.rocket.android.infrastructure ...@@ -2,7 +2,6 @@ package chat.rocket.android.infrastructure
import android.content.SharedPreferences import android.content.SharedPreferences
import androidx.core.content.edit import androidx.core.content.edit
import chat.rocket.android.infrastructure.LocalRepository.Companion.PUSH_TOKEN_KEY
import chat.rocket.common.model.User import chat.rocket.common.model.User
import com.squareup.moshi.Moshi import com.squareup.moshi.Moshi
...@@ -45,15 +44,8 @@ class SharedPreferencesLocalRepository( ...@@ -45,15 +44,8 @@ class SharedPreferencesLocalRepository(
override fun clear(key: String) = preferences.edit { remove(key) } override fun clear(key: String) = preferences.edit { remove(key) }
override fun savePushToken(url: String, token: String) {
save(PUSH_TOKEN_KEY + url, token)
}
override fun getPushToken(url: String): String? = preferences.getString(PUSH_TOKEN_KEY + url, null)
override fun clearAllFromServer(server: String) { override fun clearAllFromServer(server: String) {
clear(LocalRepository.PUSH_TOKEN_KEY) //TODO: keep this for now to clear up for some version rolls. clear(LocalRepository.KEY_PUSH_TOKEN)
clear(LocalRepository.PUSH_TOKEN_KEY + server)
clear(LocalRepository.TOKEN_KEY + server) clear(LocalRepository.TOKEN_KEY + server)
clear(LocalRepository.SETTINGS_KEY + server) clear(LocalRepository.SETTINGS_KEY + server)
clear(LocalRepository.CURRENT_USERNAME_KEY) clear(LocalRepository.CURRENT_USERNAME_KEY)
......
...@@ -152,7 +152,7 @@ class MainPresenter @Inject constructor( ...@@ -152,7 +152,7 @@ class MainPresenter @Inject constructor(
suspend fun refreshToken(token: String?) { suspend fun refreshToken(token: String?) {
token?.let { token?.let {
localRepository.savePushToken(currentServer, it) localRepository.save(LocalRepository.KEY_PUSH_TOKEN, token)
client.registerPushToken(token, getAccountsInteractor.get(), factory) client.registerPushToken(token, getAccountsInteractor.get(), factory)
} }
} }
...@@ -172,15 +172,16 @@ class MainPresenter @Inject constructor( ...@@ -172,15 +172,16 @@ class MainPresenter @Inject constructor(
} }
private suspend fun clearTokens() { private suspend fun clearTokens() {
localRepository.get(LocalRepository.PUSH_TOKEN_KEY + currentServer)?.let { serverInteractor.clear()
val pushToken = localRepository.get(LocalRepository.KEY_PUSH_TOKEN)
if (pushToken != null) {
try { try {
retryIO("unregisterPushToken") { client.unregisterPushToken(it) } retryIO("unregisterPushToken") { client.unregisterPushToken(pushToken) }
view.invalidateToken(it) view.invalidateToken(pushToken)
} catch (ex: Exception) { } catch (ex: Exception) {
Timber.d(ex, "Error unregistering push token") Timber.d(ex, "Error unregistering push token")
} }
} }
serverInteractor.clear()
localRepository.clearAllFromServer(currentServer) localRepository.clearAllFromServer(currentServer)
} }
......
...@@ -39,8 +39,8 @@ class FirebaseTokenService : FirebaseInstanceIdService() { ...@@ -39,8 +39,8 @@ class FirebaseTokenService : FirebaseInstanceIdService() {
val currentServer = getCurrentServerInteractor.get() val currentServer = getCurrentServerInteractor.get()
val client = currentServer?.let { factory.create(currentServer) } val client = currentServer?.let { factory.create(currentServer) }
if (gcmToken != null && currentServer != null) { gcmToken?.let {
localRepository.savePushToken(currentServer, gcmToken) localRepository.save(LocalRepository.KEY_PUSH_TOKEN, gcmToken)
client?.let { client?.let {
launch { launch {
try { try {
...@@ -53,7 +53,7 @@ class FirebaseTokenService : FirebaseInstanceIdService() { ...@@ -53,7 +53,7 @@ class FirebaseTokenService : FirebaseInstanceIdService() {
} }
} }
} catch (ex: Exception) { } catch (ex: Exception) {
Timber.e(ex, "Error refreshing Firebase TOKEN") Timber.d(ex, "Error refreshing Firebase TOKEN")
} }
} }
} }
\ No newline at end of file
...@@ -250,14 +250,11 @@ class PushManager @Inject constructor( ...@@ -250,14 +250,11 @@ class PushManager @Inject constructor(
.setContentIntent(contentIntent) .setContentIntent(contentIntent)
.setMessageNotification() .setMessageNotification()
if (host.isEmpty()) {
builder.setContentIntent(deleteIntent)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channelId: String val channelId: String
val channelName: String val channelName: String
if (host.isEmpty()) { if (host.isEmpty()) {
builder.setContentIntent(deleteIntent)
channelName = "Test Notification" channelName = "Test Notification"
channelId = "test-channel" channelId = "test-channel"
} else { } else {
......
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