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

DROID-2284 Sharing extension | Fix | Show error when failed to upload file and do not create wrapper object for failed uploads (#966)

This commit is contained in:
Evgenii Kozlov 2024-03-04 12:27:09 +01:00 committed by uburoiubu
parent eef1d93142
commit b615e4b66c
No known key found for this signature in database
GPG key ID: C8FB80E0A595FBB6

View file

@ -23,7 +23,6 @@ import com.anytypeio.anytype.core_models.primitives.SpaceId
import com.anytypeio.anytype.core_utils.ext.msg
import com.anytypeio.anytype.domain.account.AwaitAccountStartManager
import com.anytypeio.anytype.domain.base.fold
import com.anytypeio.anytype.domain.base.onSuccess
import com.anytypeio.anytype.domain.device.FileSharer
import com.anytypeio.anytype.domain.media.UploadFile
import com.anytypeio.anytype.domain.misc.UrlBuilder
@ -138,53 +137,68 @@ class AddToAnytypeViewModel(
// Temporary workaround to fix issue on the MW side.
type = Block.Content.File.Type.NONE
)
).onSuccess { obj ->
files.add(obj.id)
}
}
if (files.size == 1) {
if (targetSpaceId == spaceManager.get()) {
navigation.emit(OpenObjectNavigation.OpenEditor(files.first()))
} else {
with(commands) {
emit(Command.ObjectAddToSpaceToast(targetSpaceView.obj.name))
emit(Command.Dismiss)
}
}
} else {
val startTime = System.currentTimeMillis()
createPrefilledNote.async(
CreatePrefilledNote.Params(
text = EMPTY_STRING_VALUE,
space = targetSpaceId,
details = mapOf(
Relations.ORIGIN to ObjectOrigin.SHARING_EXTENSION.code.toDouble()
),
attachments = files
)
).fold(
onSuccess = { result ->
sendAnalyticsObjectCreateEvent(
analytics = analytics,
objType = MarketplaceObjectTypeIds.NOTE,
route = EventsDictionary.Routes.sharingExtension,
startTime = startTime
)
if (targetSpaceId == spaceManager.get()) {
navigation.emit(OpenObjectNavigation.OpenEditor(result))
} else {
with(commands) {
emit(Command.ObjectAddToSpaceToast(targetSpaceView.obj.name))
emit(Command.Dismiss)
}
}
onSuccess = { obj ->
files.add(obj.id)
},
onFailure = {
Timber.d(it, "Error while creating note")
sendToast("Error while creating note: ${it.msg()}")
onFailure = { e ->
Timber.e(e, "Error while uploading file").also {
sendToast(e.msg())
}
}
)
}
when (files.size) {
0 -> {
sendToast("Could not upload files")
}
1 -> {
// No need to create a wrapper object, opening file object directly instead
if (targetSpaceId == spaceManager.get()) {
navigation.emit(OpenObjectNavigation.OpenEditor(files.first()))
} else {
with(commands) {
emit(Command.ObjectAddToSpaceToast(targetSpaceView.obj.name))
emit(Command.Dismiss)
}
}
}
else -> {
// Creating a wrapper object for file objects
val startTime = System.currentTimeMillis()
createPrefilledNote.async(
CreatePrefilledNote.Params(
text = EMPTY_STRING_VALUE,
space = targetSpaceId,
details = mapOf(
Relations.ORIGIN to ObjectOrigin.SHARING_EXTENSION.code.toDouble()
),
attachments = files
)
).fold(
onSuccess = { result ->
sendAnalyticsObjectCreateEvent(
analytics = analytics,
objType = MarketplaceObjectTypeIds.NOTE,
route = EventsDictionary.Routes.sharingExtension,
startTime = startTime
)
if (targetSpaceId == spaceManager.get()) {
navigation.emit(OpenObjectNavigation.OpenEditor(result))
} else {
with(commands) {
emit(Command.ObjectAddToSpaceToast(targetSpaceView.obj.name))
emit(Command.Dismiss)
}
}
},
onFailure = {
Timber.d(it, "Error while creating note")
sendToast("Error while creating note: ${it.msg()}")
}
)
}
}
}
}