fix(chat input): should be disabled if user is not able to post

- extend `isUserAllowedToSendMessage` to also cover
`Constants.chatType.communityChat`
- let `admin` always satisfy the permissions
- hide the add emoji/reaction button instead of disabling it when the
permissions are not met
- adjust the error msg to better reflect the reality (tokens vs.
permissions)

Fixes #13777
This commit is contained in:
Lukáš Tinkl 2024-03-04 10:59:52 +01:00 committed by Lukáš Tinkl
parent 954b25a54c
commit b623c8fb2b
7 changed files with 12 additions and 9 deletions

View File

@ -168,7 +168,7 @@ QtObject:
self.viewOnlyPermissionsSatisfiedChanged()
proc getViewOnlyPermissionsSatisfied*(self: View): bool {.slot.} =
return self.viewOnlyPermissionsSatisfied
return self.viewOnlyPermissionsSatisfied or self.amIChatAdmin()
QtProperty[bool] viewOnlyPermissionsSatisfied:
read = getViewOnlyPermissionsSatisfied
notify = viewOnlyPermissionsSatisfiedChanged
@ -180,7 +180,7 @@ QtObject:
self.viewAndPostPermissionsSatisfiedChanged()
proc getViewAndPostPermissionsSatisfied*(self: View): bool {.slot.} =
return self.viewAndPostPermissionsSatisfied
return self.viewAndPostPermissionsSatisfied or self.amIChatAdmin()
QtProperty[bool] viewAndPostPermissionsSatisfied:
read = getViewAndPostPermissionsSatisfied
notify = viewAndPostPermissionsSatisfiedChanged

View File

@ -155,6 +155,7 @@ Item {
Item {
width: addEmojiButton.width + addEmojiButton.anchors.leftMargin // there is more margin between the button and the emojis than between each emoji
height: addEmojiButton.height
visible: root.enabled
StatusIcon {
id: addEmojiButton

View File

@ -589,6 +589,7 @@ QtObject {
}
readonly property QtObject _d: QtObject {
id: _d
readonly property var sectionDetailsInstantiator: Instantiator {
model: SortFilterProxyModel {
sourceModel: mainModuleInst.sectionsModel
@ -655,9 +656,10 @@ QtObject {
readonly property bool isUserAllowedToSendMessage: {
if (_d.activeChatType === Constants.chatType.oneToOne && _d.oneToOneChatContact) {
return _d.oneToOneChatContact.contactRequestState === Constants.ContactRequestState.Mutual
}
else if(_d.activeChatType === Constants.chatType.privateGroupChat) {
} else if (_d.activeChatType === Constants.chatType.privateGroupChat) {
return _d.amIMember
} else if (_d.activeChatType === Constants.chatType.communityChat) {
return currentChatContentModule().viewAndPostPermissionsSatisfied
}
return true

View File

@ -278,7 +278,7 @@ Item {
return qsTr("You need to join this community to send messages")
}
if (!root.viewAndPostPermissionsSatisfied) {
return qsTr("Sorry, you don't have the tokens needed to post in this channel.")
return qsTr("Sorry, you don't have permissions to post in this channel.")
}
return root.rootStore.chatInputPlaceHolderText
} else {

View File

@ -205,7 +205,7 @@ StatusSectionLayout {
emojiPopup: root.emojiPopup
stickersPopup: root.stickersPopup
viewAndPostHoldingsModel: root.viewAndPostPermissionsModel
viewAndPostPermissionsSatisfied: !root.rootStore.chatCommunitySectionModule.isCommunity() || root.amISectionAdmin || root.viewAndPostPermissionsSatisfied
viewAndPostPermissionsSatisfied: !root.rootStore.chatCommunitySectionModule.isCommunity() || root.viewAndPostPermissionsSatisfied
amISectionAdmin: root.amISectionAdmin
onOpenStickerPackPopup: {
Global.openPopup(statusStickerPackClickPopup, {packId: stickerPackId, store: root.stickersPopup.store} )

View File

@ -1226,7 +1226,7 @@ Rectangle {
objectName: "messageInputField"
property var lastClick: 0
property double lastClick: 0
property int cursorWhenPressed: 0
property int previousCursorPosition: 0
@ -1246,7 +1246,7 @@ Rectangle {
padding: 0
// This is needed to make sure the text area is disabled when the input is disabled
Binding on enabled {
value: root.enabled
value: control.enabled
}
Keys.onUpPressed: {
if (isEdit && !activeFocus) {

View File

@ -651,7 +651,7 @@ Loader {
(root.chatLogView && root.chatLogView.moving) ||
Global.activityPopupOpened
disableEmojis: root.isChatBlocked
disableEmojis: !d.addReactionAllowed
hideMessage: d.hideMessage
overrideBackground: root.placeholderMessage