Reactions: Remove the send reaction hack as it is now done in the SDK

This commit is contained in:
manuroe
2019-05-20 19:40:52 +02:00
parent 168646092c
commit c6b97d2797
2 changed files with 2 additions and 51 deletions
@@ -21,7 +21,6 @@ final class ReactionsMenuViewModel: ReactionsMenuViewModelType {
// MARK: - Properties
// MARK: Private
private let session: MXSession // TODO: To remove. Only required for reactUsingHack()
private let aggregations: MXAggregations
private let roomId: String
private let eventId: String
@@ -38,11 +37,10 @@ final class ReactionsMenuViewModel: ReactionsMenuViewModelType {
// MARK: - Setup
init(aggregations: MXAggregations, roomId: String, eventId: String, session: MXSession) {
init(aggregations: MXAggregations, roomId: String, eventId: String) {
self.aggregations = aggregations
self.roomId = roomId
self.eventId = eventId
self.session = session
self.loadData()
self.listenToDataUpdate()
@@ -142,16 +140,6 @@ final class ReactionsMenuViewModel: ReactionsMenuViewModelType {
return
}
// The server does not support support reaction yet
// Use a fallback mechanism
// TODO: To remove once the feature has landed on matrix.org homeserver
if let mxError = MXError(nsError: error) {
if mxError.errcode == kMXErrCodeStringUnrecognized {
sself.reactUsingHack(withReaction: reaction)
return
}
}
sself.coordinatorDelegate?.reactionsMenuViewModel(sself, didReactionFailedWithError: error, reaction: reaction.rawValue, isAddReaction: true)
})
} else {
@@ -209,41 +197,4 @@ final class ReactionsMenuViewModel: ReactionsMenuViewModelType {
self.react(withReaction: unreaction, selected: false)
}
}
/// reactUsingHack directly sends a `m.reaction` room message instead of using the `/send_relation` api.
///
/// TODO: To remove once the feature has landed on matrix.org homeserver
///
/// - Parameter reaction: the reaction
private func reactUsingHack(withReaction reaction: ReactionsMenuReaction) {
guard let room = self.session.room(withRoomId: self.roomId) else {
print("[ReactionsMenuViewModel] reactUsingHack: Error: Unknown room: \(self.roomId)")
return
}
print("[ReactionsMenuViewModel] reactUsingHack")
let reactionContent = [
"m.relates_to": [
"rel_type": "m.annotation",
"event_id": self.eventId,
"key": reaction.rawValue]
]
var nilEvent: MXEvent?
room.sendEvent(.reaction, content: reactionContent, localEcho: &nilEvent, completion: { [weak self] ( completion) in
guard let sself = self else {
return
}
switch completion {
case .success:
print("[ReactionsMenuViewModel] reactUsingHack: Success")
sself.coordinatorDelegate?.reactionsMenuViewModel(sself, didReactionComplete: reaction.rawValue, isAddReaction: true)
case.failure(let error):
print("[ReactionsMenuViewModel] reactUsingHack: Error: \(error)")
sself.coordinatorDelegate?.reactionsMenuViewModel(sself, didReactionFailedWithError: error, reaction: reaction.rawValue, isAddReaction: true)
}
})
}
}