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
0af84cf7
Commit
0af84cf7
authored
Feb 03, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement delete message action
parent
e09068ec
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
26 deletions
+55
-26
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+33
-16
ChatRoomAdapter.kt
...n/java/chat/rocket/android/chatroom/ui/ChatRoomAdapter.kt
+19
-7
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+2
-3
MessageViewModel.kt
...hat/rocket/android/chatroom/viewmodel/MessageViewModel.kt
+1
-0
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
0af84cf7
...
@@ -7,12 +7,14 @@ import chat.rocket.android.server.domain.GetSettingsInteractor
...
@@ -7,12 +7,14 @@ import chat.rocket.android.server.domain.GetSettingsInteractor
import
chat.rocket.android.server.domain.MessagesRepository
import
chat.rocket.android.server.domain.MessagesRepository
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.launchUI
import
chat.rocket.android.util.launchUI
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.util.ifNull
import
chat.rocket.common.util.ifNull
import
chat.rocket.core.internal.realtime.State
import
chat.rocket.core.internal.realtime.State
import
chat.rocket.core.internal.realtime.connect
import
chat.rocket.core.internal.realtime.connect
import
chat.rocket.core.internal.realtime.subscribeRoomMessages
import
chat.rocket.core.internal.realtime.subscribeRoomMessages
import
chat.rocket.core.internal.realtime.unsubscibre
import
chat.rocket.core.internal.realtime.unsubscibre
import
chat.rocket.core.internal.rest.deleteMessage
import
chat.rocket.core.internal.rest.messages
import
chat.rocket.core.internal.rest.messages
import
chat.rocket.core.internal.rest.sendMessage
import
chat.rocket.core.internal.rest.sendMessage
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Message
...
@@ -31,7 +33,6 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
...
@@ -31,7 +33,6 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
factory
:
RocketChatClientFactory
,
factory
:
RocketChatClientFactory
,
private
val
mapper
:
MessageViewModelMapper
)
{
private
val
mapper
:
MessageViewModelMapper
)
{
private
val
client
=
factory
.
create
(
serverInteractor
.
get
()
!!
)
private
val
client
=
factory
.
create
(
serverInteractor
.
get
()
!!
)
private
val
roomMessages
=
ArrayList
<
Message
>()
private
var
subId
:
String
?
=
null
private
var
subId
:
String
?
=
null
private
var
settings
:
Map
<
String
,
Value
<
Any
>>?
=
null
private
var
settings
:
Map
<
String
,
Value
<
Any
>>?
=
null
...
@@ -46,10 +47,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
...
@@ -46,10 +47,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
view
.
showLoading
()
view
.
showLoading
()
try
{
try
{
val
messages
=
client
.
messages
(
chatRoomId
,
roomTypeOf
(
chatRoomType
),
offset
,
30
).
result
val
messages
=
client
.
messages
(
chatRoomId
,
roomTypeOf
(
chatRoomType
),
offset
,
30
).
result
synchronized
(
roomMessages
)
{
roomMessages
.
addAll
(
messages
)
messagesRepository
.
saveAll
(
messages
)
messagesRepository
.
saveAll
(
messages
)
}
val
messagesViewModels
=
mapper
.
mapToViewModelList
(
messages
,
settings
)
val
messagesViewModels
=
mapper
.
mapToViewModelList
(
messages
,
settings
)
view
.
showMessages
(
messagesViewModels
,
serverInteractor
.
get
()
!!
)
view
.
showMessages
(
messagesViewModels
,
serverInteractor
.
get
()
!!
)
...
@@ -142,6 +140,26 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
...
@@ -142,6 +140,26 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
}
}
}
}
/**
* Delete the message with the given id.
*
* @param roomId The room id of the message to be deleted.
* @param id The id of the message to be deleted.
*/
fun
deleteMessage
(
roomId
:
String
,
id
:
String
)
{
launchUI
(
strategy
)
{
//TODO: Default delete message always to true. Until we have the permissions system
//implemented, a user will only be able to delete his own messages.
try
{
//TODO: Should honor permission 'Message_ShowDeletedStatus'
client
.
deleteMessage
(
roomId
,
id
,
true
)
}
catch
(
e
:
RocketChatException
)
{
//TODO: Handle permission error.
Timber
.
e
(
e
)
}
}
}
private
suspend
fun
listenMessages
(
roomId
:
String
)
{
private
suspend
fun
listenMessages
(
roomId
:
String
)
{
launch
(
CommonPool
+
strategy
.
jobs
)
{
launch
(
CommonPool
+
strategy
.
jobs
)
{
for
(
message
in
client
.
messagesChannel
)
{
for
(
message
in
client
.
messagesChannel
)
{
...
@@ -157,18 +175,17 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
...
@@ -157,18 +175,17 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
private
fun
updateMessage
(
streamedMessage
:
Message
)
{
private
fun
updateMessage
(
streamedMessage
:
Message
)
{
launchUI
(
strategy
)
{
launchUI
(
strategy
)
{
val
viewModelStreamedMessage
=
mapper
.
mapToViewModel
(
streamedMessage
,
settings
)
val
viewModelStreamedMessage
=
mapper
.
mapToViewModel
(
streamedMessage
,
settings
)
synchronized
(
roomMessages
)
{
val
roomMessages
=
messagesRepository
.
getByRoomId
(
streamedMessage
.
roomId
)
val
index
=
roomMessages
.
indexOfFirst
{
msg
->
msg
.
id
==
streamedMessage
.
id
}
val
index
=
roomMessages
.
indexOfFirst
{
msg
->
msg
.
id
==
streamedMessage
.
id
}
if
(
index
!=
-
1
)
{
if
(
index
>
-
1
)
{
Timber
.
d
(
"Updatind
message at $index"
)
Timber
.
d
(
"Updating
message at $index"
)
roomMessages
[
index
]
=
streamedMessage
messagesRepository
.
save
(
streamedMessage
)
view
.
dispatchUpdateMessage
(
index
,
viewModelStreamedMessage
)
view
.
dispatchUpdateMessage
(
index
,
viewModelStreamedMessage
)
}
else
{
}
else
{
Timber
.
d
(
"Adding new message"
)
Timber
.
d
(
"Adding new message"
)
roomMessages
.
add
(
0
,
streamedMessage
)
messagesRepository
.
save
(
streamedMessage
)
view
.
showNewMessage
(
viewModelStreamedMessage
)
view
.
showNewMessage
(
viewModelStreamedMessage
)
}
}
}
}
}
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomAdapter.kt
View file @
0af84cf7
...
@@ -8,6 +8,7 @@ import android.widget.ImageView
...
@@ -8,6 +8,7 @@ import android.widget.ImageView
import
android.widget.PopupMenu
import
android.widget.PopupMenu
import
android.widget.TextView
import
android.widget.TextView
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.presentation.ChatRoomPresenter
import
chat.rocket.android.chatroom.viewmodel.AttachmentType
import
chat.rocket.android.chatroom.viewmodel.AttachmentType
import
chat.rocket.android.chatroom.viewmodel.MessageViewModel
import
chat.rocket.android.chatroom.viewmodel.MessageViewModel
import
chat.rocket.android.player.PlayerActivity
import
chat.rocket.android.player.PlayerActivity
...
@@ -21,7 +22,8 @@ import kotlinx.android.synthetic.main.avatar.view.*
...
@@ -21,7 +22,8 @@ import kotlinx.android.synthetic.main.avatar.view.*
import
kotlinx.android.synthetic.main.item_message.view.*
import
kotlinx.android.synthetic.main.item_message.view.*
import
kotlinx.android.synthetic.main.message_attachment.view.*
import
kotlinx.android.synthetic.main.message_attachment.view.*
class
ChatRoomAdapter
(
private
val
serverUrl
:
String
)
:
RecyclerView
.
Adapter
<
ChatRoomAdapter
.
ViewHolder
>()
{
class
ChatRoomAdapter
(
private
val
serverUrl
:
String
,
private
val
presenter
:
ChatRoomPresenter
)
:
RecyclerView
.
Adapter
<
ChatRoomAdapter
.
ViewHolder
>()
{
init
{
init
{
setHasStableIds
(
true
)
setHasStableIds
(
true
)
...
@@ -30,7 +32,7 @@ class ChatRoomAdapter(private val serverUrl: String) : RecyclerView.Adapter<Chat
...
@@ -30,7 +32,7 @@ class ChatRoomAdapter(private val serverUrl: String) : RecyclerView.Adapter<Chat
val
dataSet
=
ArrayList
<
MessageViewModel
>()
val
dataSet
=
ArrayList
<
MessageViewModel
>()
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
=
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
=
ViewHolder
(
parent
.
inflate
(
R
.
layout
.
item_message
),
serverUrl
)
ViewHolder
(
parent
.
inflate
(
R
.
layout
.
item_message
),
serverUrl
,
presenter
)
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
=
holder
.
bind
(
dataSet
[
position
])
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
=
holder
.
bind
(
dataSet
[
position
])
...
@@ -53,16 +55,19 @@ class ChatRoomAdapter(private val serverUrl: String) : RecyclerView.Adapter<Chat
...
@@ -53,16 +55,19 @@ class ChatRoomAdapter(private val serverUrl: String) : RecyclerView.Adapter<Chat
notifyItemInserted
(
0
)
notifyItemInserted
(
0
)
}
}
fun
updateItem
(
index
:
Int
,
message
:
MessageViewModel
)
{
fun
updateItem
(
message
:
MessageViewModel
)
{
val
index
=
dataSet
.
indexOfFirst
{
it
.
id
==
message
.
id
}
if
(
index
>
-
1
)
{
dataSet
[
index
]
=
message
dataSet
[
index
]
=
message
notifyItemChanged
(
index
)
notifyItemChanged
(
index
)
}
}
}
override
fun
getItemId
(
position
:
Int
):
Long
{
override
fun
getItemId
(
position
:
Int
):
Long
{
return
dataSet
[
position
].
id
.
hashCode
().
toLong
()
return
dataSet
[
position
].
id
.
hashCode
().
toLong
()
}
}
class
ViewHolder
(
itemView
:
View
,
val
serverUrl
:
String
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
class
ViewHolder
(
itemView
:
View
,
val
serverUrl
:
String
,
val
presenter
:
ChatRoomPresenter
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
fun
bind
(
message
:
MessageViewModel
)
=
with
(
itemView
)
{
fun
bind
(
message
:
MessageViewModel
)
=
with
(
itemView
)
{
bindUserAvatar
(
message
,
image_avatar
,
image_unknown_avatar
)
bindUserAvatar
(
message
,
image_avatar
,
image_unknown_avatar
)
...
@@ -74,9 +79,16 @@ class ChatRoomAdapter(private val serverUrl: String) : RecyclerView.Adapter<Chat
...
@@ -74,9 +79,16 @@ class ChatRoomAdapter(private val serverUrl: String) : RecyclerView.Adapter<Chat
bindAttachment
(
message
,
message_attachment
,
image_attachment
,
audio_video_attachment
,
bindAttachment
(
message
,
message_attachment
,
image_attachment
,
audio_video_attachment
,
file_name
)
file_name
)
itemView
.
setOnClickListener
{
text_content
.
setOnClickListener
{
val
popup
=
PopupMenu
(
it
.
context
,
it
)
val
popup
=
PopupMenu
(
it
.
context
,
it
)
popup
.
menuInflater
.
inflate
(
R
.
menu
.
message_actions
,
popup
.
menu
)
popup
.
menuInflater
.
inflate
(
R
.
menu
.
message_actions
,
popup
.
menu
)
popup
.
setOnMenuItemClickListener
{
when
(
it
.
itemId
)
{
R
.
id
.
action_menu_msg_delete
->
presenter
.
deleteMessage
(
message
.
roomId
,
message
.
id
)
else
->
TODO
(
"Not implemented"
)
}
true
}
popup
.
show
()
popup
.
show
()
}
}
}
}
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
0af84cf7
...
@@ -39,7 +39,6 @@ private const val BUNDLE_CHAT_ROOM_TYPE = "chat_room_type"
...
@@ -39,7 +39,6 @@ private const val BUNDLE_CHAT_ROOM_TYPE = "chat_room_type"
private
const
val
BUNDLE_IS_CHAT_ROOM_READ_ONLY
=
"is_chat_room_read_only"
private
const
val
BUNDLE_IS_CHAT_ROOM_READ_ONLY
=
"is_chat_room_read_only"
class
ChatRoomFragment
:
Fragment
(),
ChatRoomView
{
class
ChatRoomFragment
:
Fragment
(),
ChatRoomView
{
@Inject
lateinit
var
presenter
:
ChatRoomPresenter
@Inject
lateinit
var
presenter
:
ChatRoomPresenter
private
lateinit
var
chatRoomId
:
String
private
lateinit
var
chatRoomId
:
String
private
lateinit
var
chatRoomName
:
String
private
lateinit
var
chatRoomName
:
String
...
@@ -78,7 +77,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
...
@@ -78,7 +77,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
override
fun
showMessages
(
dataSet
:
List
<
MessageViewModel
>,
serverUrl
:
String
)
{
override
fun
showMessages
(
dataSet
:
List
<
MessageViewModel
>,
serverUrl
:
String
)
{
activity
?.
apply
{
activity
?.
apply
{
if
(
recycler_view
.
adapter
==
null
)
{
if
(
recycler_view
.
adapter
==
null
)
{
adapter
=
ChatRoomAdapter
(
serverUrl
)
adapter
=
ChatRoomAdapter
(
serverUrl
,
presenter
)
recycler_view
.
adapter
=
adapter
recycler_view
.
adapter
=
adapter
val
linearLayoutManager
=
LinearLayoutManager
(
context
,
LinearLayoutManager
.
VERTICAL
,
true
)
val
linearLayoutManager
=
LinearLayoutManager
(
context
,
LinearLayoutManager
.
VERTICAL
,
true
)
recycler_view
.
layoutManager
=
linearLayoutManager
recycler_view
.
layoutManager
=
linearLayoutManager
...
@@ -120,7 +119,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
...
@@ -120,7 +119,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
}
}
override
fun
dispatchUpdateMessage
(
index
:
Int
,
message
:
MessageViewModel
)
{
override
fun
dispatchUpdateMessage
(
index
:
Int
,
message
:
MessageViewModel
)
{
adapter
.
updateItem
(
index
,
message
)
adapter
.
updateItem
(
message
)
}
}
override
fun
showLoading
()
=
view_loading
.
setVisible
(
true
)
override
fun
showLoading
()
=
view_loading
.
setVisible
(
true
)
...
...
app/src/main/java/chat/rocket/android/chatroom/viewmodel/MessageViewModel.kt
View file @
0af84cf7
...
@@ -32,6 +32,7 @@ data class MessageViewModel(val context: Context,
...
@@ -32,6 +32,7 @@ data class MessageViewModel(val context: Context,
private
val
parser
:
MessageParser
,
private
val
parser
:
MessageParser
,
private
val
messagesRepository
:
MessagesRepository
)
{
private
val
messagesRepository
:
MessagesRepository
)
{
val
id
:
String
=
message
.
id
val
id
:
String
=
message
.
id
val
roomId
:
String
=
message
.
roomId
val
time
:
CharSequence
val
time
:
CharSequence
val
sender
:
CharSequence
val
sender
:
CharSequence
val
content
:
CharSequence
val
content
:
CharSequence
...
...
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