mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-30 08:12:40 +00:00
Merge pull request #5869 from vector-im/ismail/5488_strip_inreplyto
Strip `in reply to` from thread summaries and latest messages
This commit is contained in:
commit
2051418e55
4 changed files with 24 additions and 20 deletions
|
@ -26,4 +26,24 @@ extension MXEvent {
|
||||||
}
|
}
|
||||||
return MXMessageType(identifier: messageTypeString)
|
return MXMessageType(identifier: messageTypeString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Lightweight version of the receiver, in which reply-specific keys are stripped. Returns the same event with the receiver if not a reply event.
|
||||||
|
/// Should be used only to update formatting behavior.
|
||||||
|
var replyStrippedVersion: MXEvent {
|
||||||
|
if self.isReply(), let newMessage = self.copy() as? MXEvent {
|
||||||
|
var jsonDict = newMessage.isEncrypted ? newMessage.clear?.jsonDictionary() : newMessage.jsonDictionary()
|
||||||
|
if var content = jsonDict?["content"] as? [String: Any] {
|
||||||
|
content.removeValue(forKey: "format")
|
||||||
|
content.removeValue(forKey: "formatted_body")
|
||||||
|
content.removeValue(forKey: kMXEventRelationRelatesToKey)
|
||||||
|
if let replyText = MXReplyEventParser().parse(newMessage)?.bodyParts.replyText {
|
||||||
|
content["body"] = replyText
|
||||||
|
}
|
||||||
|
jsonDict?["content"] = content
|
||||||
|
}
|
||||||
|
return MXEvent(fromJSON: jsonDict)
|
||||||
|
} else {
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ class ThreadSummaryView: UIView {
|
||||||
room.state { [weak self] roomState in
|
room.state { [weak self] roomState in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
let formatterError = UnsafeMutablePointer<MXKEventFormatterError>.allocate(capacity: 1)
|
let formatterError = UnsafeMutablePointer<MXKEventFormatterError>.allocate(capacity: 1)
|
||||||
let lastMessageText = eventFormatter.attributedString(from: lastMessage,
|
let lastMessageText = eventFormatter.attributedString(from: lastMessage.replyStrippedVersion,
|
||||||
with: roomState,
|
with: roomState,
|
||||||
error: formatterError)
|
error: formatterError)
|
||||||
|
|
||||||
|
|
|
@ -206,25 +206,8 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
|
||||||
guard let message = thread.rootMessage else {
|
guard let message = thread.rootMessage else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if message.isReply(), let newMessage = message.copy() as? MXEvent {
|
|
||||||
var jsonDict = newMessage.isEncrypted ? newMessage.clear?.jsonDictionary() : newMessage.jsonDictionary()
|
|
||||||
if var content = jsonDict?["content"] as? [String: Any] {
|
|
||||||
content.removeValue(forKey: "format")
|
|
||||||
content.removeValue(forKey: "formatted_body")
|
|
||||||
content.removeValue(forKey: kMXEventRelationRelatesToKey)
|
|
||||||
if let replyText = MXReplyEventParser().parse(newMessage)?.bodyParts.replyText {
|
|
||||||
content["body"] = replyText
|
|
||||||
}
|
|
||||||
jsonDict?["content"] = content
|
|
||||||
}
|
|
||||||
let trimmedMessage = MXEvent(fromJSON: jsonDict)
|
|
||||||
let formatterError = UnsafeMutablePointer<MXKEventFormatterError>.allocate(capacity: 1)
|
|
||||||
return eventFormatter.attributedString(from: trimmedMessage,
|
|
||||||
with: roomState,
|
|
||||||
error: formatterError)
|
|
||||||
}
|
|
||||||
let formatterError = UnsafeMutablePointer<MXKEventFormatterError>.allocate(capacity: 1)
|
let formatterError = UnsafeMutablePointer<MXKEventFormatterError>.allocate(capacity: 1)
|
||||||
return eventFormatter.attributedString(from: message,
|
return eventFormatter.attributedString(from: message.replyStrippedVersion,
|
||||||
with: roomState,
|
with: roomState,
|
||||||
error: formatterError)
|
error: formatterError)
|
||||||
}
|
}
|
||||||
|
@ -238,7 +221,7 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
|
||||||
}
|
}
|
||||||
let formatterError = UnsafeMutablePointer<MXKEventFormatterError>.allocate(capacity: 1)
|
let formatterError = UnsafeMutablePointer<MXKEventFormatterError>.allocate(capacity: 1)
|
||||||
return (
|
return (
|
||||||
eventFormatter.attributedString(from: message,
|
eventFormatter.attributedString(from: message.replyStrippedVersion,
|
||||||
with: roomState,
|
with: roomState,
|
||||||
error: formatterError),
|
error: formatterError),
|
||||||
eventFormatter.dateString(from: message, withTime: true)
|
eventFormatter.dateString(from: message, withTime: true)
|
||||||
|
|
1
changelog.d/5488.change
Normal file
1
changelog.d/5488.change
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Threads: Strip `ìn reply to` from thread summaries and latest messages.
|
Loading…
Reference in a new issue