Add support for updating media description and focus point when editing statuses (#3215)
* Add support for updating media description and focus point when editing statuses * Don't publish description/focus point updates via the standard api when editing a published post
This commit is contained in:
parent
d34586b7c8
commit
395e21c956
5 changed files with 43 additions and 17 deletions
|
@ -335,17 +335,20 @@ class ComposeViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val updatedItem = newMediaList.find { it.localId == localId }
|
if (!editing) {
|
||||||
if (updatedItem?.id != null) {
|
// Updates to media for already-published statuses need to go through the status edit api
|
||||||
val focus = updatedItem.focus
|
val updatedItem = newMediaList.find { it.localId == localId }
|
||||||
val focusString = if (focus != null) "${focus.x},${focus.y}" else null
|
if (updatedItem?.id != null) {
|
||||||
return api.updateMedia(updatedItem.id, updatedItem.description, focusString)
|
val focus = updatedItem.focus
|
||||||
.fold({
|
val focusString = if (focus != null) "${focus.x},${focus.y}" else null
|
||||||
true
|
return api.updateMedia(updatedItem.id, updatedItem.description, focusString)
|
||||||
}, { throwable ->
|
.fold({
|
||||||
Log.w(TAG, "failed to update media", throwable)
|
true
|
||||||
false
|
}, { throwable ->
|
||||||
})
|
Log.w(TAG, "failed to update media", throwable)
|
||||||
|
false
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,11 +48,12 @@ class MediaPreviewAdapter(
|
||||||
val addFocusId = 2
|
val addFocusId = 2
|
||||||
val editImageId = 3
|
val editImageId = 3
|
||||||
val removeId = 4
|
val removeId = 4
|
||||||
if (item.state != ComposeActivity.QueuedMedia.State.PUBLISHED) {
|
|
||||||
// Already-published items can't have their metadata edited
|
popup.menu.add(0, addCaptionId, 0, R.string.action_set_caption)
|
||||||
popup.menu.add(0, addCaptionId, 0, R.string.action_set_caption)
|
if (item.type == ComposeActivity.QueuedMedia.Type.IMAGE) {
|
||||||
if (item.type == ComposeActivity.QueuedMedia.Type.IMAGE) {
|
popup.menu.add(0, addFocusId, 0, R.string.action_set_focus)
|
||||||
popup.menu.add(0, addFocusId, 0, R.string.action_set_focus)
|
if (item.state != ComposeActivity.QueuedMedia.State.PUBLISHED) {
|
||||||
|
// Already-published items can't be edited
|
||||||
popup.menu.add(0, editImageId, 0, R.string.action_edit_image)
|
popup.menu.add(0, editImageId, 0, R.string.action_edit_image)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,9 @@ data class Attachment(
|
||||||
data class Focus(
|
data class Focus(
|
||||||
val x: Float,
|
val x: Float,
|
||||||
val y: Float
|
val y: Float
|
||||||
) : Parcelable
|
) : Parcelable {
|
||||||
|
fun toMastodonApiString(): String = "$x,$y"
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The size of an image, used to specify the width/height.
|
* The size of an image, used to specify the width/height.
|
||||||
|
|
|
@ -26,6 +26,7 @@ data class NewStatus(
|
||||||
val visibility: String,
|
val visibility: String,
|
||||||
val sensitive: Boolean,
|
val sensitive: Boolean,
|
||||||
@SerializedName("media_ids") val mediaIds: List<String>?,
|
@SerializedName("media_ids") val mediaIds: List<String>?,
|
||||||
|
@SerializedName("media_attributes") val mediaAttributes: List<MediaAttribute>?,
|
||||||
@SerializedName("scheduled_at") val scheduledAt: String?,
|
@SerializedName("scheduled_at") val scheduledAt: String?,
|
||||||
val poll: NewPoll?,
|
val poll: NewPoll?,
|
||||||
val language: String?,
|
val language: String?,
|
||||||
|
@ -37,3 +38,13 @@ data class NewPoll(
|
||||||
@SerializedName("expires_in") val expiresIn: Int,
|
@SerializedName("expires_in") val expiresIn: Int,
|
||||||
val multiple: Boolean
|
val multiple: Boolean
|
||||||
) : Parcelable
|
) : Parcelable
|
||||||
|
|
||||||
|
// It would be nice if we could reuse MediaToSend,
|
||||||
|
// but the server requires a different format for focus
|
||||||
|
@Parcelize
|
||||||
|
data class MediaAttribute(
|
||||||
|
val id: String,
|
||||||
|
val description: String?,
|
||||||
|
val focus: String?,
|
||||||
|
val thumbnail: String?,
|
||||||
|
) : Parcelable
|
||||||
|
|
|
@ -29,6 +29,7 @@ import com.keylesspalace.tusky.components.notifications.NotificationHelper
|
||||||
import com.keylesspalace.tusky.db.AccountManager
|
import com.keylesspalace.tusky.db.AccountManager
|
||||||
import com.keylesspalace.tusky.di.Injectable
|
import com.keylesspalace.tusky.di.Injectable
|
||||||
import com.keylesspalace.tusky.entity.Attachment
|
import com.keylesspalace.tusky.entity.Attachment
|
||||||
|
import com.keylesspalace.tusky.entity.MediaAttribute
|
||||||
import com.keylesspalace.tusky.entity.NewPoll
|
import com.keylesspalace.tusky.entity.NewPoll
|
||||||
import com.keylesspalace.tusky.entity.NewStatus
|
import com.keylesspalace.tusky.entity.NewStatus
|
||||||
import com.keylesspalace.tusky.entity.Status
|
import com.keylesspalace.tusky.entity.Status
|
||||||
|
@ -190,6 +191,14 @@ class SendStatusService : Service(), Injectable {
|
||||||
scheduledAt = statusToSend.scheduledAt,
|
scheduledAt = statusToSend.scheduledAt,
|
||||||
poll = statusToSend.poll,
|
poll = statusToSend.poll,
|
||||||
language = statusToSend.language,
|
language = statusToSend.language,
|
||||||
|
mediaAttributes = media.map { media ->
|
||||||
|
MediaAttribute(
|
||||||
|
id = media.id!!,
|
||||||
|
description = media.description,
|
||||||
|
focus = media.focus?.toMastodonApiString(),
|
||||||
|
thumbnail = null,
|
||||||
|
)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
val sendResult = if (statusToSend.statusId == null) {
|
val sendResult = if (statusToSend.statusId == null) {
|
||||||
|
|
Loading…
Reference in a new issue