Cleaner code

This commit is contained in:
Benoit Marty 2019-08-05 17:03:19 +02:00
parent acae0fad3e
commit 097e9714ff

View File

@ -99,39 +99,32 @@ class MessageMenuViewModel @AssistedInject constructor(@Assisted initialState: M
private fun observeEvent() { private fun observeEvent() {
RxRoom(room) RxRoom(room)
.liveTimelineEvent(eventId) .liveTimelineEvent(eventId)
?.map { .map {
actionsForEvent(it) actionsForEvent(it)
} }
?.execute { .execute {
copy(actions = it) copy(actions = it)
} }
} }


private fun actionsForEvent(event: TimelineEvent): List<SimpleAction> { private fun actionsForEvent(event: TimelineEvent): List<SimpleAction> {

val messageContent: MessageContent? = event.annotations?.editSummary?.aggregatedContent.toModel() val messageContent: MessageContent? = event.annotations?.editSummary?.aggregatedContent.toModel()
?: event.root.getClearContent().toModel() ?: event.root.getClearContent().toModel()
val type = messageContent?.type val type = messageContent?.type


return if (event.root.sendState.hasFailed()) { return arrayListOf<SimpleAction>().apply {
arrayListOf<SimpleAction>().apply { if (event.root.sendState.hasFailed()) {
if (canRetry(event)) { if (canRetry(event)) {
this.add(SimpleAction(ACTION_RESEND, R.string.global_retry, R.drawable.ic_refresh_cw, eventId)) add(SimpleAction(ACTION_RESEND, R.string.global_retry, R.drawable.ic_refresh_cw, eventId))
}
this.add(SimpleAction(ACTION_REMOVE, R.string.remove, R.drawable.ic_trash, eventId))
} }
add(SimpleAction(ACTION_REMOVE, R.string.remove, R.drawable.ic_trash, eventId))
} else if (event.root.sendState.isSending()) { } else if (event.root.sendState.isSending()) {
//TODO is uploading attachment? //TODO is uploading attachment?
arrayListOf<SimpleAction>().apply {
if (canCancel(event)) { if (canCancel(event)) {
this.add(SimpleAction(ACTION_CANCEL, R.string.cancel, R.drawable.ic_close_round, eventId)) add(SimpleAction(ACTION_CANCEL, R.string.cancel, R.drawable.ic_close_round, eventId))
}
} }
} else { } else {
arrayListOf<SimpleAction>().apply {

if (!event.root.isRedacted()) { if (!event.root.isRedacted()) {

if (canReply(event, messageContent)) { if (canReply(event, messageContent)) {
add(SimpleAction(ACTION_REPLY, R.string.reply, R.drawable.ic_reply, eventId)) add(SimpleAction(ACTION_REPLY, R.string.reply, R.drawable.ic_reply, eventId))
} }