mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-17 12:30:07 +03:00
Show edit action for poll messages if it is not voted and closed.
This commit is contained in:
parent
8af92a4091
commit
381dd5343a
1 changed files with 10 additions and 3 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue