Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
fe14cdb0
Commit
fe14cdb0
authored
May 22, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save tokens with different keys for each connected server
parent
5a678af5
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
24 additions
and
15 deletions
+24
-15
LoginPresenter.kt
...droid/authentication/login/presentation/LoginPresenter.kt
+1
-1
RegisterUsernamePresenter.kt
...egisterusername/presentation/RegisterUsernamePresenter.kt
+1
-1
SignupPresenter.kt
...oid/authentication/signup/presentation/SignupPresenter.kt
+1
-1
TwoFAPresenter.kt
...d/authentication/twofactor/presentation/TwoFAPresenter.kt
+1
-1
LocalRepository.kt
...ava/chat/rocket/android/infrastructure/LocalRepository.kt
+3
-1
SharedPreferencesLocalRepository.kt
...ndroid/infrastructure/SharedPreferencesLocalRepository.kt
+9
-1
MainPresenter.kt
...va/chat/rocket/android/main/presentation/MainPresenter.kt
+5
-6
FirebaseTokenService.kt
...ain/java/chat/rocket/android/push/FirebaseTokenService.kt
+3
-3
No files found.
app/src/main/java/chat/rocket/android/authentication/login/presentation/LoginPresenter.kt
View file @
fe14cdb0
...
...
@@ -382,7 +382,7 @@ class LoginPresenter @Inject constructor(
}
private
suspend
fun
registerPushToken
()
{
localRepository
.
get
(
LocalRepository
.
KEY_PUSH_TOKEN
)
?.
let
{
localRepository
.
get
PushToken
(
currentServer
)
?.
let
{
client
.
registerPushToken
(
it
,
getAccountsInteractor
.
get
(),
factory
)
}
// TODO: When the push token is null, at some point we should receive it with
...
...
app/src/main/java/chat/rocket/android/authentication/registerusername/presentation/RegisterUsernamePresenter.kt
View file @
fe14cdb0
...
...
@@ -65,7 +65,7 @@ class RegisterUsernamePresenter @Inject constructor(
}
private
suspend
fun
registerPushToken
()
{
localRepository
.
get
(
LocalRepository
.
KEY_PUSH_TOKEN
)
?.
let
{
localRepository
.
get
PushToken
(
currentServer
)
?.
let
{
client
.
registerPushToken
(
it
,
getAccountsInteractor
.
get
(),
factory
)
}
// TODO: When the push token is null, at some point we should receive it with
...
...
app/src/main/java/chat/rocket/android/authentication/signup/presentation/SignupPresenter.kt
View file @
fe14cdb0
...
...
@@ -95,7 +95,7 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
}
private
suspend
fun
registerPushToken
()
{
localRepository
.
get
(
LocalRepository
.
KEY_PUSH_TOKEN
)
?.
let
{
localRepository
.
get
PushToken
(
currentServer
)
?.
let
{
client
.
registerPushToken
(
it
,
getAccountsInteractor
.
get
(),
factory
)
}
// TODO: When the push token is null, at some point we should receive it with
...
...
app/src/main/java/chat/rocket/android/authentication/twofactor/presentation/TwoFAPresenter.kt
View file @
fe14cdb0
...
...
@@ -79,7 +79,7 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
fun
signup
()
=
navigator
.
toSignUp
()
private
suspend
fun
registerPushToken
()
{
localRepository
.
get
(
LocalRepository
.
KEY_PUSH_TOKEN
)
?.
let
{
localRepository
.
get
PushToken
(
currentServer
)
?.
let
{
client
.
registerPushToken
(
it
,
getAccountsInteractor
.
get
(),
factory
)
}
// TODO: When the push token is null, at some point we should receive it with
...
...
app/src/main/java/chat/rocket/android/infrastructure/LocalRepository.kt
View file @
fe14cdb0
...
...
@@ -18,9 +18,11 @@ interface LocalRepository {
fun
clearAllFromServer
(
server
:
String
)
fun
getCurrentUser
(
url
:
String
):
User
?
fun
saveCurrentUser
(
url
:
String
,
user
:
User
)
fun
savePushToken
(
url
:
String
,
token
:
String
)
fun
getPushToken
(
url
:
String
):
String
?
companion
object
{
const
val
KEY_PUSH_TOKEN
=
"KEY_PUSH_TOKEN
"
const
val
PUSH_TOKEN_KEY
=
"push_token_
"
const
val
MIGRATION_FINISHED_KEY
=
"MIGRATION_FINISHED_KEY"
const
val
TOKEN_KEY
=
"token_"
const
val
SETTINGS_KEY
=
"settings_"
...
...
app/src/main/java/chat/rocket/android/infrastructure/SharedPreferencesLocalRepository.kt
View file @
fe14cdb0
...
...
@@ -2,6 +2,7 @@ package chat.rocket.android.infrastructure
import
android.content.SharedPreferences
import
androidx.core.content.edit
import
chat.rocket.android.infrastructure.LocalRepository.Companion.PUSH_TOKEN_KEY
import
chat.rocket.common.model.User
import
com.squareup.moshi.Moshi
...
...
@@ -44,8 +45,15 @@ class SharedPreferencesLocalRepository(
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
)
{
clear
(
LocalRepository
.
KEY_PUSH_TOKEN
)
clear
(
LocalRepository
.
PUSH_TOKEN_KEY
)
//TODO: keep this for now to clear up for some version rolls.
clear
(
LocalRepository
.
PUSH_TOKEN_KEY
+
server
)
clear
(
LocalRepository
.
TOKEN_KEY
+
server
)
clear
(
LocalRepository
.
SETTINGS_KEY
+
server
)
clear
(
LocalRepository
.
CURRENT_USERNAME_KEY
)
...
...
app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt
View file @
fe14cdb0
...
...
@@ -152,7 +152,7 @@ class MainPresenter @Inject constructor(
suspend
fun
refreshToken
(
token
:
String
?)
{
token
?.
let
{
localRepository
.
save
(
LocalRepository
.
KEY_PUSH_TOKEN
,
token
)
localRepository
.
save
PushToken
(
currentServer
,
it
)
client
.
registerPushToken
(
token
,
getAccountsInteractor
.
get
(),
factory
)
}
}
...
...
@@ -172,16 +172,15 @@ class MainPresenter @Inject constructor(
}
private
suspend
fun
clearTokens
()
{
serverInteractor
.
clear
()
val
pushToken
=
localRepository
.
get
(
LocalRepository
.
KEY_PUSH_TOKEN
)
if
(
pushToken
!=
null
)
{
localRepository
.
get
(
LocalRepository
.
PUSH_TOKEN_KEY
+
currentServer
)
?.
let
{
try
{
retryIO
(
"unregisterPushToken"
)
{
client
.
unregisterPushToken
(
pushToken
)
}
view
.
invalidateToken
(
pushToken
)
retryIO
(
"unregisterPushToken"
)
{
client
.
unregisterPushToken
(
it
)
}
view
.
invalidateToken
(
it
)
}
catch
(
ex
:
Exception
)
{
Timber
.
d
(
ex
,
"Error unregistering push token"
)
}
}
serverInteractor
.
clear
()
localRepository
.
clearAllFromServer
(
currentServer
)
}
...
...
app/src/main/java/chat/rocket/android/push/FirebaseTokenService.kt
View file @
fe14cdb0
...
...
@@ -39,8 +39,8 @@ class FirebaseTokenService : FirebaseInstanceIdService() {
val
currentServer
=
getCurrentServerInteractor
.
get
()
val
client
=
currentServer
?.
let
{
factory
.
create
(
currentServer
)
}
gcmToken
?.
let
{
localRepository
.
save
(
LocalRepository
.
KEY_PUSH_TOKEN
,
gcmToken
)
if
(
gcmToken
!=
null
&&
currentServer
!=
null
)
{
localRepository
.
save
PushToken
(
currentServer
,
gcmToken
)
client
?.
let
{
launch
{
try
{
...
...
@@ -53,7 +53,7 @@ class FirebaseTokenService : FirebaseInstanceIdService() {
}
}
}
catch
(
ex
:
Exception
)
{
Timber
.
d
(
ex
,
"Error refreshing Firebase TOKEN"
)
Timber
.
e
(
ex
,
"Error refreshing Firebase TOKEN"
)
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment