Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit e370c9b

Browse files
koziodigitalincniftynei
authored andcommitted
Fixed up logic regarding error responses for event queue's in Async get events.
Removed authorship. Incremented db version.
1 parent b0f37f5 commit e370c9b

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

app/src/main/java/com/zulip/android/ZulipApp.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public class ZulipApp extends Application {
114114
*/
115115
public final Queue<Integer> unreadMessageQueue = new ConcurrentLinkedQueue<>();
116116
public String tester;
117+
private Gson gson;
117118

118119
public static ZulipApp get() {
119120
return instance;
@@ -193,15 +194,22 @@ public ZulipServices getZulipServices() {
193194
.addInterceptor(new ZulipInterceptor())
194195
.addInterceptor(logging)
195196
.build())
196-
.addConverterFactory(GsonConverterFactory.create(buildGson()))
197+
.addConverterFactory(GsonConverterFactory.create(getGson()))
197198
.baseUrl(getServerURI())
198199
.build()
199200
.create(ZulipServices.class);
200201
}
201202
return zulipServices;
202203
}
203204

204-
public Gson buildGson() {
205+
public Gson getGson() {
206+
if(gson == null) {
207+
gson = buildGson();
208+
}
209+
return gson;
210+
}
211+
212+
private Gson buildGson() {
205213
final Gson naiveGson = new GsonBuilder()
206214
.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
207215
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {

app/src/main/java/com/zulip/android/database/DatabaseHelper.java

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

3-
import java.sql.SQLException;
4-
53
import android.database.Cursor;
64
import android.database.sqlite.SQLiteDatabase;
75
import android.util.Log;
@@ -18,6 +16,8 @@
1816
import com.zulip.android.models.Stream;
1917
import com.zulip.android.util.MD5Util;
2018

19+
import java.sql.SQLException;
20+
2121
/**
2222
* Database helper class used to manage the creation and upgrading of your
2323
* database. This class also usually provides the DAOs used by the other
@@ -30,7 +30,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
3030
private static final String DATABASE_NAME = "zulip-%s.db";
3131
// any time you make changes to your database objects, you may have to
3232
// increase the database version
33-
private static final int DATABASE_VERSION = 5;
33+
private static final int DATABASE_VERSION = 6;
3434

3535
public DatabaseHelper(ZulipApp app, String email) {
3636
super(app, String.format(DATABASE_NAME, MD5Util.md5Hex(email)), null,

app/src/main/java/com/zulip/android/networking/AsyncGetEvents.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,14 @@ public void run() {
203203
.execute();
204204

205205
GetEventResponse body = eventResponse.body();
206+
206207
if (!eventResponse.isSuccessful()) {
207-
if (eventResponse.code() == 400 && ((body != null && body.getMsg().contains("Bad event queue id"))
208+
209+
NetworkError errorBody = eventResponse.errorBody() != null ?
210+
app.getGson().fromJson(eventResponse.errorBody().string(), NetworkError.class)
211+
: null;
212+
213+
if (eventResponse.code() == 400 && ((errorBody != null && errorBody.getMsg().contains("Bad event queue id"))
208214
|| eventResponse.message().contains("too old"))) {
209215
// Queue dead. Register again.
210216
Log.w(ASYNC_GET_EVENTS, "Queue dead");
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.zulip.android.networking;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
public class NetworkError {
6+
7+
@SerializedName("msg")
8+
private String msg;
9+
@SerializedName("result")
10+
private String result;
11+
12+
public String getResult() {
13+
return result;
14+
}
15+
16+
public String getMsg() {
17+
return msg;
18+
}
19+
}

0 commit comments

Comments
 (0)