Skip to content

Commit

Permalink
feat(Chat): Disable chat actions for non-contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
MishkaRogachev authored and jrainville committed Mar 28, 2023
1 parent ad4838e commit 1f54d96
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 31 deletions.
4 changes: 2 additions & 2 deletions ui/StatusQ/src/StatusQ/Components/StatusMessage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Control {
property bool editMode: false
property bool isAReply: false
property bool isEdited: false
property bool isChatBlocked: false

property bool hasMention: false
property bool isPinned: false
Expand All @@ -56,6 +55,7 @@ Control {
property bool isActiveMessage: false
property bool disableHover: false
property bool hideQuickActions: false
property bool disableEmojis: false
property color overrideBackgroundColor: "transparent"
property bool overrideBackground: false
property bool profileClickable: true
Expand Down Expand Up @@ -395,7 +395,7 @@ Control {
visible: active
sourceComponent: StatusMessageEmojiReactions {
id: emojiReactionsPanel

enabled: !root.disableEmojis
emojiReactionsModel: root.reactionsModel
icons: root.reactionIcons

Expand Down
16 changes: 13 additions & 3 deletions ui/StatusQ/src/StatusQ/Popups/StatusMenu.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtGraphicalEffects 1.13
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtGraphicalEffects 1.15

import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
Expand Down Expand Up @@ -57,6 +57,16 @@ Menu {

signal menuItemClicked(int menuIndex)

function checkIfEmpty() {
for (let i = 0; i < root.contentItem.count; ++i) {
const menuItem = root.contentItem.itemAtIndex(i)
if (menuItem.text !== undefined && menuItem.enabled) { // skip menu separators
return false
}
}
return true
}

dim: false
closePolicy: Popup.CloseOnPressOutside | Popup.CloseOnEscape
topPadding: 8
Expand Down
3 changes: 3 additions & 0 deletions ui/app/AppLayouts/Chat/views/ChatContentView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ ColumnLayout {
id: contextmenu
store: root.rootStore
reactionModel: root.rootStore.emojiReactionsModel
disabledForChat: chatType === Constants.chatType.oneToOne && !root.isUserAdded

onPinMessage: {
messageStore.pinMessage(messageId)
}
Expand Down Expand Up @@ -150,6 +152,7 @@ ColumnLayout {
isChatBlocked: root.isBlocked
channelEmoji: !chatContentModule ? "" : (chatContentModule.chatDetails.emoji || "")
isActiveChannel: root.isActiveChannel
isUserAdded: root.isUserAdded
onShowReplyArea: {
let obj = messageStore.getMessageByIdAsJson(messageId)
if (!obj) {
Expand Down
3 changes: 2 additions & 1 deletion ui/app/AppLayouts/Chat/views/ChatMessagesView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Item {
property alias chatLogView: chatLogView
property bool isChatBlocked: false
property bool isActiveChannel: false
property bool isUserAdded: true

property var messageContextMenu

Expand Down Expand Up @@ -225,7 +226,7 @@ Item {
chatLogView: ListView.view

isActiveChannel: root.isActiveChannel
isChatBlocked: root.isChatBlocked
isChatBlocked: root.isChatBlocked || !root.isUserAdded
messageContextMenu: root.messageContextMenu

messageId: model.id
Expand Down
7 changes: 6 additions & 1 deletion ui/imports/shared/status/StatusChatInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,12 @@ Rectangle {
}
}

onEnabledChanged: if (!enabled) text = ""
onEnabledChanged: {
if (!enabled) {
text = ""
control.hideExtendedArea()
}
}

cursorDelegate: Rectangle {
color: Theme.palette.primaryColor1
Expand Down
22 changes: 16 additions & 6 deletions ui/imports/shared/views/chat/MessageContextMenuView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ StatusMenu {

property string myPublicKey: ""
property bool amIChatAdmin: false
property bool disabledForChat: false

property string selectedUserPublicKey: ""
property string selectedUserDisplayName: ""
Expand Down Expand Up @@ -144,7 +145,8 @@ StatusMenu {
id: emojiContainer
width: emojiRow.width
height: visible ? emojiRow.height : 0
visible: !root.hideEmojiPicker && (root.isEmoji || !root.isProfile) && !root.pinnedPopup
visible: !root.hideEmojiPicker && (root.isEmoji || !root.isProfile) && !root.pinnedPopup && !root.disabledForChat

Row {
id: emojiRow
spacing: Style.current.halfPadding
Expand Down Expand Up @@ -190,7 +192,7 @@ StatusMenu {
height: visible ? root.topPadding : 0
}

Separator {
StatusMenuSeparator {
anchors.bottom: viewProfileAction.top
visible: !root.isEmoji && !root.hideEmojiPicker && !pinnedPopup
}
Expand Down Expand Up @@ -238,6 +240,7 @@ StatusMenu {
}

SendContactRequestMenuItem {
id: sendContactRequestMenuItem
enabled: root.isProfile && !root.isMe && !root.isContact
&& !root.isBlockedContact && !root.hasPendingContactRequest
onTriggered: {
Expand All @@ -247,6 +250,7 @@ StatusMenu {
}

StatusAction {
id: verifyIdentityAction
text: qsTr("Verify Identity")
icon.name: "checkmark-circle"
enabled: root.isProfile && !root.isMe && root.isContact
Expand All @@ -260,7 +264,8 @@ StatusMenu {
}

StatusAction {
text: isVerificationRequestSent ||
id: pendingIdentityAction
text: isVerificationRequestSent ||
root.incomingVerificationStatus === Constants.verificationStatus.verified ?
qsTr("ID Request Pending....") :
qsTr("Respond to ID Request...")
Expand All @@ -281,6 +286,7 @@ StatusMenu {
}

StatusAction {
id: renameAction
text: qsTr("Rename")
icon.name: "edit_pencil"
enabled: root.isProfile && !root.isMe
Expand All @@ -292,6 +298,7 @@ StatusMenu {
}

StatusAction {
id: unblockAction
text: qsTr("Unblock User")
icon.name: "remove-circle"
enabled: root.isProfile && !root.isMe && root.isBlockedContact
Expand Down Expand Up @@ -340,7 +347,8 @@ StatusMenu {
!root.isEmoji &&
!root.isProfile &&
!root.pinnedPopup &&
!root.isRightClickOnImage)
!root.isRightClickOnImage &&
!root.disabledForChat)
}

StatusAction {
Expand All @@ -356,7 +364,8 @@ StatusMenu {
!root.isSticker &&
!root.isProfile &&
!root.pinnedPopup &&
!root.isRightClickOnImage
!root.isRightClickOnImage &&
!root.disabledForChat
}

StatusAction {
Expand Down Expand Up @@ -406,7 +415,7 @@ StatusMenu {
}
icon.name: "pin"
enabled: {
if(root.isProfile || root.isEmoji || root.isRightClickOnImage)
if (root.isProfile || root.isEmoji || root.isRightClickOnImage || root.disabledForChat)
return false

if (root.pinnedPopup)
Expand Down Expand Up @@ -440,6 +449,7 @@ StatusMenu {
StatusAction {
id: deleteMessageAction
enabled: (root.isMyMessage || root.amIChatAdmin) &&
!root.disabledForChat &&
!root.isProfile &&
!root.isEmoji &&
!root.pinnedPopup &&
Expand Down
43 changes: 25 additions & 18 deletions ui/imports/shared/views/chat/MessageView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Loader {
imageSource = "") {

if (placeholderMessage || !(root.rootStore.mainModuleInst.activeSection.joined || isProfileClick)) {
return
return false
}

messageContextMenu.myPublicKey = userProfile.pubKey
Expand Down Expand Up @@ -164,16 +164,22 @@ Loader {
if (isReply) {
if (!quotedMessageFrom) {
// The responseTo message was deleted so we don't eneble to right click the unaviable profile
return
return false
}
messageContextMenu.messageSenderId = quotedMessageFrom
messageContextMenu.selectedUserPublicKey = quotedMessageFrom
messageContextMenu.selectedUserDisplayName = quotedMessageAuthorDetailsDisplayName
messageContextMenu.selectedUserIcon = quotedMessageAuthorDetailsThumbnailImage
}

messageContextMenu.parent = sender;
messageContextMenu.popup(point);
// Emoji container is not a menu item of messageContextMenu so checking it separatly
if (messageContextMenu.checkIfEmpty() && !isEmoji) {
return false
}

messageContextMenu.parent = sender
messageContextMenu.popup(point)
return true
}

signal showReplyArea(string messageId, string author)
Expand Down Expand Up @@ -462,6 +468,7 @@ Loader {
root.editModeOn ||
!root.rootStore.mainModuleInst.activeSection.joined

disableEmojis: root.isChatBlocked
hideMessage: d.hideMessage

overrideBackground: root.placeholderMessage
Expand Down Expand Up @@ -504,22 +511,22 @@ Loader {
}

onProfilePictureClicked: {
d.setMessageActive(root.messageId, true);
root.messageClickHandler(sender, Qt.point(mouse.x, mouse.y), true);
if (root.messageClickHandler(sender, Qt.point(mouse.x, mouse.y), true))
d.setMessageActive(root.messageId, true)
}

onReplyProfileClicked: {
d.setMessageActive(root.messageId, true);
root.messageClickHandler(sender, Qt.point(mouse.x, mouse.y), true, false, false, null, false, false, true);
if (root.messageClickHandler(sender, Qt.point(mouse.x, mouse.y), true, false, false, null, false, false, true))
d.setMessageActive(root.messageId, true)
}

onReplyMessageClicked: {
root.messageStore.messageModule.jumpToMessage(root.responseToMessageWithId)
}

onSenderNameClicked: {
d.setMessageActive(root.messageId, true);
root.messageClickHandler(sender, Qt.point(mouse.x, mouse.y), true);
if (root.messageClickHandler(sender, Qt.point(mouse.x, mouse.y), true))
d.setMessageActive(root.messageId, true)
}

onToggleReactionClicked: {
Expand All @@ -536,10 +543,10 @@ Loader {

onAddReactionClicked: {
if (root.isChatBlocked)
return;
return

d.setMessageActive(root.messageId, true);
root.messageClickHandler(sender, Qt.point(mouse.x, mouse.y), false, false, false, null, true, false);
if (root.messageClickHandler(sender, Qt.point(mouse.x, mouse.y), false, false, false, null, true, false))
d.setMessageActive(root.messageId, true)
}

onStickerClicked: {
Expand All @@ -556,9 +563,9 @@ Loader {
!root.placeholderMessage &&
delegate.contentType !== StatusMessage.ContentType.Image
onClicked: {
d.setMessageActive(root.messageId, true);
root.messageClickHandler(this, Qt.point(mouse.x, mouse.y),
false, false, false, null, root.isEmoji, false, false, false, "");
if (root.messageClickHandler(this, Qt.point(mouse.x, mouse.y),
false, false, false, null, root.isEmoji, false, false, false, ""))
d.setMessageActive(root.messageId, true)
}
}

Expand Down Expand Up @@ -729,8 +736,8 @@ Loader {
type: StatusFlatRoundButton.Type.Tertiary
tooltip.text: qsTr("Add reaction")
onClicked: {
d.setMessageActive(root.messageId, true)
root.messageClickHandler(delegate, mapToItem(delegate, mouse.x, mouse.y), false, false, false, null, true, false)
if (root.messageClickHandler(delegate, mapToItem(delegate, mouse.x, mouse.y), false, false, false, null, true, false))
d.setMessageActive(root.messageId, true)
}
}
},
Expand Down

0 comments on commit 1f54d96

Please sign in to comment.