From 097e9714ff8633e7e4b3d47591a085483e1a7918 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 5 Aug 2019 17:03:19 +0200 Subject: [PATCH] Cleaner code --- .../timeline/action/MessageMenuViewModel.kt | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt index 15e08831..fcf00173 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt @@ -99,39 +99,32 @@ class MessageMenuViewModel @AssistedInject constructor(@Assisted initialState: M private fun observeEvent() { RxRoom(room) .liveTimelineEvent(eventId) - ?.map { + .map { actionsForEvent(it) } - ?.execute { + .execute { copy(actions = it) } } private fun actionsForEvent(event: TimelineEvent): List { - val messageContent: MessageContent? = event.annotations?.editSummary?.aggregatedContent.toModel() ?: event.root.getClearContent().toModel() val type = messageContent?.type - return if (event.root.sendState.hasFailed()) { - arrayListOf().apply { + return arrayListOf().apply { + if (event.root.sendState.hasFailed()) { 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)) - } - } else if (event.root.sendState.isSending()) { - //TODO is uploading attachment? - arrayListOf().apply { + add(SimpleAction(ACTION_REMOVE, R.string.remove, R.drawable.ic_trash, eventId)) + } else if (event.root.sendState.isSending()) { + //TODO is uploading attachment? 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 { - arrayListOf().apply { - + } else { if (!event.root.isRedacted()) { - if (canReply(event, messageContent)) { add(SimpleAction(ACTION_REPLY, R.string.reply, R.drawable.ic_reply, eventId)) }