Skip to content

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 62 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
6de525c
Bump Podfile
Nov 24, 2020
e45992d
Ensure example uses platform interface from the repo instead of pub
Nov 24, 2020
26aa040
Move QuerySnapshot handling into EventChannel
Nov 24, 2020
13fd053
Formatting
Nov 24, 2020
e1fb4a9
Remove unused methods
Nov 24, 2020
d081def
Forward errors
Nov 24, 2020
067fae2
Move document snapshot listener to event channel as well
Nov 24, 2020
14b77b7
Move snapshotInSync listener to EventChannel
Nov 24, 2020
f44b877
iOS || macOS
Nov 24, 2020
a0de5b5
Perform transaction handling via EventChannel as well
Nov 24, 2020
1d215f7
initialize dictionaries
Nov 24, 2020
b73d2d2
remove now-unused method
Nov 24, 2020
79fcbe8
+/- comments
Nov 24, 2020
c5edfec
finally remove the channel reference
Nov 24, 2020
eda9935
Merge branch 'master' into fix/4108-cloud-firestore
Nov 25, 2020
f72f59a
Typo
Nov 26, 2020
08c77fd
begin android implementation
Nov 26, 2020
c308e3f
migrate query snapshots
Nov 26, 2020
6a83d4d
Remove now-unused code
Nov 26, 2020
ad7769d
Document Snapshots
Nov 26, 2020
3aa91f3
Transactions
Nov 26, 2020
22aeea1
Formatting
Nov 26, 2020
80fd511
Remove now unused classes
ened Nov 28, 2020
882cb0d
Refactor & cleanup
ened Nov 28, 2020
5e8e6b5
remove removeListener
ened Nov 28, 2020
eb302ba
Merge branch 'master' of https://github.com/FirebaseExtended/flutterf…
ened Nov 28, 2020
a86224d
Correct merge
ened Nov 28, 2020
8825473
Create a event channel per transaction
ened Nov 28, 2020
c5cfabc
Move iOS side to the new mechanism as well
ened Nov 28, 2020
9af41ee
Formatting
ened Nov 28, 2020
05e2c3d
unused import
ened Nov 28, 2020
bb41893
reactivate all tests
ened Nov 28, 2020
83753f7
ios fixes
ened Nov 28, 2020
fc0d8b0
cleanup dart side
ened Nov 28, 2020
bf907d9
formatting
ened Nov 28, 2020
0c1d7ae
cleanups
ened Nov 29, 2020
db10057
Merge branch 'master' into fix/4108-cloud-firestore
Dec 2, 2020
e40ddec
Add new failing tests
Dec 2, 2020
d6e39e1
Replace static with dedicated event channel instances
Dec 2, 2020
f33de5f
Dart tests V1
Dec 2, 2020
1ba6f0c
Extend Dart tests
Dec 2, 2020
ce15e2b
analyzer
Dec 2, 2020
46e8688
Restore link
ened Dec 3, 2020
04b099a
Formatting, android cleanup
Dec 7, 2020
f44288a
revert podfile change
Dec 7, 2020
e4a25a2
Remove print
Dec 7, 2020
616f08b
typo
Dec 7, 2020
11a729e
remove unnecessary test
Dec 7, 2020
4b781e8
Merge branch 'master' into fix/4108-cloud-firestore
Dec 17, 2020
46a3088
Merge branch 'master' into fix/4108-cloud-firestore
ened Dec 27, 2020
384a44a
formatting
ened Dec 27, 2020
1f74a61
fix tests
ened Dec 27, 2020
84b678d
java format
ened Dec 27, 2020
f8d6312
Clear transactionHandlers when plugin is destroyed
ened Dec 27, 2020
1be114c
Address PR feedback
ened Dec 27, 2020
20cf2ee
Introduce additional interface to cleanup transaction result listener…
ened Dec 27, 2020
bde86ea
Stop document/query stream listeners once error occured
ened Dec 27, 2020
dbbb837
Add multi-transaction case
ened Dec 27, 2020
cd4f9fb
Remove unused import
ened Dec 28, 2020
49505e2
Address PR feedback
ened Jan 7, 2021
c752e3a
include remaining test in refactor
ened Jan 7, 2021
49e23be
Merge branch 'master' into fix/4108-cloud-firestore
Salakar Jan 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class FlutterFirebaseFirestoreException extends Exception {
public class FlutterFirebaseFirestoreException extends Exception {
private static final String ERROR_ABORTED =
"The operation was aborted, typically due to a concurrency issue like transaction aborts, etc.";
private static final String ERROR_ALREADY_EXISTS =
Expand Down Expand Up @@ -42,7 +42,8 @@ class FlutterFirebaseFirestoreException extends Exception {
private final String code;
private final String message;

FlutterFirebaseFirestoreException(FirebaseFirestoreException nativeException, Throwable cause) {
public FlutterFirebaseFirestoreException(
FirebaseFirestoreException nativeException, Throwable cause) {
super(nativeException != null ? nativeException.getMessage() : "", cause);

String code = null;
Expand Down

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

class FlutterFirebaseFirestoreTransactionResult {
final @Nullable Exception exception;
public class FlutterFirebaseFirestoreTransactionResult {

public final @Nullable Exception exception;

private FlutterFirebaseFirestoreTransactionResult(@NonNull Exception failureException) {
exception = failureException;
Expand All @@ -18,11 +19,11 @@ private FlutterFirebaseFirestoreTransactionResult() {
exception = null;
}

static FlutterFirebaseFirestoreTransactionResult failed(@NonNull Exception exception) {
public static FlutterFirebaseFirestoreTransactionResult failed(@NonNull Exception exception) {
return new FlutterFirebaseFirestoreTransactionResult(exception);
}

static FlutterFirebaseFirestoreTransactionResult complete() {
public static FlutterFirebaseFirestoreTransactionResult complete() {
return new FlutterFirebaseFirestoreTransactionResult();
}
}
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;
}
}
}
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);
}
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;
}
}
}
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;
}
}
}
Loading