Commit d73d5e29 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Implement notifications support

parent 76425b8d
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="chat.rocket.android.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <permission
android:name="chat.rocket.android.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="chat.rocket.android.permission.C2D_MESSAGE" /> <uses-permission android:name="chat.rocket.android.permission.C2D_MESSAGE" />
...@@ -39,31 +41,33 @@ ...@@ -39,31 +41,33 @@
<activity <activity
android:name=".app.ChatRoomActivity" android:name=".app.ChatRoomActivity"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme"></activity>
</activity>
<receiver <receiver
android:name="com.google.android.gms.gcm.GcmReceiver" android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true" android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" > android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter> <intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="chat.rocket.android" /> <category android:name="chat.rocket.android" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<!--<service--> <service
<!--android:name=".push.TokenRotationService"--> android:name=".push.FirebaseTokenService"
<!--android:exported="false">--> android:exported="false">
<!--<intent-filter>--> <intent-filter>
<!--<action android:name="com.google.android.gms.iid.InstanceID" />--> <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
<!--</intent-filter>--> </intent-filter>
<!--</service>--> </service>
<service android:name=".push.PushTokenService" android:exported="true"> <service
android:name=".push.GcmListenerService"
android:exported="false">
<intent-filter> <intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> <action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter> </intent-filter>
</service> </service>
......
...@@ -15,7 +15,7 @@ import kotlinx.coroutines.experimental.launch ...@@ -15,7 +15,7 @@ import kotlinx.coroutines.experimental.launch
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class PushTokenService : FirebaseInstanceIdService() { class FirebaseTokenService : FirebaseInstanceIdService() {
@Inject @Inject
lateinit var client: RocketChatClient lateinit var client: RocketChatClient
...@@ -34,8 +34,10 @@ class PushTokenService : FirebaseInstanceIdService() { ...@@ -34,8 +34,10 @@ class PushTokenService : FirebaseInstanceIdService() {
override fun onTokenRefresh() { override fun onTokenRefresh() {
//TODO: We need to use the Cordova Project gcm_sender_id since it's the one configured on RC
// 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_defaultSenderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE), null) .getToken(getString(R.string.gcm_sender_id), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null)
gcmToken?.let { gcmToken?.let {
localRepository.save(LocalRepository.KEY_PUSH_TOKEN, gcmToken) localRepository.save(LocalRepository.KEY_PUSH_TOKEN, gcmToken)
......
...@@ -6,6 +6,8 @@ import com.google.android.gms.gcm.GcmListenerService ...@@ -6,6 +6,8 @@ import com.google.android.gms.gcm.GcmListenerService
class GcmListenerService : GcmListenerService() { class GcmListenerService : GcmListenerService() {
override fun onMessageReceived(from: String?, data: Bundle?) { override fun onMessageReceived(from: String?, data: Bundle?) {
println("UBA BA!") data?.let {
PushManager.handle(this, data)
}
} }
} }
\ No newline at end of file
package chat.rocket.android.push.di package chat.rocket.android.push.di
import chat.rocket.android.dagger.module.AppModule import chat.rocket.android.dagger.module.AppModule
import chat.rocket.android.push.PushTokenService import chat.rocket.android.push.FirebaseTokenService
import dagger.Component import dagger.Component
import javax.inject.Singleton import javax.inject.Singleton
@Singleton @Singleton
@Component(modules = arrayOf(AppModule::class, PushModule::class)) @Component(modules = arrayOf(AppModule::class, PushModule::class))
interface PushComponent { interface PushComponent {
fun inject(service: PushTokenService) fun inject(service: FirebaseTokenService)
} }
\ No newline at end of file
...@@ -3,7 +3,7 @@ package chat.rocket.android.push.di ...@@ -3,7 +3,7 @@ package chat.rocket.android.push.di
import chat.rocket.android.authentication.infraestructure.AuthTokenRepository import chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import chat.rocket.android.infrastructure.LocalRepository import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.infrastructure.SharedPreferencesRepository import chat.rocket.android.infrastructure.SharedPreferencesRepository
import chat.rocket.android.push.PushTokenService import chat.rocket.android.push.FirebaseTokenService
import chat.rocket.common.util.PlatformLogger import chat.rocket.common.util.PlatformLogger
import chat.rocket.core.RocketChatClient import chat.rocket.core.RocketChatClient
import chat.rocket.core.TokenRepository import chat.rocket.core.TokenRepository
...@@ -15,7 +15,7 @@ import javax.inject.Singleton ...@@ -15,7 +15,7 @@ import javax.inject.Singleton
@Module @Module
@Singleton @Singleton
class PushModule(val context: PushTokenService) { class PushModule(val context: FirebaseTokenService) {
@Provides @Provides
fun provideAuthTokenRepository(): TokenRepository = AuthTokenRepository() fun provideAuthTokenRepository(): TokenRepository = AuthTokenRepository()
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<!-- This is the Cordova GCM sender id-->
<string name="gcm_sender_id">673693445664</string> <string name="gcm_sender_id">673693445664</string>
</resources> </resources>
\ No newline at end of file
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