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
4535d9ee
Commit
4535d9ee
authored
Jan 03, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return a default empty PublicSetting if server does not provide any
parent
b69d908b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
28 deletions
+43
-28
RealmPublicSettingRepository.java
...ence/realm/repositories/RealmPublicSettingRepository.java
+43
-28
No files found.
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmPublicSettingRepository.java
View file @
4535d9ee
...
...
@@ -5,6 +5,9 @@ import android.support.v4.util.Pair;
import
com.hadisatrio.optional.Optional
;
import
javax.annotation.Nullable
;
import
chat.rocket.core.PublicSettingsConstants
;
import
chat.rocket.core.models.PublicSetting
;
import
chat.rocket.core.repositories.PublicSettingRepository
;
import
chat.rocket.persistence.realm.RealmStore
;
...
...
@@ -15,32 +18,44 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import
io.realm.RealmResults
;
public
class
RealmPublicSettingRepository
extends
RealmRepository
implements
PublicSettingRepository
{
private
final
String
hostname
;
public
RealmPublicSettingRepository
(
String
hostname
)
{
this
.
hostname
=
hostname
;
}
@Override
public
Single
<
Optional
<
PublicSetting
>>
getById
(
String
id
)
{
return
Single
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
{
if
(
pair
.
first
==
null
)
{
return
Flowable
.
empty
();
}
return
pair
.
first
.
where
(
RealmPublicSetting
.
class
)
.
equalTo
(
RealmPublicSetting
.
ID
,
id
)
.
findAll
()
.<
RealmResults
<
RealmPublicSetting
>>
asFlowable
();
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
filter
(
it
->
it
.
isLoaded
()
&&
it
.
isValid
()
&&
it
.
size
()
>
0
)
.
map
(
it
->
Optional
.
of
(
it
.
get
(
0
).
asPublicSetting
()))
.
first
(
Optional
.
absent
()));
}
implements
PublicSettingRepository
{
private
final
String
hostname
;
public
RealmPublicSettingRepository
(
String
hostname
)
{
this
.
hostname
=
hostname
;
}
@Override
public
Single
<
Optional
<
PublicSetting
>>
getById
(
String
id
)
{
return
Single
.
defer
(()
->
Flowable
.
using
(
()
->
new
Pair
<>(
RealmStore
.
getRealm
(
hostname
),
Looper
.
myLooper
()),
pair
->
{
if
(
pair
.
first
==
null
)
{
return
Flowable
.
empty
();
}
return
pair
.
first
.
where
(
RealmPublicSetting
.
class
)
.
equalTo
(
RealmPublicSetting
.
ID
,
id
)
.
findAll
()
.<
RealmResults
<
RealmPublicSetting
>>
asFlowable
();
},
pair
->
close
(
pair
.
first
,
pair
.
second
)
)
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
Looper
.
myLooper
()))
.
filter
(
it
->
it
.
isLoaded
()
&&
it
.
isValid
())
.
map
(
it
->
{
if
(
it
.
size
()
>
0
)
{
return
Optional
.
of
(
it
.
get
(
0
).
asPublicSetting
());
}
PublicSetting
defaultSetting
=
PublicSetting
.
builder
()
.
setId
(
id
)
.
setValue
(
""
)
.
setUpdatedAt
(
0L
)
.
build
();
return
Optional
.
of
(
defaultSetting
);
})
.
first
(
Optional
.
absent
()));
}
}
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