Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cf89dc5
using local paths
bswhite1 Jul 20, 2021
eab79b4
checking in stuff to run a custom firebase-android-sdk
bswhite1 Jul 22, 2021
2e751ed
Merge branch 'master' of github.com:bswhite1/flutterfire into master_…
bswhite1 Nov 22, 2021
14e9811
adding paths
bswhite1 Nov 24, 2021
75268d4
Merge branch 'master' of https://github.com/FirebaseExtended/flutterf…
bswhite1 Feb 24, 2022
d8c2f3e
Merge branch 'FirebaseExtended-master' into master_w_local_paths
bswhite1 Feb 24, 2022
fff0d79
old files
bswhite1 May 11, 2022
413d9cd
Merge branch 'master' of github.com:bswhite1/flutterfire into master_…
bswhite1 Dec 22, 2022
42ab1bc
fixing firebase_appinstallations links
bswhite1 Dec 22, 2022
dd255ec
fixing merge issue
bswhite1 Dec 22, 2022
bdd6164
stuff
bswhite1 Mar 24, 2023
6915d3a
Merge branch 'master' of github.com:bswhite1/flutterfire into master_…
bswhite1 Mar 24, 2023
d7cfc85
fixing merge
bswhite1 Mar 24, 2023
a68b207
updating version and error handling
bswhite1 Apr 28, 2023
b7eb7fc
Merge branch 'master' of github.com:bswhite1/flutterfire into master_…
bswhite1 Apr 28, 2023
7eb567f
testing overnight with 1.8.3+148
bswhite1 May 9, 2023
be8812a
Code cleanup
bswhite1 May 22, 2023
12453f7
code cleanup
bswhite1 May 22, 2023
35beb5a
putting most paths back to versions
bswhite1 May 22, 2023
1530c89
yaml cleanup
bswhite1 May 22, 2023
1126bae
fixing cloud_firestore_web dependancy
bswhite1 May 22, 2023
3e29e2c
more dependacy
bswhite1 May 22, 2023
f96a2c7
code cleanup
bswhite1 May 23, 2023
f4b4c53
using local version of android sdk
bswhite1 Jun 1, 2023
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 @@ -50,7 +50,8 @@ android {
dependencies {
api firebaseCoreProject
implementation platform("com.google.firebase:firebase-bom:${getRootProjectExtOrCoreProperty("FirebaseSDKVersion", firebaseCoreProject)}")
implementation 'com.google.firebase:firebase-firestore'
// implementation 'com.google.firebase:firebase-firestore'
implementation 'com.google.firebase:firebase-firestore:24.6.1-a'
implementation 'androidx.annotation:annotation:1.2.0'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.firebase.firestore.QuerySnapshot;
import com.google.firebase.firestore.SnapshotMetadata;
import io.flutter.plugin.common.StandardMessageCodec;
import io.flutter.plugins.firebase.firestore.streamhandler.QuerySnapshotWrapper;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
Expand Down Expand Up @@ -74,6 +75,8 @@ protected void writeValue(ByteArrayOutputStream stream, Object value) {
writeValue(stream, ((DocumentReference) value).getPath());
} else if (value instanceof DocumentSnapshot) {
writeDocumentSnapshot(stream, (DocumentSnapshot) value);
} else if (value instanceof QuerySnapshotWrapper) {
writeQuerySnapshotWrapper(stream, (QuerySnapshotWrapper) value);
} else if (value instanceof QuerySnapshot) {
writeQuerySnapshot(stream, (QuerySnapshot) value);
} else if (value instanceof DocumentChange) {
Expand Down Expand Up @@ -163,6 +166,15 @@ private void writeQuerySnapshot(ByteArrayOutputStream stream, QuerySnapshot valu
writeValue(stream, querySnapshotMap);
}

private void writeQuerySnapshotWrapper(ByteArrayOutputStream stream, QuerySnapshotWrapper value) {
Map<String, Object> querySnapshotChangesMap = new HashMap<>();

querySnapshotChangesMap.put("documentChanges", value.getDocumentChanges());
querySnapshotChangesMap.put("metadata", value.getMetadata());

writeValue(stream, querySnapshotChangesMap);
}

private void writeLoadBundleTaskProgress(
ByteArrayOutputStream stream, LoadBundleTaskProgress snapshot) {
Map<String, Object> snapshotMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import io.flutter.plugins.firebase.firestore.streamhandler.LoadBundleStreamHandler;
import io.flutter.plugins.firebase.firestore.streamhandler.OnTransactionResultListener;
import io.flutter.plugins.firebase.firestore.streamhandler.QuerySnapshotsStreamHandler;
import io.flutter.plugins.firebase.firestore.streamhandler.QuerySnapshotChangesStreamHandler;
import io.flutter.plugins.firebase.firestore.streamhandler.SnapshotsInSyncStreamHandler;
import io.flutter.plugins.firebase.firestore.streamhandler.TransactionStreamHandler;
import io.flutter.plugins.firebase.firestore.utils.ExceptionConverter;
Expand Down Expand Up @@ -184,6 +185,42 @@ private Task<Void> enableNetwork(Map<String, Object> arguments) {
return taskCompletionSource.getTask();
}

private Task<Void> enableDebugging(Map<String, Object> arguments) {
TaskCompletionSource<Void> taskCompletionSource = new TaskCompletionSource<>();

cachedThreadPool.execute(
() -> {
try {
FirebaseFirestore firestore =
(FirebaseFirestore) Objects.requireNonNull(arguments.get("firestore"));
firestore.setLoggingEnabled(true);
taskCompletionSource.setResult(null);
} catch (Exception e) {
taskCompletionSource.setException(e);
}
});

return taskCompletionSource.getTask();
}

private Task<Void> disableDebugging(Map<String, Object> arguments) {
TaskCompletionSource<Void> taskCompletionSource = new TaskCompletionSource<>();

cachedThreadPool.execute(
() -> {
try {
FirebaseFirestore firestore =
(FirebaseFirestore) Objects.requireNonNull(arguments.get("firestore"));
firestore.setLoggingEnabled(false);
taskCompletionSource.setResult(null);
} catch (Exception e) {
taskCompletionSource.setException(e);
}
});

return taskCompletionSource.getTask();
}

private Task<DocumentSnapshot> transactionGet(Map<String, Object> arguments) {
TaskCompletionSource<DocumentSnapshot> taskCompletionSource = new TaskCompletionSource<>();

Expand Down Expand Up @@ -582,6 +619,12 @@ public void onMethodCall(MethodCall call, @NonNull final MethodChannel.Result re
case "Firestore#enableNetwork":
methodCallTask = enableNetwork(call.arguments());
break;
case "Firestore#enableDebugging":
methodCallTask = enableDebugging(call.arguments());
break;
case "Firestore#disableDebugging":
methodCallTask = disableDebugging(call.arguments());
break;
case "Transaction#get":
methodCallTask = transactionGet(call.arguments());
break;
Expand Down Expand Up @@ -610,6 +653,11 @@ public void onMethodCall(MethodCall call, @NonNull final MethodChannel.Result re
registerEventChannel(
METHOD_CHANNEL_NAME + "/query", new QuerySnapshotsStreamHandler()));
return;
case "Query#snapshotChanges":
result.success(
registerEventChannel(
METHOD_CHANNEL_NAME + "/query", new QuerySnapshotChangesStreamHandler()));
return;
case "DocumentReference#snapshots":
result.success(
registerEventChannel(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2022, the Chromium project authors. Please see the AUTHORS file
* for details. All rights reserved. Use of this source code is governed by a
* BSD-style license that can be found in the LICENSE file.
*/

package io.flutter.plugins.firebase.firestore.streamhandler;

import static io.flutter.plugins.firebase.firestore.FlutterFirebaseFirestorePlugin.DEFAULT_ERROR_CODE;

import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.ListenerRegistration;
import com.google.firebase.firestore.MetadataChanges;
import com.google.firebase.firestore.Query;
import com.google.firebase.firestore.QuerySnapshot;
import io.flutter.plugin.common.EventChannel.EventSink;
import io.flutter.plugin.common.EventChannel.StreamHandler;
import io.flutter.plugins.firebase.firestore.FlutterFirebaseFirestorePlugin;
import io.flutter.plugins.firebase.firestore.utils.ExceptionConverter;
import io.flutter.plugins.firebase.firestore.utils.ServerTimestampBehaviorConverter;
import java.util.Map;
import java.util.Objects;
import android.util.Log;

public class QuerySnapshotChangesStreamHandler 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");
String serverTimestampBehaviorString = (String) argumentsMap.get("serverTimestampBehavior");
DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior =
ServerTimestampBehaviorConverter.toServerTimestampBehavior(serverTimestampBehaviorString);

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();

Log.e(
"QuerySnapshotChangesStreamHandler",
"OnListen exception: " + exception.getMessage());

onCancel(null);
} else {
if (querySnapshot != null) {
FlutterFirebaseFirestorePlugin.serverTimestampBehaviorHashMap.put(
querySnapshot.hashCode(), serverTimestampBehavior);
}

QuerySnapshotWrapper wrappedQuerySnapshot = new QuerySnapshotWrapper(querySnapshot);
events.success((QuerySnapshotWrapper) wrappedQuerySnapshot);
}
});
}

@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,145 @@
// Wrapper for com.google.firebase.firestore.QuerySnapshot, since it does
// not have a public constructor at this time.

// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package io.flutter.plugins.firebase.firestore.streamhandler;

import com.google.firebase.firestore.QuerySnapshot;
import static com.google.firebase.firestore.util.Preconditions.checkNotNull;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.firebase.firestore.DocumentChange;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.MetadataChanges;
import com.google.firebase.firestore.Query;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.SnapshotMetadata;
import com.google.firebase.firestore.core.ViewSnapshot;
import com.google.firebase.firestore.model.Document;

import java.util.Iterator;
import java.util.List;

public class QuerySnapshotWrapper {
private final QuerySnapshot querySnapshot;

public QuerySnapshotWrapper(QuerySnapshot querySnapshot) {
this.querySnapshot = checkNotNull(querySnapshot);
}

@NonNull
public Query getQuery() {
return querySnapshot.getQuery();
}

/** @return The metadata for this query snapshot. */
@NonNull
public SnapshotMetadata getMetadata() {
return querySnapshot.getMetadata();
}

/**
* Returns the list of documents that changed since the last snapshot. If it's the first snapshot
* all documents will be in the list as added changes.
*
* <p>Documents with changes only to their metadata will not be included.
*
* @return The list of document changes since the last snapshot.
*/
@NonNull
public List<DocumentChange> getDocumentChanges() {
return querySnapshot.getDocumentChanges();
}

/**
* Returns the list of documents that changed since the last snapshot. If it's the first snapshot
* all documents will be in the list as added changes.
*
* @param metadataChanges Indicates whether metadata-only changes (i.e. only {@code
* DocumentSnapshot.getMetadata()} changed) should be included.
* @return The list of document changes since the last snapshot.
*/
@NonNull
public List<DocumentChange> getDocumentChanges(@NonNull MetadataChanges metadataChanges) {

return querySnapshot.getDocumentChanges(metadataChanges);
}

/**
* Returns the documents in this {@code QuerySnapshot} as a List in order of the query.
*
* @return The list of documents.
*/
@NonNull
public List<DocumentSnapshot> getDocuments() {

return querySnapshot.getDocuments();
}

/** Returns true if there are no documents in the {@code QuerySnapshot}. */
public boolean isEmpty() {
return querySnapshot.isEmpty();
}

/** Returns the number of documents in the {@code QuerySnapshot}. */
public int size() {
return querySnapshot.size();
}

@NonNull
public Iterator<QueryDocumentSnapshot> iterator() {
return querySnapshot.iterator();
}

/**
* Returns the contents of the documents in the {@code QuerySnapshot}, converted to the provided
* class, as a list.
*
* @param clazz The POJO type used to convert the documents in the list.
*/
@NonNull
public <T> List<T> toObjects(@NonNull Class<T> clazz) {
return querySnapshot.toObjects(clazz);
}

/**
* Returns the contents of the documents in the {@code QuerySnapshot}, converted to the provided
* class, as a list.
*
* @param clazz The POJO type used to convert the documents in the list.
* @param serverTimestampBehavior Configures the behavior for server timestamps that have not yet
* been set to their final value.
*/
@NonNull
public <T> List<T> toObjects(
@NonNull Class<T> clazz,
@NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior) {

return querySnapshot.toObjects(clazz, serverTimestampBehavior);
}

@Override
public boolean equals(@Nullable Object obj) {
return querySnapshot.equals(obj);
}

@Override
public int hashCode() {
return querySnapshot.hashCode();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.flutter.plugins.firebase.firestore.utils.ServerTimestampBehaviorConverter;
import java.util.Map;
import java.util.Objects;
import android.util.Log;

public class QuerySnapshotsStreamHandler implements StreamHandler {

Expand Down Expand Up @@ -53,12 +54,17 @@ public void onListen(Object arguments, EventSink events) {
events.error(DEFAULT_ERROR_CODE, exception.getMessage(), exceptionDetails);
events.endOfStream();

Log.e(
"QuerySnapshotsStreamHandler",
"OnListen exception: " + exception.getMessage());

onCancel(null);
} else {
if (querySnapshot != null) {
FlutterFirebaseFirestorePlugin.serverTimestampBehaviorHashMap.put(
querySnapshot.hashCode(), serverTimestampBehavior);
}

events.success(querySnapshot);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ part 'src/load_bundle_task_snapshot.dart';
part 'src/query.dart';
part 'src/query_document_snapshot.dart';
part 'src/query_snapshot.dart';
part 'src/query_snapshot_changes.dart';
part 'src/snapshot_metadata.dart';
part 'src/transaction.dart';
part 'src/utils/codec_utility.dart';
Expand Down
10 changes: 10 additions & 0 deletions packages/cloud_firestore/cloud_firestore/lib/src/firestore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ class FirebaseFirestore extends FirebasePluginPlatform {
return _delegate.enableNetwork();
}

/// Enables debugging for this instance.
Future<void> enableDebugging() {
return _delegate.enableDebugging();
}

/// Instructs [FirebaseFirestore] to disable the debugging for the instance.
Future<void> disableDebugging() {
return _delegate.disableDebugging();
}

/// Returns a [Stream] which is called each time all of the active listeners
/// have been synchronized.
Stream<void> snapshotsInSync() {
Expand Down
Loading