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
88caa298
Commit
88caa298
authored
Sep 06, 2018
by
Kiryl Vashyla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PR #1615 fix. Chat synced time associated with roomId
parent
79d91e89
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
26 deletions
+43
-26
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+15
-12
MessagesRepository.kt
...a/chat/rocket/android/server/domain/MessagesRepository.kt
+16
-2
MemoryMessagesRepository.kt
...ndroid/server/infraestructure/MemoryMessagesRepository.kt
+6
-6
SharedPreferencesMessagesRepository.kt
...er/infraestructure/SharedPreferencesMessagesRepository.kt
+6
-6
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
88caa298
...
@@ -184,7 +184,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -184,7 +184,7 @@ class ChatRoomPresenter @Inject constructor(
isBroadcast
=
chatIsBroadcast
,
isRoom
=
true
isBroadcast
=
chatIsBroadcast
,
isRoom
=
true
)
)
)
)
val
lastSyncDate
=
messagesRepository
.
getLastSyncDate
()
val
lastSyncDate
=
messagesRepository
.
getLastSyncDate
(
chatRoomId
)
if
(
oldMessages
.
isNotEmpty
()
&&
lastSyncDate
!=
null
)
{
if
(
oldMessages
.
isNotEmpty
()
&&
lastSyncDate
!=
null
)
{
view
.
showMessages
(
oldMessages
,
clearDataSet
)
view
.
showMessages
(
oldMessages
,
clearDataSet
)
loadMissingMessages
()
loadMissingMessages
()
...
@@ -228,13 +228,16 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -228,13 +228,16 @@ class ChatRoomPresenter @Inject constructor(
}
}
messagesRepository
.
saveAll
(
messages
)
messagesRepository
.
saveAll
(
messages
)
//if success - saving last synced time
//we are saving last sync date of latest synced chat room message
if
(
messages
.
isEmpty
())
{
if
(
offset
==
0L
)
{
//chat history is empty - just saving current date
//if success - saving last synced time
messagesRepository
.
saveLastSyncDate
(
System
.
currentTimeMillis
())
if
(
messages
.
isEmpty
())
{
}
else
{
//chat history is empty - just saving current date
//assume that BE returns ordered messages, the first message is the latest one
messagesRepository
.
saveLastSyncDate
(
chatRoomId
,
System
.
currentTimeMillis
())
messagesRepository
.
saveLastSyncDate
(
messages
.
first
().
timestamp
)
}
else
{
//assume that BE returns ordered messages, the first message is the latest one
messagesRepository
.
saveLastSyncDate
(
chatRoomId
,
messages
.
first
().
timestamp
)
}
}
}
view
.
showMessages
(
view
.
showMessages
(
...
@@ -494,9 +497,9 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -494,9 +497,9 @@ class ChatRoomPresenter @Inject constructor(
private
fun
loadMissingMessages
()
{
private
fun
loadMissingMessages
()
{
launch
(
parent
=
strategy
.
jobs
)
{
launch
(
parent
=
strategy
.
jobs
)
{
if
(
chatRoomId
!=
null
&&
chatRoomType
!=
null
)
{
chatRoomId
?.
let
{
chatRoomId
->
val
roomType
=
roomTypeOf
(
chatRoomType
!!
)
val
roomType
=
roomTypeOf
(
chatRoomType
)
val
lastSyncDate
=
messagesRepository
.
getLastSyncDate
()
val
lastSyncDate
=
messagesRepository
.
getLastSyncDate
(
chatRoomId
)
// lastSyncDate or 0. LastSyncDate could be in case when we sent some messages offline(and saved them locally),
// 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
// 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
()
val
instant
=
Instant
.
ofEpochMilli
(
lastSyncDate
?:
0
).
toString
()
...
@@ -521,7 +524,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -521,7 +524,7 @@ class ChatRoomPresenter @Inject constructor(
messagesRepository
.
saveAll
(
messages
.
result
)
messagesRepository
.
saveAll
(
messages
.
result
)
//if success - saving last synced time
//if success - saving last synced time
//assume that BE returns ordered messages, the first message is the latest one
//assume that BE returns ordered messages, the first message is the latest one
messagesRepository
.
saveLastSyncDate
(
messages
.
result
.
first
().
timestamp
)
messagesRepository
.
saveLastSyncDate
(
chatRoomId
,
messages
.
result
.
first
().
timestamp
)
launchUI
(
strategy
)
{
launchUI
(
strategy
)
{
view
.
showNewMessage
(
models
,
true
)
view
.
showNewMessage
(
models
,
true
)
...
...
app/src/main/java/chat/rocket/android/server/domain/MessagesRepository.kt
View file @
88caa298
...
@@ -73,7 +73,21 @@ interface MessagesRepository {
...
@@ -73,7 +73,21 @@ interface MessagesRepository {
suspend
fun
getUnsentByRoomId
(
roomId
:
String
):
List
<
Message
>
suspend
fun
getUnsentByRoomId
(
roomId
:
String
):
List
<
Message
>
suspend
fun
saveLastSyncDate
(
currentTimeMillis
:
Long
)
/**
* Save time of the latest room messages sync.
* Call this fun only when the latest messages list being received via /history or /messages network calls
*
* @param rid The id of the room the messages are.
* @param timeMillis time of room messages sync or the latest room message timestamp(which came with /history request)
*/
suspend
fun
saveLastSyncDate
(
rid
:
String
,
timeMillis
:
Long
)
suspend
fun
getLastSyncDate
():
Long
?
/**
* Get time when the room chat history has been loaded last time.
*
* @param rid The id of the room the messages are.
*
* @return Last Sync time or Null.
*/
suspend
fun
getLastSyncDate
(
rid
:
String
):
Long
?
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/infraestructure/MemoryMessagesRepository.kt
View file @
88caa298
...
@@ -7,15 +7,15 @@ import kotlinx.coroutines.experimental.withContext
...
@@ -7,15 +7,15 @@ import kotlinx.coroutines.experimental.withContext
class
MemoryMessagesRepository
:
MessagesRepository
{
class
MemoryMessagesRepository
:
MessagesRepository
{
private
var
lastSyncDate
:
Long
?
=
null
private
var
lastSyncDate
s
:
HashMap
<
String
,
Long
>
=
HashMap
()
override
suspend
fun
saveLastSyncDate
(
currentTimeMillis
:
Long
)
{
private
val
messages
:
HashMap
<
String
,
Message
>
=
HashMap
()
lastSyncDate
=
currentTimeMillis
}
override
suspend
fun
getLastSyncDate
()
=
lastSyncDate
override
suspend
fun
saveLastSyncDate
(
rid
:
String
,
timeMillis
:
Long
)
{
lastSyncDates
[
rid
]
=
timeMillis
}
private
val
messages
:
HashMap
<
String
,
Message
>
=
HashMap
()
override
suspend
fun
getLastSyncDate
(
rid
:
String
)
=
lastSyncDates
[
rid
]
override
suspend
fun
getById
(
id
:
String
):
Message
?
=
withContext
(
CommonPool
)
{
override
suspend
fun
getById
(
id
:
String
):
Message
?
=
withContext
(
CommonPool
)
{
return
@withContext
messages
[
id
]
return
@withContext
messages
[
id
]
...
...
app/src/main/java/chat/rocket/android/server/infraestructure/SharedPreferencesMessagesRepository.kt
View file @
88caa298
...
@@ -15,25 +15,25 @@ class SharedPreferencesMessagesRepository(
...
@@ -15,25 +15,25 @@ class SharedPreferencesMessagesRepository(
)
:
MessagesRepository
{
)
:
MessagesRepository
{
private
val
KEY_LAST_SYNC_DATE
=
"KEY_LAST_SYNC_DATE"
private
val
KEY_LAST_SYNC_DATE
=
"KEY_LAST_SYNC_DATE"
override
suspend
fun
saveLastSyncDate
(
currentT
imeMillis
:
Long
)
{
override
suspend
fun
saveLastSyncDate
(
rid
:
String
,
t
imeMillis
:
Long
)
{
withContext
(
CommonPool
)
{
withContext
(
CommonPool
)
{
currentServerInteractor
.
get
()
?.
let
{
currentServerInteractor
.
get
()
?.
let
{
prefs
.
edit
().
putLong
(
getSyncDateKey
(
it
),
currentT
imeMillis
).
apply
()
prefs
.
edit
().
putLong
(
getSyncDateKey
(
it
,
rid
),
t
imeMillis
).
apply
()
}
}
}
}
}
}
override
suspend
fun
getLastSyncDate
():
Long
?
=
withContext
(
CommonPool
)
{
override
suspend
fun
getLastSyncDate
(
rid
:
String
):
Long
?
=
withContext
(
CommonPool
)
{
currentServerInteractor
.
get
()
?.
also
{
server
->
currentServerInteractor
.
get
()
?.
also
{
server
->
if
(!
prefs
.
contains
(
getSyncDateKey
(
server
)))
if
(!
prefs
.
contains
(
getSyncDateKey
(
server
,
rid
)))
return
@withContext
null
return
@withContext
null
val
time
=
prefs
.
getLong
(
getSyncDateKey
(
server
),
-
1
)
val
time
=
prefs
.
getLong
(
getSyncDateKey
(
server
,
rid
),
-
1
)
return
@withContext
if
(
time
==
-
1L
)
null
else
time
return
@withContext
if
(
time
==
-
1L
)
null
else
time
}
}
return
@withContext
null
return
@withContext
null
}
}
private
fun
getSyncDateKey
(
it
:
String
)
=
"${KEY_LAST_SYNC_DATE}_${it}
"
private
fun
getSyncDateKey
(
server
:
String
,
rid
:
String
)
=
"${KEY_LAST_SYNC_DATE}_$server $rid
"
override
suspend
fun
getById
(
id
:
String
):
Message
?
=
withContext
(
CommonPool
)
{
override
suspend
fun
getById
(
id
:
String
):
Message
?
=
withContext
(
CommonPool
)
{
currentServerInteractor
.
get
()
?.
also
{
server
->
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