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
efce1574
Commit
efce1574
authored
May 28, 2018
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Favorite/pinned messages aren't shown as the messages on the chatroom are.
parent
576b2a20
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
80 additions
and
26 deletions
+80
-26
MessageViewModel.kt
...hat/rocket/android/chatroom/viewmodel/MessageViewModel.kt
+13
-13
ReactionViewModel.kt
...at/rocket/android/chatroom/viewmodel/ReactionViewModel.kt
+5
-5
ViewModelMapper.kt
...chat/rocket/android/chatroom/viewmodel/ViewModelMapper.kt
+58
-2
FavoriteMessagesPresenter.kt
...avoritemessages/presentation/FavoriteMessagesPresenter.kt
+1
-1
FavoriteMessagesFragment.kt
...t/android/favoritemessages/ui/FavoriteMessagesFragment.kt
+1
-2
PinnedMessagesPresenter.kt
...id/pinnedmessages/presentation/PinnedMessagesPresenter.kt
+1
-1
PinnedMessagesFragment.kt
...ocket/android/pinnedmessages/ui/PinnedMessagesFragment.kt
+1
-2
No files found.
app/src/main/java/chat/rocket/android/chatroom/viewmodel/MessageViewModel.kt
View file @
efce1574
...
...
@@ -4,19 +4,19 @@ import chat.rocket.android.R
import
chat.rocket.core.model.Message
data class
MessageViewModel
(
override
val
message
:
Message
,
override
val
rawData
:
Message
,
override
val
messageId
:
String
,
override
val
avatar
:
String
,
override
val
time
:
CharSequence
,
override
val
senderName
:
CharSequence
,
override
val
content
:
CharSequence
,
override
val
isPinned
:
Boolean
,
override
var
reactions
:
List
<
ReactionViewModel
>,
override
var
nextDownStreamMessage
:
BaseViewModel
<*>?
=
null
,
override
var
preview
:
Message
?
=
null
,
var
isFirstUnread
:
Boolean
,
override
var
isTemporary
:
Boolean
=
false
override
val
message
:
Message
,
override
val
rawData
:
Message
,
override
val
messageId
:
String
,
override
val
avatar
:
String
,
override
val
time
:
CharSequence
,
override
val
senderName
:
CharSequence
,
override
val
content
:
CharSequence
,
override
val
isPinned
:
Boolean
,
override
var
reactions
:
List
<
ReactionViewModel
>,
override
var
nextDownStreamMessage
:
BaseViewModel
<*>?
=
null
,
override
var
preview
:
Message
?
=
null
,
var
isFirstUnread
:
Boolean
,
override
var
isTemporary
:
Boolean
=
false
)
:
BaseMessageViewModel
<
Message
>
{
override
val
viewType
:
Int
get
()
=
BaseViewModel
.
ViewType
.
MESSAGE
.
viewType
...
...
app/src/main/java/chat/rocket/android/chatroom/viewmodel/ReactionViewModel.kt
View file @
efce1574
package
chat.rocket.android.chatroom.viewmodel
data class
ReactionViewModel
(
val
messageId
:
String
,
val
shortname
:
String
,
val
unicode
:
CharSequence
,
val
count
:
Int
,
val
usernames
:
List
<
String
>
=
emptyList
()
val
messageId
:
String
,
val
shortname
:
String
,
val
unicode
:
CharSequence
,
val
count
:
Int
,
val
usernames
:
List
<
String
>
=
emptyList
()
)
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/viewmodel/ViewModelMapper.kt
View file @
efce1574
...
...
@@ -74,12 +74,18 @@ class ViewModelMapper @Inject constructor(
suspend
fun
map
(
messages
:
List
<
Message
>,
roomViewModel
:
RoomViewModel
=
RoomViewModel
(
roles
=
emptyList
(),
isBroadcast
=
true
)
roomViewModel
:
RoomViewModel
=
RoomViewModel
(
roles
=
emptyList
(),
isBroadcast
=
true
),
asNotReversed
:
Boolean
=
false
):
List
<
BaseViewModel
<*
>>
=
withContext
(
CommonPool
)
{
val
list
=
ArrayList
<
BaseViewModel
<*>>(
messages
.
size
)
messages
.
forEach
{
list
.
addAll
(
translate
(
it
,
roomViewModel
))
}
messages
.
forEach
{
list
.
addAll
(
if
(
asNotReversed
)
translateAsNotReversed
(
it
,
roomViewModel
)
else
translate
(
it
,
roomViewModel
)
)
}
return
@withContext
list
}
...
...
@@ -123,6 +129,56 @@ class ViewModelMapper @Inject constructor(
return
@withContext
list
}
private
suspend
fun
translateAsNotReversed
(
message
:
Message
,
roomViewModel
:
RoomViewModel
):
List
<
BaseViewModel
<*
>>
=
withContext
(
CommonPool
)
{
val
list
=
ArrayList
<
BaseViewModel
<*>>()
mapMessage
(
message
).
let
{
if
(
list
.
isNotEmpty
())
{
it
.
preview
=
list
.
first
().
preview
}
list
.
add
(
it
)
}
message
.
attachments
?.
forEach
{
val
attachment
=
mapAttachment
(
message
,
it
)
attachment
?.
let
{
list
.
add
(
attachment
)
}
}
message
.
urls
?.
forEach
{
val
url
=
mapUrl
(
message
,
it
)
url
?.
let
{
list
.
add
(
url
)
}
}
for
(
i
in
list
.
size
-
1
downTo
0
)
{
val
next
=
if
(
i
-
1
<
0
)
null
else
list
[
i
-
1
]
list
[
i
].
nextDownStreamMessage
=
next
}
if
(
isBroadcastReplyAvailable
(
roomViewModel
,
message
))
{
roomsInteractor
.
getById
(
currentServer
,
message
.
roomId
)
?.
let
{
chatRoom
->
val
replyViewModel
=
mapMessageReply
(
message
,
chatRoom
)
list
.
first
().
nextDownStreamMessage
=
replyViewModel
list
.
add
(
0
,
replyViewModel
)
}
}
list
.
dropLast
(
1
).
forEach
{
it
.
reactions
=
emptyList
()
}
list
.
last
().
reactions
=
getReactions
(
message
)
list
.
last
().
nextDownStreamMessage
=
null
return
@withContext
list
}
private
fun
isBroadcastReplyAvailable
(
roomViewModel
:
RoomViewModel
,
message
:
Message
):
Boolean
{
val
senderUsername
=
message
.
sender
?.
username
return
roomViewModel
.
isRoom
&&
roomViewModel
.
isBroadcast
&&
...
...
app/src/main/java/chat/rocket/android/favoritemessages/presentation/FavoriteMessagesPresenter.kt
View file @
efce1574
...
...
@@ -35,7 +35,7 @@ class FavoriteMessagesPresenter @Inject constructor(
view
.
showLoading
()
roomsInteractor
.
getById
(
serverUrl
,
roomId
)
?.
let
{
val
favoriteMessages
=
client
.
getFavoriteMessages
(
roomId
,
it
.
type
,
offset
)
val
messageList
=
mapper
.
map
(
favoriteMessages
.
result
)
val
messageList
=
mapper
.
map
(
favoriteMessages
.
result
,
asNotReversed
=
true
)
view
.
showFavoriteMessages
(
messageList
)
offset
+=
1
*
30
}.
ifNull
{
...
...
app/src/main/java/chat/rocket/android/favoritemessages/ui/FavoriteMessagesFragment.kt
View file @
efce1574
...
...
@@ -69,8 +69,7 @@ class FavoriteMessagesFragment : Fragment(), FavoriteMessagesView {
adapter
=
ChatRoomAdapter
(
enableActions
=
false
)
recycler_view
.
adapter
=
adapter
val
linearLayoutManager
=
LinearLayoutManager
(
context
,
LinearLayoutManager
.
VERTICAL
,
true
)
linearLayoutManager
.
stackFromEnd
=
true
LinearLayoutManager
(
context
,
LinearLayoutManager
.
VERTICAL
,
false
)
recycler_view
.
layoutManager
=
linearLayoutManager
recycler_view
.
itemAnimator
=
DefaultItemAnimator
()
if
(
favoriteMessages
.
size
>=
30
)
{
...
...
app/src/main/java/chat/rocket/android/pinnedmessages/presentation/PinnedMessagesPresenter.kt
View file @
efce1574
...
...
@@ -36,7 +36,7 @@ class PinnedMessagesPresenter @Inject constructor(
view
.
showLoading
()
roomsInteractor
.
getById
(
serverUrl
,
roomId
)
?.
let
{
val
pinnedMessages
=
client
.
getPinnedMessages
(
roomId
,
it
.
type
,
offset
)
val
messageList
=
mapper
.
map
(
pinnedMessages
.
result
)
val
messageList
=
mapper
.
map
(
pinnedMessages
.
result
,
asNotReversed
=
true
)
view
.
showPinnedMessages
(
messageList
)
offset
+=
1
*
30
}.
ifNull
{
...
...
app/src/main/java/chat/rocket/android/pinnedmessages/ui/PinnedMessagesFragment.kt
View file @
efce1574
...
...
@@ -71,8 +71,7 @@ class PinnedMessagesFragment : Fragment(), PinnedMessagesView {
adapter
=
ChatRoomAdapter
(
enableActions
=
false
)
recycler_view_pinned
.
adapter
=
adapter
val
linearLayoutManager
=
LinearLayoutManager
(
context
,
LinearLayoutManager
.
VERTICAL
,
true
)
linearLayoutManager
.
stackFromEnd
=
true
LinearLayoutManager
(
context
,
LinearLayoutManager
.
VERTICAL
,
false
)
recycler_view_pinned
.
layoutManager
=
linearLayoutManager
recycler_view_pinned
.
itemAnimator
=
DefaultItemAnimator
()
if
(
pinnedMessages
.
size
>=
30
)
{
...
...
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