1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-3637 Chats | Enhancement | Open chat by push notification (#2425)

This commit is contained in:
Evgenii Kozlov 2025-05-21 16:39:08 +02:00 committed by GitHub
parent 89c9ef6ad9
commit 6ff5b57790
Signed by: github
GPG key ID: B5690EEEBB952194
4 changed files with 96 additions and 10 deletions

View file

@ -12,6 +12,7 @@ import com.anytypeio.anytype.core_models.NotificationPayload
import com.anytypeio.anytype.core_models.NotificationStatus
import com.anytypeio.anytype.core_models.Wallpaper
import com.anytypeio.anytype.core_models.exceptions.NeedToUpdateApplicationException
import com.anytypeio.anytype.core_models.multiplayer.SpaceType
import com.anytypeio.anytype.core_utils.ext.cancel
import com.anytypeio.anytype.domain.account.AwaitAccountStartManager
import com.anytypeio.anytype.domain.account.InterceptAccountStatus
@ -451,6 +452,31 @@ class MainViewModel(
}
}
fun onOpenChatTriggeredByPush(chatId: String, spaceId: String) {
viewModelScope.launch {
if (spaceManager.get() != spaceId) {
spaceManager.set(spaceId)
.onSuccess {
commands.emit(
Command.LaunchChat(
space = spaceId,
chat = chatId
)
)
}.onFailure {
Timber.e(it, "Error while switching space when launching chat from push notification")
}
} else {
commands.emit(
Command.LaunchChat(
space = spaceId,
chat = chatId
)
)
}
}
}
sealed class Command {
data class ShowDeletedAccountScreen(val deadline: Long) : Command()
data object LogoutDueToAccountDeletion : Command()
@ -467,6 +493,11 @@ class MainViewModel(
data object Notifications: Command()
data object RequestNotificationPermission: Command()
data class LaunchChat(
val space: Id,
val chat: Id
): Command()
data class Navigate(val destination: OpenObjectNavigation): Command()
sealed class Deeplink : Command() {
@ -480,7 +511,8 @@ class MainViewModel(
sealed class SideEffect {
data class SwitchSpace(
val home: Id,
val chat: Id?
val chat: Id? = null,
val spaceType: SpaceType? = null
): SideEffect()
}
}