mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Add support for adding/editing/removing media captions. (#3547)
* Add support for editing media captions. * Add composer snapshots. * PR comment.
This commit is contained in:
@@ -91,6 +91,13 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
|
||||
html: String?,
|
||||
intentionalMentions: IntentionalMentions) async { }
|
||||
|
||||
func editCaption(_ eventOrTransactionID: EventOrTransactionId,
|
||||
message: String,
|
||||
html: String?,
|
||||
intentionalMentions: IntentionalMentions) async { }
|
||||
|
||||
func removeCaption(_ eventOrTransactionID: EventOrTransactionId) async { }
|
||||
|
||||
func redact(_ eventOrTransactionID: EventOrTransactionId) async { }
|
||||
|
||||
func pin(eventID: String) async { }
|
||||
|
||||
@@ -238,7 +238,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
html: html,
|
||||
intentionalMentions: intentionalMentions.toRustMentions())
|
||||
|
||||
switch await activeTimeline.edit(eventOrTransactionID, newContent: messageContent) {
|
||||
switch await activeTimeline.edit(eventOrTransactionID, newContent: .roomMessage(content: messageContent)) {
|
||||
case .success:
|
||||
MXLog.info("Finished editing message by event")
|
||||
case let .failure(error):
|
||||
@@ -246,6 +246,34 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func editCaption(_ eventOrTransactionID: EventOrTransactionId,
|
||||
message: String,
|
||||
html: String?,
|
||||
intentionalMentions: IntentionalMentions) async {
|
||||
// We're waiting on an API for including mentions: https://github.com/matrix-org/matrix-rust-sdk/issues/4302
|
||||
MXLog.info("Editing timeline item caption: \(eventOrTransactionID) in \(roomID)")
|
||||
|
||||
// When formattedCaption is nil, caption will be parsed as markdown and generate the HTML for us.
|
||||
let newContent = createCaptionEdit(caption: message, formattedCaption: html.map { .init(format: .html, body: $0) })
|
||||
switch await activeTimeline.edit(eventOrTransactionID, newContent: newContent) {
|
||||
case .success:
|
||||
MXLog.info("Finished editing caption")
|
||||
case let .failure(error):
|
||||
MXLog.error("Failed editing caption with error: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func removeCaption(_ eventOrTransactionID: EventOrTransactionId) async {
|
||||
// Set a `nil` caption to remove it from the event.
|
||||
let newContent = createCaptionEdit(caption: nil, formattedCaption: nil)
|
||||
switch await activeTimeline.edit(eventOrTransactionID, newContent: newContent) {
|
||||
case .success:
|
||||
MXLog.info("Finished removing caption.")
|
||||
case let .failure(error):
|
||||
MXLog.error("Failed removing caption with error: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func redact(_ eventOrTransactionID: EventOrTransactionId) async {
|
||||
MXLog.info("Send redaction in \(roomID)")
|
||||
|
||||
|
||||
+7
@@ -56,6 +56,13 @@ protocol RoomTimelineControllerProtocol {
|
||||
html: String?,
|
||||
intentionalMentions: IntentionalMentions) async
|
||||
|
||||
func editCaption(_ eventOrTransactionID: EventOrTransactionId,
|
||||
message: String,
|
||||
html: String?,
|
||||
intentionalMentions: IntentionalMentions) async
|
||||
|
||||
func removeCaption(_ eventOrTransactionID: EventOrTransactionId) async
|
||||
|
||||
func toggleReaction(_ reaction: String, to eventOrTransactionID: EventOrTransactionId) async
|
||||
|
||||
func redact(_ eventOrTransactionID: EventOrTransactionId) async
|
||||
|
||||
+9
@@ -26,6 +26,15 @@ protocol EventBasedMessageTimelineItemProtocol: EventBasedTimelineItemProtocol {
|
||||
}
|
||||
|
||||
extension EventBasedMessageTimelineItemProtocol {
|
||||
var supportsMediaCaption: Bool {
|
||||
switch contentType {
|
||||
case .audio, .file, .image, .video:
|
||||
true
|
||||
case .emote, .notice, .text, .location, .voice:
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
var hasMediaCaption: Bool {
|
||||
switch contentType {
|
||||
case .audio(let content):
|
||||
|
||||
@@ -164,9 +164,9 @@ final class TimelineProxy: TimelineProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func edit(_ eventOrTransactionID: EventOrTransactionId, newContent: RoomMessageEventContentWithoutRelation) async -> Result<Void, TimelineProxyError> {
|
||||
func edit(_ eventOrTransactionID: EventOrTransactionId, newContent: EditedContent) async -> Result<Void, TimelineProxyError> {
|
||||
do {
|
||||
try await timeline.edit(eventOrTransactionId: eventOrTransactionID, newContent: .roomMessage(content: newContent))
|
||||
try await timeline.edit(eventOrTransactionId: eventOrTransactionID, newContent: newContent)
|
||||
|
||||
MXLog.info("Finished editing timeline item: \(eventOrTransactionID)")
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ protocol TimelineProxyProtocol {
|
||||
func paginateForwards(requestSize: UInt16) async -> Result<Void, TimelineProxyError>
|
||||
|
||||
func edit(_ eventOrTransactionID: EventOrTransactionId,
|
||||
newContent: RoomMessageEventContentWithoutRelation) async -> Result<Void, TimelineProxyError>
|
||||
newContent: EditedContent) async -> Result<Void, TimelineProxyError>
|
||||
|
||||
func redact(_ eventOrTransactionID: EventOrTransactionId,
|
||||
reason: String?) async -> Result<Void, TimelineProxyError>
|
||||
|
||||
Reference in New Issue
Block a user