Skip to content

Commit

Permalink
Fix Polls Memory Leak in Alerts + Creation Poll Action shown inside T…
Browse files Browse the repository at this point in the history
…hreads (#3445)

* Fix Poll Controller Memory Leaks when used in alerts

* Fix poll creation action shown inside threads
  • Loading branch information
nuno-vieira committed Oct 2, 2024
1 parent 785121d commit f9c63f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions Sources/StreamChatUI/ChatMessageList/ChatMessageListVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/StreamChatUI/Composer/ComposerVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down

0 comments on commit f9c63f4

Please sign in to comment.