Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save push notified messages to the database without entering the app #4463

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package com.nextcloud.talk.chat.data
import android.os.Bundle
import com.nextcloud.talk.chat.data.io.LifecycleAwareManager
import com.nextcloud.talk.chat.data.model.ChatMessage
import com.nextcloud.talk.data.database.model.ChatMessageEntity
import com.nextcloud.talk.models.domain.ConversationModel
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -65,6 +66,11 @@ interface ChatMessageRepository : LifecycleAwareManager {
*/
suspend fun getMessage(messageId: Long, bundle: Bundle): Flow<ChatMessage>

/**
* TODO
*/
suspend fun updateDBAfterPushNotification(message: ChatMessageEntity)

/**
* Destroys unused resources.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ class OfflineFirstChatRepository @Inject constructor(
.map(ChatMessageEntity::asModel)
}

override suspend fun updateDBAfterPushNotification(message: ChatMessageEntity) {
// TODO Figure this out
}

@Suppress("UNCHECKED_CAST", "MagicNumber")
private fun getMessagesFromServer(bundle: Bundle): Pair<Int, List<ChatMessageJson>>? {
val fieldMap = bundle.getSerializable(BundleKeys.KEY_FIELD_MAP) as HashMap<String, Int>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ abstract class TalkDatabase : RoomDatabase() {
return Room
.databaseBuilder(context.applicationContext, TalkDatabase::class.java, dbName)
// comment out openHelperFactory to view the database entries in Android Studio for debugging
.openHelperFactory(factory)
// .openHelperFactory(factory)
.addMigrations(
Migrations.MIGRATION_6_8,
Migrations.MIGRATION_7_8,
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager
import com.nextcloud.talk.callnotification.CallNotificationActivity
import com.nextcloud.talk.chat.data.ChatMessageRepository
import com.nextcloud.talk.chat.data.network.ChatNetworkDataSource
import com.nextcloud.talk.conversationlist.data.network.OfflineFirstConversationsRepository
import com.nextcloud.talk.models.SignatureVerification
import com.nextcloud.talk.models.domain.ConversationModel
import com.nextcloud.talk.models.json.chat.ChatUtils.Companion.getParsedMessage
Expand Down Expand Up @@ -96,6 +98,9 @@ import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.JavaNetCookieJar
import okhttp3.OkHttpClient
import retrofit2.Retrofit
Expand Down Expand Up @@ -131,6 +136,12 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
@Inject
lateinit var userManager: UserManager

@Inject
lateinit var chatMessageRepository: ChatMessageRepository

@Inject
lateinit var conversationsRepository: OfflineFirstConversationsRepository

@JvmField
@Inject
var okHttpClient: OkHttpClient? = null
Expand Down Expand Up @@ -203,6 +214,16 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
} else {
showNotification(mainActivityIntent, null)
}

loadMessageToDB()
}

private fun loadMessageToDB() {
val token = pushMessage.id

CoroutineScope(Dispatchers.Default).launch {
// TODO
}
}

private fun handleRemoteTalkSharePushMessage() {
Expand Down
Loading