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
6b157720
Commit
6b157720
authored
Apr 11, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sort saved local messages according to their timestamps
parent
903ca99c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
76 deletions
+69
-76
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+68
-75
SharedPreferencesMessagesRepository.kt
...er/infraestructure/SharedPreferencesMessagesRepository.kt
+1
-1
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
6b157720
...
...
@@ -73,21 +73,14 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
launchUI
(
strategy
)
{
view
.
showLoading
()
try
{
val
oldMessages
=
messagesRepository
.
getByRoomId
(
chatRoomId
)
.
sortedWith
(
compareBy
(
Message
::
timestamp
)).
reversed
()
val
oldMessages
=
messagesRepository
.
getByRoomId
(
chatRoomId
)
view
.
showMessages
(
mapper
.
map
(
oldMessages
))
val
messages
=
retryIO
(
description
=
"messages chatRoom: $chatRoomId, type: $chatRoomType, offset: $offset"
)
{
client
.
messages
(
chatRoomId
,
roomTypeOf
(
chatRoomType
),
offset
,
30
).
result
}
retryIO
(
description
=
"messages chatRoom: $chatRoomId, type: $chatRoomType, offset: $offset"
)
{
client
.
messages
(
chatRoomId
,
roomTypeOf
(
chatRoomType
),
offset
,
30
).
result
}
messagesRepository
.
saveAll
(
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
)
val
messagesViewModels
=
mapper
.
map
(
messages
)
view
.
showMessages
(
messagesViewModels
)
// TODO: For now we are marking the room as read if we can get the messages (I mean, no exception occurs)
...
...
@@ -120,26 +113,26 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
val
message
=
if
(
messageId
==
null
)
{
val
username
=
localRepository
.
username
()
val
newMessage
=
Message
(
id
=
id
,
roomId
=
chatRoomId
,
message
=
text
,
timestamp
=
Instant
.
now
().
toEpochMilli
(),
sender
=
SimpleUser
(
null
,
username
,
username
),
attachments
=
null
,
avatar
=
currentServer
.
avatarUrl
(
username
!!
),
channels
=
null
,
editedAt
=
null
,
editedBy
=
null
,
groupable
=
false
,
parseUrls
=
false
,
pinned
=
false
,
mentions
=
emptyList
(),
reactions
=
null
,
senderAlias
=
null
,
type
=
null
,
updatedAt
=
null
,
urls
=
null
,
isTemporary
=
true
id
=
id
,
roomId
=
chatRoomId
,
message
=
text
,
timestamp
=
Instant
.
now
().
toEpochMilli
(),
sender
=
SimpleUser
(
null
,
username
,
username
),
attachments
=
null
,
avatar
=
currentServer
.
avatarUrl
(
username
!!
),
channels
=
null
,
editedAt
=
null
,
editedBy
=
null
,
groupable
=
false
,
parseUrls
=
false
,
pinned
=
false
,
mentions
=
emptyList
(),
reactions
=
null
,
senderAlias
=
null
,
type
=
null
,
updatedAt
=
null
,
urls
=
null
,
isTemporary
=
true
)
messagesRepository
.
save
(
newMessage
)
view
.
showNewMessage
(
mapper
.
map
(
newMessage
))
...
...
@@ -244,35 +237,35 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
if
(
chatRoomId
!=
null
&&
chatRoomType
!=
null
)
{
val
roomType
=
roomTypeOf
(
chatRoomType
!!
)
messagesRepository
.
getByRoomId
(
chatRoomId
!!
)
.
sortedByDescending
{
it
.
timestamp
}.
firstOrNull
()
?.
let
{
lastMessage
->
val
instant
=
Instant
.
ofEpochMilli
(
lastMessage
.
timestamp
).
toString
()
try
{
val
messages
=
retryIO
(
description
=
"history($chatRoomId, $roomType, $instant)"
)
{
client
.
history
(
chatRoomId
!!
,
roomType
,
count
=
50
,
oldest
=
instant
)
}
Timber
.
d
(
"History: $messages"
)
.
sortedByDescending
{
it
.
timestamp
}.
firstOrNull
()
?.
let
{
lastMessage
->
val
instant
=
Instant
.
ofEpochMilli
(
lastMessage
.
timestamp
).
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
)
messagesRepository
.
saveAll
(
messages
.
result
)
if
(
messages
.
result
.
isNotEmpty
())
{
val
models
=
mapper
.
map
(
messages
.
result
)
messagesRepository
.
saveAll
(
messages
.
result
)
launchUI
(
strategy
)
{
view
.
showNewMessage
(
models
)
}
launchUI
(
strategy
)
{
view
.
showNewMessage
(
models
)
}
if
(
messages
.
result
.
size
==
50
)
{
// we loaded at least count messages, try one more to fetch more messages
loadMissingMessages
()
}
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"
)
ex
.
printStackTrace
()
}
}
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"
)
ex
.
printStackTrace
()
}
}
}
}
}
...
...
@@ -335,7 +328,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
val
id
=
m
.
id
val
username
=
m
.
sender
?.
username
val
user
=
"@"
+
if
(
settings
.
useRealName
())
m
.
sender
?.
name
?:
m
.
sender
?.
username
else
m
.
sender
?.
username
?:
m
.
sender
?.
username
else
m
.
sender
?.
username
val
mention
=
if
(
mentionAuthor
&&
me
?.
username
!=
username
)
user
else
""
val
type
=
roomTypeOf
(
roomType
)
val
room
=
when
(
type
)
{
...
...
@@ -346,9 +339,9 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
is
RoomType
.
Custom
->
"custom"
//TODO: put appropriate callback string here.
}
view
.
showReplyingAction
(
username
=
user
,
replyMarkdown
=
"[ ]($currentServer/$room/$roomName?msg=$id) $mention "
,
quotedMessage
=
mapper
.
map
(
message
).
last
().
preview
?.
message
?:
""
username
=
user
,
replyMarkdown
=
"[ ]($currentServer/$room/$roomName?msg=$id) $mention "
,
quotedMessage
=
mapper
.
map
(
message
).
last
().
preview
?.
message
?:
""
)
}
}
...
...
@@ -426,7 +419,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
val
self
=
localRepository
.
get
(
LocalRepository
.
CURRENT_USERNAME_KEY
)
// Take at most the 100 most recent messages distinguished by user. Can return less.
val
recentMessages
=
messagesRepository
.
getRecentMessages
(
chatRoomId
,
100
)
.
filterNot
{
filterSelfOut
&&
it
.
sender
?.
username
==
self
}
.
filterNot
{
filterSelfOut
&&
it
.
sender
?.
username
==
self
}
val
activeUsers
=
mutableListOf
<
PeopleSuggestionViewModel
>()
recentMessages
.
forEach
{
val
sender
=
it
.
sender
!!
...
...
@@ -437,7 +430,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
val
status
=
if
(
found
!=
null
)
found
.
status
else
UserStatus
.
Offline
()
val
searchList
=
mutableListOf
(
username
,
name
)
activeUsers
.
add
(
PeopleSuggestionViewModel
(
avatarUrl
,
username
,
username
,
name
,
status
,
true
,
searchList
))
true
,
searchList
))
}
// Filter out from members list the active users.
val
others
=
members
.
filterNot
{
member
->
...
...
@@ -477,7 +470,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
val
searchList
=
mutableListOf
(
username
,
name
)
it
.
emails
?.
forEach
{
email
->
searchList
.
add
(
email
.
address
)
}
PeopleSuggestionViewModel
(
currentServer
.
avatarUrl
(
username
),
username
,
username
,
name
,
it
.
status
,
false
,
searchList
)
username
,
username
,
name
,
it
.
status
,
false
,
searchList
)
}.
filterNot
{
filterSelfOut
&&
self
!=
null
&&
self
==
it
.
text
})
}
ROOMS
->
{
...
...
@@ -504,19 +497,19 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
launchUI
(
strategy
)
{
try
{
val
chatRooms
=
getChatRoomsInteractor
.
get
(
currentServer
)
.
filterNot
{
it
.
type
is
RoomType
.
DirectMessage
||
it
.
type
is
RoomType
.
Livechat
}
.
map
{
chatRoom
->
val
name
=
chatRoom
.
name
val
fullName
=
chatRoom
.
fullName
?:
""
ChatRoomSuggestionViewModel
(
text
=
name
,
name
=
name
,
fullName
=
fullName
,
searchList
=
listOf
(
name
,
fullName
)
)
}
.
filterNot
{
it
.
type
is
RoomType
.
DirectMessage
||
it
.
type
is
RoomType
.
Livechat
}
.
map
{
chatRoom
->
val
name
=
chatRoom
.
name
val
fullName
=
chatRoom
.
fullName
?:
""
ChatRoomSuggestionViewModel
(
text
=
name
,
name
=
name
,
fullName
=
fullName
,
searchList
=
listOf
(
name
,
fullName
)
)
}
view
.
populateRoomSuggestions
(
chatRooms
)
}
catch
(
e
:
RocketChatException
)
{
Timber
.
e
(
e
)
...
...
app/src/main/java/chat/rocket/android/server/infraestructure/SharedPreferencesMessagesRepository.kt
View file @
6b157720
...
...
@@ -29,7 +29,7 @@ class SharedPreferencesMessagesRepository(
val
values
=
prefs
.
all
.
values
as
Collection
<
String
>
return
@withContext
values
.
mapNotNull
{
adapter
.
fromJson
(
it
)
}.
filter
{
it
.
roomId
==
rid
}.
toList
()
}.
toList
()
.
sortedWith
(
compareBy
(
Message
::
timestamp
)).
reversed
()
}
override
suspend
fun
getRecentMessages
(
rid
:
String
,
count
:
Long
):
List
<
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