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
3eb9b754
Commit
3eb9b754
authored
Feb 13, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes
parent
3678835c
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
128 additions
and
90 deletions
+128
-90
MainActivity.java
.../main/java/chat/rocket/android/activity/MainActivity.java
+20
-50
MainContract.java
.../main/java/chat/rocket/android/activity/MainContract.java
+2
-0
MainPresenter.java
...main/java/chat/rocket/android/activity/MainPresenter.java
+29
-1
SidebarMainFragment.java
.../rocket/android/fragment/sidebar/SidebarMainFragment.java
+2
-1
SidebarMainPresenter.java
...rocket/android/fragment/sidebar/SidebarMainPresenter.java
+5
-5
RealmMessageRepository.java
...ersistence/realm/repositories/RealmMessageRepository.java
+5
-5
RealmRepository.java
...ocket/persistence/realm/repositories/RealmRepository.java
+1
-6
RealmRoomRepository.java
...t/persistence/realm/repositories/RealmRoomRepository.java
+8
-9
RealmSessionRepository.java
...ersistence/realm/repositories/RealmSessionRepository.java
+3
-3
RealmUserRepository.java
...t/persistence/realm/repositories/RealmUserRepository.java
+2
-2
CanCreateRoomInteractor.java
...chat/rocket/core/interactors/CanCreateRoomInteractor.java
+4
-5
RoomInteractor.java
...ain/java/chat/rocket/core/interactors/RoomInteractor.java
+38
-0
SessionInteractor.java
.../java/chat/rocket/core/interactors/SessionInteractor.java
+7
-1
RoomRepository.java
...in/java/chat/rocket/core/repositories/RoomRepository.java
+1
-1
SessionRepository.java
...java/chat/rocket/core/repositories/SessionRepository.java
+1
-1
No files found.
app/src/main/java/chat/rocket/android/activity/MainActivity.java
View file @
3eb9b754
...
...
@@ -8,7 +8,6 @@ import android.support.v7.graphics.drawable.DrawerArrowDrawable;
import
android.support.v7.widget.Toolbar
;
import
android.view.View
;
import
java.util.List
;
import
chat.rocket.android.LaunchUtil
;
import
chat.rocket.android.R
;
import
chat.rocket.android.api.MethodCallHelper
;
...
...
@@ -18,15 +17,16 @@ import chat.rocket.android.fragment.sidebar.SidebarMainFragment;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.core.interactors.CanCreateRoomInteractor
;
import
chat.rocket.persistence.realm.models.ddp.RealmRoom
;
import
chat.rocket.core.interactors.RoomInteractor
;
import
chat.rocket.core.interactors.SessionInteractor
;
import
chat.rocket.persistence.realm.models.ddp.RealmUser
;
import
chat.rocket.persistence.realm.models.internal.RealmSession
;
import
chat.rocket.persistence.realm.RealmHelper
;
import
chat.rocket.persistence.realm.RealmListObserver
;
import
chat.rocket.persistence.realm.RealmObjectObserver
;
import
chat.rocket.persistence.realm.RealmStore
;
import
chat.rocket.android.service.ConnectivityManager
;
import
chat.rocket.android.widget.RoomToolbar
;
import
chat.rocket.persistence.realm.repositories.RealmRoomRepository
;
import
chat.rocket.persistence.realm.repositories.RealmSessionRepository
;
import
chat.rocket.persistence.realm.repositories.RealmUserRepository
;
import
hugo.weaving.DebugLog
;
...
...
@@ -37,7 +37,6 @@ import hugo.weaving.DebugLog;
public
class
MainActivity
extends
AbstractAuthedActivity
implements
MainContract
.
View
{
private
RealmObjectObserver
<
RealmSession
>
sessionObserver
;
private
RealmListObserver
<
RealmRoom
>
unreadRoomSubscriptionObserver
;
private
boolean
isForeground
;
private
StatusTicker
statusTicker
;
...
...
@@ -180,14 +179,19 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
if
(
presenter
!=
null
)
{
presenter
.
release
();
}
CanCreateRoomInteractor
interactor
=
new
CanCreateRoomInteractor
(
RoomInteractor
roomInteractor
=
new
RoomInteractor
(
new
RealmRoomRepository
(
hostname
));
CanCreateRoomInteractor
createRoomInteractor
=
new
CanCreateRoomInteractor
(
new
RealmUserRepository
(
hostname
),
new
RealmSessionRepository
(
hostname
)
new
SessionInteractor
(
new
RealmSessionRepository
(
hostname
)
)
);
presenter
=
new
MainPresenter
(
interactor
);
presenter
=
new
MainPresenter
(
roomInteractor
,
createRoomInteractor
);
updateSessionObserver
();
updateUnreadRoomSubscriptionObserver
();
updateSidebarMainFragment
();
}
...
...
@@ -235,44 +239,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
}
}
private
void
updateUnreadRoomSubscriptionObserver
()
{
if
(
unreadRoomSubscriptionObserver
!=
null
)
{
unreadRoomSubscriptionObserver
.
unsub
();
unreadRoomSubscriptionObserver
=
null
;
}
if
(
hostname
==
null
)
{
return
;
}
RealmHelper
realmHelper
=
RealmStore
.
get
(
hostname
);
if
(
realmHelper
==
null
)
{
return
;
}
unreadRoomSubscriptionObserver
=
realmHelper
.
createListObserver
(
realm
->
realm
.
where
(
RealmRoom
.
class
)
.
equalTo
(
RealmRoom
.
ALERT
,
true
)
.
equalTo
(
RealmRoom
.
OPEN
,
true
)
.
findAll
())
.
setOnUpdateListener
(
this
::
updateRoomToolbarUnreadCount
);
unreadRoomSubscriptionObserver
.
sub
();
}
private
void
updateRoomToolbarUnreadCount
(
List
<
RealmRoom
>
unreadRooms
)
{
RoomToolbar
toolbar
=
(
RoomToolbar
)
findViewById
(
R
.
id
.
activity_main_toolbar
);
if
(
toolbar
!=
null
)
{
//ref: Rocket.Chat:client/startup/unread.js
final
int
numUnreadChannels
=
unreadRooms
.
size
();
int
numMentionsSum
=
0
;
for
(
RealmRoom
room
:
unreadRooms
)
{
numMentionsSum
+=
room
.
getUnread
();
}
toolbar
.
setUnreadBudge
(
numUnreadChannels
,
numMentionsSum
);
}
}
private
void
updateSidebarMainFragment
()
{
getSupportFragmentManager
().
beginTransaction
()
.
replace
(
R
.
id
.
sidebar_fragment_container
,
SidebarMainFragment
.
create
(
hostname
))
...
...
@@ -291,10 +257,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
sessionObserver
.
unsub
();
sessionObserver
=
null
;
}
if
(
unreadRoomSubscriptionObserver
!=
null
)
{
unreadRoomSubscriptionObserver
.
unsub
();
unreadRoomSubscriptionObserver
=
null
;
}
super
.
onDestroy
();
}
...
...
@@ -314,6 +276,14 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
closeSidebarIfNeeded
();
}
@Override
public
void
showUnreadCount
(
int
roomsCount
,
int
mentionsCount
)
{
RoomToolbar
toolbar
=
(
RoomToolbar
)
findViewById
(
R
.
id
.
activity_main_toolbar
);
if
(
toolbar
!=
null
)
{
toolbar
.
setUnreadBudge
(
roomsCount
,
mentionsCount
);
}
}
//TODO: consider this class to define in layouthelper for more complicated operation.
private
static
class
StatusTicker
{
public
static
final
int
STATUS_DISMISS
=
0
;
...
...
app/src/main/java/chat/rocket/android/activity/MainContract.java
View file @
3eb9b754
...
...
@@ -9,6 +9,8 @@ public interface MainContract {
void
showHome
();
void
showRoom
(
String
hostname
,
String
roomId
);
void
showUnreadCount
(
int
roomsCount
,
int
mentionsCount
);
}
interface
Presenter
extends
BaseContract
.
Presenter
<
View
>
{
...
...
app/src/main/java/chat/rocket/android/activity/MainPresenter.java
View file @
3eb9b754
package
chat
.
rocket
.
android
.
activity
;
import
android.support.annotation.NonNull
;
import
android.support.v4.util.Pair
;
import
chat.rocket.android.BackgroundLooper
;
import
chat.rocket.android.shared.BasePresenter
;
import
chat.rocket.core.interactors.CanCreateRoomInteractor
;
import
chat.rocket.core.interactors.RoomInteractor
;
import
rx.Observable
;
import
rx.Subscription
;
import
rx.android.schedulers.AndroidSchedulers
;
...
...
@@ -10,11 +15,34 @@ public class MainPresenter extends BasePresenter<MainContract.View>
implements
MainContract
.
Presenter
{
private
final
CanCreateRoomInteractor
canCreateRoomInteractor
;
private
final
RoomInteractor
roomInteractor
;
public
MainPresenter
(
CanCreateRoomInteractor
canCreateRoomInteractor
)
{
public
MainPresenter
(
RoomInteractor
roomInteractor
,
CanCreateRoomInteractor
canCreateRoomInteractor
)
{
this
.
roomInteractor
=
roomInteractor
;
this
.
canCreateRoomInteractor
=
canCreateRoomInteractor
;
}
@Override
public
void
bindView
(
@NonNull
MainContract
.
View
view
)
{
super
.
bindView
(
view
);
subscribeToUnreadCount
();
}
private
void
subscribeToUnreadCount
()
{
final
Subscription
subscription
=
Observable
.
combineLatest
(
roomInteractor
.
getTotalUnreadRoomsCount
(),
roomInteractor
.
getTotalUnreadMentionsCount
(),
(
Pair:
:
new
)
)
.
subscribeOn
(
AndroidSchedulers
.
from
(
BackgroundLooper
.
get
()))
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
pair
->
view
.
showUnreadCount
(
pair
.
first
,
pair
.
second
));
addSubscription
(
subscription
);
}
@Override
public
void
onOpenRoom
(
String
hostname
,
String
roomId
)
{
final
Subscription
subscription
=
canCreateRoomInteractor
.
canCreate
(
roomId
)
...
...
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainFragment.java
View file @
3eb9b754
...
...
@@ -22,6 +22,7 @@ import chat.rocket.android.fragment.sidebar.dialog.AddChannelDialogFragment;
import
chat.rocket.android.fragment.sidebar.dialog.AddDirectMessageDialogFragment
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.layouthelper.chatroom.RoomListManager
;
import
chat.rocket.core.interactors.RoomInteractor
;
import
chat.rocket.core.models.Room
;
import
chat.rocket.core.models.User
;
import
chat.rocket.android.renderer.UserRenderer
;
...
...
@@ -64,7 +65,7 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
presenter
=
new
SidebarMainPresenter
(
hostname
,
new
R
ealmRoomRepository
(
hostname
),
new
R
oomInteractor
(
new
RealmRoomRepository
(
hostname
)
),
new
RealmUserRepository
(
hostname
),
TextUtils
.
isEmpty
(
hostname
)
?
null
:
new
MethodCallHelper
(
getContext
(),
hostname
)
);
...
...
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainPresenter.java
View file @
3eb9b754
...
...
@@ -7,8 +7,8 @@ import chat.rocket.android.api.MethodCallHelper;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.shared.BasePresenter
;
import
chat.rocket.core.interactors.RoomInteractor
;
import
chat.rocket.core.models.User
;
import
chat.rocket.core.repositories.RoomRepository
;
import
chat.rocket.core.repositories.UserRepository
;
import
rx.Subscription
;
import
rx.android.schedulers.AndroidSchedulers
;
...
...
@@ -17,14 +17,14 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
implements
SidebarMainContract
.
Presenter
{
private
final
String
hostname
;
private
final
Room
Repository
roomRepository
;
private
final
Room
Interactor
roomInteractor
;
private
final
UserRepository
userRepository
;
private
final
MethodCallHelper
methodCallHelper
;
public
SidebarMainPresenter
(
String
hostname
,
Room
Repository
roomRepository
,
public
SidebarMainPresenter
(
String
hostname
,
Room
Interactor
roomInteractor
,
UserRepository
userRepository
,
MethodCallHelper
methodCallHelper
)
{
this
.
hostname
=
hostname
;
this
.
room
Repository
=
roomRepository
;
this
.
room
Interactor
=
roomInteractor
;
this
.
userRepository
=
userRepository
;
this
.
methodCallHelper
=
methodCallHelper
;
}
...
...
@@ -72,7 +72,7 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
}
private
void
subscribeToRooms
()
{
final
Subscription
subscription
=
room
Repository
.
getOpenRooms
()
final
Subscription
subscription
=
room
Interactor
.
getOpenRooms
()
.
distinctUntilChanged
()
.
subscribeOn
(
AndroidSchedulers
.
from
(
BackgroundLooper
.
get
()))
.
observeOn
(
AndroidSchedulers
.
mainThread
())
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmMessageRepository.java
View file @
3eb9b754
...
...
@@ -32,7 +32,7 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
if
(
realm
==
null
||
looper
==
null
)
{
return
Single
.
just
(
null
);
}
...
...
@@ -63,7 +63,7 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
if
(
realm
==
null
||
looper
==
null
)
{
return
Single
.
just
(
false
);
}
...
...
@@ -110,7 +110,7 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
if
(
realm
==
null
||
looper
==
null
)
{
return
Single
.
just
(
false
);
}
...
...
@@ -143,7 +143,7 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
if
(
realm
==
null
||
looper
==
null
)
{
return
Observable
.
just
(
null
);
}
...
...
@@ -165,7 +165,7 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
if
(
realm
==
null
||
looper
==
null
)
{
return
Single
.
just
(
0
);
}
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmRepository.java
View file @
3eb9b754
...
...
@@ -7,11 +7,6 @@ import io.realm.Realm;
public
class
RealmRepository
{
protected
void
close
(
Realm
realm
,
Looper
looper
)
{
new
Handler
(
looper
).
post
(
new
Runnable
()
{
@Override
public
void
run
()
{
realm
.
close
();
}
});
new
Handler
(
looper
).
post
(
realm:
:
close
);
}
}
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmRoomRepository.java
View file @
3eb9b754
...
...
@@ -25,24 +25,23 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
}
@Override
public
Observable
<
List
<
Room
>>
get
OpenRooms
()
{
public
Observable
<
List
<
Room
>>
get
All
()
{
return
Observable
.
defer
(()
->
{
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
if
(
realm
==
null
||
looper
==
null
)
{
return
Observable
.
just
(
null
);
}
return
realm
.
where
(
RealmRoom
.
class
)
.
equalTo
(
RealmRoom
.
OPEN
,
true
)
.
findAll
()
.
asObservable
()
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
looper
))
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
.
filter
(
roomSubscriptions
->
roomSubscriptions
!=
null
&&
roomSubscriptions
.
isLoaded
()
&&
roomSubscriptions
.
isValid
())
.
map
(
roomSubscriptions
->
toList
(
roomSubscriptions
)
);
.
map
(
this
::
toList
);
});
}
...
...
@@ -52,7 +51,7 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
if
(
realm
==
null
||
looper
==
null
)
{
return
Observable
.
just
(
null
);
}
...
...
@@ -64,7 +63,7 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
.
filter
(
roomSubscription
->
roomSubscription
!=
null
&&
roomSubscription
.
isLoaded
()
&&
roomSubscription
.
isValid
())
.
map
(
roomSubscription
->
roomSubscription
.
asRoom
()
);
.
map
(
RealmRoom:
:
asRoom
);
});
}
...
...
@@ -74,7 +73,7 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
if
(
realm
==
null
||
looper
==
null
)
{
return
Observable
.
just
(
null
);
}
...
...
@@ -86,7 +85,7 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
.
filter
(
loadMessageProcedure
->
loadMessageProcedure
!=
null
&&
loadMessageProcedure
.
isLoaded
()
&&
loadMessageProcedure
.
isValid
())
.
map
(
loadMessageProcedure
->
loadMessageProcedure
.
asRoomHistoryState
()
);
.
map
(
LoadMessageProcedure:
:
asRoomHistoryState
);
});
}
...
...
@@ -96,7 +95,7 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
if
(
realm
==
null
||
looper
==
null
)
{
return
Single
.
just
(
false
);
}
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmSessionRepository.java
View file @
3eb9b754
...
...
@@ -19,17 +19,17 @@ public class RealmSessionRepository extends RealmRepository implements SessionRe
}
@Override
public
Observable
<
Session
>
get
Default
(
)
{
public
Observable
<
Session
>
get
ById
(
int
id
)
{
return
Observable
.
defer
(()
->
{
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
if
(
realm
==
null
||
looper
==
null
)
{
return
Observable
.
just
(
null
);
}
return
realm
.
where
(
RealmSession
.
class
)
.
equalTo
(
RealmSession
.
ID
,
RealmSession
.
DEFAULT_ID
)
.
equalTo
(
RealmSession
.
ID
,
id
)
.
findAll
()
.<
RealmSession
>
asObservable
()
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
looper
))
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmUserRepository.java
View file @
3eb9b754
...
...
@@ -24,7 +24,7 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
if
(
realm
==
null
||
looper
==
null
)
{
return
Observable
.
just
(
null
);
}
...
...
@@ -42,7 +42,7 @@ public class RealmUserRepository extends RealmRepository implements UserReposito
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
looper
))
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
.
filter
(
it
->
it
!=
null
&&
it
.
isLoaded
()
&&
it
.
isValid
())
.
map
(
it
->
it
.
asUser
()
);
.
map
(
RealmUser:
:
asUser
);
});
}
}
rocket-chat-core/src/main/java/chat/rocket/core/interactors/CanCreateRoomInteractor.java
View file @
3eb9b754
package
chat
.
rocket
.
core
.
interactors
;
import
chat.rocket.core.repositories.SessionRepository
;
import
chat.rocket.core.repositories.UserRepository
;
import
rx.Observable
;
import
rx.Single
;
...
...
@@ -8,18 +7,18 @@ import rx.Single;
public
class
CanCreateRoomInteractor
{
private
final
UserRepository
userRepository
;
private
final
Session
Repository
sessionRepository
;
private
final
Session
Interactor
sessionInteractor
;
public
CanCreateRoomInteractor
(
UserRepository
userRepository
,
Session
Repository
sessionRepository
)
{
Session
Interactor
sessionInteractor
)
{
this
.
userRepository
=
userRepository
;
this
.
session
Repository
=
sessionRepository
;
this
.
session
Interactor
=
sessionInteractor
;
}
public
Single
<
Boolean
>
canCreate
(
String
roomId
)
{
return
Observable
.
zip
(
userRepository
.
getCurrent
(),
session
Repository
.
getDefault
(),
session
Interactor
.
getDefault
(),
Observable
.
just
(
roomId
),
(
user
,
session
,
room
)
->
user
!=
null
&&
session
!=
null
&&
room
!=
null
)
...
...
rocket-chat-core/src/main/java/chat/rocket/core/interactors/RoomInteractor.java
0 → 100644
View file @
3eb9b754
package
chat
.
rocket
.
core
.
interactors
;
import
java.util.List
;
import
chat.rocket.core.models.Room
;
import
chat.rocket.core.repositories.RoomRepository
;
import
rx.Observable
;
public
class
RoomInteractor
{
private
final
RoomRepository
roomRepository
;
public
RoomInteractor
(
RoomRepository
roomRepository
)
{
this
.
roomRepository
=
roomRepository
;
}
public
Observable
<
Integer
>
getTotalUnreadMentionsCount
()
{
return
roomRepository
.
getAll
()
.
flatMap
(
rooms
->
Observable
.
from
(
rooms
)
.
filter
(
room
->
room
.
isOpen
()
&&
room
.
isAlert
())
.
map
(
Room:
:
getUnread
)
.
defaultIfEmpty
(
0
)
.
reduce
((
unreadCount
,
unreadCount2
)
->
unreadCount
+
unreadCount2
));
}
public
Observable
<
Integer
>
getTotalUnreadRoomsCount
()
{
return
roomRepository
.
getAll
()
.
flatMap
(
rooms
->
Observable
.
from
(
rooms
)
.
filter
(
room
->
room
.
isOpen
()
&&
room
.
isAlert
())
.
count
());
}
public
Observable
<
List
<
Room
>>
getOpenRooms
()
{
return
roomRepository
.
getAll
()
.
flatMap
(
rooms
->
Observable
.
from
(
rooms
)
.
filter
(
Room:
:
isOpen
)
.
toList
());
}
}
rocket-chat-core/src/main/java/chat/rocket/core/interactors/SessionInteractor.java
View file @
3eb9b754
...
...
@@ -6,14 +6,20 @@ import rx.Observable;
public
class
SessionInteractor
{
private
static
final
int
DEFAULT_ID
=
0
;
private
final
SessionRepository
sessionRepository
;
public
SessionInteractor
(
SessionRepository
sessionRepository
)
{
this
.
sessionRepository
=
sessionRepository
;
}
public
Observable
<
Session
>
getDefault
()
{
return
sessionRepository
.
getById
(
DEFAULT_ID
);
}
public
Observable
<
Session
.
State
>
getSessionState
()
{
return
sessionRepository
.
getDefault
()
return
getDefault
()
.
map
(
this
::
getStateFrom
);
}
...
...
rocket-chat-core/src/main/java/chat/rocket/core/repositories/RoomRepository.java
View file @
3eb9b754
...
...
@@ -8,7 +8,7 @@ import rx.Single;
public
interface
RoomRepository
{
Observable
<
List
<
Room
>>
get
OpenRooms
();
Observable
<
List
<
Room
>>
get
All
();
Observable
<
Room
>
getById
(
String
roomId
);
...
...
rocket-chat-core/src/main/java/chat/rocket/core/repositories/SessionRepository.java
View file @
3eb9b754
...
...
@@ -5,5 +5,5 @@ import rx.Observable;
public
interface
SessionRepository
{
Observable
<
Session
>
get
Default
(
);
Observable
<
Session
>
get
ById
(
int
id
);
}
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