Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: udpate image description when editing posts #643

Merged
merged 3 commits into from
Dec 15, 2024
Merged
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 @@ -8,6 +8,7 @@ import de.jensklingenberg.ktorfit.http.GET
import de.jensklingenberg.ktorfit.http.POST
import de.jensklingenberg.ktorfit.http.PUT
import de.jensklingenberg.ktorfit.http.Path
import io.ktor.client.request.forms.FormDataContent
import io.ktor.client.request.forms.MultiPartFormDataContent

interface MediaService {
Expand All @@ -24,7 +25,7 @@ interface MediaService {
@PUT("v1/media/{id}")
suspend fun update(
@Path("id") id: String,
@Body content: MultiPartFormDataContent,
@Body content: FormDataContent,
): MediaAttachment

@DELETE("v1/media/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.Placeholder
import androidx.compose.ui.text.PlaceholderVerticalAlign
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.em
import com.livefast.eattrash.raccoonforfriendica.core.appearance.theme.IconSize
import com.livefast.eattrash.raccoonforfriendica.core.commonui.components.CustomImage
import com.livefast.eattrash.raccoonforfriendica.core.utils.substituteAllOccurrences
import com.livefast.eattrash.raccoonforfriendica.core.utils.uuid.getUuid
Expand Down Expand Up @@ -100,7 +100,7 @@ fun TextWithCustomEmojis(
),
) {
CustomImage(
modifier = Modifier.size(with(LocalDensity.current) { EMOJI_SIZE.toDp() }),
modifier = Modifier.size(IconSize.m),
url = emoji.url,
contentDescription = null,
contentScale = ContentScale.FillWidth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package com.livefast.eattrash.raccoonforfriendica.domain.content.repository
import com.livefast.eattrash.raccoonforfriendica.core.api.provider.ServiceProvider
import com.livefast.eattrash.raccoonforfriendica.domain.content.data.AttachmentModel
import com.livefast.eattrash.raccoonforfriendica.domain.content.repository.utils.toModel
import io.ktor.client.request.forms.FormDataContent
import io.ktor.client.request.forms.MultiPartFormDataContent
import io.ktor.client.request.forms.formData
import io.ktor.http.Headers
import io.ktor.http.HttpHeaders
import io.ktor.http.parameters
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -73,8 +75,9 @@ internal class DefaultMediaRepository(
withContext(Dispatchers.IO) {
runCatching {
val content =
MultiPartFormDataContent(
formData {
FormDataContent(
parameters {
append("description", alt)
},
)
provider.media.update(id = id, content = content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import dev.mokkery.answering.returns
import dev.mokkery.every
import dev.mokkery.everySuspend
import dev.mokkery.matcher.any
import dev.mokkery.matcher.matching
import dev.mokkery.mock
import dev.mokkery.verifySuspend
import kotlinx.coroutines.test.runTest
Expand Down Expand Up @@ -81,7 +82,13 @@ class DefaultMediaRepositoryTest {

assertTrue(res)
verifySuspend {
mediaService.update(id = any(), content = any())
mediaService.update(
id = any(),
content =
matching {
it.formData["description"] == "fake-description"
},
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1183,18 +1183,10 @@ class ComposerViewModel(
) {
screenModelScope.launch {
val successful =
if (shouldUserPhotoRepository) {
photoRepository.update(
id = attachment.id,
album = attachment.album.orEmpty(),
alt = description,
)
} else {
mediaRepository.update(
id = attachment.id,
alt = description,
)
}
mediaRepository.update(
id = attachment.id,
alt = description,
)

if (successful) {
updateAttachmentInState(attachment.id) {
Expand Down
Loading