Commit d73d5e29 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Implement notifications support

parent 76425b8d
......@@ -6,7 +6,9 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<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" />
......@@ -39,31 +41,33 @@
<activity
android:name=".app.ChatRoomActivity"
android:theme="@style/AppTheme">
</activity>
android:theme="@style/AppTheme"></activity>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="chat.rocket.android" />
</intent-filter>
</receiver>
<!--<service-->
<!--android:name=".push.TokenRotationService"-->
<!--android:exported="false">-->
<!--<intent-filter>-->
<!--<action android:name="com.google.android.gms.iid.InstanceID" />-->
<!--</intent-filter>-->
<!--</service>-->
<service
android:name=".push.FirebaseTokenService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".push.PushTokenService" android:exported="true">
<service
android:name=".push.GcmListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
......
......@@ -15,7 +15,7 @@ import kotlinx.coroutines.experimental.launch
import timber.log.Timber
import javax.inject.Inject
class PushTokenService : FirebaseInstanceIdService() {
class FirebaseTokenService : FirebaseInstanceIdService() {
@Inject
lateinit var client: RocketChatClient
......@@ -34,8 +34,10 @@ class PushTokenService : FirebaseInstanceIdService() {
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)
.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 {
localRepository.save(LocalRepository.KEY_PUSH_TOKEN, gcmToken)
......
......@@ -6,6 +6,8 @@ import com.google.android.gms.gcm.GcmListenerService
class GcmListenerService : GcmListenerService() {
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
import chat.rocket.android.dagger.module.AppModule
import chat.rocket.android.push.PushTokenService
import chat.rocket.android.push.FirebaseTokenService
import dagger.Component
import javax.inject.Singleton
@Singleton
@Component(modules = arrayOf(AppModule::class, PushModule::class))
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
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.android.push.FirebaseTokenService
import chat.rocket.common.util.PlatformLogger
import chat.rocket.core.RocketChatClient
import chat.rocket.core.TokenRepository
......@@ -15,7 +15,7 @@ import javax.inject.Singleton
@Module
@Singleton
class PushModule(val context: PushTokenService) {
class PushModule(val context: FirebaseTokenService) {
@Provides
fun provideAuthTokenRepository(): TokenRepository = AuthTokenRepository()
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- This is the Cordova GCM sender id-->
<string name="gcm_sender_id">673693445664</string>
</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