status-desktop/storybook/pages/StatusChatInputPage.qml

275 lines
9.6 KiB
QML
Raw Normal View History

2022-12-06 07:55:50 +00:00
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import Storybook 1.0
import Models 1.0
import utils 1.0
import shared.status 1.0
import shared.stores 1.0 as SharedStores
2022-12-06 07:55:50 +00:00
import StatusQ.Core.Utils 0.1
import AppLayouts.Chat.stores 1.0 as ChatStores
2022-12-06 07:55:50 +00:00
SplitView {
id: root
Logs { id: logs }
2022-12-06 07:55:50 +00:00
QtObject {
id: globalUtilsMock
property bool ready: false
property var globalUtils: QtObject {
function plainText(htmlText) {
return htmlText.replace(/(?:<style[^]+?>[^]+?<\/style>|[\n]|<script[^]+?>[^]+?<\/script>|<(?:!|\/?[a-zA-Z]+).*?\/?>)/g,'')
}
function isCompressedPubKey(publicKey) {
return false
}
}
Component.onCompleted: {
Utils.globalUtilsInst = globalUtilsMock.globalUtils
Global.dragArea = null
globalUtilsMock.ready = true
}
}
UsersModel {
id: fakeUsersModel
}
feat(LinkPreviews): Integrate Link previews with the backend (#12523) * feat(StatusQ): Adding numberToLocaleStringInCompactForm function to LocaleUtils This function will format the number in a compact form E.g: 1000 -> 1K; 1000000 -> 1M; 1100000 -> 1.1M + adding tests fix(statusQ): Update numberToLocaleStringInCompactForm to return the locale number when greter than 999T fix(StatusQ): extend the test_numberToLocaleStringInCompactForm with new data * feat(LinkPreviews): Update the link preview area in StatusChatInput to use the new model Changes: 1. Create a new component `LinkPreviewMiniCardDelegate.qml` that filters the model data to properly fill the link preview card with the needed data based on the preview type 2. Update storybook pages 3. Small updates to LinkPreviewMiniCard * feat(LinkPreviews): Update the link previews in message history to use the new backend Changes: 1. Create delegate items for LinkPreviewCard and gif link preview to clean the LinksMessageView component and filter the model data based on the preview type 2. Remove UserProfileCard and reuse the LinkPreviewCard to display contacts link previews 3. Update LinkPreviewCard so that it can accommodate status link previews (communities, channels, contacts). The generic properties (title, description, footer) have been dropped and replaced with specialised properties for each preview type. 4. Fix LinkPreviewCard layout to better accommodate different content variants (missing properties, long/short title, missing description, missing icon) 5. Fixing the link preview context menu and click actions fix: Move inline components to separate files Fixing the linux builds using Qt 5.15.2 affected by this bug: https://bugreports.qt.io/browse/QTBUG-89180 * fix: Align LinkPreviewMiniCard implementation with LinkPreviewCard and remove state based model filtering
2023-10-25 15:20:02 +00:00
LinkPreviewModel {
id: fakeLinksModel
}
2022-12-06 07:55:50 +00:00
SplitView {
orientation: Qt.Vertical
SplitView.fillWidth: true
//dummy item to position chatInput at the bottom
Item {
SplitView.fillHeight: true
SplitView.fillWidth: true
}
Loader {
id: chatInputLoader
active: globalUtilsMock.ready
2022-12-06 07:55:50 +00:00
sourceComponent: StatusChatInput {
id: chatInput
property var globalUtils: globalUtilsMock.globalUtils
feat: Add settings card to control link previews settings in chat input This commit adds the link preview settings card in the chat input area and connects the settings to the controller. Not included in this commit: Backend for the preserving the settings, syncing the settings and enforcing the settings on the backend side. Whenever an url is detected in the chat input area, the link preview settings card is presented. This card enables the user to choose one of the following options: 1. `Show for this message` - All the link previews in the current message will be loaded without asking again. The current message can be defined as the message currently typed/pasted in the chat input. Deleting or sending the current content is resetting this setting and the link preview settings card will be presented again when a new url is detected. 2. `Always show previews` - All the link previews will be loaded automatically. The link preview settings card will not be presented again (in the current state, this settings is enabled for the lifetime of the controller. This will change once the settings are preserved and synced) 3. `Never show previews` - No link preview will be loaded. Same as the `Always show previews` option, this will be preserved for the lifetime of the controller for now. 4. Dismiss (x button) - The link preview settings card will be dismissed. It will be loaded again when a new link preview is detected The same options can be loaded as a context menu on the link preview card. Changes: 1. Adding `LinkPreviewSettingsCard` 2. Adding the settings context menu to `LinkPreviewSettingsCard` and `LinkPreviewMiniCard` 3. Connect settings events to the nim controller 4. Adding the controller logic for settings change 5. Adding the link preview dismiss settings flag to the preserverd properties and use it as a condition to load the settings. 6. Adding/Updating corresponding storybook pages
2023-10-09 08:45:16 +00:00
property string unformattedText: chatInput.textInput.getText(0, chatInput.textInput.length)
readonly property ModelChangeTracker urlsModelChangeTracker: ModelChangeTracker {
model: fakeLinksModel
}
onUnformattedTextChanged: {
textEditConnection.enabled = false
feat: Add settings card to control link previews settings in chat input This commit adds the link preview settings card in the chat input area and connects the settings to the controller. Not included in this commit: Backend for the preserving the settings, syncing the settings and enforcing the settings on the backend side. Whenever an url is detected in the chat input area, the link preview settings card is presented. This card enables the user to choose one of the following options: 1. `Show for this message` - All the link previews in the current message will be loaded without asking again. The current message can be defined as the message currently typed/pasted in the chat input. Deleting or sending the current content is resetting this setting and the link preview settings card will be presented again when a new url is detected. 2. `Always show previews` - All the link previews will be loaded automatically. The link preview settings card will not be presented again (in the current state, this settings is enabled for the lifetime of the controller. This will change once the settings are preserved and synced) 3. `Never show previews` - No link preview will be loaded. Same as the `Always show previews` option, this will be preserved for the lifetime of the controller for now. 4. Dismiss (x button) - The link preview settings card will be dismissed. It will be loaded again when a new link preview is detected The same options can be loaded as a context menu on the link preview card. Changes: 1. Adding `LinkPreviewSettingsCard` 2. Adding the settings context menu to `LinkPreviewSettingsCard` and `LinkPreviewMiniCard` 3. Connect settings events to the nim controller 4. Adding the controller logic for settings change 5. Adding the link preview dismiss settings flag to the preserverd properties and use it as a condition to load the settings. 6. Adding/Updating corresponding storybook pages
2023-10-09 08:45:16 +00:00
d.loadLinkPreviews(unformattedText)
textEditConnection.enabled = true
}
Connections {
id: textEditConnection
target: chatInput.textInput
function onTextChanged() {
if(unformattedText !== chatInput.textInput.getText(0, chatInput.textInput.length))
unformattedText = chatInput.textInput.getText(0, chatInput.textInput.length)
}
}
enabled: enabledCheckBox.checked
linkPreviewModel: fakeLinksModel
urlsList: {
urlsModelChangeTracker.revision
ModelUtils.modelToFlatArray(fakeLinksModel, "url")
}
feat: Add settings card to control link previews settings in chat input This commit adds the link preview settings card in the chat input area and connects the settings to the controller. Not included in this commit: Backend for the preserving the settings, syncing the settings and enforcing the settings on the backend side. Whenever an url is detected in the chat input area, the link preview settings card is presented. This card enables the user to choose one of the following options: 1. `Show for this message` - All the link previews in the current message will be loaded without asking again. The current message can be defined as the message currently typed/pasted in the chat input. Deleting or sending the current content is resetting this setting and the link preview settings card will be presented again when a new url is detected. 2. `Always show previews` - All the link previews will be loaded automatically. The link preview settings card will not be presented again (in the current state, this settings is enabled for the lifetime of the controller. This will change once the settings are preserved and synced) 3. `Never show previews` - No link preview will be loaded. Same as the `Always show previews` option, this will be preserved for the lifetime of the controller for now. 4. Dismiss (x button) - The link preview settings card will be dismissed. It will be loaded again when a new link preview is detected The same options can be loaded as a context menu on the link preview card. Changes: 1. Adding `LinkPreviewSettingsCard` 2. Adding the settings context menu to `LinkPreviewSettingsCard` and `LinkPreviewMiniCard` 3. Connect settings events to the nim controller 4. Adding the controller logic for settings change 5. Adding the link preview dismiss settings flag to the preserverd properties and use it as a condition to load the settings. 6. Adding/Updating corresponding storybook pages
2023-10-09 08:45:16 +00:00
askToEnableLinkPreview: askToEnableLinkPreviewSwitch.checked
onAskToEnableLinkPreviewChanged: {
if(askToEnableLinkPreview) {
fakeLinksModel.clear()
d.loadLinkPreviews(unformattedText)
}
}
usersStore: ChatStores.UsersStore {
2022-12-06 07:55:50 +00:00
readonly property var usersModel: fakeUsersModel
}
sharedStore: SharedStores.RootStore {
isWalletEnabled: true
gifUnfurlingEnabled: true
property var gifStore: SharedStores.GifStore {
property var gifColumnA: ListModel {}
}
}
onSendMessage: {
logs.logEvent("StatusChatInput::sendMessage", ["MessageWithPk"], [chatInput.getTextWithPublicKeys()])
logs.logEvent("StatusChatInput::sendMessage", ["PlainText"], [globalUtilsMock.globalUtils.plainText(chatInput.getTextWithPublicKeys())])
logs.logEvent("StatusChatInput::sendMessage", ["RawText"], [chatInput.textInput.text])
}
feat: Add settings card to control link previews settings in chat input This commit adds the link preview settings card in the chat input area and connects the settings to the controller. Not included in this commit: Backend for the preserving the settings, syncing the settings and enforcing the settings on the backend side. Whenever an url is detected in the chat input area, the link preview settings card is presented. This card enables the user to choose one of the following options: 1. `Show for this message` - All the link previews in the current message will be loaded without asking again. The current message can be defined as the message currently typed/pasted in the chat input. Deleting or sending the current content is resetting this setting and the link preview settings card will be presented again when a new url is detected. 2. `Always show previews` - All the link previews will be loaded automatically. The link preview settings card will not be presented again (in the current state, this settings is enabled for the lifetime of the controller. This will change once the settings are preserved and synced) 3. `Never show previews` - No link preview will be loaded. Same as the `Always show previews` option, this will be preserved for the lifetime of the controller for now. 4. Dismiss (x button) - The link preview settings card will be dismissed. It will be loaded again when a new link preview is detected The same options can be loaded as a context menu on the link preview card. Changes: 1. Adding `LinkPreviewSettingsCard` 2. Adding the settings context menu to `LinkPreviewSettingsCard` and `LinkPreviewMiniCard` 3. Connect settings events to the nim controller 4. Adding the controller logic for settings change 5. Adding the link preview dismiss settings flag to the preserverd properties and use it as a condition to load the settings. 6. Adding/Updating corresponding storybook pages
2023-10-09 08:45:16 +00:00
onEnableLinkPreviewForThisMessage: {
linkPreviewSwitch.checked = true
askToEnableLinkPreviewSwitch.checked = false
}
onEnableLinkPreview: {
linkPreviewSwitch.checked = true
askToEnableLinkPreviewSwitch.checked = false
}
onDisableLinkPreview: {
linkPreviewSwitch.checked = false
askToEnableLinkPreviewSwitch.checked = false
}
onDismissLinkPreviewSettings: {
askToEnableLinkPreviewSwitch.checked = false
linkPreviewSwitch.checked = false
}
onDismissLinkPreview: (index) => {
fakeLinksModel.setProperty(index, "unfurled", false)
fakeLinksModel.setProperty(index, "immutable", true)
}
2022-12-06 07:55:50 +00:00
}
}
LogsAndControlsPanel {
id: logsAndControlsPanel
SplitView.minimumHeight: 100
SplitView.preferredHeight: 200
logsView.logText: logs.logText
}
feat: Add settings card to control link previews settings in chat input This commit adds the link preview settings card in the chat input area and connects the settings to the controller. Not included in this commit: Backend for the preserving the settings, syncing the settings and enforcing the settings on the backend side. Whenever an url is detected in the chat input area, the link preview settings card is presented. This card enables the user to choose one of the following options: 1. `Show for this message` - All the link previews in the current message will be loaded without asking again. The current message can be defined as the message currently typed/pasted in the chat input. Deleting or sending the current content is resetting this setting and the link preview settings card will be presented again when a new url is detected. 2. `Always show previews` - All the link previews will be loaded automatically. The link preview settings card will not be presented again (in the current state, this settings is enabled for the lifetime of the controller. This will change once the settings are preserved and synced) 3. `Never show previews` - No link preview will be loaded. Same as the `Always show previews` option, this will be preserved for the lifetime of the controller for now. 4. Dismiss (x button) - The link preview settings card will be dismissed. It will be loaded again when a new link preview is detected The same options can be loaded as a context menu on the link preview card. Changes: 1. Adding `LinkPreviewSettingsCard` 2. Adding the settings context menu to `LinkPreviewSettingsCard` and `LinkPreviewMiniCard` 3. Connect settings events to the nim controller 4. Adding the controller logic for settings change 5. Adding the link preview dismiss settings flag to the preserverd properties and use it as a condition to load the settings. 6. Adding/Updating corresponding storybook pages
2023-10-09 08:45:16 +00:00
QtObject {
id: d
property bool linkPreviewsEnabled: linkPreviewSwitch.checked && !askToEnableLinkPreviewSwitch.checked
onLinkPreviewsEnabledChanged: {
loadLinkPreviews(chatInputLoader.item ? chatInputLoader.item.unformattedText : "")
}
function loadLinkPreviews(text) {
var words = text.split(/\s+/)
feat: Add settings card to control link previews settings in chat input This commit adds the link preview settings card in the chat input area and connects the settings to the controller. Not included in this commit: Backend for the preserving the settings, syncing the settings and enforcing the settings on the backend side. Whenever an url is detected in the chat input area, the link preview settings card is presented. This card enables the user to choose one of the following options: 1. `Show for this message` - All the link previews in the current message will be loaded without asking again. The current message can be defined as the message currently typed/pasted in the chat input. Deleting or sending the current content is resetting this setting and the link preview settings card will be presented again when a new url is detected. 2. `Always show previews` - All the link previews will be loaded automatically. The link preview settings card will not be presented again (in the current state, this settings is enabled for the lifetime of the controller. This will change once the settings are preserved and synced) 3. `Never show previews` - No link preview will be loaded. Same as the `Always show previews` option, this will be preserved for the lifetime of the controller for now. 4. Dismiss (x button) - The link preview settings card will be dismissed. It will be loaded again when a new link preview is detected The same options can be loaded as a context menu on the link preview card. Changes: 1. Adding `LinkPreviewSettingsCard` 2. Adding the settings context menu to `LinkPreviewSettingsCard` and `LinkPreviewMiniCard` 3. Connect settings events to the nim controller 4. Adding the controller logic for settings change 5. Adding the link preview dismiss settings flag to the preserverd properties and use it as a condition to load the settings. 6. Adding/Updating corresponding storybook pages
2023-10-09 08:45:16 +00:00
fakeLinksModel.clear()
words.forEach(function(word){
if(Utils.isURL(word)) {
feat(LinkPreviews): Integrate Link previews with the backend (#12523) * feat(StatusQ): Adding numberToLocaleStringInCompactForm function to LocaleUtils This function will format the number in a compact form E.g: 1000 -> 1K; 1000000 -> 1M; 1100000 -> 1.1M + adding tests fix(statusQ): Update numberToLocaleStringInCompactForm to return the locale number when greter than 999T fix(StatusQ): extend the test_numberToLocaleStringInCompactForm with new data * feat(LinkPreviews): Update the link preview area in StatusChatInput to use the new model Changes: 1. Create a new component `LinkPreviewMiniCardDelegate.qml` that filters the model data to properly fill the link preview card with the needed data based on the preview type 2. Update storybook pages 3. Small updates to LinkPreviewMiniCard * feat(LinkPreviews): Update the link previews in message history to use the new backend Changes: 1. Create delegate items for LinkPreviewCard and gif link preview to clean the LinksMessageView component and filter the model data based on the preview type 2. Remove UserProfileCard and reuse the LinkPreviewCard to display contacts link previews 3. Update LinkPreviewCard so that it can accommodate status link previews (communities, channels, contacts). The generic properties (title, description, footer) have been dropped and replaced with specialised properties for each preview type. 4. Fix LinkPreviewCard layout to better accommodate different content variants (missing properties, long/short title, missing description, missing icon) 5. Fixing the link preview context menu and click actions fix: Move inline components to separate files Fixing the linux builds using Qt 5.15.2 affected by this bug: https://bugreports.qt.io/browse/QTBUG-89180 * fix: Align LinkPreviewMiniCard implementation with LinkPreviewCard and remove state based model filtering
2023-10-25 15:20:02 +00:00
const linkPreview = fakeLinksModel.getStandardLinkPreview()
linkPreview.url = encodeURI(word)
linkPreview.unfurled = Math.random() > 0.2
linkPreview.immutable = !d.linkPreviewsEnabled
linkPreview.empty = Math.random() > 0.7
fakeLinksModel.append(linkPreview)
feat: Add settings card to control link previews settings in chat input This commit adds the link preview settings card in the chat input area and connects the settings to the controller. Not included in this commit: Backend for the preserving the settings, syncing the settings and enforcing the settings on the backend side. Whenever an url is detected in the chat input area, the link preview settings card is presented. This card enables the user to choose one of the following options: 1. `Show for this message` - All the link previews in the current message will be loaded without asking again. The current message can be defined as the message currently typed/pasted in the chat input. Deleting or sending the current content is resetting this setting and the link preview settings card will be presented again when a new url is detected. 2. `Always show previews` - All the link previews will be loaded automatically. The link preview settings card will not be presented again (in the current state, this settings is enabled for the lifetime of the controller. This will change once the settings are preserved and synced) 3. `Never show previews` - No link preview will be loaded. Same as the `Always show previews` option, this will be preserved for the lifetime of the controller for now. 4. Dismiss (x button) - The link preview settings card will be dismissed. It will be loaded again when a new link preview is detected The same options can be loaded as a context menu on the link preview card. Changes: 1. Adding `LinkPreviewSettingsCard` 2. Adding the settings context menu to `LinkPreviewSettingsCard` and `LinkPreviewMiniCard` 3. Connect settings events to the nim controller 4. Adding the controller logic for settings change 5. Adding the link preview dismiss settings flag to the preserverd properties and use it as a condition to load the settings. 6. Adding/Updating corresponding storybook pages
2023-10-09 08:45:16 +00:00
}
})
}
}
2022-12-06 07:55:50 +00:00
}
Pane {
SplitView.minimumWidth: 300
SplitView.preferredWidth: 300
ColumnLayout {
anchors.fill: parent
CheckBox {
id: enabledCheckBox
text: "enabled"
checked: true
}
TabBar {
id: bar
TabButton {
text: "Attachments"
}
TabButton {
text: "Users"
}
}
StackLayout {
currentIndex: bar.currentIndex
ColumnLayout {
id: attachmentsTab
Layout.fillWidth: true
Layout.fillHeight: true
Label {
text: "Images"
Layout.fillWidth: true
}
ComboBox {
id: imageNb
editable: true
model: 20
validator: IntValidator {bottom: 0; top: 20;}
focus: true
onCurrentIndexChanged: {
if(!chatInputLoader.item)
return
const urls = []
for (let i = 0; i < imageNb.currentIndex ; i++) {
urls.push("https://picsum.photos/200/300?random=" + i)
}
console.log(urls.length)
chatInputLoader.item.fileUrlsAndSources = urls
}
}
Label {
text: "Links"
Layout.fillWidth: true
}
feat: Add settings card to control link previews settings in chat input This commit adds the link preview settings card in the chat input area and connects the settings to the controller. Not included in this commit: Backend for the preserving the settings, syncing the settings and enforcing the settings on the backend side. Whenever an url is detected in the chat input area, the link preview settings card is presented. This card enables the user to choose one of the following options: 1. `Show for this message` - All the link previews in the current message will be loaded without asking again. The current message can be defined as the message currently typed/pasted in the chat input. Deleting or sending the current content is resetting this setting and the link preview settings card will be presented again when a new url is detected. 2. `Always show previews` - All the link previews will be loaded automatically. The link preview settings card will not be presented again (in the current state, this settings is enabled for the lifetime of the controller. This will change once the settings are preserved and synced) 3. `Never show previews` - No link preview will be loaded. Same as the `Always show previews` option, this will be preserved for the lifetime of the controller for now. 4. Dismiss (x button) - The link preview settings card will be dismissed. It will be loaded again when a new link preview is detected The same options can be loaded as a context menu on the link preview card. Changes: 1. Adding `LinkPreviewSettingsCard` 2. Adding the settings context menu to `LinkPreviewSettingsCard` and `LinkPreviewMiniCard` 3. Connect settings events to the nim controller 4. Adding the controller logic for settings change 5. Adding the link preview dismiss settings flag to the preserverd properties and use it as a condition to load the settings. 6. Adding/Updating corresponding storybook pages
2023-10-09 08:45:16 +00:00
Switch {
id: linkPreviewSwitch
text: "Link Preview enabled"
}
Switch {
id: askToEnableLinkPreviewSwitch
text: "Ask to enable Link Preview"
checked: true
}
ComboBox {
id: linksNb
editable: true
model: 20
validator: IntValidator {bottom: 0; top: 20;}
onCurrentIndexChanged: {
if(!chatInputLoader.item)
return
let urls = ""
for (let i = 0; i < linksNb.currentIndex ; i++) {
urls += "https://www.youtube.com/watch?v=9bZkp7q19f0" + Math.floor(Math.random() * 100) + " "
}
chatInputLoader.item.textInput.text = urls
}
}
}
UsersModelEditor {
id: modelEditor
Layout.fillWidth: true
Layout.fillHeight: true
model: fakeUsersModel
onRemoveClicked: fakeUsersModel.remove(index, 1)
onRemoveAllClicked: fakeUsersModel.clear()
onAddClicked: fakeUsersModel.append(modelEditor.getNewUser(fakeUsersModel.count))
}
}
Label {
text: "Attachments"
Layout.fillWidth: true
}
}
}
2022-12-06 07:55:50 +00:00
}
// category: Components
feat: Add settings card to control link previews settings in chat input This commit adds the link preview settings card in the chat input area and connects the settings to the controller. Not included in this commit: Backend for the preserving the settings, syncing the settings and enforcing the settings on the backend side. Whenever an url is detected in the chat input area, the link preview settings card is presented. This card enables the user to choose one of the following options: 1. `Show for this message` - All the link previews in the current message will be loaded without asking again. The current message can be defined as the message currently typed/pasted in the chat input. Deleting or sending the current content is resetting this setting and the link preview settings card will be presented again when a new url is detected. 2. `Always show previews` - All the link previews will be loaded automatically. The link preview settings card will not be presented again (in the current state, this settings is enabled for the lifetime of the controller. This will change once the settings are preserved and synced) 3. `Never show previews` - No link preview will be loaded. Same as the `Always show previews` option, this will be preserved for the lifetime of the controller for now. 4. Dismiss (x button) - The link preview settings card will be dismissed. It will be loaded again when a new link preview is detected The same options can be loaded as a context menu on the link preview card. Changes: 1. Adding `LinkPreviewSettingsCard` 2. Adding the settings context menu to `LinkPreviewSettingsCard` and `LinkPreviewMiniCard` 3. Connect settings events to the nim controller 4. Adding the controller logic for settings change 5. Adding the link preview dismiss settings flag to the preserverd properties and use it as a condition to load the settings. 6. Adding/Updating corresponding storybook pages
2023-10-09 08:45:16 +00:00
// https://www.figma.com/file/Mr3rqxxgKJ2zMQ06UAKiWL/💬-Chat⎜Desktop?type=design&node-id=23155-66084&mode=design&t=VWBVK4DOUxr1BmTp-0