Commit 4ef462e5 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Revert Realm plugin version to 3.7.2 (latest version before the breaking...

Revert Realm plugin version to 3.7.2 (latest version before the breaking changes) and thus add back the interop rxjava lib
parent 39906e0f
......@@ -120,6 +120,7 @@ dependencies {
compile rxbindingDependencies.rxBinding
compile rxbindingDependencies.rxBindingSupport
compile rxbindingDependencies.rxBindingAppcompact
compile "com.github.akarnokd:rxjava2-interop:0.11.0"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$rootProject.ext.kotlinVersion"
compile "com.google.firebase:firebase-core:$playLibVersion"
compile "com.google.firebase:firebase-crash:$playLibVersion"
......
......@@ -166,7 +166,11 @@ import io.reactivex.subjects.PublishSubject;
@DebugLog
private Single<Boolean> connectToServerIfNeeded(String hostname, boolean forceConnect) {
return Single.defer(() -> {
final int connectivity = serverConnectivityList.get(hostname);
Integer state = serverConnectivityList.get(hostname);
if (state == null) {
state = ServerConnectivity.STATE_DISCONNECTED;
}
final int connectivity = state;
if (!forceConnect && connectivity == ServerConnectivity.STATE_CONNECTED) {
return Single.just(true);
}
......
......@@ -16,8 +16,8 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.51"
classpath 'io.realm:realm-gradle-plugin:4.2.0-SNAPSHOT'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.60"
classpath 'io.realm:realm-gradle-plugin:3.7.2'
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
classpath 'com.google.gms:google-services:3.0.0'
classpath 'com.github.triplet.gradle:play-publisher:1.1.5'
......
......@@ -17,7 +17,6 @@ public class RealmStore {
.migration(new Migration())
.schemaVersion(5)
// Just in case
.deleteRealmIfMigrationNeeded()
.build();
}
......@@ -49,7 +48,7 @@ public class RealmStore {
sStore.put(name, new RealmConfiguration.Builder()
.name(name + ".realm")
.modules(new RocketChatServerModule())
.deleteRealmIfMigrationNeeded().build());
.build());
}
return new RealmHelper(sStore.get(name));
}
......
......@@ -12,6 +12,7 @@ import chat.rocket.core.models.LoginServiceConfiguration;
import chat.rocket.core.repositories.LoginServiceConfigurationRepository;
import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.persistence.realm.models.ddp.RealmMeteorLoginServiceConfiguration;
import hu.akarnokd.rxjava.interop.RxJavaInterop;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
......@@ -35,10 +36,10 @@ public class RealmLoginServiceConfigurationRepository extends RealmRepository
return Flowable.empty();
}
return pair.first.where(RealmMeteorLoginServiceConfiguration.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmMeteorLoginServiceConfiguration.class)
.equalTo(RealmMeteorLoginServiceConfiguration.SERVICE, serviceName)
.findAll()
.<RealmResults<RealmMeteorLoginServiceConfiguration>>asFlowable();
.<RealmResults<RealmMeteorLoginServiceConfiguration>>asObservable());
},
pair -> close(pair.first, pair.second)
)
......@@ -57,9 +58,9 @@ public class RealmLoginServiceConfigurationRepository extends RealmRepository
return Flowable.empty();
}
return pair.first.where(RealmMeteorLoginServiceConfiguration.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmMeteorLoginServiceConfiguration.class)
.findAll()
.asFlowable();
.asObservable());
},
pair -> close(pair.first, pair.second)
)
......
......@@ -17,6 +17,7 @@ import chat.rocket.persistence.realm.RealmHelper;
import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.persistence.realm.models.ddp.RealmMessage;
import chat.rocket.persistence.realm.models.ddp.RealmUser;
import hu.akarnokd.rxjava.interop.RxJavaInterop;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
......@@ -41,11 +42,10 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
return Flowable.empty();
}
return
pair.first.where(RealmMessage.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmMessage.class)
.equalTo(RealmMessage.ID, messageId)
.findAll()
.<RealmResults<RealmMessage>>asFlowable();
.<RealmResults<RealmMessage>>asObservable());
},
pair -> close(pair.first, pair.second)
)
......@@ -112,10 +112,10 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
realm.beginTransaction();
return realm.where(RealmMessage.class)
return RxJavaInterop.toV2Flowable(realm.where(RealmMessage.class)
.equalTo(RealmMessage.ID, message.getId())
.findAll()
.<RealmResults<RealmMessage>>asFlowable()
.<RealmResults<RealmMessage>>asObservable())
.filter(realmObject -> realmObject.isLoaded() && realmObject.isValid())
.firstElement()
.toSingle()
......@@ -140,13 +140,13 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
return Flowable.empty();
}
return pair.first.where(RealmMessage.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmMessage.class)
.notEqualTo(RealmMessage.SYNC_STATE, SyncState.DELETE_NOT_SYNCED)
.notEqualTo(RealmMessage.SYNC_STATE, SyncState.DELETING)
.equalTo(RealmMessage.ROOM_ID, room.getRoomId())
.isNotNull(RealmMessage.USER)
.findAllSorted(RealmMessage.TIMESTAMP, Sort.DESCENDING)
.asFlowable();
.asObservable());
},
pair -> close(pair.first, pair.second)
)
......@@ -165,12 +165,12 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
return Flowable.empty();
}
return pair.first.where(RealmMessage.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmMessage.class)
.equalTo(RealmMessage.ROOM_ID, room.getId())
.greaterThanOrEqualTo(RealmMessage.TIMESTAMP, room.getLastSeen())
.notEqualTo(RealmMessage.USER_ID, user.getId())
.findAll()
.asFlowable();
.asObservable());
},
pair -> close(pair.first, pair.second)
)
......
......@@ -9,6 +9,7 @@ import chat.rocket.core.models.Permission;
import chat.rocket.core.repositories.PermissionRepository;
import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.persistence.realm.models.ddp.RealmPermission;
import hu.akarnokd.rxjava.interop.RxJavaInterop;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
......@@ -30,10 +31,10 @@ public class RealmPermissionRepository extends RealmRepository implements Permis
if (pair.first == null) {
return Flowable.empty();
}
return pair.first.where(RealmPermission.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmPermission.class)
.equalTo(RealmPermission.Columns.ID, id)
.findAll()
.<RealmResults<RealmPermission>>asFlowable();
.<RealmResults<RealmPermission>>asObservable());
},
pair -> close(pair.first, pair.second)
)
......
......@@ -9,6 +9,7 @@ import chat.rocket.core.models.PublicSetting;
import chat.rocket.core.repositories.PublicSettingRepository;
import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.persistence.realm.models.ddp.RealmPublicSetting;
import hu.akarnokd.rxjava.interop.RxJavaInterop;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
......@@ -31,10 +32,10 @@ public class RealmPublicSettingRepository extends RealmRepository
if (pair.first == null) {
return Flowable.empty();
}
return pair.first.where(RealmPublicSetting.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmPublicSetting.class)
.equalTo(RealmPublicSetting.ID, id)
.findAll()
.<RealmResults<RealmPublicSetting>>asFlowable();
.<RealmResults<RealmPublicSetting>>asObservable());
},
pair -> close(pair.first, pair.second)
)
......
......@@ -16,6 +16,7 @@ import chat.rocket.persistence.realm.RealmHelper;
import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.persistence.realm.models.ddp.RealmRoom;
import chat.rocket.persistence.realm.models.internal.LoadMessageProcedure;
import hu.akarnokd.rxjava.interop.RxJavaInterop;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
......@@ -41,9 +42,9 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
return Flowable.empty();
}
return pair.first.where(RealmRoom.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmRoom.class)
.findAll()
.asFlowable();
.asObservable());
},
pair -> close(pair.first, pair.second)
)
......@@ -70,7 +71,7 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
return Flowable.just(Optional.<RealmRoom>absent());
}
return realmRoom.<RealmRoom>asFlowable()
return RxJavaInterop.toV2Flowable(realmRoom.<RealmRoom>asObservable())
.filter(
roomSubscription -> roomSubscription.isLoaded()
&& roomSubscription.isValid())
......@@ -105,7 +106,7 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
return Flowable.just(Optional.<LoadMessageProcedure>absent());
}
return messageProcedure.<LoadMessageProcedure>asFlowable()
return RxJavaInterop.toV2Flowable(messageProcedure.<LoadMessageProcedure>asObservable())
.filter(loadMessageProcedure -> loadMessageProcedure.isLoaded()
&& loadMessageProcedure.isValid())
.map(Optional::of);
......@@ -156,7 +157,7 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
if (pair.first == null) {
return Flowable.empty();
}
return pair.first.where(RealmRoom.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmRoom.class)
.like(RealmRoom.NAME, "*" + name + "*", Case.INSENSITIVE)
.beginGroup()
.equalTo(RealmRoom.TYPE, RealmRoom.TYPE_CHANNEL)
......@@ -165,7 +166,7 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
.endGroup()
.findAllSorted(RealmRoom.NAME,
direction.equals(SortDirection.ASC) ? Sort.ASCENDING : Sort.DESCENDING)
.asFlowable();
.asObservable());
},
pair -> close(pair.first, pair.second)
)
......@@ -183,14 +184,14 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
if (pair.first == null) {
return Flowable.empty();
}
return pair.first.where(RealmRoom.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmRoom.class)
.beginGroup()
.equalTo(RealmRoom.TYPE, RealmRoom.TYPE_CHANNEL)
.or()
.equalTo(RealmRoom.TYPE, RealmRoom.TYPE_PRIVATE)
.endGroup()
.findAllSorted(RealmRoom.LAST_SEEN, Sort.ASCENDING)
.asFlowable();
.asObservable());
},
pair -> close(pair.first, pair.second)
)
......
......@@ -12,6 +12,7 @@ import chat.rocket.core.repositories.RoomRoleRepository;
import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.persistence.realm.models.ddp.RealmRoomRole;
import chat.rocket.persistence.realm.models.ddp.RealmUser;
import hu.akarnokd.rxjava.interop.RxJavaInterop;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
......@@ -33,11 +34,11 @@ public class RealmRoomRoleRepository extends RealmRepository implements RoomRole
if (pair.first == null) {
return Flowable.empty();
}
return pair.first.where(RealmRoomRole.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmRoomRole.class)
.equalTo(RealmRoomRole.Columns.ROOM_ID, room.getId())
.equalTo(RealmRoomRole.Columns.USER + "." + RealmUser.ID, user.getId())
.findAll()
.<RealmResults<RealmRoomRole>>asFlowable();
.<RealmResults<RealmRoomRole>>asObservable());
},
pair -> close(pair.first, pair.second)
)
......
......@@ -8,6 +8,7 @@ import com.hadisatrio.optional.Optional;
import chat.rocket.core.models.ServerInfo;
import chat.rocket.core.repositories.ServerInfoRepository;
import chat.rocket.persistence.realm.models.RealmBasedServerInfo;
import hu.akarnokd.rxjava.interop.RxJavaInterop;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
......@@ -26,7 +27,7 @@ public class RealmServerInfoRepository extends RealmRepository implements Server
return Flowable.just(Optional.<RealmBasedServerInfo>absent());
}
return info.<RealmBasedServerInfo>asFlowable()
return RxJavaInterop.toV2Flowable(info.<RealmBasedServerInfo>asObservable())
.filter(it -> it.isLoaded() && it.isValid())
.map(Optional::of);
},
......
......@@ -9,6 +9,7 @@ import chat.rocket.core.models.Session;
import chat.rocket.core.repositories.SessionRepository;
import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.persistence.realm.models.internal.RealmSession;
import hu.akarnokd.rxjava.interop.RxJavaInterop;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
......@@ -31,10 +32,10 @@ public class RealmSessionRepository extends RealmRepository implements SessionRe
return Flowable.empty();
}
return pair.first.where(RealmSession.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmSession.class)
.equalTo(RealmSession.ID, id)
.findAll()
.<RealmSession>asFlowable();
.<RealmSession>asObservable());
},
pair -> close(pair.first, pair.second)
)
......@@ -75,8 +76,8 @@ public class RealmSessionRepository extends RealmRepository implements SessionRe
realm.beginTransaction();
return realm.copyToRealmOrUpdate(realmSession)
.asFlowable()
return RxJavaInterop.toV2Flowable(realm.copyToRealmOrUpdate(realmSession)
.asObservable())
.filter(it -> it != null && it.isLoaded() && it.isValid())
.firstElement()
.doOnSuccess(it -> realm.commitTransaction())
......
......@@ -6,6 +6,7 @@ import chat.rocket.core.repositories.SpotlightRepository
import chat.rocket.persistence.realm.RealmStore
import chat.rocket.persistence.realm.models.ddp.RealmSpotlight
import chat.rocket.persistence.realm.models.ddp.RealmSpotlight.Columns
import hu.akarnokd.rxjava.interop.RxJavaInterop
import io.reactivex.Flowable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.realm.Realm
......@@ -23,9 +24,9 @@ class RealmSpotlightRepository(private val hostname: String) : RealmRepository()
return@using Flowable.empty()
}
return@using pair.first.where(RealmSpotlight::class.java)
.findAllSorted(Columns.TYPE, Sort.DESCENDING)
.asFlowable()
return@using RxJavaInterop.toV2Flowable(pair.first.where(RealmSpotlight::class.java)
.findAllSorted(Columns.TYPE, Sort.DESCENDING)
.asObservable())
}) { pair -> close(pair.first, pair.second) }
.unsubscribeOn(AndroidSchedulers.from(Looper.myLooper()!!))
.filter { realmSpotlightResults -> realmSpotlightResults.isLoaded && realmSpotlightResults.isValid }
......
......@@ -12,6 +12,7 @@ import chat.rocket.core.repositories.SpotlightRoomRepository;
import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.persistence.realm.models.ddp.RealmRoom;
import chat.rocket.persistence.realm.models.ddp.RealmSpotlightRoom;
import hu.akarnokd.rxjava.interop.RxJavaInterop;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.realm.Case;
......@@ -34,7 +35,7 @@ public class RealmSpotlightRoomRepository extends RealmRepository implements Spo
return Flowable.empty();
}
return pair.first.where(RealmSpotlightRoom.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmSpotlightRoom.class)
.like(RealmSpotlightRoom.Columns.NAME, "*" + name + "*", Case.INSENSITIVE)
.beginGroup()
.equalTo(RealmSpotlightRoom.Columns.TYPE, RealmRoom.TYPE_CHANNEL)
......@@ -42,7 +43,7 @@ public class RealmSpotlightRoomRepository extends RealmRepository implements Spo
.equalTo(RealmSpotlightRoom.Columns.TYPE, RealmRoom.TYPE_PRIVATE)
.endGroup()
.findAllSorted(RealmSpotlightRoom.Columns.NAME, direction.equals(SortDirection.ASC) ? Sort.ASCENDING : Sort.DESCENDING)
.asFlowable();
.asObservable());
},
pair -> close(pair.first, pair.second)
)
......
......@@ -11,6 +11,7 @@ import chat.rocket.core.models.SpotlightUser;
import chat.rocket.core.repositories.SpotlightUserRepository;
import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.persistence.realm.models.ddp.RealmSpotlightUser;
import hu.akarnokd.rxjava.interop.RxJavaInterop;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.realm.Case;
......@@ -33,7 +34,7 @@ public class RealmSpotlightUserRepository extends RealmRepository implements Spo
return Flowable.empty();
}
return pair.first.where(RealmSpotlightUser.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmSpotlightUser.class)
.beginGroup()
.like(RealmSpotlightUser.Columns.USERNAME, "*" + name + "*", Case.INSENSITIVE)
.isNull(RealmSpotlightUser.Columns.NAME)
......@@ -45,7 +46,7 @@ public class RealmSpotlightUserRepository extends RealmRepository implements Spo
.endGroup()
.findAllSorted(RealmSpotlightUser.Columns.USERNAME,
direction.equals(SortDirection.ASC) ? Sort.ASCENDING : Sort.DESCENDING)
.asFlowable();
.asObservable());
},
pair -> close(pair.first, pair.second)
)
......
......@@ -12,6 +12,7 @@ import chat.rocket.core.models.User;
import chat.rocket.core.repositories.UserRepository;
import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.persistence.realm.models.ddp.RealmUser;
import hu.akarnokd.rxjava.interop.RxJavaInterop;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.realm.Case;
......@@ -35,9 +36,9 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
return Flowable.empty();
}
return pair.first.where(RealmUser.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmUser.class)
.findAll()
.asFlowable();
.asObservable());
},
pair -> close(pair.first, pair.second))
.unsubscribeOn(AndroidSchedulers.from(Looper.myLooper()))
......@@ -69,10 +70,10 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
return Flowable.empty();
}
return pair.first.where(RealmUser.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmUser.class)
.isNotEmpty(RealmUser.EMAILS)
.findAll()
.<RealmResults<RealmUser>>asFlowable();
.<RealmResults<RealmUser>>asObservable());
},
pair -> close(pair.first, pair.second));
}
......@@ -111,7 +112,7 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
return Flowable.just(Optional.absent());
}
return realmUser.<RealmUser>asFlowable()
return RxJavaInterop.toV2Flowable(realmUser.<RealmUser>asObservable())
.filter(user -> user.isLoaded() && user.isValid())
.map(Optional::of);
}
......@@ -134,10 +135,10 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
return Flowable.empty();
}
return pair.first.where(RealmUser.class)
return RxJavaInterop.toV2Flowable(pair.first.where(RealmUser.class)
.like(RealmUser.USERNAME, "*" + name + "*", Case.INSENSITIVE)
.findAllSorted(RealmUser.USERNAME, Sort.DESCENDING)
.asFlowable();
.asObservable());
},
pair -> close(pair.first, pair.second));
}
......
......@@ -5,6 +5,7 @@ apply plugin: 'java'
dependencies {
compile extraDependencies.rxJava
compile extraDependencies.optional
compile "com.github.akarnokd:rxjava2-interop:0.11.0"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$rootProject.ext.kotlinVersion"
compile 'com.google.code.findbugs:jsr305:3.0.1'
compileOnly 'com.google.auto.value:auto-value:1.3'
......
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