Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
d8e2bef9
Commit
d8e2bef9
authored
Sep 28, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change new hostname reselection logic on logout
parent
2bf9e8c8
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
244 additions
and
124 deletions
+244
-124
RocketChatCache.java
app/src/main/java/chat/rocket/android/RocketChatCache.java
+24
-4
MainActivity.java
.../main/java/chat/rocket/android/activity/MainActivity.java
+1
-1
SidebarMainContract.java
.../rocket/android/fragment/sidebar/SidebarMainContract.java
+2
-2
SidebarMainFragment.java
.../rocket/android/fragment/sidebar/SidebarMainFragment.java
+4
-4
SidebarMainPresenter.java
...rocket/android/fragment/sidebar/SidebarMainPresenter.java
+4
-9
RealmLoginServiceConfigurationRepository.java
...epositories/RealmLoginServiceConfigurationRepository.java
+21
-9
RealmMessageRepository.java
...ersistence/realm/repositories/RealmMessageRepository.java
+34
-16
RealmPermissionRepository.java
...istence/realm/repositories/RealmPermissionRepository.java
+10
-5
RealmPublicSettingRepository.java
...ence/realm/repositories/RealmPublicSettingRepository.java
+10
-5
RealmRoomRepository.java
...t/persistence/realm/repositories/RealmRoomRepository.java
+44
-24
RealmRoomRoleRepository.java
...rsistence/realm/repositories/RealmRoomRoleRepository.java
+11
-6
RealmSessionRepository.java
...ersistence/realm/repositories/RealmSessionRepository.java
+11
-5
RealmSpotlightRepository.kt
...ersistence/realm/repositories/RealmSpotlightRepository.kt
+6
-1
RealmSpotlightRoomRepository.java
...ence/realm/repositories/RealmSpotlightRoomRepository.java
+16
-10
RealmSpotlightUserRepository.java
...ence/realm/repositories/RealmSpotlightUserRepository.java
+20
-14
RealmUserRepository.java
...t/persistence/realm/repositories/RealmUserRepository.java
+26
-9
No files found.
app/src/main/java/chat/rocket/android/RocketChatCache.java
View file @
d8e2bef9
...
@@ -60,7 +60,7 @@ public class RocketChatCache {
...
@@ -60,7 +60,7 @@ public class RocketChatCache {
json
=
new
JSONObject
(
hostnameList
);
json
=
new
JSONObject
(
hostnameList
);
}
}
JSONObject
serverInfoJson
=
new
JSONObject
();
JSONObject
serverInfoJson
=
new
JSONObject
();
serverInfoJson
.
put
(
"
hostname
"
,
hostnameAvatarUri
);
serverInfoJson
.
put
(
"
avatar
"
,
hostnameAvatarUri
);
serverInfoJson
.
put
(
"sitename"
,
siteName
);
serverInfoJson
.
put
(
"sitename"
,
siteName
);
// Replace server avatar uri if exists.
// Replace server avatar uri if exists.
json
.
put
(
hostname
,
hostnameAvatarUri
==
null
?
JSONObject
.
NULL
:
serverInfoJson
);
json
.
put
(
hostname
,
hostnameAvatarUri
==
null
?
JSONObject
.
NULL
:
serverInfoJson
);
...
@@ -82,7 +82,7 @@ public class RocketChatCache {
...
@@ -82,7 +82,7 @@ public class RocketChatCache {
String
hostname
=
iter
.
next
();
String
hostname
=
iter
.
next
();
JSONObject
serverInfoJson
=
jsonObj
.
getJSONObject
(
hostname
);
JSONObject
serverInfoJson
=
jsonObj
.
getJSONObject
(
hostname
);
serverList
.
add
(
new
Pair
<>(
hostname
,
new
Pair
<>(
serverList
.
add
(
new
Pair
<>(
hostname
,
new
Pair
<>(
"http://"
+
hostname
+
"/"
+
serverInfoJson
.
getString
(
"
hostname
"
),
"http://"
+
hostname
+
"/"
+
serverInfoJson
.
getString
(
"
avatar
"
),
serverInfoJson
.
getString
(
"sitename"
))));
serverInfoJson
.
getString
(
"sitename"
))));
}
}
return
serverList
;
return
serverList
;
...
@@ -100,12 +100,30 @@ public class RocketChatCache {
...
@@ -100,12 +100,30 @@ public class RocketChatCache {
try
{
try
{
JSONObject
jsonObj
=
new
JSONObject
(
json
);
JSONObject
jsonObj
=
new
JSONObject
(
json
);
jsonObj
.
remove
(
hostname
);
jsonObj
.
remove
(
hostname
);
setString
(
KEY_HOSTNAME_LIST
,
jsonObj
.
toString
());
String
result
=
jsonObj
.
length
()
==
0
?
null
:
jsonObj
.
toString
();
setString
(
KEY_HOSTNAME_LIST
,
result
);
}
catch
(
JSONException
e
)
{
}
catch
(
JSONException
e
)
{
RCLog
.
e
(
e
);
RCLog
.
e
(
e
);
}
}
}
}
@Nullable
public
String
getFirstLoggedHostnameIfAny
()
{
String
json
=
getString
(
KEY_HOSTNAME_LIST
,
null
);
if
(
json
!=
null
)
{
try
{
JSONObject
jsonObj
=
new
JSONObject
(
json
);
if
(
jsonObj
.
length
()
>
0
&&
jsonObj
.
keys
().
hasNext
())
{
// Returns the first hostname on the list.
return
jsonObj
.
keys
().
next
();
}
}
catch
(
JSONException
e
)
{
RCLog
.
e
(
e
);
}
}
return
null
;
}
public
String
getSelectedRoomId
()
{
public
String
getSelectedRoomId
()
{
try
{
try
{
JSONObject
jsonObject
=
getSelectedRoomIdJsonObject
();
JSONObject
jsonObject
=
getSelectedRoomIdJsonObject
();
...
@@ -194,7 +212,9 @@ public class RocketChatCache {
...
@@ -194,7 +212,9 @@ public class RocketChatCache {
try
{
try
{
JSONObject
selectedRoomIdJsonObject
=
getSelectedRoomIdJsonObject
();
JSONObject
selectedRoomIdJsonObject
=
getSelectedRoomIdJsonObject
();
selectedRoomIdJsonObject
.
remove
(
currentHostname
);
selectedRoomIdJsonObject
.
remove
(
currentHostname
);
setString
(
KEY_SELECTED_ROOM_ID
,
selectedRoomIdJsonObject
.
toString
());
String
result
=
selectedRoomIdJsonObject
.
length
()
==
0
?
null
:
selectedRoomIdJsonObject
.
toString
();
setString
(
KEY_SELECTED_ROOM_ID
,
result
);
}
catch
(
JSONException
e
)
{
}
catch
(
JSONException
e
)
{
Logger
.
report
(
e
);
Logger
.
report
(
e
);
RCLog
.
e
(
e
);
RCLog
.
e
(
e
);
...
...
app/src/main/java/chat/rocket/android/activity/MainActivity.java
View file @
d8e2bef9
...
@@ -329,7 +329,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
...
@@ -329,7 +329,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
}
}
@DebugLog
@DebugLog
public
void
cleanUpBeforeLogout
()
{
public
void
beforeLogoutCleanUp
()
{
presenter
.
beforeLogoutCleanUp
();
presenter
.
beforeLogoutCleanUp
();
}
}
...
...
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainContract.java
View file @
d8e2bef9
...
@@ -45,8 +45,8 @@ public interface SidebarMainContract {
...
@@ -45,8 +45,8 @@ public interface SidebarMainContract {
void
onUserOffline
();
void
onUserOffline
();
void
onLogout
(
Continuation
continuation
);
void
onLogout
(
Continuation
<
Void
,
Object
>
continuation
);
void
cleanUpBeforeLogout
();
void
beforeLogoutCleanUp
();
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainFragment.java
View file @
d8e2bef9
...
@@ -339,14 +339,14 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
...
@@ -339,14 +339,14 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
private
void
setupLogoutButton
()
{
private
void
setupLogoutButton
()
{
rootView
.
findViewById
(
R
.
id
.
btn_logout
).
setOnClickListener
(
view
->
{
rootView
.
findViewById
(
R
.
id
.
btn_logout
).
setOnClickListener
(
view
->
{
closeUserActionContainer
();
closeUserActionContainer
();
// Clear relative data and set new hostname if any.
presenter
.
beforeLogoutCleanUp
();
final
Activity
activity
=
getActivity
();
final
Activity
activity
=
getActivity
();
if
(
activity
!=
null
&&
activity
instanceof
MainActivity
)
{
if
(
activity
!=
null
&&
activity
instanceof
MainActivity
)
{
((
MainActivity
)
activity
).
showLogoutMessage
();
((
MainActivity
)
activity
).
showLogoutMessage
();
// Clear subscriptions.
// Clear subscriptions
on MainPresenter
.
((
MainActivity
)
activity
).
cleanUpBeforeLogout
();
((
MainActivity
)
activity
).
beforeLogoutCleanUp
();
}
}
// Clear relative data and set new hostname if any.
presenter
.
cleanUpBeforeLogout
();
});
});
}
}
...
...
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainPresenter.java
View file @
d8e2bef9
...
@@ -22,7 +22,6 @@ import chat.rocket.android.shared.BasePresenter;
...
@@ -22,7 +22,6 @@ import chat.rocket.android.shared.BasePresenter;
import
chat.rocket.core.interactors.RoomInteractor
;
import
chat.rocket.core.interactors.RoomInteractor
;
import
chat.rocket.core.models.Room
;
import
chat.rocket.core.models.Room
;
import
chat.rocket.core.models.RoomSidebar
;
import
chat.rocket.core.models.RoomSidebar
;
import
chat.rocket.core.models.ServerInfo
;
import
chat.rocket.core.models.Spotlight
;
import
chat.rocket.core.models.Spotlight
;
import
chat.rocket.core.models.User
;
import
chat.rocket.core.models.User
;
import
chat.rocket.core.repositories.SpotlightRepository
;
import
chat.rocket.core.repositories.SpotlightRepository
;
...
@@ -139,7 +138,7 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
...
@@ -139,7 +138,7 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
}
}
@Override
@Override
public
void
onLogout
(
Continuation
continuation
)
{
public
void
onLogout
(
Continuation
<
Void
,
Object
>
continuation
)
{
methodCallHelper
.
logout
().
continueWith
(
task
->
{
methodCallHelper
.
logout
().
continueWith
(
task
->
{
if
(
task
.
isFaulted
())
{
if
(
task
.
isFaulted
())
{
Logger
.
report
(
task
.
getError
());
Logger
.
report
(
task
.
getError
());
...
@@ -150,21 +149,17 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
...
@@ -150,21 +149,17 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
}
}
@Override
@Override
public
void
cleanUpBeforeLogout
()
{
public
void
beforeLogoutCleanUp
()
{
clearSubscriptions
();
String
currentHostname
=
rocketChatCache
.
getSelectedServerHostname
();
String
currentHostname
=
rocketChatCache
.
getSelectedServerHostname
();
RealmHelper
realmHelper
=
RealmStore
.
getOrCreate
(
currentHostname
);
RealmHelper
realmHelper
=
RealmStore
.
getOrCreate
(
currentHostname
);
realmHelper
.
executeTransaction
(
realm
->
{
realmHelper
.
executeTransaction
(
realm
->
{
realm
.
deleteAll
();
realm
.
deleteAll
();
ConnectivityManagerApi
connectivityManagerApi
=
ConnectivityManager
.
getInstance
(
RocketChatApplication
.
getInstance
());
ConnectivityManagerApi
connectivityManagerApi
=
ConnectivityManager
.
getInstance
(
RocketChatApplication
.
getInstance
());
connectivityManagerApi
.
removeServer
(
currentHostname
);
connectivityManagerApi
.
removeServer
(
currentHostname
);
List
<
ServerInfo
>
serverList
=
connectivityManagerApi
.
getServerList
();
String
newHostname
=
null
;
if
(
serverList
!=
null
&&
serverList
.
size
()
>
0
)
{
newHostname
=
serverList
.
get
(
0
).
getHostname
();
}
rocketChatCache
.
removeHostname
(
currentHostname
);
rocketChatCache
.
removeHostname
(
currentHostname
);
rocketChatCache
.
removeSelectedRoomId
(
currentHostname
);
rocketChatCache
.
removeSelectedRoomId
(
currentHostname
);
rocketChatCache
.
setSelectedServerHostname
(
newHostname
);
rocketChatCache
.
setSelectedServerHostname
(
rocketChatCache
.
getFirstLoggedHostnameIfAny
()
);
view
.
onLogoutCleanUp
();
view
.
onLogoutCleanUp
();
return
null
;
return
null
;
});
});
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmLoginServiceConfigurationRepository.java
View file @
d8e2bef9
...
@@ -29,11 +29,17 @@ public class RealmLoginServiceConfigurationRepository extends RealmRepository
...
@@ -29,11 +29,17 @@ public class RealmLoginServiceConfigurationRepository extends RealmRepository
public
Single
<
Optional
<
LoginServiceConfiguration
>>
getByName
(
String
serviceName
)
{
public
Single
<
Optional
<
LoginServiceConfiguration
>>
getByName
(
String
serviceName
)
{
return
Single
.
defer
(()
->
Flowable
.
using
(
return
Single
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
.
toV2Flowable
(
pair
->
{
pair
.
first
.
where
(
RealmMeteorLoginServiceConfiguration
.
class
)
if
(
pair
.
first
==
null
)
{
.
equalTo
(
RealmMeteorLoginServiceConfiguration
.
SERVICE
,
serviceName
)
return
Flowable
.
empty
();
.
findAll
()
}
.<
RealmResults
<
RealmMeteorLoginServiceConfiguration
>>
asObservable
()),
return
RxJavaInterop
.
toV2Flowable
(
pair
.
first
.
where
(
RealmMeteorLoginServiceConfiguration
.
class
)
.
equalTo
(
RealmMeteorLoginServiceConfiguration
.
SERVICE
,
serviceName
)
.
findAll
()
.<
RealmResults
<
RealmMeteorLoginServiceConfiguration
>>
asObservable
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
...
@@ -46,10 +52,16 @@ public class RealmLoginServiceConfigurationRepository extends RealmRepository
...
@@ -46,10 +52,16 @@ public class RealmLoginServiceConfigurationRepository extends RealmRepository
public
Flowable
<
List
<
LoginServiceConfiguration
>>
getAll
()
{
public
Flowable
<
List
<
LoginServiceConfiguration
>>
getAll
()
{
return
Flowable
.
defer
(()
->
Flowable
.
using
(
return
Flowable
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
pair
->
{
.
toV2Flowable
(
pair
.
first
.
where
(
RealmMeteorLoginServiceConfiguration
.
class
)
if
(
pair
.
first
==
null
)
{
.
findAll
()
return
Flowable
.
empty
();
.
asObservable
()),
}
return
RxJavaInterop
.
toV2Flowable
(
pair
.
first
.
where
(
RealmMeteorLoginServiceConfiguration
.
class
)
.
findAll
()
.
asObservable
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmMessageRepository.java
View file @
d8e2bef9
...
@@ -36,11 +36,17 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
...
@@ -36,11 +36,17 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
public
Single
<
Optional
<
Message
>>
getById
(
String
messageId
)
{
public
Single
<
Optional
<
Message
>>
getById
(
String
messageId
)
{
return
Single
.
defer
(()
->
Flowable
.
using
(
return
Single
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
.
toV2Flowable
(
pair
->
{
pair
.
first
.
where
(
RealmMessage
.
class
)
if
(
pair
.
first
==
null
)
{
.
equalTo
(
RealmMessage
.
ID
,
messageId
)
return
Flowable
.
empty
();
.
findAll
()
}
.<
RealmResults
<
RealmMessage
>>
asObservable
()),
return
RxJavaInterop
.
toV2Flowable
(
pair
.
first
.
where
(
RealmMessage
.
class
)
.
equalTo
(
RealmMessage
.
ID
,
messageId
)
.
findAll
()
.<
RealmResults
<
RealmMessage
>>
asObservable
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
...
@@ -133,11 +139,17 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
...
@@ -133,11 +139,17 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
public
Flowable
<
List
<
Message
>>
getAllFrom
(
Room
room
)
{
public
Flowable
<
List
<
Message
>>
getAllFrom
(
Room
room
)
{
return
Flowable
.
defer
(()
->
Flowable
.
using
(
return
Flowable
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
.
toV2Flowable
(
pair
.
first
.
where
(
RealmMessage
.
class
)
pair
->
{
.
equalTo
(
RealmMessage
.
ROOM_ID
,
room
.
getRoomId
())
if
(
pair
.
first
==
null
)
{
.
isNotNull
(
RealmMessage
.
USER
)
return
Flowable
.
empty
();
.
findAllSorted
(
RealmMessage
.
TIMESTAMP
,
Sort
.
DESCENDING
)
}
.
asObservable
()),
return
RxJavaInterop
.
toV2Flowable
(
pair
.
first
.
where
(
RealmMessage
.
class
)
.
equalTo
(
RealmMessage
.
ROOM_ID
,
room
.
getRoomId
())
.
isNotNull
(
RealmMessage
.
USER
)
.
findAllSorted
(
RealmMessage
.
TIMESTAMP
,
Sort
.
DESCENDING
)
.
asObservable
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
...
@@ -150,12 +162,18 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
...
@@ -150,12 +162,18 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
public
Single
<
Integer
>
unreadCountFor
(
Room
room
,
User
user
)
{
public
Single
<
Integer
>
unreadCountFor
(
Room
room
,
User
user
)
{
return
Single
.
defer
(()
->
Flowable
.
using
(
return
Single
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
.
toV2Flowable
(
pair
.
first
.
where
(
RealmMessage
.
class
)
pair
->
{
.
equalTo
(
RealmMessage
.
ROOM_ID
,
room
.
getId
())
if
(
pair
.
first
==
null
)
{
.
greaterThanOrEqualTo
(
RealmMessage
.
TIMESTAMP
,
room
.
getLastSeen
())
return
Flowable
.
empty
();
.
notEqualTo
(
RealmMessage
.
USER_ID
,
user
.
getId
())
}
.
findAll
()
.
asObservable
()),
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
()
.
asObservable
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmPermissionRepository.java
View file @
d8e2bef9
...
@@ -26,11 +26,16 @@ public class RealmPermissionRepository extends RealmRepository implements Permis
...
@@ -26,11 +26,16 @@ public class RealmPermissionRepository extends RealmRepository implements Permis
public
Single
<
Optional
<
Permission
>>
getById
(
String
id
)
{
public
Single
<
Optional
<
Permission
>>
getById
(
String
id
)
{
return
Single
.
defer
(()
->
Flowable
.
using
(
return
Single
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
.
toV2Flowable
(
pair
->
{
pair
.
first
.
where
(
RealmPermission
.
class
)
if
(
pair
.
first
==
null
)
{
.
equalTo
(
RealmPermission
.
Columns
.
ID
,
id
)
return
Flowable
.
empty
();
.
findAll
()
}
.<
RealmResults
<
RealmPermission
>>
asObservable
()),
return
RxJavaInterop
.
toV2Flowable
(
pair
.
first
.
where
(
RealmPermission
.
class
)
.
equalTo
(
RealmPermission
.
Columns
.
ID
,
id
)
.
findAll
()
.<
RealmResults
<
RealmPermission
>>
asObservable
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmPublicSettingRepository.java
View file @
d8e2bef9
...
@@ -27,11 +27,16 @@ public class RealmPublicSettingRepository extends RealmRepository
...
@@ -27,11 +27,16 @@ public class RealmPublicSettingRepository extends RealmRepository
public
Single
<
Optional
<
PublicSetting
>>
getById
(
String
id
)
{
public
Single
<
Optional
<
PublicSetting
>>
getById
(
String
id
)
{
return
Single
.
defer
(()
->
Flowable
.
using
(
return
Single
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
.
toV2Flowable
(
pair
->
{
pair
.
first
.
where
(
RealmPublicSetting
.
class
)
if
(
pair
.
first
==
null
)
{
.
equalTo
(
RealmPublicSetting
.
ID
,
id
)
return
Flowable
.
empty
();
.
findAll
()
}
.<
RealmResults
<
RealmPublicSetting
>>
asObservable
()),
return
RxJavaInterop
.
toV2Flowable
(
pair
.
first
.
where
(
RealmPublicSetting
.
class
)
.
equalTo
(
RealmPublicSetting
.
ID
,
id
)
.
findAll
()
.<
RealmResults
<
RealmPublicSetting
>>
asObservable
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmRoomRepository.java
View file @
d8e2bef9
...
@@ -34,10 +34,16 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
...
@@ -34,10 +34,16 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
public
Flowable
<
List
<
Room
>>
getAll
()
{
public
Flowable
<
List
<
Room
>>
getAll
()
{
return
Flowable
.
defer
(()
->
Flowable
.
using
(
return
Flowable
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
.
toV2Flowable
(
pair
->
{
pair
.
first
.
where
(
RealmRoom
.
class
)
if
(
pair
.
first
==
null
)
{
.
findAll
()
return
Flowable
.
empty
();
.
asObservable
()),
}
return
RxJavaInterop
.
toV2Flowable
(
pair
.
first
.
where
(
RealmRoom
.
class
)
.
findAll
()
.
asObservable
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
...
@@ -51,6 +57,10 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
...
@@ -51,6 +57,10 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
return
Flowable
.
defer
(()
->
Flowable
.
using
(
return
Flowable
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
{
pair
->
{
if
(
pair
.
first
==
null
)
{
return
Flowable
.
empty
();
}
RealmRoom
realmRoom
=
pair
.
first
.
where
(
RealmRoom
.
class
)
RealmRoom
realmRoom
=
pair
.
first
.
where
(
RealmRoom
.
class
)
.
equalTo
(
RealmRoom
.
ROOM_ID
,
roomId
)
.
equalTo
(
RealmRoom
.
ROOM_ID
,
roomId
)
.
findFirst
();
.
findFirst
();
...
@@ -150,17 +160,22 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
...
@@ -150,17 +160,22 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
public
Flowable
<
List
<
Room
>>
getSortedLikeName
(
String
name
,
SortDirection
direction
,
int
limit
)
{
public
Flowable
<
List
<
Room
>>
getSortedLikeName
(
String
name
,
SortDirection
direction
,
int
limit
)
{
return
Flowable
.
defer
(()
->
Flowable
.
using
(
return
Flowable
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
.
toV2Flowable
(
pair
->
{
pair
.
first
.
where
(
RealmRoom
.
class
)
if
(
pair
.
first
==
null
)
{
.
like
(
RealmRoom
.
NAME
,
"*"
+
name
+
"*"
,
Case
.
INSENSITIVE
)
return
Flowable
.
empty
();
.
beginGroup
()
}
.
equalTo
(
RealmRoom
.
TYPE
,
RealmRoom
.
TYPE_CHANNEL
)
return
RxJavaInterop
.
toV2Flowable
(
.
or
()
pair
.
first
.
where
(
RealmRoom
.
class
)
.
equalTo
(
RealmRoom
.
TYPE
,
RealmRoom
.
TYPE_PRIVATE
)
.
like
(
RealmRoom
.
NAME
,
"*"
+
name
+
"*"
,
Case
.
INSENSITIVE
)
.
endGroup
()
.
beginGroup
()
.
findAllSorted
(
RealmRoom
.
NAME
,
.
equalTo
(
RealmRoom
.
TYPE
,
RealmRoom
.
TYPE_CHANNEL
)
direction
.
equals
(
SortDirection
.
ASC
)
?
Sort
.
ASCENDING
:
Sort
.
DESCENDING
)
.
or
()
.
asObservable
()),
.
equalTo
(
RealmRoom
.
TYPE
,
RealmRoom
.
TYPE_PRIVATE
)
.
endGroup
()
.
findAllSorted
(
RealmRoom
.
NAME
,
direction
.
equals
(
SortDirection
.
ASC
)
?
Sort
.
ASCENDING
:
Sort
.
DESCENDING
)
.
asObservable
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
...
@@ -173,15 +188,20 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
...
@@ -173,15 +188,20 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
public
Flowable
<
List
<
Room
>>
getLatestSeen
(
int
limit
)
{
public
Flowable
<
List
<
Room
>>
getLatestSeen
(
int
limit
)
{
return
Flowable
.
defer
(()
->
Flowable
.
using
(
return
Flowable
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
.
toV2Flowable
(
pair
->
{
pair
.
first
.
where
(
RealmRoom
.
class
)
if
(
pair
.
first
==
null
)
{
.
beginGroup
()
return
Flowable
.
empty
();
.
equalTo
(
RealmRoom
.
TYPE
,
RealmRoom
.
TYPE_CHANNEL
)
}
.
or
()
return
RxJavaInterop
.
toV2Flowable
(
.
equalTo
(
RealmRoom
.
TYPE
,
RealmRoom
.
TYPE_PRIVATE
)
pair
.
first
.
where
(
RealmRoom
.
class
)
.
endGroup
()
.
beginGroup
()
.
findAllSorted
(
RealmRoom
.
LAST_SEEN
,
Sort
.
ASCENDING
)
.
equalTo
(
RealmRoom
.
TYPE
,
RealmRoom
.
TYPE_CHANNEL
)
.
asObservable
()),
.
or
()
.
equalTo
(
RealmRoom
.
TYPE
,
RealmRoom
.
TYPE_PRIVATE
)
.
endGroup
()
.
findAllSorted
(
RealmRoom
.
LAST_SEEN
,
Sort
.
ASCENDING
)
.
asObservable
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmRoomRoleRepository.java
View file @
d8e2bef9
...
@@ -29,12 +29,17 @@ public class RealmRoomRoleRepository extends RealmRepository implements RoomRole
...
@@ -29,12 +29,17 @@ public class RealmRoomRoleRepository extends RealmRepository implements RoomRole
public
Single
<
Optional
<
RoomRole
>>
getFor
(
Room
room
,
User
user
)
{
public
Single
<
Optional
<
RoomRole
>>
getFor
(
Room
room
,
User
user
)
{
return
Single
.
defer
(()
->
Flowable
.
using
(
return
Single
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
.
toV2Flowable
(
pair
->
{
pair
.
first
.
where
(
RealmRoomRole
.
class
)
if
(
pair
.
first
==
null
)
{
.
equalTo
(
RealmRoomRole
.
Columns
.
ROOM_ID
,
room
.
getId
())
return
Flowable
.
empty
();
.
equalTo
(
RealmRoomRole
.
Columns
.
USER
+
"."
+
RealmUser
.
ID
,
user
.
getId
())
}
.
findAll
()
return
RxJavaInterop
.
toV2Flowable
(
.<
RealmResults
<
RealmRoomRole
>>
asObservable
()),
pair
.
first
.
where
(
RealmRoomRole
.
class
)
.
equalTo
(
RealmRoomRole
.
Columns
.
ROOM_ID
,
room
.
getId
())
.
equalTo
(
RealmRoomRole
.
Columns
.
USER
+
"."
+
RealmUser
.
ID
,
user
.
getId
())
.
findAll
()
.<
RealmResults
<
RealmRoomRole
>>
asObservable
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmSessionRepository.java
View file @
d8e2bef9
...
@@ -26,11 +26,17 @@ public class RealmSessionRepository extends RealmRepository implements SessionRe
...
@@ -26,11 +26,17 @@ public class RealmSessionRepository extends RealmRepository implements SessionRe
public
Flowable
<
Optional
<
Session
>>
getById
(
int
id
)
{
public
Flowable
<
Optional
<
Session
>>
getById
(
int
id
)
{
return
Flowable
.
defer
(()
->
Flowable
.
using
(
return
Flowable
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
.
toV2Flowable
(
pair
->
{
pair
.
first
.
where
(
RealmSession
.
class
)
if
(
pair
.
first
==
null
)
{
.
equalTo
(
RealmSession
.
ID
,
id
)
return
Flowable
.
empty
();
.
findAll
()
}
.<
RealmSession
>
asObservable
()),
return
RxJavaInterop
.
toV2Flowable
(
pair
.
first
.
where
(
RealmSession
.
class
)
.
equalTo
(
RealmSession
.
ID
,
id
)
.
findAll
()
.<
RealmSession
>
asObservable
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmSpotlightRepository.kt
View file @
d8e2bef9
...
@@ -20,7 +20,12 @@ class RealmSpotlightRepository(private val hostname: String) : RealmRepository()
...
@@ -20,7 +20,12 @@ class RealmSpotlightRepository(private val hostname: String) : RealmRepository()
override
fun
getSuggestionsFor
(
term
:
String
,
limit
:
Int
):
Flowable
<
List
<
Spotlight
>>
{
override
fun
getSuggestionsFor
(
term
:
String
,
limit
:
Int
):
Flowable
<
List
<
Spotlight
>>
{
return
Flowable
.
defer
{
Flowable
.
using
<
RealmResults
<
RealmSpotlight
>,
Pair
<
Realm
,
Looper
>>({
return
Flowable
.
defer
{
Flowable
.
using
<
RealmResults
<
RealmSpotlight
>,
Pair
<
Realm
,
Looper
>>({
Pair
(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
())
Pair
(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
())
},
{
pair
->
RxJavaInterop
.
toV2Flowable
<
RealmResults
<
RealmSpotlight
>>(
pair
.
first
.
where
(
RealmSpotlight
::
class
.
java
)
},
{
pair
->
if
(
pair
.
first
==
null
)
{
return
@using
Flowable
.
empty
()
}
return
@using
RxJavaInterop
.
toV2Flowable
<
RealmResults
<
RealmSpotlight
>>(
pair
.
first
.
where
(
RealmSpotlight
::
class
.
java
)
.
findAllSorted
(
Columns
.
TYPE
,
Sort
.
DESCENDING
)
.
findAllSorted
(
Columns
.
TYPE
,
Sort
.
DESCENDING
)
.
asObservable
())
.
asObservable
())
})
{
pair
->
close
(
pair
.
first
,
pair
.
second
)
}
})
{
pair
->
close
(
pair
.
first
,
pair
.
second
)
}
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmSpotlightRoomRepository.java
View file @
d8e2bef9
...
@@ -29,16 +29,22 @@ public class RealmSpotlightRoomRepository extends RealmRepository implements Spo
...
@@ -29,16 +29,22 @@ public class RealmSpotlightRoomRepository extends RealmRepository implements Spo
public
Flowable
<
List
<
SpotlightRoom
>>
getSuggestionsFor
(
String
name
,
SortDirection
direction
,
int
limit
)
{
public
Flowable
<
List
<
SpotlightRoom
>>
getSuggestionsFor
(
String
name
,
SortDirection
direction
,
int
limit
)
{
return
Flowable
.
defer
(()
->
Flowable
.
using
(
return
Flowable
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
.
toV2Flowable
(
pair
->
{
pair
.
first
.
where
(
RealmSpotlightRoom
.
class
)
if
(
pair
.
first
==
null
)
{
.
like
(
RealmSpotlightRoom
.
Columns
.
NAME
,
"*"
+
name
+
"*"
,
Case
.
INSENSITIVE
)
return
Flowable
.
empty
();
.
beginGroup
()
}
.
equalTo
(
RealmSpotlightRoom
.
Columns
.
TYPE
,
RealmRoom
.
TYPE_CHANNEL
)
.
or
()
return
RxJavaInterop
.
toV2Flowable
(
.
equalTo
(
RealmSpotlightRoom
.
Columns
.
TYPE
,
RealmRoom
.
TYPE_PRIVATE
)
pair
.
first
.
where
(
RealmSpotlightRoom
.
class
)
.
endGroup
()
.
like
(
RealmSpotlightRoom
.
Columns
.
NAME
,
"*"
+
name
+
"*"
,
Case
.
INSENSITIVE
)
.
findAllSorted
(
RealmSpotlightRoom
.
Columns
.
NAME
,
direction
.
equals
(
SortDirection
.
ASC
)
?
Sort
.
ASCENDING
:
Sort
.
DESCENDING
)
.
beginGroup
()
.
asObservable
()),
.
equalTo
(
RealmSpotlightRoom
.
Columns
.
TYPE
,
RealmRoom
.
TYPE_CHANNEL
)
.
or
()
.
equalTo
(
RealmSpotlightRoom
.
Columns
.
TYPE
,
RealmRoom
.
TYPE_PRIVATE
)
.
endGroup
()
.
findAllSorted
(
RealmSpotlightRoom
.
Columns
.
NAME
,
direction
.
equals
(
SortDirection
.
ASC
)
?
Sort
.
ASCENDING
:
Sort
.
DESCENDING
)
.
asObservable
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmSpotlightUserRepository.java
View file @
d8e2bef9
...
@@ -28,20 +28,26 @@ public class RealmSpotlightUserRepository extends RealmRepository implements Spo
...
@@ -28,20 +28,26 @@ public class RealmSpotlightUserRepository extends RealmRepository implements Spo
public
Flowable
<
List
<
SpotlightUser
>>
getSuggestionsFor
(
String
name
,
SortDirection
direction
,
int
limit
)
{
public
Flowable
<
List
<
SpotlightUser
>>
getSuggestionsFor
(
String
name
,
SortDirection
direction
,
int
limit
)
{
return
Flowable
.
defer
(()
->
Flowable
.
using
(
return
Flowable
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
.
toV2Flowable
(
pair
->
{
pair
.
first
.
where
(
RealmSpotlightUser
.
class
)
if
(
pair
.
first
==
null
)
{
.
beginGroup
()
return
Flowable
.
empty
();
.
like
(
RealmSpotlightUser
.
Columns
.
USERNAME
,
"*"
+
name
+
"*"
,
Case
.
INSENSITIVE
)
}
.
isNull
(
RealmSpotlightUser
.
Columns
.
NAME
)
.
endGroup
()
return
RxJavaInterop
.
toV2Flowable
(
.
or
()
pair
.
first
.
where
(
RealmSpotlightUser
.
class
)
.
beginGroup
()
.
beginGroup
()
.
like
(
RealmSpotlightUser
.
Columns
.
NAME
,
"*"
+
name
+
"*"
,
Case
.
INSENSITIVE
)
.
like
(
RealmSpotlightUser
.
Columns
.
USERNAME
,
"*"
+
name
+
"*"
,
Case
.
INSENSITIVE
)
.
isNotNull
(
RealmSpotlightUser
.
Columns
.
USERNAME
)
.
isNull
(
RealmSpotlightUser
.
Columns
.
NAME
)
.
endGroup
()
.
endGroup
()
.
findAllSorted
(
RealmSpotlightUser
.
Columns
.
USERNAME
,
.
or
()
direction
.
equals
(
SortDirection
.
ASC
)
?
Sort
.
ASCENDING
:
Sort
.
DESCENDING
)
.
beginGroup
()
.
asObservable
()),
.
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
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmUserRepository.java
View file @
d8e2bef9
...
@@ -31,10 +31,16 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
...
@@ -31,10 +31,16 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
public
Flowable
<
List
<
User
>>
getAll
()
{
public
Flowable
<
List
<
User
>>
getAll
()
{
return
Flowable
.
defer
(()
->
Flowable
.
using
(
return
Flowable
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
.
toV2Flowable
(
pair
->
{
pair
.
first
.
where
(
RealmUser
.
class
)
if
(
pair
.
first
==
null
)
{
.
findAll
()
return
Flowable
.
empty
();
.
asObservable
()),
}
return
RxJavaInterop
.
toV2Flowable
(
pair
.
first
.
where
(
RealmUser
.
class
)
.
findAll
()
.
asObservable
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
))
pair
->
close
(
pair
.
first
,
pair
.
second
))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
filter
(
roomSubscriptions
->
roomSubscriptions
!=
null
&&
roomSubscriptions
.
isLoaded
()
.
filter
(
roomSubscriptions
->
roomSubscriptions
!=
null
&&
roomSubscriptions
.
isLoaded
()
...
@@ -64,6 +70,7 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
...
@@ -64,6 +70,7 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
if
(
pair
.
first
==
null
)
{
if
(
pair
.
first
==
null
)
{
return
Flowable
.
empty
();
return
Flowable
.
empty
();
}
}
return
RxJavaInterop
.
toV2Flowable
(
return
RxJavaInterop
.
toV2Flowable
(
pair
.
first
.
where
(
RealmUser
.
class
)
pair
.
first
.
where
(
RealmUser
.
class
)
.
isNotEmpty
(
RealmUser
.
EMAILS
)
.
isNotEmpty
(
RealmUser
.
EMAILS
)
...
@@ -95,6 +102,10 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
...
@@ -95,6 +102,10 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
}
}
private
Flowable
<
Optional
<
RealmUser
>>
realmQueryUsername
(
Realm
realm
,
String
username
)
{
private
Flowable
<
Optional
<
RealmUser
>>
realmQueryUsername
(
Realm
realm
,
String
username
)
{
if
(
realm
==
null
)
{
return
Flowable
.
empty
();
}
RealmUser
realmUser
=
realm
.
where
(
RealmUser
.
class
)
RealmUser
realmUser
=
realm
.
where
(
RealmUser
.
class
)
.
equalTo
(
RealmUser
.
USERNAME
,
username
)
.
equalTo
(
RealmUser
.
USERNAME
,
username
)
.
findFirst
();
.
findFirst
();
...
@@ -123,11 +134,17 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
...
@@ -123,11 +134,17 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
private
Flowable
<
RealmResults
<
RealmUser
>>
realmGetSortedLikeName
(
String
name
)
{
private
Flowable
<
RealmResults
<
RealmUser
>>
realmGetSortedLikeName
(
String
name
)
{
return
Flowable
.
using
(
return
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
RxJavaInterop
.
toV2Flowable
(
pair
->
{
pair
.
first
.
where
(
RealmUser
.
class
)
if
(
pair
.
first
==
null
)
{
.
like
(
RealmUser
.
USERNAME
,
"*"
+
name
+
"*"
,
Case
.
INSENSITIVE
)
return
Flowable
.
empty
();
.
findAllSorted
(
RealmUser
.
USERNAME
,
Sort
.
DESCENDING
)
}
.
asObservable
()),
return
RxJavaInterop
.
toV2Flowable
(
pair
.
first
.
where
(
RealmUser
.
class
)
.
like
(
RealmUser
.
USERNAME
,
"*"
+
name
+
"*"
,
Case
.
INSENSITIVE
)
.
findAllSorted
(
RealmUser
.
USERNAME
,
Sort
.
DESCENDING
)
.
asObservable
());
},
pair
->
close
(
pair
.
first
,
pair
.
second
));
pair
->
close
(
pair
.
first
,
pair
.
second
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment