|
1 | 1 | package com.zulip.android.networking;
|
2 | 2 |
|
3 |
| -import java.io.IOException; |
4 |
| -import java.net.SocketTimeoutException; |
5 |
| -import java.sql.SQLException; |
6 |
| -import java.util.ArrayList; |
7 |
| -import java.util.HashMap; |
8 |
| -import java.util.concurrent.Callable; |
9 |
| - |
10 |
| -import org.apache.commons.lang.time.StopWatch; |
11 |
| -import org.json.JSONArray; |
12 |
| -import org.json.JSONException; |
13 |
| -import org.json.JSONObject; |
14 |
| - |
15 | 3 | import android.content.Intent;
|
16 | 4 | import android.os.SystemClock;
|
17 | 5 | import android.util.Log;
|
18 | 6 |
|
19 | 7 | import com.j256.ormlite.dao.RuntimeExceptionDao;
|
20 | 8 | import com.j256.ormlite.misc.TransactionManager;
|
| 9 | +import com.zulip.android.ZulipApp; |
| 10 | +import com.zulip.android.activities.ZulipActivity; |
21 | 11 | import com.zulip.android.models.Message;
|
22 | 12 | import com.zulip.android.models.MessageRange;
|
23 | 13 | import com.zulip.android.models.Person;
|
24 | 14 | import com.zulip.android.models.Stream;
|
25 | 15 | import com.zulip.android.util.ZLog;
|
| 16 | + |
| 17 | +import org.apache.commons.lang.time.StopWatch; |
| 18 | +import org.json.JSONArray; |
| 19 | +import org.json.JSONException; |
| 20 | +import org.json.JSONObject; |
| 21 | + |
| 22 | +import java.io.IOException; |
| 23 | +import java.net.SocketTimeoutException; |
| 24 | +import java.sql.SQLException; |
| 25 | +import java.util.ArrayList; |
| 26 | +import java.util.HashMap; |
| 27 | +import java.util.concurrent.Callable; |
26 | 28 | import com.zulip.android.activities.ZulipActivity;
|
27 | 29 | import com.zulip.android.ZulipApp;
|
28 | 30 | import com.zulip.android.widget.ZulipWidget;
|
@@ -104,21 +106,23 @@ private void register() throws JSONException, IOException {
|
104 | 106 | StopWatch watch = new StopWatch();
|
105 | 107 | watch.start();
|
106 | 108 | request.setMethodAndUrl("POST", "v1/register");
|
107 |
| - String responseData = request.execute().body().string(); |
| 109 | + Response responseData = request.execute(); |
108 | 110 | watch.stop();
|
109 | 111 | Log.i("perf", "net: v1/register: " + watch.toString());
|
110 | 112 |
|
111 | 113 | watch.reset();
|
112 | 114 | watch.start();
|
113 |
| - JSONObject response = new JSONObject(responseData); |
| 115 | + JSONObject response = new JSONObject(responseData.body().toString()); |
114 | 116 | watch.stop();
|
115 | 117 | Log.i("perf", "json: v1/register: " + watch.toString());
|
116 | 118 |
|
117 |
| - registeredOrGotEventsThisRun = true; |
118 |
| - app.setEventQueueId(response.getString("queue_id")); |
119 |
| - app.setLastEventId(response.getInt("last_event_id")); |
| 119 | + if(responseData.isSuccessful()) { |
| 120 | + registeredOrGotEventsThisRun = true; |
| 121 | + app.setEventQueueId(response.getString("queue_id")); |
| 122 | + app.setLastEventId(response.getInt("last_event_id")); |
120 | 123 |
|
121 |
| - processRegister(response); |
| 124 | + processRegister(response); |
| 125 | + } |
122 | 126 | }
|
123 | 127 |
|
124 | 128 | public void run() {
|
|
0 commit comments