Commit 09780fe3 authored by Tiago Cunha's avatar Tiago Cunha

Added a solution for Settings and Preferences keys

Changed the way to identify an unread room
parent f2791a03
...@@ -146,7 +146,7 @@ public class RoomListManager { ...@@ -146,7 +146,7 @@ public class RoomListManager {
String type = roomSubscription.getType(); String type = roomSubscription.getType();
if (unreadRoomMode && roomSubscription.getUnread() > 0) { if (unreadRoomMode && roomSubscription.isAlert()) {
insertOrUpdateItem(unreadRoomsContainer, roomSubscription); insertOrUpdateItem(unreadRoomsContainer, roomSubscription);
removeItemIfExists(channelsContainer, name); removeItemIfExists(channelsContainer, name);
removeItemIfExists(dmContainer, name); removeItemIfExists(dmContainer, name);
......
package chat.rocket.android.model.ddp; package chat.rocket.android.model.ddp;
import io.realm.RealmObject; import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
public class Preferences extends RealmObject { public class Preferences extends RealmObject {
@PrimaryKey private String id;
private boolean newRoomNotification; private boolean newRoomNotification;
private boolean newMessageNotification; private boolean newMessageNotification;
private boolean useEmojis; private boolean useEmojis;
......
package chat.rocket.android.model.ddp; package chat.rocket.android.model.ddp;
import io.realm.RealmObject; import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
public class Settings extends RealmObject { public class Settings extends RealmObject {
@PrimaryKey private String id;
private Preferences preferences; private Preferences preferences;
public Preferences getPreferences() { public Preferences getPreferences() {
......
...@@ -3,6 +3,9 @@ package chat.rocket.android.service.ddp.base; ...@@ -3,6 +3,9 @@ package chat.rocket.android.service.ddp.base;
import android.content.Context; import android.content.Context;
import io.realm.RealmObject; import io.realm.RealmObject;
import org.json.JSONException;
import org.json.JSONObject;
import chat.rocket.android.api.DDPClientWrapper; import chat.rocket.android.api.DDPClientWrapper;
import chat.rocket.android.model.ddp.User; import chat.rocket.android.model.ddp.User;
import chat.rocket.android.realm_helper.RealmHelper; import chat.rocket.android.realm_helper.RealmHelper;
...@@ -30,4 +33,23 @@ public class UserDataSubscriber extends AbstractBaseSubscriber { ...@@ -30,4 +33,23 @@ public class UserDataSubscriber extends AbstractBaseSubscriber {
protected Class<? extends RealmObject> getModelClass() { protected Class<? extends RealmObject> getModelClass() {
return User.class; return User.class;
} }
@Override
protected JSONObject customizeFieldJson(JSONObject json) throws JSONException {
json = super.customizeFieldJson(json);
// The user object may have some children without a proper primary key (ex.: settings)
// Here we identify this and add a local key
if (json.has("settings")) {
final JSONObject settingsJson = json.getJSONObject("settings");
settingsJson.put("id", json.getString("_id"));
if (settingsJson.has("preferences")) {
final JSONObject preferencesJson = settingsJson.getJSONObject("preferences");
preferencesJson.put("id", json.getString("_id"));
}
}
return json;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment