Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not store messages from extension if app is receiving events #2481

Merged
merged 7 commits into from Feb 14, 2023

Conversation

polqf
Copy link
Contributor

@polqf polqf commented Feb 7, 2023

🔗 Issue Links

Resolves #2309
Resolves https://github.com/GetStream/ios-issues-tracking/issues/264

🎯 Goal

Make channel unread counts accurate

📝 Summary

Unread counts were not accurate when the app was in the foreground handling the updates both using WS events and Push Notifications

🛠 Implementation

This PR stops the notification extension from saving data to the DB if the host app is connected through WS, and processing those events.
This communication is done using a shared UserDefaults based on App Groups.

🧪 Manual Testing Notes

  1. Open the app and leave it on the channel list
  2. Using another device/simulator, send messages to the previous device
  3. The unread count should have the correct amount

The issue was frequently visible when sending replies to a thread (sending those messages to the channel, as well)

☑️ Contributor Checklist

  • I have signed the Stream CLA (required)
  • This change follows zero ⚠️ policy (required)
  • This change should be manually QAed
  • Changelog is updated with client-facing changes
  • New code is covered by unit tests
  • Comparison screenshots added for visual changes
  • Affected documentation updated (docusaurus, tutorial, CMS)

🎁 Meme

@polqf polqf force-pushed the bugfix/unread-counts-when-push-extension branch from 5bb3c82 to b1625ac Compare February 7, 2023 12:13
@github-actions
Copy link

github-actions bot commented Feb 7, 2023

1 Warning
⚠️ The changes should be manually QAed before the Pull Request will be merged
1 Message
📖 There seems to be app changes but CHANGELOG wasn't modified.
Please include an entry if the PR includes user-facing changes.
You can find it at CHANGELOG.md.

Generated by 🚫 Danger

@polqf polqf marked this pull request as ready for review February 7, 2023 17:15
@polqf polqf requested a review from a team as a code owner February 7, 2023 17:15
@testableapple testableapple added the 🤞 Ready For QA A PR that is Ready for QA label Feb 7, 2023
Sources/StreamChat/Repositories/MessageRepository.swift Outdated Show resolved Hide resolved
@@ -14,6 +15,52 @@ final class NSManagedObject_Tests: XCTestCase {
func test_entityName_custom() {
XCTAssertEqual(EntityWithCustomName.entityName, "CustomName")
}

func test_discardChanges_shouldClearChangesForTheObject() throws {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of ClearChanges consider using Discard to match the action you are performing and help the reader understand better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it like trying to describe a word with the word itself? 😂 That's why a went for it, but happy to change it if is not that readable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not that it isn't readable just for consistency :). Up to you :)

@testableapple testableapple removed the 🤞 Ready For QA A PR that is Ready for QA label Feb 8, 2023
Copy link
Contributor

@ipavlidakis ipavlidakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@polqf polqf force-pushed the bugfix/unread-counts-when-push-extension branch from 82b719c to 90d725a Compare February 9, 2023 12:16
@testableapple testableapple added the 🤞 Ready For QA A PR that is Ready for QA label Feb 9, 2023
Copy link
Contributor

@testableapple testableapple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@emerge-tools
Copy link

emerge-tools bot commented Feb 9, 2023

📏 Size Analysis

Total install size 10.6 MB | This change: ⬆️ +179.3 kB (+1.71%)

Image of diff

🗂 See size breakdown
Item Install size
ChatSample/Strings.CFStrings 🔺 12.4 kB
ChatSample/External Methods 🔺 8.3 kB
➕ ChatSample/SentryProfiler.captureEnvelope 🔺 7.5 kB
ChatSample/Strings.Unmapped 🔺 5.1 kB
➖ ChatSample/SentryTraceState ⬇️ 4.0 kB
ChatSample/Code Signature 🔺 3.4 kB
➕ StreamChat.framework/StreamChat.MessageRepository.getMessage(cid,messageId,store,completion) 🔺 3.2 kB
➕ ChatSample/SentryNetworkTracker.captureFailedRequests: 🔺 3.2 kB
➖ ChatSample/SentryProfiler.buildEnvelopeItemForTransaction: ⬇️ 2.7 kB
➕ ChatSample/CL.CLLocationManagerDelegate.Objc Metadata 🔺 2.4 kB
➕ ChatSample/SentryFileManager.initWithOptions:andCurrentDateProvider:dispatchQueueWrapper:error: 🔺 2.3 kB
➖ StreamChat.framework/StreamChat.MessageRepository.getMessage(cid,messageId,completion) ⬇️ 2.2 kB
➖ ChatSample/SentryCrashDeadlockMonitor ⬇️ 1.9 kB
➕ ChatSample/processBacktrace 🔺 1.8 kB
ChatSample/SentryNetworkTracker.urlSessionTaskResume: 🔺 1.8 kB
ChatSample/DYLD.Exports 🔺 1.7 kB
➕ ChatSample/SentryUIViewControllerSwizzling.swizzleUIViewControllersOfClassesInImageOf: 🔺 1.6 kB
ChatSample/SentryOptions.Objc Metadata 🔺 1.6 kB
ChatSample/SentryOptions.validateOptions:didFailWithError: 🔺 1.5 kB
➕ ChatSample/SentryTracer.addMeasurements: 🔺 1.4 kB

🔎 See the full size analysis (c53fbe1) merging into develop (2c2ef9e)

Provide a baseSha and pullRequestNumber with your upload to ensure diffs are correct. Read more in the docs

@polqf polqf force-pushed the bugfix/unread-counts-when-push-extension branch from c53fbe1 to c454f3b Compare February 13, 2023 11:01
@sonarcloud
Copy link

sonarcloud bot commented Feb 13, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

95.8% 95.8% Coverage
0.0% 0.0% Duplication

@polqf polqf merged commit 90b6ac8 into develop Feb 14, 2023
@polqf polqf deleted the bugfix/unread-counts-when-push-extension branch February 14, 2023 10:19
ipavlidakis pushed a commit that referenced this pull request Feb 16, 2023
* Do not store messages from extension if app is receiving events

* Add tests for NotificationExtensionLifecycle

* Update tests for ChatRemoteNotificationHandler

* Add tests for NSManagedObjectContext.discard

* Address PR comments

* Do not set a default value for 'store' in MessageRepository.getMessage

* Fix specs compilation issue
@polqf polqf mentioned this pull request Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤞 Ready For QA A PR that is Ready for QA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unread count is broken in stream-chat.
3 participants