Reply to a poll (#2087)

* Refactor TimelineItemReplyDetails for polls

* Fix reply for polls

* Update reply details factory

* Revert Poll Hashable conformance

* PR comments
This commit is contained in:
Alfonso Grillo
2023-11-15 16:57:34 +01:00
committed by GitHub
parent 0b9da83470
commit 9f1092b0b6
8 changed files with 179 additions and 150 deletions
@@ -19,6 +19,11 @@ import Foundation
enum TimelineItemReplyDetails: Hashable {
case notLoaded(eventID: String)
case loading(eventID: String)
case loaded(sender: TimelineItemSender, contentType: EventBasedMessageTimelineItemContentType)
case loaded(sender: TimelineItemSender, eventContent: TimelineEventContent)
case error(eventID: String, message: String)
}
enum TimelineEventContent: Hashable {
case message(EventBasedMessageTimelineItemContentType)
case poll(question: String)
}
@@ -628,47 +628,55 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
avatarURL: nil)
}
let replyContent: EventBasedMessageTimelineItemContentType
let replyContent: TimelineEventContent
switch timelineItem.kind() {
case .message:
switch timelineItem.asMessage()?.msgtype() {
case .audio(let content):
if content.voice != nil {
replyContent = .voice(buildAudioTimelineItemContent(content))
} else {
replyContent = .audio(buildAudioTimelineItemContent(content))
}
case .emote(let content):
replyContent = .emote(buildEmoteTimelineItemContent(senderDisplayName: sender.displayName, senderID: sender.id, messageContent: content))
case .file(let content):
replyContent = .file(buildFileTimelineItemContent(content))
case .image(let content):
replyContent = .image(buildImageTimelineItemContent(content))
case .notice(let content):
replyContent = .notice(buildNoticeTimelineItemContent(content))
case .text(let content):
replyContent = .text(buildTextTimelineItemContent(content))
case .video(let content):
replyContent = .video(buildVideoTimelineItemContent(content))
case .location(let content):
replyContent = .location(buildLocationTimelineItemContent(content))
case .other, .none:
replyContent = .text(.init(body: L10n.commonUnsupportedEvent))
}
return timelineItemReplyDetails(for: timelineItem.asMessage()?.msgtype(), sender: sender)
case .poll(let question, _, _, _, _, _):
replyContent = .text(.init(body: question))
replyContent = .poll(question: question)
case .sticker(let body, _, _):
replyContent = .text(.init(body: body))
replyContent = .message(.text(.init(body: body)))
default:
replyContent = .text(.init(body: L10n.commonUnsupportedEvent))
replyContent = .message(.text(.init(body: L10n.commonUnsupportedEvent)))
}
return .loaded(sender: sender, contentType: replyContent)
return .loaded(sender: sender, eventContent: replyContent)
case let .error(message):
return .error(eventID: details.eventId, message: message)
}
}
private func timelineItemReplyDetails(for messageType: MessageType?, sender: TimelineItemSender) -> TimelineItemReplyDetails {
let replyContent: EventBasedMessageTimelineItemContentType
switch messageType {
case .audio(let content):
if content.voice != nil {
replyContent = .voice(buildAudioTimelineItemContent(content))
} else {
replyContent = .audio(buildAudioTimelineItemContent(content))
}
case .emote(let content):
replyContent = .emote(buildEmoteTimelineItemContent(senderDisplayName: sender.displayName, senderID: sender.id, messageContent: content))
case .file(let content):
replyContent = .file(buildFileTimelineItemContent(content))
case .image(let content):
replyContent = .image(buildImageTimelineItemContent(content))
case .notice(let content):
replyContent = .notice(buildNoticeTimelineItemContent(content))
case .text(let content):
replyContent = .text(buildTextTimelineItemContent(content))
case .video(let content):
replyContent = .video(buildVideoTimelineItemContent(content))
case .location(let content):
replyContent = .location(buildLocationTimelineItemContent(content))
case .other, .none:
replyContent = .text(.init(body: L10n.commonUnsupportedEvent))
}
return .loaded(sender: sender, eventContent: .message(replyContent))
}
}
private extension LocationRoomTimelineItemContent.AssetType {