Skip to content

Commit 6f95882

Browse files
author
Joe Hansche
committed
Change to getCurrentSessionTokenAsync()
This allows the results to be chained together via tasks, and also allows the CurrentUserController to be overridden to provide additional functionality for retrieving the session token. This matches how the ParseCloud and ParseObject retrieve the session token.
1 parent 55fb3e5 commit 6f95882

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

ParseLiveQuery/src/main/java/com/parse/ParseLiveQueryClientImpl.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.parse;
22

3-
43
import android.util.Log;
54
import android.util.SparseArray;
65

@@ -179,7 +178,6 @@ private void parseMessage(String message) throws LiveQueryException {
179178
} catch (JSONException e) {
180179
throw new LiveQueryException.InvalidResponseException(message);
181180
}
182-
183181
}
184182

185183
private void handleSubscribedEvent(JSONObject jsonObject) throws JSONException {
@@ -237,8 +235,13 @@ private WebSocketClient.WebSocketClientCallback getWebSocketClientCallback() {
237235
@Override
238236
public void onOpen() {
239237
Log.v(LOG_TAG, "Socket opened");
240-
String sessionToken = ParseUser.getCurrentSessionToken();
241-
sendOperationAsync(new ConnectClientOperation(applicationId, sessionToken)).continueWith(new Continuation<Void, Void>() {
238+
ParseUser.getCurrentSessionTokenAsync().onSuccessTask(new Continuation<String, Task<Void>>() {
239+
@Override
240+
public Task<Void> then(Task<String> task) throws Exception {
241+
String sessionToken = task.getResult();
242+
return sendOperationAsync(new ConnectClientOperation(applicationId, sessionToken));
243+
}
244+
}).continueWith(new Continuation<Void, Void>() {
242245
public Void then(Task<Void> task) {
243246
Exception error = task.getError();
244247
if (error != null) {
@@ -279,5 +282,4 @@ public void stateChanged() {
279282
}
280283
};
281284
}
282-
283285
}

ParseLiveQuery/src/test/java/com/parse/TestParseLiveQueryClient.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class TestParseLiveQueryClient {
3737
private WebSocketClient webSocketClient;
3838
private WebSocketClient.WebSocketClientCallback webSocketClientCallback;
3939
private ParseLiveQueryClient<ParseObject> parseLiveQueryClient;
40+
4041
private ParseUser mockUser;
4142

4243
@Before
@@ -52,6 +53,12 @@ public Task<ParseUser> answer(InvocationOnMock invocation) throws Throwable {
5253
return Task.forResult(mockUser);
5354
}
5455
});
56+
when(currentUserController.getCurrentSessionTokenAsync()).thenAnswer(new Answer<Task<String>>() {
57+
@Override
58+
public Task<String> answer(InvocationOnMock invocation) throws Throwable {
59+
return Task.forResult(mockUser.getSessionToken());
60+
}
61+
});
5562
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);
5663

5764
parseLiveQueryClient = ParseLiveQueryClient.Factory.getClient(new URI(""), new WebSocketClientFactory() {

0 commit comments

Comments
 (0)