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
1071f098
Commit
1071f098
authored
Feb 13, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A little better (?)
parent
d0e6bc2f
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
143 additions
and
97 deletions
+143
-97
RoomFragment.java
...a/chat/rocket/android/fragment/chatroom/RoomFragment.java
+7
-1
RoomPresenter.java
.../chat/rocket/android/fragment/chatroom/RoomPresenter.java
+36
-59
ModelListAdapter.java
...ocket/android/layouthelper/chatroom/ModelListAdapter.java
+1
-2
RealmMessageRepository.java
...ersistence/realm/repositories/RealmMessageRepository.java
+18
-33
MessageInteractor.java
.../java/chat/rocket/core/interactors/MessageInteractor.java
+81
-0
MessageRepository.java
...java/chat/rocket/core/repositories/MessageRepository.java
+0
-2
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomFragment.java
View file @
1071f098
...
...
@@ -45,6 +45,7 @@ import chat.rocket.android.layouthelper.extra_action.upload.AudioUploadActionIte
import
chat.rocket.android.layouthelper.extra_action.upload.ImageUploadActionItem
;
import
chat.rocket.android.layouthelper.extra_action.upload.VideoUploadActionItem
;
import
chat.rocket.android.log.RCLog
;
import
chat.rocket.core.interactors.MessageInteractor
;
import
chat.rocket.core.models.Message
;
import
chat.rocket.core.models.Room
;
import
chat.rocket.persistence.realm.repositories.RealmMessageRepository
;
...
...
@@ -109,11 +110,16 @@ public class RoomFragment extends AbstractChatRoomFragment
hostname
=
args
.
getString
(
HOSTNAME
);
roomId
=
args
.
getString
(
ROOM_ID
);
MessageInteractor
messageInteractor
=
new
MessageInteractor
(
new
RealmMessageRepository
(
hostname
),
new
RealmRoomRepository
(
hostname
)
);
presenter
=
new
RoomPresenter
(
roomId
,
new
RealmUserRepository
(
hostname
),
messageInteractor
,
new
RealmRoomRepository
(
hostname
),
new
RealmMessageRepository
(
hostname
),
new
MethodCallHelper
(
getContext
(),
hostname
),
ConnectivityManager
.
getInstance
(
getContext
())
);
...
...
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomPresenter.java
View file @
1071f098
...
...
@@ -4,15 +4,15 @@ import android.support.annotation.NonNull;
import
android.support.annotation.Nullable
;
import
android.support.v4.util.Pair
;
import
java.util.UUID
;
import
chat.rocket.android.BackgroundLooper
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.shared.BasePresenter
;
import
chat.rocket.core.SyncState
;
import
chat.rocket.core.interactors.MessageInteractor
;
import
chat.rocket.core.models.Message
;
import
chat.rocket.core.models.Room
HistoryState
;
import
chat.rocket.core.
repositories.MessageRepository
;
import
chat.rocket.core.models.Room
;
import
chat.rocket.core.
models.User
;
import
chat.rocket.core.repositories.RoomRepository
;
import
chat.rocket.core.repositories.UserRepository
;
import
chat.rocket.android.service.ConnectivityManagerApi
;
...
...
@@ -24,21 +24,22 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
implements
RoomContract
.
Presenter
{
private
final
String
roomId
;
private
final
MessageInteractor
messageInteractor
;
private
final
UserRepository
userRepository
;
private
final
RoomRepository
roomRepository
;
private
final
MessageRepository
messageRepository
;
private
final
MethodCallHelper
methodCallHelper
;
private
final
ConnectivityManagerApi
connectivityManagerApi
;
public
RoomPresenter
(
String
roomId
,
UserRepository
userRepository
,
public
RoomPresenter
(
String
roomId
,
UserRepository
userRepository
,
MessageInteractor
messageInteractor
,
RoomRepository
roomRepository
,
MessageRepository
messageRepository
,
MethodCallHelper
methodCallHelper
,
ConnectivityManagerApi
connectivityManagerApi
)
{
this
.
roomId
=
roomId
;
this
.
userRepository
=
userRepository
;
this
.
messageInteractor
=
messageInteractor
;
this
.
roomRepository
=
roomRepository
;
this
.
messageRepository
=
messageRepository
;
this
.
methodCallHelper
=
methodCallHelper
;
this
.
connectivityManagerApi
=
connectivityManagerApi
;
}
...
...
@@ -54,16 +55,8 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
@Override
public
void
loadMessages
()
{
RoomHistoryState
roomHistoryState
=
RoomHistoryState
.
builder
()
.
setRoomId
(
roomId
)
.
setSyncState
(
SyncState
.
NOT_SYNCED
)
.
setCount
(
100
)
.
setReset
(
true
)
.
setComplete
(
false
)
.
setTimestamp
(
0
)
.
build
();
final
Subscription
subscription
=
roomRepository
.
setHistoryState
(
roomHistoryState
)
final
Subscription
subscription
=
getSingleRoom
()
.
flatMap
(
messageInteractor:
:
loadMessages
)
.
subscribeOn
(
AndroidSchedulers
.
from
(
BackgroundLooper
.
get
()))
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
success
->
{
...
...
@@ -78,16 +71,8 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
@Override
public
void
loadMoreMessages
()
{
final
Subscription
subscription
=
roomRepository
.
getHistoryStateByRoomId
(
roomId
)
.
filter
(
roomHistoryState
->
{
int
syncState
=
roomHistoryState
.
getSyncState
();
return
!
roomHistoryState
.
isComplete
()
&&
(
syncState
==
SyncState
.
SYNCED
||
syncState
==
SyncState
.
FAILED
);
})
.
first
()
.
toSingle
()
.
flatMap
(
roomHistoryState
->
roomRepository
.
setHistoryState
(
roomHistoryState
.
withSyncState
(
SyncState
.
NOT_SYNCED
)))
final
Subscription
subscription
=
getSingleRoom
()
.
flatMap
(
messageInteractor:
:
loadMoreMessages
)
.
subscribeOn
(
AndroidSchedulers
.
from
(
BackgroundLooper
.
get
()))
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
success
->
{
...
...
@@ -112,23 +97,8 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
@Override
public
void
sendMessage
(
String
messageText
)
{
final
Subscription
subscription
=
userRepository
.
getCurrent
()
.
filter
(
user
->
user
!=
null
)
.
first
()
.
toSingle
()
.
flatMap
(
user
->
{
Message
message
=
Message
.
builder
()
.
setId
(
UUID
.
randomUUID
().
toString
())
.
setSyncState
(
SyncState
.
NOT_SYNCED
)
.
setTimestamp
(
System
.
currentTimeMillis
())
.
setRoomId
(
roomId
)
.
setMessage
(
messageText
)
.
setGroupable
(
false
)
.
setUser
(
user
)
.
build
();
return
messageRepository
.
save
(
message
);
})
final
Subscription
subscription
=
getRoomUserPair
()
.
flatMap
(
pair
->
messageInteractor
.
send
(
pair
.
first
,
pair
.
second
,
messageText
))
.
subscribeOn
(
AndroidSchedulers
.
from
(
BackgroundLooper
.
get
()))
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
success
->
{
...
...
@@ -142,8 +112,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
@Override
public
void
resendMessage
(
Message
message
)
{
final
Subscription
subscription
=
messageRepository
.
resend
(
message
.
withSyncState
(
SyncState
.
NOT_SYNCED
))
final
Subscription
subscription
=
messageInteractor
.
resend
(
message
)
.
subscribeOn
(
AndroidSchedulers
.
from
(
BackgroundLooper
.
get
()))
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
();
...
...
@@ -153,7 +122,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
@Override
public
void
deleteMessage
(
Message
message
)
{
final
Subscription
subscription
=
message
Repository
.
delete
(
message
)
final
Subscription
subscription
=
message
Interactor
.
delete
(
message
)
.
subscribeOn
(
AndroidSchedulers
.
from
(
BackgroundLooper
.
get
()))
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
();
...
...
@@ -163,17 +132,8 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
@Override
public
void
onUnreadCount
()
{
final
Subscription
subscription
=
Single
.
zip
(
userRepository
.
getCurrent
()
.
filter
(
user
->
user
!=
null
)
.
first
()
.
toSingle
(),
roomRepository
.
getById
(
roomId
)
.
first
()
.
toSingle
(),
(
user
,
room
)
->
new
Pair
<>(
room
,
user
)
)
.
flatMap
(
roomUserPair
->
messageRepository
final
Subscription
subscription
=
getRoomUserPair
()
.
flatMap
(
roomUserPair
->
messageInteractor
.
unreadCountFor
(
roomUserPair
.
first
,
roomUserPair
.
second
))
.
subscribeOn
(
AndroidSchedulers
.
from
(
BackgroundLooper
.
get
()))
.
observeOn
(
AndroidSchedulers
.
mainThread
())
...
...
@@ -232,11 +192,28 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
private
void
getMessages
()
{
final
Subscription
subscription
=
roomRepository
.
getById
(
roomId
)
.
first
()
.
flatMap
(
message
Repository
:
:
getAllFrom
)
.
flatMap
(
message
Interactor
:
:
getAllFrom
)
.
subscribeOn
(
AndroidSchedulers
.
from
(
BackgroundLooper
.
get
()))
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
messages
->
view
.
showMessages
(
messages
));
addSubscription
(
subscription
);
}
private
Single
<
Pair
<
Room
,
User
>>
getRoomUserPair
()
{
return
Single
.
zip
(
getSingleRoom
(),
userRepository
.
getCurrent
()
.
filter
(
user
->
user
!=
null
)
.
first
()
.
toSingle
(),
Pair:
:
new
);
}
private
Single
<
Room
>
getSingleRoom
()
{
return
roomRepository
.
getById
(
roomId
)
.
first
()
.
toSingle
();
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/ModelListAdapter.java
View file @
1071f098
...
...
@@ -25,9 +25,8 @@ public abstract class ModelListAdapter<T, VM, VH extends ModelViewHolder<VM>>
protected
abstract
int
getRealmModelViewType
(
VM
model
);
protected
abstract
@LayoutRes
int
getLayout
(
int
viewType
);
protected
abstract
int
getLayout
(
int
viewType
);
protected
abstract
VH
onCreateRealmModelViewHolder
(
int
viewType
,
View
itemView
);
...
...
persistence-realm/src/main/java/chat/rocket/persistence/realm/repositories/RealmMessageRepository.java
View file @
1071f098
...
...
@@ -69,47 +69,32 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
return
Single
.
just
(
false
);
}
// need to improve this for real
final
JSONObject
messageToSend
=
new
JSONObject
()
.
put
(
RealmMessage
.
ID
,
message
.
getId
())
.
put
(
RealmMessage
.
SYNC_STATE
,
message
.
getSyncState
())
.
put
(
RealmMessage
.
TIMESTAMP
,
message
.
getTimestamp
())
.
put
(
RealmMessage
.
ROOM_ID
,
message
.
getRoomId
())
.
put
(
RealmMessage
.
USER
,
new
JSONObject
()
.
put
(
RealmUser
.
ID
,
message
.
getUser
().
getId
()))
.
put
(
RealmMessage
.
MESSAGE
,
message
.
getMessage
());
realm
.
beginTransaction
();
RealmMessage
realmMessage
=
realm
.
where
(
RealmMessage
.
class
)
.
equalTo
(
RealmMessage
.
ID
,
message
.
getId
())
.
findFirst
();
return
realm
.
createOrUpdateObjectFromJson
(
RealmMessage
.
class
,
messageToSend
)
.
asObservable
()
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
looper
))
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
.
filter
(
it
->
it
!=
null
&&
it
.
isLoaded
()
&&
it
.
isValid
())
.
first
()
.
doOnNext
(
it
->
realm
.
commitTransaction
())
.
toSingle
()
.
map
(
realmObject
->
true
);
});
if
(
realmMessage
==
null
)
{
realmMessage
=
new
RealmMessage
();
}
else
{
realmMessage
=
realm
.
copyFromRealm
(
realmMessage
);
}
@Override
public
Single
<
Boolean
>
resend
(
Message
message
)
{
return
Single
.
defer
(()
->
{
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
(
);
realmMessage
.
setId
(
message
.
getId
());
realmMessage
.
setSyncState
(
message
.
getSyncState
());
realmMessage
.
setTimestamp
(
message
.
getTimestamp
());
realmMessage
.
setRoomId
(
message
.
getRoomId
()
);
realmMessage
.
setMessage
(
message
.
getMessage
()
);
if
(
realm
==
null
)
{
return
Single
.
just
(
false
);
RealmUser
realmUser
=
realmMessage
.
getUser
();
if
(
realmUser
==
null
)
{
realmUser
=
new
RealmUser
();
}
final
JSONObject
messageToSend
=
new
JSONObject
()
.
put
(
RealmMessage
.
ID
,
message
.
getId
())
.
put
(
RealmMessage
.
SYNC_STATE
,
message
.
getSyncState
());
realmUser
.
setId
(
message
.
getUser
().
getId
());
realm
.
beginTransaction
();
return
realm
.
c
reateOrUpdateObjectFromJson
(
RealmMessage
.
class
,
messageToSend
)
return
realm
.
c
opyToRealmOrUpdate
(
realmMessage
)
.
asObservable
()
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
looper
))
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
...
...
rocket-chat-core/src/main/java/chat/rocket/core/interactors/MessageInteractor.java
0 → 100644
View file @
1071f098
package
chat
.
rocket
.
core
.
interactors
;
import
java.util.List
;
import
java.util.UUID
;
import
chat.rocket.core.SyncState
;
import
chat.rocket.core.models.Message
;
import
chat.rocket.core.models.Room
;
import
chat.rocket.core.models.RoomHistoryState
;
import
chat.rocket.core.models.User
;
import
chat.rocket.core.repositories.MessageRepository
;
import
chat.rocket.core.repositories.RoomRepository
;
import
rx.Observable
;
import
rx.Single
;
public
class
MessageInteractor
{
private
final
MessageRepository
messageRepository
;
private
final
RoomRepository
roomRepository
;
public
MessageInteractor
(
MessageRepository
messageRepository
,
RoomRepository
roomRepository
)
{
this
.
messageRepository
=
messageRepository
;
this
.
roomRepository
=
roomRepository
;
}
public
Single
<
Boolean
>
loadMessages
(
Room
room
)
{
final
RoomHistoryState
roomHistoryState
=
RoomHistoryState
.
builder
()
.
setRoomId
(
room
.
getRoomId
())
.
setSyncState
(
SyncState
.
NOT_SYNCED
)
.
setCount
(
100
)
.
setReset
(
true
)
.
setComplete
(
false
)
.
setTimestamp
(
0
)
.
build
();
return
roomRepository
.
setHistoryState
(
roomHistoryState
);
}
public
Single
<
Boolean
>
loadMoreMessages
(
Room
room
)
{
return
roomRepository
.
getHistoryStateByRoomId
(
room
.
getRoomId
())
.
filter
(
roomHistoryState
->
{
int
syncState
=
roomHistoryState
.
getSyncState
();
return
!
roomHistoryState
.
isComplete
()
&&
(
syncState
==
SyncState
.
SYNCED
||
syncState
==
SyncState
.
FAILED
);
})
.
first
()
.
toSingle
()
.
flatMap
(
roomHistoryState
->
roomRepository
.
setHistoryState
(
roomHistoryState
.
withSyncState
(
SyncState
.
NOT_SYNCED
)));
}
public
Single
<
Boolean
>
send
(
Room
destination
,
User
sender
,
String
messageText
)
{
final
Message
message
=
Message
.
builder
()
.
setId
(
UUID
.
randomUUID
().
toString
())
.
setSyncState
(
SyncState
.
NOT_SYNCED
)
.
setTimestamp
(
System
.
currentTimeMillis
())
.
setRoomId
(
destination
.
getRoomId
())
.
setMessage
(
messageText
)
.
setGroupable
(
false
)
.
setUser
(
sender
)
.
build
();
return
messageRepository
.
save
(
message
);
}
public
Single
<
Boolean
>
resend
(
Message
message
)
{
return
messageRepository
.
save
(
message
.
withSyncState
(
SyncState
.
NOT_SYNCED
));
}
public
Single
<
Boolean
>
delete
(
Message
message
)
{
return
messageRepository
.
delete
(
message
);
}
public
Single
<
Integer
>
unreadCountFor
(
Room
room
,
User
user
)
{
return
messageRepository
.
unreadCountFor
(
room
,
user
);
}
public
Observable
<
List
<
Message
>>
getAllFrom
(
Room
room
)
{
return
messageRepository
.
getAllFrom
(
room
);
}
}
rocket-chat-core/src/main/java/chat/rocket/core/repositories/MessageRepository.java
View file @
1071f098
...
...
@@ -13,8 +13,6 @@ public interface MessageRepository {
Single
<
Boolean
>
save
(
Message
message
);
Single
<
Boolean
>
resend
(
Message
message
);
Single
<
Boolean
>
delete
(
Message
message
);
Observable
<
List
<
Message
>>
getAllFrom
(
Room
room
);
...
...
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