hide input field until mutual contacts and notify on contact accepted

This commit is contained in:
Jonathan Rainville 2021-05-26 14:56:04 -04:00
parent d827433ad4
commit 7b95031ee6
4 changed files with 21 additions and 10 deletions

View File

@ -63,6 +63,8 @@ QtObject:
) )
result.setup result.setup
proc contactListChanged*(self: ContactsView) {.signal.}
proc updateContactList*(self: ContactsView, contacts: seq[Profile]) = proc updateContactList*(self: ContactsView, contacts: seq[Profile]) =
for contact in contacts: for contact in contacts:
self.contactList.updateContact(contact) self.contactList.updateContact(contact)
@ -72,8 +74,7 @@ QtObject:
self.blockedContacts.updateContact(contact) self.blockedContacts.updateContact(contact)
if contact.systemTags.contains(contactRequest) and not contact.systemTags.contains(contactAdded) and not contact.systemTags.contains(contactBlocked): if contact.systemTags.contains(contactRequest) and not contact.systemTags.contains(contactAdded) and not contact.systemTags.contains(contactBlocked):
self.contactRequests.updateContact(contact) self.contactRequests.updateContact(contact)
self.contactListChanged()
proc contactListChanged*(self: ContactsView) {.signal.}
proc getContactList(self: ContactsView): QVariant {.slot.} = proc getContactList(self: ContactsView): QVariant {.slot.} =
return newQVariant(self.contactList) return newQVariant(self.contactList)
@ -89,7 +90,7 @@ QtObject:
proc notifyOnNewContactRequests*(self: ContactsView, contacts: seq[Profile]) = proc notifyOnNewContactRequests*(self: ContactsView, contacts: seq[Profile]) =
for contact in contacts: for contact in contacts:
if contact.systemTags.contains(contactRequest) and not contact.systemTags.contains(contactAdded) and not contact.systemTags.contains(contactBlocked): if contact.systemTags.contains(contactRequest) and not contact.systemTags.contains(contactBlocked):
self.contactRequestAdded(status_ens.userNameOrAlias(contact), contact.address) self.contactRequestAdded(status_ens.userNameOrAlias(contact), contact.address)
QtProperty[QVariant] list: QtProperty[QVariant] list:

View File

@ -35,6 +35,7 @@ StackLayout {
property string activeChatId: chatsModel.activeChannel.id property string activeChatId: chatsModel.activeChannel.id
property bool isBlocked: profileModel.contacts.isContactBlocked(activeChatId) property bool isBlocked: profileModel.contacts.isContactBlocked(activeChatId)
property bool isContact: profileModel.contacts.isAdded(activeChatId) property bool isContact: profileModel.contacts.isAdded(activeChatId)
property bool contactRequestReceived: profileModel.contacts.contactRequestReceived(activeChatId)
property string currentNotificationChatId property string currentNotificationChatId
property string currentNotificationCommunityId property string currentNotificationCommunityId
@ -343,10 +344,13 @@ StackLayout {
StatusChatInput { StatusChatInput {
id: chatInput id: chatInput
visible: { visible: {
const community = chatsModel.communities.activeCommunity
if (chatsModel.activeChannel.chatType === Constants.chatTypePrivateGroupChat) { if (chatsModel.activeChannel.chatType === Constants.chatTypePrivateGroupChat) {
return chatsModel.activeChannel.isMember return chatsModel.activeChannel.isMember
} }
if (chatsModel.activeChannel.chatType === Constants.chatTypeOneToOne) {
return isContact && contactRequestReceived
}
const community = chatsModel.communities.activeCommunity
return !community.active || return !community.active ||
community.access === Constants.communityChatPublicAccess || community.access === Constants.communityChatPublicAccess ||
community.admin || community.admin ||

View File

@ -4,7 +4,7 @@ import "../../../../../shared"
import "../../../../../shared/status" import "../../../../../shared/status"
Item { Item {
visible: chatsModel.activeChannel.chatType === Constants.chatTypeOneToOne && !isContact visible: chatsModel.activeChannel.chatType === Constants.chatTypeOneToOne && (!isContact || !contactRequestReceived)
width: parent.width width: parent.width
height: childrenRect.height height: childrenRect.height
@ -18,7 +18,8 @@ Item {
StyledText { StyledText {
id: contactText1 id: contactText1
text: qsTr("You need to be mutual contacts with this person for them to receive your messages") text: !isContact ? qsTr("You need to be mutual contacts with this person for them to receive your messages") :
qsTr("Waiting for %1 to accept your request").arg(Utils.removeStatusEns(chatsModel.activeChannel.name))
anchors.top: waveImg.bottom anchors.top: waveImg.bottom
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
@ -29,7 +30,8 @@ Item {
StyledText { StyledText {
id: contactText2 id: contactText2
text: qsTr("Just click this button to add them as contact. They will receive a notification all once they accept you as contact as well, you'll be able to chat") visible: !isContact
text: qsTr("Just click this button to add them as contact. They will receive a notification. Once they accept the request, you'll be able to chat")
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
anchors.top: contactText1.bottom anchors.top: contactText1.bottom
@ -39,6 +41,7 @@ Item {
} }
StatusButton { StatusButton {
visible: !isContact
text: qsTr("Add to contacts") text: qsTr("Add to contacts")
anchors.top: contactText2.bottom anchors.top: contactText2.bottom
anchors.topMargin: Style.current.smallPadding anchors.topMargin: Style.current.smallPadding

View File

@ -125,7 +125,10 @@ Rectangle {
if (!appSettings.notifyOnNewRequests) { if (!appSettings.notifyOnNewRequests) {
return return
} }
systemTray.showMessage(qsTr("New contact request"), const isContact = profileModel.contacts.isAdded(address)
systemTray.showMessage(isContact ? qsTr("Contact request accepted") :
qsTr("New contact request"),
isContact ? qsTr("You can now chat with %1").arg(Utils.removeStatusEns(name)) :
qsTr("%1 requests to become contacts").arg(Utils.removeStatusEns(name)), qsTr("%1 requests to become contacts").arg(Utils.removeStatusEns(name)),
SystemTrayIcon.NoIcon, SystemTrayIcon.NoIcon,
Constants.notificationPopupTTL) Constants.notificationPopupTTL)