feat(chat): Update chat ui for the blocked contact

Close #9935
This commit is contained in:
MishkaRogachev 2023-04-21 19:05:34 +04:00 committed by Jonathan Rainville
parent 206800bd5b
commit 0fc84852f3
4 changed files with 96 additions and 36 deletions

View File

@ -162,16 +162,6 @@ Item {
} }
} }
ChatRequestMessagePanel {
anchors.fill: parent
anchors.bottomMargin: Style.current.bigPadding
isUserAdded: root.isUserAdded
visible: root.activeChatType === Constants.chatType.oneToOne && !root.isUserAdded
onAddContactClicked: {
root.rootStore.addContact(root.activeChatId);
}
}
Component { Component {
id: cmpSendTransactionNoEns id: cmpSendTransactionNoEns
ChatCommandModal { ChatCommandModal {

View File

@ -1,9 +1,6 @@
import QtQuick 2.15 import QtQuick 2.15
import QtQml 2.15 import QtQml 2.15
import Qt.labs.platform 1.1 import QtQuick.Controls 2.15
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import QtGraphicalEffects 1.0
import StatusQ.Core.Theme 0.1 import StatusQ.Core.Theme 0.1
import StatusQ.Core.Utils 0.1 as StatusQUtils import StatusQ.Core.Utils 0.1 as StatusQUtils
@ -57,32 +54,49 @@ ColumnLayout {
property Component sendTransactionWithEnsModal property Component sendTransactionWithEnsModal
property bool isBlocked: false property bool isBlocked: false
property int contactRequestState: Constants.ContactRequestState.None
property bool stickersLoaded: false property bool stickersLoaded: false
onIsActiveChannelChanged: d.updateContactRequestState()
QtObject { QtObject {
id: d id: d
property bool isUserAdded readonly property var conns1: Connections {
target: root.contactsStore.myContactsModel ?? null
function updateIsUserAdded() { function onItemChanged(pubKey) {
if (pubKey === root.chatId)
d.updateContactRequestState()
}
}
readonly property var conns2: Connections {
target: root.contactsStore.receivedContactRequestsModel ?? null
function onItemChanged(pubKey) {
if (pubKey === root.chatId)
d.updateContactRequestState()
}
}
readonly property var conns3: Connections {
target: root.contactsStore.sentContactRequestsModel ?? null
function onItemChanged(pubKey) {
if (pubKey === root.chatId)
d.updateContactRequestState()
}
}
function updateContactRequestState() {
if (root.chatType !== Constants.chatType.oneToOne) { if (root.chatType !== Constants.chatType.oneToOne) {
return false return
} }
isUserAdded = Qt.binding(() => {isActiveChannel; return Utils.getContactDetailsAsJson(root.chatId, false).isAdded}) root.contactRequestState = Utils.getContactDetailsAsJson(root.chatId).contactRequestState
} }
Component.onCompleted: updateIsUserAdded() Component.onCompleted: d.updateContactRequestState()
}
Connections {
target: root.contactsStore.myContactsModel
function onItemChanged(pubKey) {
if (pubKey === root.chatId) {
d.updateIsUserAdded()
}
}
} }
Loader { Loader {
@ -110,7 +124,7 @@ ColumnLayout {
sourceComponent: MessageContextMenuView { sourceComponent: MessageContextMenuView {
store: root.rootStore store: root.rootStore
reactionModel: root.rootStore.emojiReactionsModel reactionModel: root.rootStore.emojiReactionsModel
disabledForChat: chatType === Constants.chatType.oneToOne && !d.isUserAdded disabledForChat: chatType === Constants.chatType.oneToOne && d.contactRequestState !== Constants.ContactRequestState.Mutual
onPinMessage: { onPinMessage: {
messageStore.pinMessage(messageId) messageStore.pinMessage(messageId)
@ -178,7 +192,10 @@ ColumnLayout {
stickersPopup: root.stickersPopup stickersPopup: root.stickersPopup
usersStore: root.usersStore usersStore: root.usersStore
stickersLoaded: root.stickersLoaded stickersLoaded: root.stickersLoaded
isChatBlocked: root.isBlocked || (root.chatType === Constants.chatType.oneToOne && !d.isUserAdded) publicKey: root.chatId
isOneToOne: root.chatType === Constants.chatType.oneToOne
contactRequestState: root.contactRequestState
isChatBlocked: root.isBlocked
channelEmoji: !chatContentModule ? "" : (chatContentModule.chatDetails.emoji || "") channelEmoji: !chatContentModule ? "" : (chatContentModule.chatDetails.emoji || "")
isActiveChannel: root.isActiveChannel isActiveChannel: root.isActiveChannel
onShowReplyArea: { onShowReplyArea: {
@ -231,7 +248,7 @@ ColumnLayout {
anchors.margins: Style.current.smallPadding anchors.margins: Style.current.smallPadding
enabled: root.rootStore.sectionDetails.joined && !root.rootStore.sectionDetails.amIBanned && enabled: root.rootStore.sectionDetails.joined && !root.rootStore.sectionDetails.amIBanned &&
!(chatType === Constants.chatType.oneToOne && !d.isUserAdded) !(chatType === Constants.chatType.oneToOne && d.contactRequestState !== Constants.ContactRequestState.Mutual)
store: root.rootStore store: root.rootStore
usersStore: root.usersStore usersStore: root.usersStore

View File

@ -33,10 +33,13 @@ Item {
property var emojiPopup property var emojiPopup
property var stickersPopup property var stickersPopup
property string publicKey: ""
property bool stickersLoaded: false property bool stickersLoaded: false
property alias chatLogView: chatLogView property alias chatLogView: chatLogView
property bool isChatBlocked: false property bool isChatBlocked: false
property bool isOneToOne: false
property bool isActiveChannel: false property bool isActiveChannel: false
property int contactRequestState: Constants.ContactRequestState.None
property var messageContextMenu property var messageContextMenu
@ -185,7 +188,7 @@ Item {
highlightRangeMode: ListView.ApplyRange highlightRangeMode: ListView.ApplyRange
highlightMoveDuration: 200 highlightMoveDuration: 200
preferredHighlightBegin: 0 preferredHighlightBegin: 0
preferredHighlightEnd: chatLogView.height/2 preferredHighlightEnd: chatLogView.height / 2
model: messageStore.messagesModel model: messageStore.messagesModel
@ -250,7 +253,7 @@ Item {
chatLogView: ListView.view chatLogView: ListView.view
isActiveChannel: root.isActiveChannel isActiveChannel: root.isActiveChannel
isChatBlocked: root.isChatBlocked isChatBlocked: root.isChatBlocked || (root.isOneToOne && d.contactRequestState !== Constants.ContactRequestState.Mutual)
messageContextMenu: root.messageContextMenu messageContextMenu: root.messageContextMenu
messageId: model.id messageId: model.id
@ -329,6 +332,23 @@ Item {
messageStore.setEditModeOff(model.id) messageStore.setEditModeOff(model.id)
} }
} }
header: {
if (root.isOneToOne) {
switch (root.contactRequestState) {
case Constants.ContactRequestState.None: // no break
case Constants.ContactRequestState.Dismissed:
return sendContactRequestComponent
case Constants.ContactRequestState.Received:
return acceptContactRequestComponent
case Constants.ContactRequestState.Sent:
return pendingContactRequestComponent
default:
break
}
}
return null
}
onHeaderChanged: chatLogView.positionViewAtBeginning()
} }
MessageDialog { MessageDialog {
@ -337,4 +357,38 @@ Item {
text: qsTr("Failed to send message.") text: qsTr("Failed to send message.")
icon: StandardIcon.Critical icon: StandardIcon.Critical
} }
Component {
id: sendContactRequestComponent
StatusButton {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Send Contact Request")
onClicked: {
Global.openContactRequestPopup(root.publicKey, null)
}
}
}
Component {
id: acceptContactRequestComponent
StatusButton {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Accept Contact Request")
onClicked: {
root.contactsStore.acceptContactRequest(root.publicKey, "")
}
}
}
Component {
id: pendingContactRequestComponent
StatusButton {
anchors.horizontalCenter: parent.horizontalCenter
enabled: false
text: qsTr("Contact Request Pending...")
}
}
} }

View File

@ -406,7 +406,6 @@ Pane {
StatusMenu { StatusMenu {
id: moreMenu id: moreMenu
width: 230 width: 230
// FIXME: raly on contactRequestState !!!
SendContactRequestMenuItem { SendContactRequestMenuItem {
enabled: !d.isContact && !d.isBlocked && !d.contactRequestState === Constants.ContactRequestState.Sent && enabled: !d.isContact && !d.isBlocked && !d.contactRequestState === Constants.ContactRequestState.Sent &&
d.contactDetails.trustStatus === Constants.trustStatus.untrustworthy // we have an action button otherwise d.contactDetails.trustStatus === Constants.trustStatus.untrustworthy // we have an action button otherwise