mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3637 Chats | Fix | Opening chats from push notifications - fixes (#2435)
This commit is contained in:
parent
5e94be2acc
commit
8c4b4b992b
4 changed files with 87 additions and 22 deletions
|
@ -11,6 +11,7 @@ import androidx.core.app.NotificationCompat
|
|||
import com.anytypeio.anytype.R
|
||||
import com.anytypeio.anytype.app.AndroidApplication
|
||||
import com.anytypeio.anytype.core_models.DecryptedPushContent
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Relations
|
||||
import com.anytypeio.anytype.core_ui.views.Relations1
|
||||
import com.anytypeio.anytype.domain.device.DeviceTokenStoringService
|
||||
|
@ -80,12 +81,18 @@ class AnytypePushService : FirebaseMessagingService() {
|
|||
private fun handleDecryptedContent(content: DecryptedPushContent) {
|
||||
Timber.d("Decrypted content: $content")
|
||||
when (content.type) {
|
||||
1 -> handleNewMessage(content.newMessage)
|
||||
1 -> handleNewMessage(
|
||||
message = content.newMessage,
|
||||
space = content.spaceId
|
||||
)
|
||||
else -> Timber.w("Unknown message type: ${content.type}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleNewMessage(message: DecryptedPushContent.Message) {
|
||||
private fun handleNewMessage(
|
||||
message: DecryptedPushContent.Message,
|
||||
space: Id
|
||||
) {
|
||||
Timber.d("New message received: $message")
|
||||
|
||||
// Create an intent to open the app when notification is tapped
|
||||
|
@ -93,7 +100,7 @@ class AnytypePushService : FirebaseMessagingService() {
|
|||
action = ACTION_OPEN_CHAT
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
putExtra(Relations.CHAT_ID, message.chatId)
|
||||
putExtra(Relations.SPACE_ID, message.spaceName)
|
||||
putExtra(Relations.SPACE_ID, space)
|
||||
}
|
||||
|
||||
val pendingIntent = PendingIntent.getActivity(
|
||||
|
|
|
@ -13,12 +13,14 @@ import androidx.navigation.fragment.findNavController
|
|||
import com.anytypeio.anytype.BuildConfig
|
||||
import com.anytypeio.anytype.R
|
||||
import com.anytypeio.anytype.app.DefaultAppActionManager.Companion.ACTION_CREATE_NEW_TYPE_KEY
|
||||
import com.anytypeio.anytype.core_models.Relations
|
||||
import com.anytypeio.anytype.core_utils.ext.gone
|
||||
import com.anytypeio.anytype.core_utils.ext.orNull
|
||||
import com.anytypeio.anytype.core_utils.ext.toast
|
||||
import com.anytypeio.anytype.core_utils.ext.visible
|
||||
import com.anytypeio.anytype.core_utils.ui.BaseFragment
|
||||
import com.anytypeio.anytype.databinding.FragmentSplashBinding
|
||||
import com.anytypeio.anytype.device.AnytypePushService
|
||||
import com.anytypeio.anytype.di.common.componentManager
|
||||
import com.anytypeio.anytype.other.DefaultDeepLinkResolver
|
||||
import com.anytypeio.anytype.presentation.confgs.ChatConfig
|
||||
|
@ -200,6 +202,27 @@ class SplashFragment : BaseFragment<FragmentSplashBinding>(R.layout.fragment_spl
|
|||
Timber.e(it, "Error while navigating to object from splash")
|
||||
}
|
||||
}
|
||||
is SplashViewModel.Command.NavigateToChat -> {
|
||||
runCatching {
|
||||
findNavController().navigate(R.id.actionOpenVaultFromSplash)
|
||||
findNavController().navigate(
|
||||
R.id.actionOpenSpaceFromVault,
|
||||
args = HomeScreenFragment.args(
|
||||
space = command.space,
|
||||
deeplink = null
|
||||
)
|
||||
)
|
||||
findNavController().navigate(
|
||||
R.id.chatScreen,
|
||||
args = ChatFragment.args(
|
||||
space = command.space,
|
||||
ctx = command.chat
|
||||
)
|
||||
)
|
||||
}.onFailure {
|
||||
Timber.e(it, "Error while navigating to chat from push")
|
||||
}
|
||||
}
|
||||
is SplashViewModel.Command.NavigateToObjectType -> {
|
||||
runCatching {
|
||||
findNavController().navigate(R.id.actionOpenVaultFromSplash)
|
||||
|
@ -324,32 +347,48 @@ class SplashFragment : BaseFragment<FragmentSplashBinding>(R.layout.fragment_spl
|
|||
}
|
||||
is SplashViewModel.Command.CheckAppStartIntent -> {
|
||||
val intent = activity?.intent
|
||||
if (intent != null && (intent.action == Intent.ACTION_VIEW || intent.action == Intent.ACTION_SEND)) {
|
||||
val data = intent.dataString.orNull() ?: intent.extras?.getString(Intent.EXTRA_TEXT)
|
||||
if (data != null && DefaultDeepLinkResolver.isDeepLink(data)) {
|
||||
// Clearing intent to only handle it once:
|
||||
with(intent) {
|
||||
setAction(null)
|
||||
setData(null)
|
||||
putExtras(Bundle())
|
||||
}
|
||||
vm.onDeepLinkLaunch(data)
|
||||
} else {
|
||||
val bundle = intent.extras
|
||||
if (bundle != null) {
|
||||
val type = bundle.getString(ACTION_CREATE_NEW_TYPE_KEY)
|
||||
if (type != null) {
|
||||
vm.onIntentCreateNewObject(type = type)
|
||||
Timber.d("Checking app start intent: $intent, action: ${intent?.action}")
|
||||
when {
|
||||
intent != null && (intent.action == Intent.ACTION_VIEW || intent.action == Intent.ACTION_SEND) -> {
|
||||
val data =
|
||||
intent.dataString.orNull() ?: intent.extras?.getString(Intent.EXTRA_TEXT)
|
||||
if (data != null && DefaultDeepLinkResolver.isDeepLink(data)) {
|
||||
// Clearing intent to only handle it once:
|
||||
with(intent) {
|
||||
setAction(null)
|
||||
setData(null)
|
||||
putExtras(Bundle())
|
||||
}
|
||||
vm.onDeepLinkLaunch(data)
|
||||
} else {
|
||||
val bundle = intent.extras
|
||||
if (bundle != null) {
|
||||
val type = bundle.getString(ACTION_CREATE_NEW_TYPE_KEY)
|
||||
if (type != null) {
|
||||
vm.onIntentCreateNewObject(type = type)
|
||||
} else {
|
||||
vm.onIntentActionNotFound()
|
||||
}
|
||||
} else {
|
||||
vm.onIntentActionNotFound()
|
||||
}
|
||||
}
|
||||
}
|
||||
intent?.action == AnytypePushService.ACTION_OPEN_CHAT -> {
|
||||
val chatId = intent.getStringExtra(Relations.CHAT_ID)
|
||||
val spaceId = intent.getStringExtra(Relations.SPACE_ID)
|
||||
if (!chatId.isNullOrEmpty() && !spaceId.isNullOrEmpty()) {
|
||||
vm.onIntentTriggeredByChatPush(
|
||||
space = spaceId,
|
||||
chat = chatId
|
||||
)
|
||||
} else {
|
||||
vm.onIntentActionNotFound()
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
vm.onIntentActionNotFound()
|
||||
else -> {
|
||||
vm.onIntentActionNotFound()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -453,6 +453,7 @@ class MainViewModel(
|
|||
}
|
||||
|
||||
fun onOpenChatTriggeredByPush(chatId: String, spaceId: String) {
|
||||
Timber.d("onOpenChatTriggeredByPush: $chatId, $spaceId")
|
||||
viewModelScope.launch {
|
||||
if (spaceManager.get() != spaceId) {
|
||||
spaceManager.set(spaceId)
|
||||
|
|
|
@ -278,6 +278,23 @@ class SplashViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
fun onIntentTriggeredByChatPush(space: Id, chat: Id) {
|
||||
viewModelScope.launch {
|
||||
spaceManager.set(space = space)
|
||||
.onSuccess {
|
||||
commands.emit(
|
||||
Command.NavigateToChat(
|
||||
space = space,
|
||||
chat = chat
|
||||
)
|
||||
)
|
||||
}
|
||||
.onFailure {
|
||||
Timber.e(it, "Error while setting space due to chat intent")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onIntentActionNotFound() {
|
||||
proceedWithNavigation()
|
||||
}
|
||||
|
@ -463,6 +480,7 @@ class SplashViewModel(
|
|||
data object NavigateToAuthStart : Command()
|
||||
data object CheckAppStartIntent : Command()
|
||||
data class NavigateToObject(val id: Id, val space: Id, val chat: Id?) : Command()
|
||||
data class NavigateToChat(val space: Id, val chat: Id) : Command()
|
||||
data class NavigateToObjectSet(val id: Id, val space: Id, val chat: Id?) : Command()
|
||||
data class NavigateToDateObject(val id: Id, val space: Id, val chat: Id?) : Command()
|
||||
data class NavigateToObjectType(val id: Id, val space: Id, val chat: Id?) : Command()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue