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
be16d670
Commit
be16d670
authored
Aug 24, 2018
by
Kiryl Vashyla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chat history issues fx: on presenter and repository side
parent
f15bca5b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
2 deletions
+55
-2
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+21
-2
MessagesRepository.kt
...a/chat/rocket/android/server/domain/MessagesRepository.kt
+4
-0
MemoryMessagesRepository.kt
...ndroid/server/infraestructure/MemoryMessagesRepository.kt
+8
-0
SharedPreferencesMessagesRepository.kt
...er/infraestructure/SharedPreferencesMessagesRepository.kt
+22
-0
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
be16d670
...
...
@@ -183,7 +183,8 @@ class ChatRoomPresenter @Inject constructor(
isBroadcast
=
chatIsBroadcast
,
isRoom
=
true
)
)
if
(
oldMessages
.
isNotEmpty
())
{
val
lastSyncDate
=
messagesRepository
.
getLastSyncDate
()
if
(
oldMessages
.
isNotEmpty
()
&&
lastSyncDate
!=
null
)
{
view
.
showMessages
(
oldMessages
,
clearDataSet
)
loadMissingMessages
()
}
else
{
...
...
@@ -225,6 +226,15 @@ class ChatRoomPresenter @Inject constructor(
client
.
messages
(
chatRoomId
,
roomTypeOf
(
chatRoomType
),
offset
,
30
).
result
}
messagesRepository
.
saveAll
(
messages
)
//if success - saving last synced time
if
(
messages
.
isEmpty
())
{
messagesRepository
.
saveLastSyncDate
(
System
.
currentTimeMillis
())
}
else
{
//TODO sort
messagesRepository
.
saveLastSyncDate
(
messages
.
last
().
timestamp
)
}
view
.
showMessages
(
mapper
.
map
(
messages
,
...
...
@@ -493,8 +503,14 @@ class ChatRoomPresenter @Inject constructor(
if
(
chatRoomId
!=
null
&&
chatRoomType
!=
null
)
{
val
roomType
=
roomTypeOf
(
chatRoomType
!!
)
messagesRepository
.
getByRoomId
(
chatRoomId
!!
)
//FIXME last message could not be sent
.
sortedByDescending
{
it
.
timestamp
}.
firstOrNull
()
?.
let
{
lastMessage
->
val
instant
=
Instant
.
ofEpochMilli
(
lastMessage
.
timestamp
).
toString
()
val
lastSyncDate
=
messagesRepository
.
getLastSyncDate
()
// lastSyncDate or 0. LastSyncDate could be in case when we sent some messages offline(and saved them locally),
// but never has obtained chatMessages(or history) from remote. In this case we should sync all chat history from beginning
val
instant
=
Instant
.
ofEpochMilli
(
lastSyncDate
?:
0
).
toString
()
try
{
val
messages
=
retryIO
(
description
=
"history($chatRoomId, $roomType, $instant)"
)
{
...
...
@@ -513,6 +529,9 @@ class ChatRoomPresenter @Inject constructor(
isRoom
=
true
))
messagesRepository
.
saveAll
(
messages
.
result
)
//if success - saving last synced time
// TODO sort and peek the latest date
messagesRepository
.
saveLastSyncDate
(
messages
.
result
.
last
().
timestamp
)
launchUI
(
strategy
)
{
view
.
showNewMessage
(
models
,
true
)
...
...
app/src/main/java/chat/rocket/android/server/domain/MessagesRepository.kt
View file @
be16d670
...
...
@@ -72,4 +72,8 @@ interface MessagesRepository {
suspend
fun
getAllUnsent
():
List
<
Message
>
suspend
fun
getUnsentByRoomId
(
roomId
:
String
):
List
<
Message
>
suspend
fun
saveLastSyncDate
(
currentTimeMillis
:
Long
)
suspend
fun
getLastSyncDate
():
Long
?
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/infraestructure/MemoryMessagesRepository.kt
View file @
be16d670
...
...
@@ -7,6 +7,14 @@ import kotlinx.coroutines.experimental.withContext
class
MemoryMessagesRepository
:
MessagesRepository
{
private
var
lastSyncDate
:
Long
?
=
null
override
suspend
fun
saveLastSyncDate
(
it
:
Long
)
{
lastSyncDate
=
it
}
override
suspend
fun
getLastSyncDate
()
=
lastSyncDate
private
val
messages
:
HashMap
<
String
,
Message
>
=
HashMap
()
override
suspend
fun
getById
(
id
:
String
):
Message
?
=
withContext
(
CommonPool
)
{
...
...
app/src/main/java/chat/rocket/android/server/infraestructure/SharedPreferencesMessagesRepository.kt
View file @
be16d670
...
...
@@ -13,6 +13,28 @@ class SharedPreferencesMessagesRepository(
private
val
moshi
:
Moshi
,
private
val
currentServerInteractor
:
GetCurrentServerInteractor
)
:
MessagesRepository
{
private
val
KEY_LAST_SYNC_DATE
=
"KEY_LAST_SYNC_DATE"
override
suspend
fun
saveLastSyncDate
(
currentTimeMillis
:
Long
)
{
withContext
(
CommonPool
)
{
currentServerInteractor
.
get
()
?.
let
{
prefs
.
edit
().
putLong
(
getSyncDateKey
(
it
),
currentTimeMillis
).
apply
()
}
}
}
override
suspend
fun
getLastSyncDate
():
Long
?
=
withContext
(
CommonPool
)
{
currentServerInteractor
.
get
()
?.
also
{
server
->
if
(!
prefs
.
contains
(
getSyncDateKey
(
server
)))
return
@withContext
null
//
val
time
=
prefs
.
getLong
(
getSyncDateKey
(
server
),
-
1
)
return
@withContext
if
(
time
==
-
1L
)
null
else
time
}
return
@withContext
null
}
private
fun
getSyncDateKey
(
it
:
String
)
=
"${KEY_LAST_SYNC_DATE}_${it}"
override
suspend
fun
getById
(
id
:
String
):
Message
?
=
withContext
(
CommonPool
)
{
currentServerInteractor
.
get
()
?.
also
{
server
->
...
...
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