-
Notifications
You must be signed in to change notification settings - Fork 4k
feat(cloud_firestore): Move Snapshot handling into a EventChannel #4209
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
Merged
Merged
Changes from all commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
6de525c
Bump Podfile
e45992d
Ensure example uses platform interface from the repo instead of pub
26aa040
Move QuerySnapshot handling into EventChannel
13fd053
Formatting
e1fb4a9
Remove unused methods
d081def
Forward errors
067fae2
Move document snapshot listener to event channel as well
14b77b7
Move snapshotInSync listener to EventChannel
f44b877
iOS || macOS
a0de5b5
Perform transaction handling via EventChannel as well
1d215f7
initialize dictionaries
b73d2d2
remove now-unused method
79fcbe8
+/- comments
c5edfec
finally remove the channel reference
eda9935
Merge branch 'master' into fix/4108-cloud-firestore
f72f59a
Typo
08c77fd
begin android implementation
c308e3f
migrate query snapshots
6a83d4d
Remove now-unused code
ad7769d
Document Snapshots
3aa91f3
Transactions
22aeea1
Formatting
80fd511
Remove now unused classes
ened 882cb0d
Refactor & cleanup
ened 5e8e6b5
remove removeListener
ened eb302ba
Merge branch 'master' of https://github.com/FirebaseExtended/flutterf…
ened a86224d
Correct merge
ened 8825473
Create a event channel per transaction
ened c5cfabc
Move iOS side to the new mechanism as well
ened 9af41ee
Formatting
ened 05e2c3d
unused import
ened bb41893
reactivate all tests
ened 83753f7
ios fixes
ened fc0d8b0
cleanup dart side
ened bf907d9
formatting
ened 0c1d7ae
cleanups
ened db10057
Merge branch 'master' into fix/4108-cloud-firestore
e40ddec
Add new failing tests
d6e39e1
Replace static with dedicated event channel instances
f33de5f
Dart tests V1
1ba6f0c
Extend Dart tests
ce15e2b
analyzer
46e8688
Restore link
ened 04b099a
Formatting, android cleanup
f44288a
revert podfile change
e4a25a2
Remove print
616f08b
typo
11a729e
remove unnecessary test
4b781e8
Merge branch 'master' into fix/4108-cloud-firestore
46a3088
Merge branch 'master' into fix/4108-cloud-firestore
ened 384a44a
formatting
ened 1f74a61
fix tests
ened 84b678d
java format
ened f8d6312
Clear transactionHandlers when plugin is destroyed
ened 1be114c
Address PR feedback
ened 20cf2ee
Introduce additional interface to cleanup transaction result listener…
ened bde86ea
Stop document/query stream listeners once error occured
ened dbbb837
Add multi-transaction case
ened cd4f9fb
Remove unused import
ened 49505e2
Address PR feedback
ened c752e3a
include remaining test in refactor
ened 49e23be
Merge branch 'master' into fix/4108-cloud-firestore
Salakar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
377 changes: 138 additions & 239 deletions
377
...d/src/main/java/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestorePlugin.java
Large diffs are not rendered by default.
Oops, something went wrong.
180 changes: 0 additions & 180 deletions
180
...ava/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestoreTransactionHandler.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...a/io/flutter/plugins/firebase/firestore/streamhandler/DocumentSnapshotsStreamHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.flutter.plugins.firebase.firestore.streamhandler; | ||
|
||
import static io.flutter.plugins.firebase.firestore.FlutterFirebaseFirestorePlugin.DEFAULT_ERROR_CODE; | ||
|
||
import com.google.firebase.firestore.DocumentReference; | ||
import com.google.firebase.firestore.ListenerRegistration; | ||
import com.google.firebase.firestore.MetadataChanges; | ||
import io.flutter.plugin.common.EventChannel.EventSink; | ||
import io.flutter.plugin.common.EventChannel.StreamHandler; | ||
import io.flutter.plugins.firebase.firestore.utils.ExceptionConverter; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class DocumentSnapshotsStreamHandler implements StreamHandler { | ||
|
||
ListenerRegistration listenerRegistration; | ||
|
||
@Override | ||
public void onListen(Object arguments, EventSink events) { | ||
@SuppressWarnings("unchecked") | ||
Map<String, Object> argumentsMap = (Map<String, Object>) arguments; | ||
|
||
MetadataChanges metadataChanges = | ||
(Boolean) Objects.requireNonNull(argumentsMap.get("includeMetadataChanges")) | ||
? MetadataChanges.INCLUDE | ||
: MetadataChanges.EXCLUDE; | ||
|
||
DocumentReference documentReference = | ||
(DocumentReference) Objects.requireNonNull(argumentsMap.get("reference")); | ||
|
||
listenerRegistration = | ||
documentReference.addSnapshotListener( | ||
metadataChanges, | ||
(documentSnapshot, exception) -> { | ||
if (exception != null) { | ||
Map<String, String> exceptionDetails = ExceptionConverter.createDetails(exception); | ||
events.error(DEFAULT_ERROR_CODE, exception.getMessage(), exceptionDetails); | ||
events.endOfStream(); | ||
|
||
onCancel(null); | ||
} else { | ||
events.success(documentSnapshot); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onCancel(Object arguments) { | ||
if (listenerRegistration != null) { | ||
listenerRegistration.remove(); | ||
listenerRegistration = null; | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...java/io/flutter/plugins/firebase/firestore/streamhandler/OnTransactionResultListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.flutter.plugins.firebase.firestore.streamhandler; | ||
|
||
import java.util.Map; | ||
|
||
/** callback when a transaction result has been computed. */ | ||
public interface OnTransactionResultListener { | ||
void receiveTransactionResponse(Map<String, Object> result); | ||
} |
58 changes: 58 additions & 0 deletions
58
...java/io/flutter/plugins/firebase/firestore/streamhandler/QuerySnapshotsStreamHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.flutter.plugins.firebase.firestore.streamhandler; | ||
|
||
import static io.flutter.plugins.firebase.firestore.FlutterFirebaseFirestorePlugin.DEFAULT_ERROR_CODE; | ||
|
||
import com.google.firebase.firestore.ListenerRegistration; | ||
import com.google.firebase.firestore.MetadataChanges; | ||
import com.google.firebase.firestore.Query; | ||
import io.flutter.plugin.common.EventChannel.EventSink; | ||
import io.flutter.plugin.common.EventChannel.StreamHandler; | ||
import io.flutter.plugins.firebase.firestore.utils.ExceptionConverter; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class QuerySnapshotsStreamHandler implements StreamHandler { | ||
|
||
ListenerRegistration listenerRegistration; | ||
|
||
@Override | ||
public void onListen(Object arguments, EventSink events) { | ||
@SuppressWarnings("unchecked") | ||
Map<String, Object> argumentsMap = (Map<String, Object>) arguments; | ||
|
||
MetadataChanges metadataChanges = | ||
(Boolean) Objects.requireNonNull(argumentsMap.get("includeMetadataChanges")) | ||
? MetadataChanges.INCLUDE | ||
: MetadataChanges.EXCLUDE; | ||
|
||
Query query = (Query) argumentsMap.get("query"); | ||
|
||
if (query == null) { | ||
throw new IllegalArgumentException( | ||
"An error occurred while parsing query arguments, see native logs for more information. Please report this issue."); | ||
} | ||
|
||
listenerRegistration = | ||
query.addSnapshotListener( | ||
metadataChanges, | ||
(querySnapshot, exception) -> { | ||
if (exception != null) { | ||
Map<String, String> exceptionDetails = ExceptionConverter.createDetails(exception); | ||
events.error(DEFAULT_ERROR_CODE, exception.getMessage(), exceptionDetails); | ||
events.endOfStream(); | ||
|
||
onCancel(null); | ||
} else { | ||
events.success(querySnapshot); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onCancel(Object arguments) { | ||
if (listenerRegistration != null) { | ||
listenerRegistration.remove(); | ||
listenerRegistration = null; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ava/io/flutter/plugins/firebase/firestore/streamhandler/SnapshotsInSyncStreamHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.flutter.plugins.firebase.firestore.streamhandler; | ||
|
||
import com.google.firebase.firestore.FirebaseFirestore; | ||
import com.google.firebase.firestore.ListenerRegistration; | ||
import io.flutter.plugin.common.EventChannel.EventSink; | ||
import io.flutter.plugin.common.EventChannel.StreamHandler; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class SnapshotsInSyncStreamHandler implements StreamHandler { | ||
|
||
ListenerRegistration listenerRegistration; | ||
|
||
@Override | ||
public void onListen(Object arguments, EventSink events) { | ||
@SuppressWarnings("unchecked") | ||
Map<String, Object> argumentsMap = (Map<String, Object>) arguments; | ||
|
||
FirebaseFirestore firestore = | ||
(FirebaseFirestore) Objects.requireNonNull(argumentsMap.get("firestore")); | ||
|
||
Runnable snapshotsInSyncRunnable = () -> events.success(null); | ||
|
||
listenerRegistration = firestore.addSnapshotsInSyncListener(snapshotsInSyncRunnable); | ||
} | ||
|
||
@Override | ||
public void onCancel(Object arguments) { | ||
if (listenerRegistration != null) { | ||
listenerRegistration.remove(); | ||
listenerRegistration = null; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.