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
903ca99c
Commit
903ca99c
authored
Apr 11, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix timestamp for offline messages and showing saved local messages on chat
parent
998f24f2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
10 deletions
+18
-10
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+11
-3
MessageService.kt
...va/chat/rocket/android/chatroom/service/MessageService.kt
+1
-1
MessagesRepository.kt
...a/chat/rocket/android/server/domain/MessagesRepository.kt
+2
-2
MemoryMessagesRepository.kt
...ndroid/server/infraestructure/MemoryMessagesRepository.kt
+2
-2
SharedPreferencesMessagesRepository.kt
...er/infraestructure/SharedPreferencesMessagesRepository.kt
+2
-2
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
903ca99c
...
...
@@ -73,13 +73,21 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
launchUI
(
strategy
)
{
view
.
showLoading
()
try
{
val
oldMessages
=
messagesRepository
.
getByRoomId
(
chatRoomId
).
sortedWith
(
compareBy
(
Message
::
timestamp
)).
reversed
()
view
.
showMessages
(
mapper
.
map
(
oldMessages
))
val
messages
=
retryIO
(
description
=
"messages chatRoom: $chatRoomId, type: $chatRoomType, offset: $offset"
)
{
client
.
messages
(
chatRoomId
,
roomTypeOf
(
chatRoomType
),
offset
,
30
).
result
}
messagesRepository
.
saveAll
(
messages
)
val
messagesViewModels
=
mapper
.
map
(
messages
)
val
unsentMessages
=
messagesRepository
.
getUnsentByRoomId
(
chatRoomId
)
var
mergedMessages
=
messages
.
toMutableList
()
mergedMessages
.
addAll
(
unsentMessages
)
val
allMessages
=
mergedMessages
.
toList
().
filterNot
{
message
->
unsentMessages
.
find
{
it
.
id
==
message
.
id
}
!=
null
}
val
messagesViewModels
=
mapper
.
map
(
allMessages
)
view
.
showMessages
(
messagesViewModels
)
// TODO: For now we are marking the room as read if we can get the messages (I mean, no exception occurs)
...
...
@@ -88,7 +96,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
subscribeMessages
(
chatRoomId
)
}
catch
(
ex
:
Exception
)
{
ex
.
printStackTrace
(
)
Timber
.
e
(
ex
)
ex
.
message
?.
let
{
view
.
showMessage
(
it
)
}.
ifNull
{
...
...
@@ -115,7 +123,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
id
=
id
,
roomId
=
chatRoomId
,
message
=
text
,
timestamp
=
Instant
.
now
().
epochSecond
,
timestamp
=
Instant
.
now
().
toEpochMilli
()
,
sender
=
SimpleUser
(
null
,
username
,
username
),
attachments
=
null
,
avatar
=
currentServer
.
avatarUrl
(
username
!!
),
...
...
app/src/main/java/chat/rocket/android/chatroom/service/MessageService.kt
View file @
903ca99c
...
...
@@ -49,7 +49,7 @@ class MessageService : JobService() {
}
private
suspend
fun
retrySendingMessages
(
currentServer
:
String
)
{
val
temporaryMessages
=
messageRepository
.
getAll
Temporary
()
val
temporaryMessages
=
messageRepository
.
getAll
Unsent
()
if
(
temporaryMessages
.
isNotEmpty
())
{
val
connectionManager
=
factory
.
create
(
currentServer
)
val
client
=
connectionManager
.
client
...
...
app/src/main/java/chat/rocket/android/server/domain/MessagesRepository.kt
View file @
903ca99c
...
...
@@ -69,7 +69,7 @@ interface MessagesRepository {
*/
suspend
fun
removeByRoomId
(
rid
:
String
)
suspend
fun
getAll
Temporary
():
List
<
Message
>
suspend
fun
getAll
Unsent
():
List
<
Message
>
suspend
fun
get
AllTemporary
ByRoomId
(
roomId
:
String
):
List
<
Message
>
suspend
fun
get
Unsent
ByRoomId
(
roomId
:
String
):
List
<
Message
>
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/infraestructure/MemoryMessagesRepository.kt
View file @
903ca99c
...
...
@@ -26,7 +26,7 @@ class MemoryMessagesRepository : MessagesRepository {
return
@withContext
messages
.
values
.
toList
()
}
override
suspend
fun
get
AllTemporary
ByRoomId
(
roomId
:
String
):
List
<
Message
>
=
withContext
(
CommonPool
)
{
override
suspend
fun
get
Unsent
ByRoomId
(
roomId
:
String
):
List
<
Message
>
=
withContext
(
CommonPool
)
{
val
allByRoomId
=
getByRoomId
(
roomId
)
if
(
allByRoomId
.
isEmpty
())
{
return
@withContext
emptyList
<
Message
>()
...
...
@@ -34,7 +34,7 @@ class MemoryMessagesRepository : MessagesRepository {
return
@withContext
allByRoomId
.
filter
{
it
.
isTemporary
?:
false
&&
it
.
roomId
==
roomId
}
}
override
suspend
fun
getAll
Temporary
():
List
<
Message
>
=
withContext
(
CommonPool
)
{
override
suspend
fun
getAll
Unsent
():
List
<
Message
>
=
withContext
(
CommonPool
)
{
val
all
=
getAll
()
if
(
all
.
isEmpty
())
{
return
@withContext
emptyList
<
Message
>()
...
...
app/src/main/java/chat/rocket/android/server/infraestructure/SharedPreferencesMessagesRepository.kt
View file @
903ca99c
...
...
@@ -46,7 +46,7 @@ class SharedPreferencesMessagesRepository(
return
@withContext
values
.
mapNotNull
{
adapter
.
fromJson
(
it
)
}
}
override
suspend
fun
getAll
Temporary
():
List
<
Message
>
=
withContext
(
CommonPool
)
{
override
suspend
fun
getAll
Unsent
():
List
<
Message
>
=
withContext
(
CommonPool
)
{
if
(
prefs
.
all
.
values
.
isEmpty
())
{
return
@withContext
emptyList
<
Message
>()
}
...
...
@@ -56,7 +56,7 @@ class SharedPreferencesMessagesRepository(
.
filter
{
it
.
isTemporary
?:
false
}
}
override
suspend
fun
get
AllTemporary
ByRoomId
(
roomId
:
String
):
List
<
Message
>
=
withContext
(
CommonPool
)
{
override
suspend
fun
get
Unsent
ByRoomId
(
roomId
:
String
):
List
<
Message
>
=
withContext
(
CommonPool
)
{
val
allByRoomId
=
getByRoomId
(
roomId
)
if
(
allByRoomId
.
isEmpty
())
{
return
@withContext
emptyList
<
Message
>()
...
...
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