fix: tapping buttons in composite messages (e.g. polls) - WPB-19793#3696
fix: tapping buttons in composite messages (e.g. polls) - WPB-19793#3696
Conversation
| guard let moc = parentMessage.managedObjectContext, | ||
| let buttonId = button?.id, | ||
| let messageId = parentMessage.nonce, | ||
| !hasSelectedButton else { return } | ||
| guard let context = parentMessage.managedObjectContext else { return } | ||
|
|
||
| context.performGroupedBlock { [weak self] in | ||
| guard let self, let messageId = parentMessage.nonce, let buttonId = button?.id, !hasSelectedButton else { return } | ||
|
|
||
| moc.performGroupedBlock { [weak self] in | ||
| guard let self else { return } | ||
| let buttonState = buttonState ?? | ||
| ButtonState.insert(with: buttonId, message: parentMessage, inContext: moc) | ||
| ButtonState.insert(with: buttonId, message: parentMessage, inContext: context) | ||
| parentMessage.buttonStates?.resetExpired() | ||
| guard parentMessage.isSenderInConversation else { | ||
| buttonState.isExpired = true | ||
| moc.saveOrRollback() | ||
| context.saveOrRollback() |
There was a problem hiding this comment.
Two things done here:
- rename
moctocontext - move accessing
nonceinto thecontext.performclosure, so that it works with any context
There was a problem hiding this comment.
question: was it a background context before that had no parent? or just no automaticallySaveToParent?
There was a problem hiding this comment.
Yes, some views or models belonging to views have core data entities set which have been fetched on a background context.
Test Results4 265 tests 4 238 ✅ 6m 16s ⏱️ Results for commit 2911e30. ♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where tapping buttons in composite messages (like polls) wasn't working due to dangling Core Data objects from a background context remaining in the view hierarchy after a performance improvement.
- Adds a workaround to force recreation of conversation message views for composite messages
- Ensures composite messages use the correct Core Data context by checking
isCompositeproperty - Updates dependency versions and reorganizes plist configuration
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| ConversationTableViewDataSource.swift | Implements the main fix by forcing cell description recreation for composite messages |
| CompositeMessageItemContent.swift | Improves code style with final class modifier and simplifies variable naming |
| Wire-Info.plist | Reorganizes configuration keys (moves OpenLinksExternally and adds UIDesignRequiresCompatibility) |
| Package.resolved | Updates swift-argument-parser dependency from 1.5.0 to 1.6.1 |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
netbe
left a comment
There was a problem hiding this comment.
Fix looks good, I left some comments please have a look.
| guard let moc = parentMessage.managedObjectContext, | ||
| let buttonId = button?.id, | ||
| let messageId = parentMessage.nonce, | ||
| !hasSelectedButton else { return } | ||
| guard let context = parentMessage.managedObjectContext else { return } | ||
|
|
||
| context.performGroupedBlock { [weak self] in | ||
| guard let self, let messageId = parentMessage.nonce, let buttonId = button?.id, !hasSelectedButton else { return } | ||
|
|
||
| moc.performGroupedBlock { [weak self] in | ||
| guard let self else { return } | ||
| let buttonState = buttonState ?? | ||
| ButtonState.insert(with: buttonId, message: parentMessage, inContext: moc) | ||
| ButtonState.insert(with: buttonId, message: parentMessage, inContext: context) | ||
| parentMessage.buttonStates?.resetExpired() | ||
| guard parentMessage.isSenderInConversation else { | ||
| buttonState.isExpired = true | ||
| moc.saveOrRollback() | ||
| context.saveOrRollback() |
There was a problem hiding this comment.
question: was it a background context before that had no parent? or just no automaticallySaveToParent?
…3696) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Issue
A performance improvement #2921 earlier this year broke composite messages.
Some dangling Core Data objects from a temporary background context remain in the view/model hierarchy.
So when a button of a composite message is tapped, it cannot be handled properly.
This PR adds a workaround which forces the recreation of conversation message views if the message is a composite message.
Testing
Create a poll in a Proteus conversation and try to vote.
Checklist
[WPB-XXX].UI accessibility checklist
If your PR includes UI changes, please utilize this checklist: