From f9c63f40dc5ca9b3c7df44ffec151f0f9bdbd364 Mon Sep 17 00:00:00 2001 From: Nuno Vieira Date: Wed, 2 Oct 2024 16:57:44 +0100 Subject: [PATCH] Fix Polls Memory Leak in Alerts + Creation Poll Action shown inside Threads (#3445) * Fix Poll Controller Memory Leaks when used in alerts * Fix poll creation action shown inside threads --- .../ChatMessageList/ChatMessageListVC.swift | 13 +++++++------ Sources/StreamChatUI/Composer/ComposerVC.swift | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Sources/StreamChatUI/ChatMessageList/ChatMessageListVC.swift b/Sources/StreamChatUI/ChatMessageList/ChatMessageListVC.swift index 1d9d7fe62a..d40bb06562 100644 --- a/Sources/StreamChatUI/ChatMessageList/ChatMessageListVC.swift +++ b/Sources/StreamChatUI/ChatMessageList/ChatMessageListVC.swift @@ -1132,13 +1132,13 @@ open class ChatMessageListVC: _ViewController, in message: ChatMessage ) { guard let currentUserId = client.currentUserId else { return } - let pollController = client.pollController(messageId: message.id, pollId: poll.id) alertRouter.showPollAddCommentAlert( for: poll, in: message.id, currentUserId: currentUserId ) { [weak self] comment in - pollController.castPollVote(answerText: comment, optionId: nil) { error in + let pollController = self?.client.pollController(messageId: message.id, pollId: poll.id) + pollController?.castPollVote(answerText: comment, optionId: nil) { error in self?.notificationFeedbackGenerator?.notificationOccurred(error == nil ? .success : .error) } } @@ -1149,16 +1149,16 @@ open class ChatMessageListVC: _ViewController, didTapSuggestOptionForPoll poll: Poll, in message: ChatMessage ) { - let pollController = client.pollController(messageId: message.id, pollId: poll.id) alertRouter.showPollAddSuggestionAlert( for: poll, in: message.id ) { [weak self] suggestion in + let pollController = self?.client.pollController(messageId: message.id, pollId: poll.id) let isDuplicate = poll.options.contains(where: { $0.text == suggestion }) if isDuplicate { return } - pollController.suggestPollOption(text: suggestion) { error in + pollController?.suggestPollOption(text: suggestion) { error in self?.notificationFeedbackGenerator?.notificationOccurred(error == nil ? .success : .error) } } @@ -1170,8 +1170,9 @@ open class ChatMessageListVC: _ViewController, in message: ChatMessage ) { let pollController = client.pollController(messageId: message.id, pollId: poll.id) - alertRouter.showPollEndVoteAlert(for: poll, in: message.id) { - pollController.closePoll { [weak self] error in + alertRouter.showPollEndVoteAlert(for: poll, in: message.id) { [weak self] in + let pollController = self?.client.pollController(messageId: message.id, pollId: poll.id) + pollController?.closePoll { [weak self] error in self?.notificationFeedbackGenerator?.notificationOccurred(error == nil ? .success : .error) } } diff --git a/Sources/StreamChatUI/Composer/ComposerVC.swift b/Sources/StreamChatUI/Composer/ComposerVC.swift index 91688d9fd1..689f4dc7db 100644 --- a/Sources/StreamChatUI/Composer/ComposerVC.swift +++ b/Sources/StreamChatUI/Composer/ComposerVC.swift @@ -845,7 +845,7 @@ open class ComposerVC: _ViewController, handler: { [weak self] _ in self?.showCamera() } ) : nil - let showPollCreationAction = isPollCreationEnabled ? UIAlertAction( + let showPollCreationAction = isPollCreationEnabled && !content.isInsideThread ? UIAlertAction( title: L10n.Composer.Picker.poll, style: .default, handler: { [weak self] _ in self?.showPollCreation() }