Commit a2a23c21 authored by Tiago Cunha's avatar Tiago Cunha

New format on stuff, fixes

parent 0040eb30
......@@ -33,6 +33,14 @@ public class Migration implements RealmMigration {
.addField(RealmSpotlightRoom.Columns.ID, String.class, FieldAttribute.PRIMARY_KEY)
.addField(RealmSpotlightRoom.Columns.NAME, String.class)
.addField(RealmSpotlightRoom.Columns.TYPE, String.class);
oldVersion++;
}
if (oldVersion == 2) {
RealmObjectSchema roomSchema = schema.get("RealmSpotlightUser");
roomSchema.addField(RealmSpotlightUser.Columns.NAME, String.class);
}
}
}
......@@ -14,7 +14,9 @@ public class RealmStore {
return new RealmConfiguration.Builder()
.name(name + ".realm")
.modules(new RocketChatLibraryModule())
.deleteRealmIfMigrationNeeded().build();
.migration(new Migration())
.schemaVersion(3)
.build();
}
public static void put(String name) {
......
......@@ -15,7 +15,7 @@ public class RocketChatPersistenceRealm {
new RealmConfiguration.Builder()
.name("rocket.chat.persistence.realm")
.modules(new RocketChatLibraryModule())
.schemaVersion(2)
.schemaVersion(3)
.migration(new Migration())
.build());
}
......
......@@ -10,11 +10,13 @@ public class RealmSpotlightUser extends RealmObject {
public interface Columns {
String ID = "_id";
String USERNAME = "username";
String NAME = "name";
String STATUS = "status";
}
@PrimaryKey private String _id;
private String username;
private String name;
private String status;
public String getId() {
......@@ -33,6 +35,14 @@ public class RealmSpotlightUser extends RealmObject {
this.username = username;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return status;
}
......@@ -45,6 +55,7 @@ public class RealmSpotlightUser extends RealmObject {
return SpotlightUser.builder()
.setId(_id)
.setUsername(username)
.setName(name)
.setStatus(status)
.build();
}
......
......@@ -6,6 +6,7 @@ import com.fernandocejas.arrow.optional.Optional;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.realm.Case;
import io.realm.Realm;
import io.realm.RealmResults;
import io.realm.Sort;
......@@ -149,7 +150,7 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
() -> new Pair<>(RealmStore.getRealm(hostname), Looper.myLooper()),
pair -> RxJavaInterop.toV2Flowable(
pair.first.where(RealmRoom.class)
.like(RealmRoom.NAME, "*" + name + "*")
.like(RealmRoom.NAME, "*" + name + "*", Case.INSENSITIVE)
.beginGroup()
.equalTo(RealmRoom.TYPE, RealmRoom.TYPE_CHANNEL)
.or()
......
......@@ -4,6 +4,7 @@ import android.os.Looper;
import android.support.v4.util.Pair;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.realm.Case;
import io.realm.Sort;
import java.util.ArrayList;
......@@ -32,7 +33,7 @@ public class RealmSpotlightRoomRepository extends RealmRepository
() -> new Pair<>(RealmStore.getRealm(hostname), Looper.myLooper()),
pair -> RxJavaInterop.toV2Flowable(
pair.first.where(RealmSpotlightRoom.class)
.like(RealmSpotlightRoom.Columns.NAME, "*" + name + "*")
.like(RealmSpotlightRoom.Columns.NAME, "*" + name + "*", Case.INSENSITIVE)
.beginGroup()
.equalTo(RealmSpotlightRoom.Columns.TYPE, RealmRoom.TYPE_CHANNEL)
.or()
......
......@@ -4,6 +4,7 @@ import android.os.Looper;
import android.support.v4.util.Pair;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.realm.Case;
import io.realm.Sort;
import java.util.ArrayList;
......@@ -31,7 +32,15 @@ public class RealmSpotlightUserRepository extends RealmRepository
() -> new Pair<>(RealmStore.getRealm(hostname), Looper.myLooper()),
pair -> RxJavaInterop.toV2Flowable(
pair.first.where(RealmSpotlightUser.class)
.like(RealmSpotlightUser.Columns.USERNAME, "*" + name + "*")
.beginGroup()
.like(RealmSpotlightUser.Columns.USERNAME, "*" + name + "*", Case.INSENSITIVE)
.isNull(RealmSpotlightUser.Columns.NAME)
.endGroup()
.or()
.beginGroup()
.like(RealmSpotlightUser.Columns.NAME, "*" + name + "*", Case.INSENSITIVE)
.isNotNull(RealmSpotlightUser.Columns.USERNAME)
.endGroup()
.findAllSorted(RealmSpotlightUser.Columns.USERNAME,
direction.equals(SortDirection.ASC) ? Sort.ASCENDING : Sort.DESCENDING)
.asObservable()),
......
......@@ -5,6 +5,7 @@ import android.support.v4.util.Pair;
import com.fernandocejas.arrow.optional.Optional;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.realm.Case;
import io.realm.RealmResults;
import io.realm.Sort;
......@@ -54,7 +55,7 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
() -> new Pair<>(RealmStore.getRealm(hostname), Looper.myLooper()),
pair -> RxJavaInterop.toV2Flowable(
pair.first.where(RealmUser.class)
.like(RealmUser.USERNAME, "*" + name + "*")
.like(RealmUser.USERNAME, "*" + name + "*", Case.INSENSITIVE)
.findAllSorted(RealmUser.USERNAME,
direction.equals(SortDirection.ASC) ? Sort.ASCENDING : Sort.DESCENDING)
.asObservable()),
......
......@@ -11,6 +11,9 @@ public abstract class SpotlightUser {
public abstract String getUsername();
@Nullable
public abstract String getName();
@Nullable
public abstract String getStatus();
......@@ -25,6 +28,8 @@ public abstract class SpotlightUser {
public abstract Builder setUsername(String username);
public abstract Builder setName(String name);
public abstract Builder setStatus(String status);
public abstract SpotlightUser build();
......
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