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
c8ec586b
Commit
c8ec586b
authored
Aug 25, 2018
by
Kiryl Vashyla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
loadMissingMessages() improved: unused messages polling from local repository removed
parent
7760bd1a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
42 deletions
+38
-42
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+38
-42
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
c8ec586b
...
...
@@ -503,51 +503,47 @@ class ChatRoomPresenter @Inject constructor(
launch
(
parent
=
strategy
.
jobs
)
{
if
(
chatRoomId
!=
null
&&
chatRoomType
!=
null
)
{
val
roomType
=
roomTypeOf
(
chatRoomType
!!
)
messagesRepository
.
getByRoomId
(
chatRoomId
!!
)
.
sortedByDescending
{
it
.
timestamp
}.
firstOrNull
()
?.
let
{
lastMessage
->
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)"
)
{
client
.
history
(
chatRoomId
!!
,
roomType
,
count
=
50
,
oldest
=
instant
)
}
Timber
.
d
(
"History: $messages"
)
if
(
messages
.
result
.
isNotEmpty
())
{
val
models
=
mapper
.
map
(
messages
.
result
,
RoomUiModel
(
roles
=
chatRoles
,
isBroadcast
=
chatIsBroadcast
,
// FIXME: Why are we fixing isRoom attribute to true here?
isRoom
=
true
))
messagesRepository
.
saveAll
(
messages
.
result
)
//if success - saving last synced time
//assume that BE returns ordered messages, the first message is the latest one
messagesRepository
.
saveLastSyncDate
(
messages
.
result
.
first
().
timestamp
)
launchUI
(
strategy
)
{
view
.
showNewMessage
(
models
,
true
)
}
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)"
)
{
client
.
history
(
chatRoomId
!!
,
roomType
,
count
=
50
,
oldest
=
instant
)
}
Timber
.
d
(
"History: $messages"
)
if
(
messages
.
result
.
size
==
50
)
{
// we loaded at least count messages, try one more to fetch more messages
loadMissingMessages
()
}
}
}
catch
(
ex
:
Exception
)
{
// TODO - we need to better treat connection problems here, but no let gaps
// on the messages list
Timber
.
d
(
ex
,
"Error fetching channel history"
)
if
(
messages
.
result
.
isNotEmpty
())
{
val
models
=
mapper
.
map
(
messages
.
result
,
RoomUiModel
(
roles
=
chatRoles
,
isBroadcast
=
chatIsBroadcast
,
// FIXME: Why are we fixing isRoom attribute to true here?
isRoom
=
true
))
messagesRepository
.
saveAll
(
messages
.
result
)
//if success - saving last synced time
//assume that BE returns ordered messages, the first message is the latest one
messagesRepository
.
saveLastSyncDate
(
messages
.
result
.
first
().
timestamp
)
launchUI
(
strategy
)
{
view
.
showNewMessage
(
models
,
true
)
}
if
(
messages
.
result
.
size
==
50
)
{
// we loaded at least count messages, try one more to fetch more messages
loadMissingMessages
()
}
}
}
catch
(
ex
:
Exception
)
{
// TODO - we need to better treat connection problems here, but no let gaps
// on the messages list
Timber
.
d
(
ex
,
"Error fetching channel history"
)
}
}
}
}
...
...
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