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
5f2696ac
Commit
5f2696ac
authored
Apr 13, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix loading same page always on chat
parent
e605713a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
14 deletions
+20
-14
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+20
-14
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
5f2696ac
...
@@ -6,8 +6,6 @@ import chat.rocket.android.chatroom.adapter.AutoCompleteType
...
@@ -6,8 +6,6 @@ import chat.rocket.android.chatroom.adapter.AutoCompleteType
import
chat.rocket.android.chatroom.adapter.PEOPLE
import
chat.rocket.android.chatroom.adapter.PEOPLE
import
chat.rocket.android.chatroom.adapter.ROOMS
import
chat.rocket.android.chatroom.adapter.ROOMS
import
chat.rocket.android.chatroom.domain.UriInteractor
import
chat.rocket.android.chatroom.domain.UriInteractor
import
chat.rocket.android.chatroom.viewmodel.BaseViewModel
import
chat.rocket.android.chatroom.viewmodel.MessageViewModel
import
chat.rocket.android.chatroom.viewmodel.ViewModelMapper
import
chat.rocket.android.chatroom.viewmodel.ViewModelMapper
import
chat.rocket.android.chatroom.viewmodel.suggestion.ChatRoomSuggestionViewModel
import
chat.rocket.android.chatroom.viewmodel.suggestion.ChatRoomSuggestionViewModel
import
chat.rocket.android.chatroom.viewmodel.suggestion.CommandSuggestionViewModel
import
chat.rocket.android.chatroom.viewmodel.suggestion.CommandSuggestionViewModel
...
@@ -75,19 +73,17 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
...
@@ -75,19 +73,17 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
launchUI
(
strategy
)
{
launchUI
(
strategy
)
{
view
.
showLoading
()
view
.
showLoading
()
try
{
try
{
val
localMessages
=
messagesRepository
.
getByRoomId
(
chatRoomId
)
if
(
offset
==
0L
)
{
val
oldMessages
=
mapper
.
map
(
localMessages
)
val
localMessages
=
messagesRepository
.
getByRoomId
(
chatRoomId
)
view
.
showMessages
(
oldMessages
)
val
oldMessages
=
mapper
.
map
(
localMessages
)
if
(
oldMessages
.
isEmpty
())
{
if
(
oldMessages
.
isNotEmpty
())
{
val
messages
=
view
.
showMessages
(
oldMessages
)
retryIO
(
description
=
"messages chatRoom: $chatRoomId, type: $chatRoomType, offset: $offset"
)
{
loadMissingMessages
()
client
.
messages
(
chatRoomId
,
roomTypeOf
(
chatRoomType
),
offset
,
30
).
result
}
else
{
}
loadAndShowMessages
(
chatRoomId
,
chatRoomType
,
offset
)
messagesRepository
.
saveAll
(
messages
)
}
val
allMessages
=
mapper
.
map
(
messages
)
view
.
showMessages
(
allMessages
)
}
else
{
}
else
{
load
MissingMessages
(
)
load
AndShowMessages
(
chatRoomId
,
chatRoomType
,
offset
)
}
}
// TODO: For now we are marking the room as read if we can get the messages (I mean, no exception occurs)
// TODO: For now we are marking the room as read if we can get the messages (I mean, no exception occurs)
...
@@ -112,6 +108,16 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
...
@@ -112,6 +108,16 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
}
}
}
}
private
suspend
fun
loadAndShowMessages
(
chatRoomId
:
String
,
chatRoomType
:
String
,
offset
:
Long
=
0
)
{
val
messages
=
retryIO
(
description
=
"messages chatRoom: $chatRoomId, type: $chatRoomType, offset: $offset"
)
{
client
.
messages
(
chatRoomId
,
roomTypeOf
(
chatRoomType
),
offset
,
30
).
result
}
messagesRepository
.
saveAll
(
messages
)
val
allMessages
=
mapper
.
map
(
messages
)
view
.
showMessages
(
allMessages
)
}
fun
sendMessage
(
chatRoomId
:
String
,
text
:
String
,
messageId
:
String
?)
{
fun
sendMessage
(
chatRoomId
:
String
,
text
:
String
,
messageId
:
String
?)
{
launchUI
(
strategy
)
{
launchUI
(
strategy
)
{
try
{
try
{
...
...
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