diff --git a/MatrixSDK/Data/MXRoom.m b/MatrixSDK/Data/MXRoom.m index 201e665931..020dbe5eef 100644 --- a/MatrixSDK/Data/MXRoom.m +++ b/MatrixSDK/Data/MXRoom.m @@ -2192,6 +2192,18 @@ - (void)getReplyContentBodiesWithEventToReply:(MXEvent*)eventToReply senderMessageBody = question; } + if (eventToReply.eventType == MXEventTypePollEnd) + { + MXEvent* pollStartEvent = [mxSession.store eventWithEventId:eventToReply.relatesTo.eventId inRoom:self.roomId]; + + if (pollStartEvent) { + NSString *question = [MXEventContentPollStart modelFromJSON:pollStartEvent.content].question; + senderMessageBody = question; + } else { + // we need a fallback to avoid crashes since the m.poll.start event may be missing. + senderMessageBody = eventToReply.relatesTo.eventId; + } + } else if (eventToReply.eventType == MXEventTypeBeaconInfo) { senderMessageBody = stringLocalizer.senderSentTheirLiveLocation; @@ -2437,12 +2449,17 @@ - (NSString*)replyMessageFormattedBodyFromEventToReply:(MXEvent*)eventToReply - (BOOL)canReplyToEvent:(MXEvent *)eventToReply { - if(eventToReply.eventType == MXEventTypePollStart) + if (eventToReply.eventType == MXEventTypePollStart) + { + return YES; + } + + if (eventToReply.eventType == MXEventTypePollEnd) { return YES; } - if(eventToReply.eventType == MXEventTypeBeaconInfo) + if (eventToReply.eventType == MXEventTypeBeaconInfo) { return YES; } diff --git a/MatrixSDK/Room/Polls/PollAggregator.swift b/MatrixSDK/Room/Polls/PollAggregator.swift index e896631d55..134bfa480d 100644 --- a/MatrixSDK/Room/Polls/PollAggregator.swift +++ b/MatrixSDK/Room/Polls/PollAggregator.swift @@ -71,6 +71,25 @@ public class PollAggregator { } } + public convenience init(session: MXSession, room: MXRoom, pollEvent: MXEvent) throws { + var pollStartEventId: String? + + switch pollEvent.eventType { + case .pollStart: + pollStartEventId = pollEvent.eventId + case .pollEnd: + pollStartEventId = pollEvent.relatesTo.eventId + default: + pollStartEventId = nil + } + + guard let pollStartEventId = pollStartEventId else { + throw PollAggregatorError.invalidPollStartEvent + } + + try self.init(session: session, room: room, pollStartEventId: pollStartEventId) + } + public init(session: MXSession, room: MXRoom, pollStartEventId: String) throws { self.session = session self.room = room diff --git a/changelog.d/pr-1674.change b/changelog.d/pr-1674.change new file mode 100644 index 0000000000..36c0645ef7 --- /dev/null +++ b/changelog.d/pr-1674.change @@ -0,0 +1 @@ +Polls: add support for rendering/replying to poll ended events.