Show edit action for poll messages if it is not voted and closed.

This commit is contained in:
Onuray Sahin 2022-01-19 13:00:21 +03:00
parent 8af92a4091
commit 381dd5343a
1 changed files with 10 additions and 3 deletions

View File

@ -466,14 +466,15 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
}
private fun canEdit(event: TimelineEvent, myUserId: String, actionPermissions: ActionPermissions): Boolean {
// Only event of type EventType.MESSAGE are supported for the moment
if (event.root.getClearType() != EventType.MESSAGE) return false
// Only event of type EventType.MESSAGE and EventType.POLL_START are supported for the moment
if (event.root.getClearType() !in listOf(EventType.MESSAGE, EventType.POLL_START)) return false
if (!actionPermissions.canSendMessage) return false
// TODO if user is admin or moderator
val messageContent = event.root.getClearContent().toModel<MessageContent>()
return event.root.senderId == myUserId && (
messageContent?.msgType == MessageType.MSGTYPE_TEXT ||
messageContent?.msgType == MessageType.MSGTYPE_EMOTE
messageContent?.msgType == MessageType.MSGTYPE_EMOTE ||
canEditPoll(event)
)
}
@ -516,4 +517,10 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
canRedact(event, actionPermissions) &&
event.annotations?.pollResponseSummary?.closedTime == null
}
private fun canEditPoll(event: TimelineEvent): Boolean {
return event.root.getClearType() == EventType.POLL_START &&
event.annotations?.pollResponseSummary?.closedTime == null &&
event.annotations?.pollResponseSummary?.aggregatedContent?.totalVotes ?: 0 == 0
}
}