Skip to content

Commit 6df6a81

Browse files
committed
Bring Java responses more in line with iOS
1 parent f6aaee5 commit 6df6a81

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

android/src/main/java/io/fullstack/firestack/database/FirestackDatabase.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
159159
} else {
160160
Log.d(TAG, "No value passed to push: " + newPath);
161161
WritableMap res = Arguments.createMap();
162-
res.putString("result", "success");
162+
res.putString("status", "success");
163163
res.putString("ref", newPath);
164164
callback.invoke(null, res);
165165
}
@@ -180,7 +180,7 @@ public void on(final String path,
180180
}
181181

182182
WritableMap resp = Arguments.createMap();
183-
resp.putString("result", "success");
183+
resp.putString("status", "success");
184184
resp.putString("handle", path);
185185
callback.invoke(null, resp);
186186
}
@@ -205,13 +205,31 @@ public void onOnce(final String path,
205205
public void off(
206206
final String path,
207207
final String modifiersString,
208-
@Deprecated final String name,
208+
final String name,
209209
final Callback callback) {
210-
this.removeDBHandle(path, modifiersString);
210+
211+
String key = this.getDBListenerKey(path, modifiersString);
212+
FirestackDatabaseReference r = mDBListeners.get(key);
213+
214+
if (r != null) {
215+
if (name == null || "".equals(name)) {
216+
r.cleanup();
217+
mDBListeners.remove(key);
218+
} else {
219+
//TODO: Remove individual listeners as per iOS code
220+
//1) Remove event handler
221+
//2) If no more listeners, remove from listeners map
222+
r.cleanup();
223+
mDBListeners.remove(key);
224+
}
225+
}
226+
211227
Log.d(TAG, "Removed listener " + path + "/" + modifiersString);
212228
WritableMap resp = Arguments.createMap();
213229
resp.putString("handle", path);
214-
resp.putString("result", "success");
230+
resp.putString("status", "success");
231+
resp.putString("modifiersString", modifiersString);
232+
//TODO: Remaining listeners
215233
callback.invoke(null, resp);
216234
}
217235

@@ -304,14 +322,4 @@ private FirestackDatabaseReference getDBHandle(final String path,
304322
private String getDBListenerKey(String path, String modifiersString) {
305323
return path + " | " + modifiersString;
306324
}
307-
308-
private void removeDBHandle(final String path, String modifiersString) {
309-
String key = this.getDBListenerKey(path, modifiersString);
310-
FirestackDatabaseReference r = mDBListeners.get(key);
311-
312-
if (r != null) {
313-
r.cleanup();
314-
mDBListeners.remove(key);
315-
}
316-
}
317325
}

android/src/main/java/io/fullstack/firestack/database/FirestackDatabaseReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void onCancelled(DatabaseError error) {
9292
Log.d(TAG, "Added ValueEventListener for path: " + mPath + " with modifiers: "+ mModifiersString);
9393
//this.setListeningTo(mPath, modifiersString, "value");
9494
} else {
95-
Log.w(TAG, "trying to add duplicate ValueEventListener for path: " + mPath + " with modifiers: "+ mModifiersString);
95+
Log.w(TAG, "Trying to add duplicate ValueEventListener for path: " + mPath + " with modifiers: "+ mModifiersString);
9696
}
9797
}
9898

0 commit comments

Comments
 (0)