Skip to content

Commit

Permalink
[firestore] update sdks and implement FieldValue.increment & Timestam…
Browse files Browse the repository at this point in the history
…p support

[skip ci]
  • Loading branch information
Salakar committed Apr 6, 2019
1 parent 85dc8cc commit b84473f
Show file tree
Hide file tree
Showing 21 changed files with 816 additions and 548 deletions.
26 changes: 13 additions & 13 deletions android/build.gradle
Expand Up @@ -143,8 +143,8 @@ dependencies {

// Required dependencies
//noinspection GradleCompatible
compileOnly "com.google.firebase:firebase-core:16.0.6"
compileOnly "com.google.android.gms:play-services-base:16.0.1"
compileOnly "com.google.firebase:firebase-core:16.0.8"
compileOnly "com.google.android.gms:play-services-base:16.1.0"

/* -------------------------
* OPTIONAL FIREBASE SDKS
Expand All @@ -157,27 +157,27 @@ dependencies {
exclude group: 'com.android.support', module: 'customtabs'
}
// Authentication
compileOnly "com.google.firebase:firebase-auth:16.1.0"
compileOnly "com.google.firebase:firebase-auth:16.2.0"
// Analytics
compileOnly "com.google.firebase:firebase-analytics:16.0.6"
compileOnly "com.google.firebase:firebase-analytics:16.4.0"
// Performance Monitoring
compileOnly "com.google.firebase:firebase-perf:16.2.3"
compileOnly "com.google.firebase:firebase-perf:16.2.4"
// Remote Config
compileOnly "com.google.firebase:firebase-config:16.1.2"
compileOnly "com.google.firebase:firebase-config:16.4.1"
// Cloud Storage
compileOnly "com.google.firebase:firebase-storage:16.0.5"
compileOnly "com.google.firebase:firebase-storage:16.1.0"
// Invites
compileOnly "com.google.firebase:firebase-invites:16.0.6"
compileOnly "com.google.firebase:firebase-invites:16.1.1"
// Dynamic Links
compileOnly "com.google.firebase:firebase-dynamic-links:16.1.5"
compileOnly "com.google.firebase:firebase-dynamic-links:16.1.8"
// Real-time Database
compileOnly "com.google.firebase:firebase-database:16.0.5"
compileOnly "com.google.firebase:firebase-database:16.1.0"
// Cloud Functions
compileOnly "com.google.firebase:firebase-functions:16.1.3"
compileOnly "com.google.firebase:firebase-functions:16.3.0"
// Cloud Firestore
compileOnly "com.google.firebase:firebase-firestore:17.1.5"
compileOnly "com.google.firebase:firebase-firestore:18.2.0"
// Cloud Messaging / FCM
compileOnly "com.google.firebase:firebase-messaging:17.3.4"
compileOnly "com.google.firebase:firebase-messaging:17.5.0"
// Crashlytics
compileOnly('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') {
transitive = true
Expand Down
Expand Up @@ -9,6 +9,7 @@
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.google.firebase.Timestamp;
import com.google.firebase.firestore.Blob;
import com.google.firebase.firestore.DocumentChange;
import com.google.firebase.firestore.DocumentReference;
Expand Down Expand Up @@ -41,6 +42,8 @@ class FirestoreSerialize {
private static final String KEY_META = "metadata";
private static final String KEY_CHANGES = "changes";
private static final String KEY_OPTIONS = "options";
private static final String KEY_SECONDS = "seconds";
private static final String KEY_NANOSECONDS = "nanoseconds";
private static final String KEY_LATITUDE = "latitude";
private static final String KEY_LONGITUDE = "longitude";
private static final String KEY_DOCUMENTS = "documents";
Expand All @@ -62,12 +65,14 @@ class FirestoreSerialize {
private static final String TYPE_OBJECT = "object";
private static final String TYPE_BOOLEAN = "boolean";
private static final String TYPE_GEOPOINT = "geopoint";
private static final String TYPE_TIMESTAMP = "timestamp";
private static final String TYPE_INFINITY = "infinity";
private static final String TYPE_REFERENCE = "reference";
private static final String TYPE_DOCUMENTID = "documentid";
private static final String TYPE_FIELDVALUE = "fieldvalue";
private static final String TYPE_FIELDVALUE_DELETE = "delete";
private static final String TYPE_FIELDVALUE_TIMESTAMP = "timestamp";
private static final String TYPE_FIELDVALUE_INCREMENT = "increment";
private static final String TYPE_FIELDVALUE_UNION = "union";
private static final String TYPE_FIELDVALUE_REMOVE = "remove";
private static final String TYPE_FIELDVALUE_TYPE = "type";
Expand Down Expand Up @@ -95,8 +100,9 @@ static WritableMap snapshotToWritableMap(DocumentSnapshot documentSnapshot) {

documentMap.putMap(KEY_META, metadata);
documentMap.putString(KEY_PATH, documentSnapshot.getReference().getPath());
if (documentSnapshot.exists())
if (documentSnapshot.exists()) {
documentMap.putMap(KEY_DATA, objectMapToWritable(documentSnapshot.getData()));
}

return documentMap;
}
Expand Down Expand Up @@ -311,6 +317,18 @@ private static WritableMap buildTypeMap(Object value) {
return typeMap;
}


if (value instanceof Timestamp) {
WritableMap timestampMap = Arguments.createMap();

timestampMap.putDouble(KEY_SECONDS, ((Timestamp) value).getSeconds());
timestampMap.putInt(KEY_NANOSECONDS, ((Timestamp) value).getNanoseconds());

typeMap.putString(TYPE, TYPE_TIMESTAMP);
typeMap.putMap(VALUE, timestampMap);
return typeMap;
}

if (value instanceof GeoPoint) {
WritableMap geoPoint = Arguments.createMap();

Expand Down Expand Up @@ -449,6 +467,15 @@ static Object parseTypeMap(FirebaseFirestore firestore, ReadableMap typeMap) {
return firestore.document(path);
}

if (TYPE_TIMESTAMP.equals(type)) {
ReadableMap timestampMap = typeMap.getMap(VALUE);

return new Timestamp(
(long) timestampMap.getDouble(KEY_SECONDS),
timestampMap.getInt(KEY_NANOSECONDS)
);
}

if (TYPE_FIELDVALUE.equals(type)) {
ReadableMap fieldValueMap = typeMap.getMap(VALUE);
String fieldValueType = fieldValueMap.getString(TYPE_FIELDVALUE_TYPE);
Expand All @@ -457,6 +484,10 @@ static Object parseTypeMap(FirebaseFirestore firestore, ReadableMap typeMap) {
return FieldValue.serverTimestamp();
}

if (TYPE_FIELDVALUE_INCREMENT.equals(fieldValueType)) {
return FieldValue.increment(fieldValueMap.getDouble(TYPE_FIELDVALUE_ELEMENTS));
}

if (TYPE_FIELDVALUE_DELETE.equals(fieldValueType)) {
return FieldValue.delete();
}
Expand Down
Expand Up @@ -456,9 +456,9 @@ public void settings(String appName, ReadableMap settings, final Promise promise
.isSslEnabled());
}

// if (settings.hasKey("timestampsInSnapshots")) {
// // TODO: Not supported on Android yet
// }
if (settings.hasKey("timestampsInSnapshots")) {
firestoreSettings.setTimestampsInSnapshotsEnabled(settings.getBoolean("timestampsInSnapshots"));
}

firestore.setFirestoreSettings(firestoreSettings.build());
promise.resolve(null);
Expand Down
Expand Up @@ -26,7 +26,6 @@

import io.invertase.firebase.Utils;


public class RNFirebaseFirestoreDocumentReference {
private static final String TAG = "RNFBFSDocumentReference";
private static Map<String, ListenerRegistration> documentSnapshotListeners = new HashMap<>();
Expand Down
3 changes: 1 addition & 2 deletions ios/RNFirebase/firestore/RNFirebaseFirestore.m
Expand Up @@ -384,8 +384,7 @@ - (id)init {
firestoreSettings.sslEnabled = firestore.settings.sslEnabled;
}
if (settings[@"timestampsInSnapshots"]) {
// TODO: Enable when available on Android
// firestoreSettings.timestampsInSnapshotsEnabled = settings[@"timestampsInSnapshots"];
firestoreSettings.timestampsInSnapshotsEnabled = settings[@"timestampsInSnapshots"];
}

[firestore setSettings:firestoreSettings];
Expand Down

0 comments on commit b84473f

Please sign in to comment.