feat: Show toast notifications when the link preview setting changes from chat input

This commit is contained in:
Alex Jbanca 2023-10-17 11:11:26 +03:00 committed by Alex Jbanca
parent 1cd00b77a0
commit d7707a14a8
3 changed files with 41 additions and 29 deletions

View File

@ -39,8 +39,7 @@ Control {
id: root
implicitWidth: 374
topPadding: 15
bottomPadding: 15
verticalPadding: 15
leftPadding: 12
rightPadding: 8
@ -151,6 +150,14 @@ Control {
readonly property string openedState: "opened"
readonly property string closedState: "closed"
readonly property string iconColor: switch(root.type) {
case StatusToastMessage.Type.Success:
return Theme.palette.successColor1
case StatusToastMessage.Type.Danger:
return Theme.palette.dangerColor1
default:
return Theme.palette.primaryColor1
}
}
Timer {
@ -234,7 +241,6 @@ Control {
Layout.alignment: Qt.AlignVCenter
radius: (root.width/2)
color: {
print("color type", root.type)
switch(root.type) {
case StatusToastMessage.Type.Success:
return Theme.palette.successColor2
@ -255,14 +261,7 @@ Control {
Component {
id: loadingInd
StatusLoadingIndicator {
color: switch(root.type) {
case StatusToastMessage.Type.Success:
return Theme.palette.successColor1
case StatusToastMessage.Type.Danger:
return Theme.palette.dangerColor1
default:
return Theme.palette.primaryColor1
}
color: d.iconColor
}
}
Component {
@ -271,17 +270,7 @@ Control {
anchors.centerIn: parent
width: root.icon.width
height: root.icon.height
color: {
print("color type", root.type)
switch(root.type) {
case StatusToastMessage.Type.Success:
return Theme.palette.successColor1
case StatusToastMessage.Type.Danger:
return Theme.palette.dangerColor1
default:
return Theme.palette.primaryColor1
}
}
color: d.iconColor
icon: root.icon.name
}
}

View File

@ -89,6 +89,13 @@ Item {
chatSectionModule: root.rootStore.chatCommunitySectionModule
}
readonly property string linkPreviewBeginAnchor: `<a style="text-decoration:none" href="#${Constants.appSection.profile}/${Constants.settingsSubsection.messaging}">`
readonly property string linkPreviewEndAnchor: `</a>`
readonly property string linkPreviewEnabledNotification: qsTr("Link previews will be shown for all sites. You can manage link previews in %1.", "Go to settings").arg(linkPreviewBeginAnchor + qsTr("Settings", "Go to settings page") + linkPreviewEndAnchor)
readonly property string linkPreviewDisabledNotification: qsTr("Link previews will never be shown. You can manage link previews in %1.").arg(linkPreviewBeginAnchor + qsTr("Settings", "Go to settings page") + linkPreviewEndAnchor)
readonly property string linkPreviewEnabledForMessageNotification: qsTr("Link previews will be shown for this message. You can manage link previews in %1.").arg(linkPreviewBeginAnchor + qsTr("Settings", "Go to settings page") + linkPreviewEndAnchor)
function getChatContentModule(chatId) {
root.parentModule.prepareChatContentModuleForChatId(chatId)
return root.parentModule.getChatContentModule()
@ -335,10 +342,21 @@ Item {
}
onLinkPreviewReloaded: (link) => d.activeChatContentModule.inputAreaModule.reloadLinkPreview(link)
onEnableLinkPreview: () => d.activeChatContentModule.inputAreaModule.enableLinkPreview()
onDisableLinkPreview: () => d.activeChatContentModule.inputAreaModule.disableLinkPreview()
onEnableLinkPreviewForThisMessage: () => d.activeChatContentModule.inputAreaModule.setLinkPreviewEnabledForCurrentMessage(true)
onDismissLinkPreviewSettings: () => d.activeChatContentModule.inputAreaModule.setLinkPreviewEnabledForCurrentMessage(false)
onEnableLinkPreview: () => {
d.activeChatContentModule.inputAreaModule.enableLinkPreview()
Global.displayToastMessage(d.linkPreviewEnabledNotification, "", "show", false, Constants.ephemeralNotificationType.success, "")
}
onDisableLinkPreview: () => {
d.activeChatContentModule.inputAreaModule.disableLinkPreview()
Global.displayToastMessage(d.linkPreviewDisabledNotification, "", "hide", false, Constants.ephemeralNotificationType.danger, "")
}
onEnableLinkPreviewForThisMessage: () => {
d.activeChatContentModule.inputAreaModule.setLinkPreviewEnabledForCurrentMessage(true)
Global.displayToastMessage(d.linkPreviewEnabledForMessageNotification, "", "show", false, Constants.ephemeralNotificationType.success, "")
}
onDismissLinkPreviewSettings: () => {
d.activeChatContentModule.inputAreaModule.setLinkPreviewEnabledForCurrentMessage(false)
}
onDismissLinkPreview: (index) => d.activeChatContentModule.inputAreaModule.removeLinkPreviewData(index)
}

View File

@ -1565,7 +1565,7 @@ Item {
anchors.rightMargin: 8
anchors.bottom: parent.bottom
anchors.bottomMargin: 60
width: 343
width: 374
height: Math.min(parent.height - 120, toastArea.contentHeight)
spacing: 8
verticalLayoutDirection: ListView.BottomToTop
@ -1573,6 +1573,7 @@ Item {
clip: false
delegate: StatusToastMessage {
width: ListView.view.width
primaryText: model.title
secondaryText: model.subTitle
icon.name: model.icon
@ -1585,8 +1586,12 @@ Item {
this.open = false
}
onLinkActivated: {
if (link.startsWith("#")) // internal link to section
globalConns.onAppSectionBySectionTypeChanged(link.substring(1))
if (link.startsWith("#") && link !== "#") { // internal link to section
const sectionArgs = link.substring(1).split("/")
const section = sectionArgs[0]
let subsection = sectionArgs.length > 1 ? sectionArgs[1] : 0
Global.changeAppSectionBySectionType(section, subsection)
}
else
Global.openLink(link)
}