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
b255de89
Commit
b255de89
authored
Jan 03, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement registering of generated instance id token on login and also on token rotation
parent
f1dc23f6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
133 additions
and
3 deletions
+133
-3
LoginPresenter.kt
...droid/authentication/login/presentation/LoginPresenter.kt
+16
-2
TwoFAPresenter.kt
...d/authentication/twofactor/presentation/TwoFAPresenter.kt
+15
-1
PushTokenService.kt
...rc/main/java/chat/rocket/android/push/PushTokenService.kt
+51
-0
PushComponent.kt
...rc/main/java/chat/rocket/android/push/di/PushComponent.kt
+12
-0
PushModule.kt
app/src/main/java/chat/rocket/android/push/di/PushModule.kt
+39
-0
No files found.
app/src/main/java/chat/rocket/android/authentication/login/presentation/LoginPresenter.kt
View file @
b255de89
...
...
@@ -3,12 +3,15 @@ package chat.rocket.android.authentication.login.presentation
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.infrastructure.SharedPreferencesRepository
import
chat.rocket.android.util.launchUI
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.RocketChatTwoFactorException
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.login
import
chat.rocket.core.internal.rest.registerPushToken
import
okhttp3.HttpUrl
import
okhttp3.OkHttpClient
import
javax.inject.Inject
...
...
@@ -35,10 +38,10 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
view
.
showLoading
()
try
{
val
token
=
client
.
login
(
username
,
password
)
registerPushToken
()
navigator
.
toChatList
()
}
catch
(
ex
:
RocketChatException
)
{
when
(
ex
)
{
when
(
ex
)
{
is
RocketChatTwoFactorException
->
navigator
.
toTwoFA
(
navigator
.
currentServer
!!
,
username
,
password
)
else
->
...
...
@@ -53,4 +56,15 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
fun
signup
()
{
navigator
.
toSignUp
(
navigator
.
currentServer
!!
)
}
private
suspend
fun
registerPushToken
()
{
// TODO: put it on constructor
val
localRepository
:
LocalRepository
=
SharedPreferencesRepository
(
navigator
.
activity
)
localRepository
.
get
(
LocalRepository
.
KEY_PUSH_TOKEN
)
?.
let
{
client
.
registerPushToken
(
it
)
}
// TODO: Schedule push token registering when it comes up null
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/twofactor/presentation/TwoFAPresenter.kt
View file @
b255de89
...
...
@@ -3,11 +3,14 @@ package chat.rocket.android.authentication.twofactor.presentation
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.infrastructure.SharedPreferencesRepository
import
chat.rocket.android.util.launchUI
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.login
import
chat.rocket.core.internal.rest.registerPushToken
import
okhttp3.HttpUrl
import
okhttp3.OkHttpClient
import
javax.inject.Inject
...
...
@@ -34,7 +37,7 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
view
.
showLoading
()
try
{
val
token
=
client
.
login
(
username
,
password
,
pin
)
registerPushToken
()
navigator
.
toChatList
()
}
catch
(
ex
:
RocketChatException
)
{
view
.
onLoginError
(
ex
.
message
)
...
...
@@ -47,4 +50,15 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
fun
signup
()
{
navigator
.
toSignUp
(
navigator
.
currentServer
!!
)
}
private
suspend
fun
registerPushToken
()
{
// TODO: put it on constructor
val
localRepository
:
LocalRepository
=
SharedPreferencesRepository
(
navigator
.
activity
)
localRepository
.
get
(
LocalRepository
.
KEY_PUSH_TOKEN
)
?.
let
{
client
.
registerPushToken
(
it
)
}
// TODO: Schedule push token registering when it comes up null
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/push/PushTokenService.kt
0 → 100644
View file @
b255de89
package
chat.rocket.android.push
import
chat.rocket.android.R
import
chat.rocket.android.dagger.module.AppModule
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.push.di.DaggerPushComponent
import
chat.rocket.android.push.di.PushModule
import
chat.rocket.common.RocketChatException
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.registerPushToken
import
com.google.android.gms.gcm.GoogleCloudMessaging
import
com.google.android.gms.iid.InstanceID
import
com.google.firebase.iid.FirebaseInstanceIdService
import
kotlinx.coroutines.experimental.launch
import
timber.log.Timber
import
javax.inject.Inject
class
PushTokenService
:
FirebaseInstanceIdService
()
{
@Inject
lateinit
var
client
:
RocketChatClient
@Inject
lateinit
var
localRepository
:
LocalRepository
override
fun
onCreate
()
{
super
.
onCreate
()
DaggerPushComponent
.
builder
()
.
appModule
(
AppModule
())
.
pushModule
(
PushModule
(
this
))
.
build
()
.
inject
(
this
)
}
override
fun
onTokenRefresh
()
{
val
gcmToken
=
InstanceID
.
getInstance
(
this
)
.
getToken
(
getString
(
R
.
string
.
gcm_defaultSenderId
,
GoogleCloudMessaging
.
INSTANCE_ID_SCOPE
),
null
)
gcmToken
?.
let
{
localRepository
.
save
(
LocalRepository
.
KEY_PUSH_TOKEN
,
gcmToken
)
launch
{
try
{
client
.
registerPushToken
(
gcmToken
)
}
catch
(
ex
:
RocketChatException
)
{
Timber
.
e
(
ex
)
}
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/push/di/PushComponent.kt
0 → 100644
View file @
b255de89
package
chat.rocket.android.push.di
import
chat.rocket.android.dagger.module.AppModule
import
chat.rocket.android.push.PushTokenService
import
dagger.Component
import
javax.inject.Singleton
@Singleton
@Component
(
modules
=
arrayOf
(
AppModule
::
class
,
PushModule
::
class
))
interface
PushComponent
{
fun
inject
(
service
:
PushTokenService
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/push/di/PushModule.kt
0 → 100644
View file @
b255de89
package
chat.rocket.android.push.di
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.infrastructure.SharedPreferencesRepository
import
chat.rocket.android.push.PushTokenService
import
chat.rocket.common.util.PlatformLogger
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.TokenRepository
import
dagger.Module
import
dagger.Provides
import
okhttp3.HttpUrl
import
okhttp3.OkHttpClient
import
javax.inject.Singleton
@Module
@Singleton
class
PushModule
(
val
context
:
PushTokenService
)
{
@Provides
fun
provideAuthTokenRepository
():
TokenRepository
=
AuthTokenRepository
()
@Provides
fun
provideLocalRepository
():
LocalRepository
=
SharedPreferencesRepository
(
context
)
// @Provides
// fun provideCurrentServer() = "https://open.rocket.chat"
@Provides
fun
provideRocketChatClient
(
okHttpClient
:
OkHttpClient
,
repository
:
TokenRepository
,
logger
:
PlatformLogger
):
RocketChatClient
{
return
RocketChatClient
.
create
{
httpClient
=
okHttpClient
restUrl
=
HttpUrl
.
parse
(
"https://unstable.rocket.chat"
)
!!
websocketUrl
=
"https://unstable.rocket.chat"
tokenRepository
=
repository
platformLogger
=
logger
}
}
}
\ 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