2024-10-15 19:26:12 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
2020-09-29 09:06:57 +00:00
|
|
|
import QtQuick.Dialogs 1.3
|
2023-02-06 09:09:14 +00:00
|
|
|
|
2021-09-28 15:04:06 +00:00
|
|
|
import utils 1.0
|
2021-10-21 15:07:13 +00:00
|
|
|
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared 1.0
|
2023-09-26 14:16:53 +00:00
|
|
|
import shared.controls.chat 1.0
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared.panels 1.0
|
2021-10-28 09:45:21 +00:00
|
|
|
import shared.popups 1.0
|
2024-09-04 14:27:24 +00:00
|
|
|
import shared.stores 1.0 as SharedStores
|
2020-09-29 09:06:57 +00:00
|
|
|
|
2024-10-07 12:31:53 +00:00
|
|
|
import mainui 1.0
|
|
|
|
|
2021-10-27 21:27:49 +00:00
|
|
|
//TODO remove this dependency
|
2022-03-08 18:49:33 +00:00
|
|
|
import AppLayouts.Chat.panels 1.0
|
2024-05-22 08:13:39 +00:00
|
|
|
import AppLayouts.Chat.stores 1.0 as ChatStores
|
2020-09-29 09:06:57 +00:00
|
|
|
|
2023-02-06 12:52:03 +00:00
|
|
|
import StatusQ 0.1
|
2022-07-13 12:29:38 +00:00
|
|
|
import StatusQ.Core 0.1
|
2021-07-28 11:08:32 +00:00
|
|
|
import StatusQ.Core.Theme 0.1
|
2022-03-07 14:56:05 +00:00
|
|
|
import StatusQ.Core.Utils 0.1 as StatusQUtils
|
2021-10-20 22:47:23 +00:00
|
|
|
import StatusQ.Components 0.1
|
2021-10-18 10:34:16 +00:00
|
|
|
import StatusQ.Controls 0.1 as StatusQ
|
2021-07-28 11:08:32 +00:00
|
|
|
|
2020-09-29 09:06:57 +00:00
|
|
|
Rectangle {
|
|
|
|
id: control
|
2023-06-28 20:19:00 +00:00
|
|
|
objectName: "statusChatInput"
|
2022-07-05 10:12:27 +00:00
|
|
|
|
2022-08-10 19:18:20 +00:00
|
|
|
signal stickerSelected(string hashId, string packId, string url)
|
2020-12-07 14:59:24 +00:00
|
|
|
signal sendMessage(var event)
|
2022-12-21 12:52:52 +00:00
|
|
|
signal keyUpPress()
|
2023-09-26 14:16:53 +00:00
|
|
|
signal linkPreviewReloaded(string link)
|
2023-10-09 08:45:16 +00:00
|
|
|
signal enableLinkPreview()
|
|
|
|
signal enableLinkPreviewForThisMessage()
|
|
|
|
signal disableLinkPreview()
|
|
|
|
signal dismissLinkPreviewSettings()
|
|
|
|
signal dismissLinkPreview(int index)
|
|
|
|
|
2024-09-06 13:11:47 +00:00
|
|
|
property var usersModel
|
2024-09-04 14:27:24 +00:00
|
|
|
property SharedStores.RootStore sharedStore
|
2022-02-08 12:08:02 +00:00
|
|
|
|
2022-03-07 14:56:05 +00:00
|
|
|
property var emojiPopup: null
|
2022-11-14 20:21:00 +00:00
|
|
|
property var stickersPopup: null
|
2022-03-07 14:56:05 +00:00
|
|
|
// Use this to only enable the Connections only when this Input opens the Emoji popup
|
2022-07-05 08:51:29 +00:00
|
|
|
property bool closeGifPopupAfterSelection: true
|
2022-03-07 14:56:05 +00:00
|
|
|
|
2022-08-22 09:54:19 +00:00
|
|
|
property bool emojiEvent: false
|
|
|
|
property bool isColonPressed: false
|
2020-09-29 09:06:57 +00:00
|
|
|
property bool isReply: false
|
2023-06-07 13:18:29 +00:00
|
|
|
readonly property string replyMessageId: replyArea.messageId
|
2021-08-17 13:28:10 +00:00
|
|
|
|
2020-09-29 09:06:57 +00:00
|
|
|
property bool isImage: false
|
2021-06-29 14:49:32 +00:00
|
|
|
property bool isEdit: false
|
2020-09-29 09:06:57 +00:00
|
|
|
|
2023-09-22 14:25:38 +00:00
|
|
|
readonly property int messageLimit: 2000 // actual message limit, we don't allow sending more than that
|
|
|
|
readonly property int messageLimitSoft: 200 // we start showing a char counter when this no. of chars left in the message
|
|
|
|
readonly property int messageLimitHard: 20000 // still cut-off attempts to paste beyond this limit, for app usability reasons
|
2020-09-29 09:06:57 +00:00
|
|
|
|
|
|
|
property int chatType
|
|
|
|
|
2022-07-15 10:32:26 +00:00
|
|
|
property string chatInputPlaceholder: qsTr("Message")
|
2020-12-02 09:10:22 +00:00
|
|
|
|
2020-09-29 09:06:57 +00:00
|
|
|
property alias textInput: messageInputField
|
|
|
|
|
2022-11-25 14:08:12 +00:00
|
|
|
property var fileUrlsAndSources: []
|
2020-12-07 14:59:24 +00:00
|
|
|
|
2023-09-26 14:16:53 +00:00
|
|
|
property var linkPreviewModel: null
|
|
|
|
|
2024-09-06 13:11:47 +00:00
|
|
|
property var urlsList: []
|
2023-10-23 16:21:35 +00:00
|
|
|
|
2023-10-09 08:45:16 +00:00
|
|
|
property bool askToEnableLinkPreview: false
|
|
|
|
|
2024-08-29 15:36:38 +00:00
|
|
|
property int imageErrorMessageLocation: StatusChatInput.ImageErrorMessageLocation.Top // TODO: Remove this property?
|
2021-03-10 04:59:01 +00:00
|
|
|
|
2021-08-24 09:10:26 +00:00
|
|
|
property alias suggestions: suggestionsBox
|
|
|
|
|
2021-03-10 04:59:01 +00:00
|
|
|
enum ImageErrorMessageLocation {
|
|
|
|
Top,
|
|
|
|
Bottom
|
|
|
|
}
|
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
function parseMessage(message) {
|
|
|
|
let mentionsMap = new Map()
|
|
|
|
let index = 0
|
|
|
|
while (true) {
|
|
|
|
index = message.indexOf("<a href=", index)
|
|
|
|
if (index < 0) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
const startIndex = index
|
|
|
|
const endIndex = message.indexOf("</a>", index) + 4
|
|
|
|
if (endIndex < 0) {
|
|
|
|
index += 8 // "<a href="
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
const addrIndex = message.indexOf("0x", index + 8)
|
|
|
|
if (addrIndex < 0) {
|
|
|
|
index += 8 // "<a href="
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
const addrEndIndex = message.indexOf("\"", addrIndex)
|
|
|
|
if (addrEndIndex < 0) {
|
|
|
|
index += 8 // "<a href="
|
|
|
|
continue
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
2022-07-05 10:12:27 +00:00
|
|
|
const mentionLink = message.substring(startIndex, endIndex)
|
|
|
|
const linkTag = message.substring(index, endIndex)
|
|
|
|
const linkText = linkTag.replace(/(<([^>]+)>)/ig,"").trim()
|
|
|
|
const atSymbol = linkText.startsWith("@") ? '' : '@'
|
|
|
|
const mentionTag = Constants.mentionSpanTag + atSymbol + linkText + '</span> '
|
|
|
|
mentionsMap.set(mentionLink, mentionTag)
|
|
|
|
index += linkTag.length
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
2022-07-05 10:12:27 +00:00
|
|
|
|
|
|
|
let text = message;
|
|
|
|
|
|
|
|
for (let [key, value] of mentionsMap)
|
|
|
|
text = text.replace(new RegExp(key, 'g'), value)
|
|
|
|
|
|
|
|
textInput.text = text
|
|
|
|
textInput.cursorPosition = textInput.length
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
2022-07-05 10:12:27 +00:00
|
|
|
|
2023-09-26 14:20:59 +00:00
|
|
|
function setText(text) {
|
|
|
|
textInput.clear()
|
|
|
|
textInput.append(text)
|
|
|
|
}
|
|
|
|
|
2024-08-26 08:16:59 +00:00
|
|
|
function clear() {
|
|
|
|
textInput.clear()
|
|
|
|
}
|
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
implicitWidth: layout.implicitWidth + layout.anchors.leftMargin + layout.anchors.rightMargin
|
|
|
|
implicitHeight: layout.implicitHeight + layout.anchors.topMargin + layout.anchors.bottomMargin
|
2020-09-29 09:06:57 +00:00
|
|
|
|
2024-10-15 19:26:12 +00:00
|
|
|
color: Theme.palette.transparent
|
2022-02-09 09:43:23 +00:00
|
|
|
|
2022-08-22 09:54:19 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
2023-04-06 16:36:25 +00:00
|
|
|
readonly property string emojiReplacementSymbols: ":='xX><0O;*dB8-D#%\\"
|
|
|
|
|
2022-08-22 09:54:19 +00:00
|
|
|
//mentions helper properties
|
|
|
|
property string copiedTextPlain: ""
|
|
|
|
property string copiedTextFormatted: ""
|
2022-09-29 20:04:30 +00:00
|
|
|
property var copiedMentionsPos: []
|
2022-08-22 09:54:19 +00:00
|
|
|
property int copyTextStart: 0
|
|
|
|
|
2022-09-06 09:45:16 +00:00
|
|
|
property int leftOfMentionIndex: -1
|
|
|
|
property int rightOfMentionIndex: -1
|
2024-08-27 13:42:45 +00:00
|
|
|
readonly property int nbEmojisInClipboard: StatusQUtils.Emoji.nbEmojis(ClipboardUtils.html)
|
2023-06-07 13:18:29 +00:00
|
|
|
|
|
|
|
property bool emojiPopupOpened: false
|
|
|
|
property bool stickersPopupOpened: false
|
|
|
|
|
|
|
|
// common popups are emoji, jif and stickers
|
|
|
|
// Put controlWidth as argument with default value for binding
|
|
|
|
function getCommonPopupRelativePosition(popup, popupParent, controlWidth = control.width) {
|
2023-06-14 15:09:46 +00:00
|
|
|
const popupWidth = emojiPopup ? emojiPopup.width : 0
|
|
|
|
const popupHeight = emojiPopup ? emojiPopup.height : 0
|
2024-10-15 19:26:12 +00:00
|
|
|
const controlX = controlWidth - popupWidth - Theme.halfPadding
|
2023-06-14 15:09:46 +00:00
|
|
|
const controlY = -popupHeight
|
2023-06-07 13:18:29 +00:00
|
|
|
return popupParent.mapFromItem(control, controlX, controlY)
|
|
|
|
}
|
|
|
|
|
|
|
|
readonly property point emojiPopupPosition: getCommonPopupRelativePosition(emojiPopup, emojiBtn)
|
|
|
|
readonly property point stickersPopupPosition: getCommonPopupRelativePosition(stickersPopup, stickersBtn)
|
|
|
|
|
2022-09-02 12:11:13 +00:00
|
|
|
readonly property StateGroup emojiPopupTakeover: StateGroup {
|
|
|
|
states: State {
|
2023-06-07 13:18:29 +00:00
|
|
|
when: d.emojiPopupOpened
|
2022-09-02 12:11:13 +00:00
|
|
|
|
|
|
|
PropertyChanges {
|
|
|
|
target: emojiPopup
|
|
|
|
|
2023-06-07 13:18:29 +00:00
|
|
|
parent: emojiBtn
|
2022-09-02 12:11:13 +00:00
|
|
|
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
|
2023-06-07 13:18:29 +00:00
|
|
|
x: d.emojiPopupPosition.x
|
|
|
|
y: d.emojiPopupPosition.y
|
2022-09-02 12:11:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-14 20:21:00 +00:00
|
|
|
readonly property StateGroup stickersPopupTakeover: StateGroup {
|
|
|
|
states: State {
|
2023-06-07 13:18:29 +00:00
|
|
|
when: d.stickersPopupOpened
|
2022-11-14 20:21:00 +00:00
|
|
|
|
|
|
|
PropertyChanges {
|
|
|
|
target: stickersPopup
|
|
|
|
|
2023-06-07 13:18:29 +00:00
|
|
|
parent: stickersBtn
|
2022-11-14 20:21:00 +00:00
|
|
|
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
|
2023-06-07 13:18:29 +00:00
|
|
|
x: d.stickersPopupPosition.x
|
|
|
|
y: d.stickersPopupPosition.y
|
2022-11-14 20:21:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-06 09:45:16 +00:00
|
|
|
|
2023-06-07 13:18:29 +00:00
|
|
|
property Menu textFormatMenu: null
|
2023-05-23 12:46:16 +00:00
|
|
|
|
2022-09-29 20:04:30 +00:00
|
|
|
function copyMentions(start, end) {
|
|
|
|
copiedMentionsPos = []
|
|
|
|
for (let k = 0; k < mentionsPos.length; k++) {
|
|
|
|
if (mentionsPos[k].leftIndex >= start && mentionsPos[k].rightIndex <= end) {
|
|
|
|
const mention = {
|
|
|
|
name: mentionsPos[k].name,
|
|
|
|
pubKey: mentionsPos[k].pubKey,
|
|
|
|
leftIndex: mentionsPos[k].leftIndex - start,
|
|
|
|
rightIndex: mentionsPos[k].rightIndex - start
|
|
|
|
}
|
|
|
|
copiedMentionsPos.push(mention)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-28 14:12:11 +00:00
|
|
|
function sortMentions() {
|
|
|
|
if (mentionsPos.length < 2) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
mentionsPos = mentionsPos.sort(function(a, b){
|
|
|
|
return a.leftIndex - b.leftIndex
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-09-06 09:45:16 +00:00
|
|
|
function updateMentionsPositions() {
|
|
|
|
if (mentionsPos.length == 0) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const unformattedText = messageInputField.getText(0, messageInputField.length)
|
|
|
|
if (!unformattedText.includes("@")) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const keyEvent = messageInputField.keyEvent
|
|
|
|
if ((keyEvent.key === Qt.Key_Right) || (keyEvent.key === Qt.Key_Left)
|
|
|
|
|| (keyEvent.key === Qt.Key_Up) || (keyEvent.key === Qt.Key_Down)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-28 14:12:11 +00:00
|
|
|
let lastRightIndex = -1
|
2022-09-06 09:45:16 +00:00
|
|
|
for (var k = 0; k < mentionsPos.length; k++) {
|
2022-09-28 14:12:11 +00:00
|
|
|
const aliasIndex = unformattedText.indexOf(mentionsPos[k].name, lastRightIndex)
|
|
|
|
if (aliasIndex === -1) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
lastRightIndex = aliasIndex + mentionsPos[k].name.length
|
2022-09-06 09:45:16 +00:00
|
|
|
|
2022-09-28 14:12:11 +00:00
|
|
|
if (aliasIndex - 1 !== mentionsPos[k].leftIndex) {
|
2022-09-06 09:45:16 +00:00
|
|
|
mentionsPos[k].leftIndex = aliasIndex - 1
|
|
|
|
mentionsPos[k].rightIndex = aliasIndex + mentionsPos[k].name.length
|
|
|
|
}
|
|
|
|
}
|
2022-12-15 10:29:10 +00:00
|
|
|
|
|
|
|
sortMentions()
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanMentionsPos() {
|
|
|
|
if(mentionsPos.length == 0) return
|
|
|
|
|
|
|
|
const unformattedText = messageInputField.getText(0, messageInputField.length)
|
2023-01-25 18:31:00 +00:00
|
|
|
mentionsPos = mentionsPos.filter(mention => unformattedText.charAt(mention.leftIndex) === "@")
|
2022-12-15 10:29:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function insertMention(aliasName, publicKey, lastAtPosition, lastCursorPosition) {
|
|
|
|
let startInd = aliasName.indexOf("(");
|
|
|
|
if (startInd > 0){
|
|
|
|
aliasName = aliasName.substring(0, startInd-1)
|
|
|
|
}
|
|
|
|
|
|
|
|
const hasEmoji = StatusQUtils.Emoji.hasEmoji(messageInputField.text)
|
|
|
|
const spanPlusAlias = `${Constants.mentionSpanTag}@${aliasName}</a></span> `;
|
|
|
|
|
|
|
|
let rightIndex = hasEmoji ? lastCursorPosition + 2 : lastCursorPosition
|
|
|
|
messageInputField.remove(lastAtPosition, rightIndex)
|
|
|
|
messageInputField.insert(lastAtPosition, spanPlusAlias)
|
|
|
|
messageInputField.cursorPosition = lastAtPosition + aliasName.length + 2;
|
|
|
|
if (messageInputField.cursorPosition === 0) {
|
|
|
|
// It reset to 0 for some reason, go back to the end
|
|
|
|
messageInputField.cursorPosition = messageInputField.length
|
|
|
|
}
|
|
|
|
|
|
|
|
mentionsPos = mentionsPos.filter(mention => mention.leftIndex !== lastAtPosition)
|
|
|
|
mentionsPos.push({name: aliasName, pubKey: publicKey, leftIndex: lastAtPosition, rightIndex: (lastAtPosition+aliasName.length + 1)});
|
|
|
|
d.sortMentions()
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeMention(mention) {
|
|
|
|
const index = mentionsPos.indexOf(mention)
|
|
|
|
if(index >= 0) {
|
|
|
|
mentionsPos.splice(index, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
messageInputField.remove(mention.leftIndex, mention.rightIndex)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getMentionAtPosition(position: int) {
|
|
|
|
return mentionsPos.find(mention => mention.leftIndex < position && mention.rightIndex > position)
|
2022-09-06 09:45:16 +00:00
|
|
|
}
|
2024-09-03 15:02:02 +00:00
|
|
|
|
|
|
|
function getSelectedTextWithFormationChars(messageInputField) {
|
|
|
|
const formationChars = ["*", "`", "~"]
|
|
|
|
let i = 1
|
|
|
|
let text = ""
|
|
|
|
while (true) {
|
|
|
|
if (messageInputField.selectionStart - i < 0 && messageInputField.selectionEnd + i > messageInputField.length) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
text = messageInputField.getText(messageInputField.selectionStart - i, messageInputField.selectionEnd + i)
|
|
|
|
|
|
|
|
if (!formationChars.includes(text.charAt(0)) ||
|
|
|
|
!formationChars.includes(text.charAt(text.length - 1))) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
return text
|
|
|
|
}
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function insertInTextInput(start, text) {
|
2023-09-22 14:25:38 +00:00
|
|
|
// Replace new lines with entities because `insert` gets rid of them
|
2020-09-29 09:06:57 +00:00
|
|
|
messageInputField.insert(start, text.replace(/\n/g, "<br/>"));
|
|
|
|
}
|
|
|
|
|
2022-03-07 14:56:05 +00:00
|
|
|
Connections {
|
2023-06-07 13:18:29 +00:00
|
|
|
enabled: d.emojiPopupOpened
|
2022-03-07 14:56:05 +00:00
|
|
|
target: emojiPopup
|
|
|
|
|
2023-01-18 09:25:36 +00:00
|
|
|
function onEmojiSelected(text: string, atCursor: bool) {
|
2022-03-07 14:56:05 +00:00
|
|
|
insertInTextInput(atCursor ? messageInputField.cursorPosition : messageInputField.length, text)
|
|
|
|
emojiBtn.highlighted = false
|
|
|
|
messageInputField.forceActiveFocus();
|
|
|
|
}
|
2023-01-10 11:43:30 +00:00
|
|
|
function onClosed() {
|
2023-06-07 13:18:29 +00:00
|
|
|
d.emojiPopupOpened = false
|
2022-03-07 14:56:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-14 20:21:00 +00:00
|
|
|
Connections {
|
2023-06-07 13:18:29 +00:00
|
|
|
enabled: d.stickersPopupOpened
|
2022-11-14 20:21:00 +00:00
|
|
|
target: control.stickersPopup
|
|
|
|
|
2023-01-18 09:25:36 +00:00
|
|
|
function onStickerSelected(hashId: string, packId: string, url: string ) {
|
2022-11-14 20:21:00 +00:00
|
|
|
control.stickerSelected(hashId, packId, url)
|
|
|
|
control.hideExtendedArea();
|
|
|
|
messageInputField.forceActiveFocus();
|
|
|
|
}
|
2023-01-10 11:43:30 +00:00
|
|
|
function onClosed() {
|
2023-06-07 13:18:29 +00:00
|
|
|
d.stickersPopupOpened = false
|
2022-11-14 20:21:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-21 19:51:41 +00:00
|
|
|
property var mentionsPos: []
|
|
|
|
|
2020-11-17 03:07:01 +00:00
|
|
|
function isUploadFilePressed(event) {
|
2023-06-07 13:18:29 +00:00
|
|
|
return (event.key === Qt.Key_U) && (event.modifiers & Qt.ControlModifier) && imageBtn.visible && !imageBtn.highlighted
|
2020-11-17 03:07:01 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 15:58:36 +00:00
|
|
|
function checkTextInsert() {
|
|
|
|
if (emojiSuggestions.visible) {
|
2021-12-08 21:20:43 +00:00
|
|
|
replaceWithEmoji(extrapolateCursorPosition(), emojiSuggestions.shortname, emojiSuggestions.unicode);
|
2021-01-21 15:58:36 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (suggestionsBox.visible) {
|
|
|
|
suggestionsBox.selectCurrentItem();
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-02-21 19:51:41 +00:00
|
|
|
function onKeyPress(event) {
|
2023-09-22 14:25:38 +00:00
|
|
|
// get text without HTML formatting
|
|
|
|
const messageLength = messageInputField.getText(0, messageInputField.length).length;
|
|
|
|
|
2020-09-29 09:06:57 +00:00
|
|
|
if (event.modifiers === Qt.NoModifier && (event.key === Qt.Key_Enter || event.key === Qt.Key_Return)) {
|
2021-01-21 15:58:36 +00:00
|
|
|
if (checkTextInsert()) {
|
2020-10-20 17:38:48 +00:00
|
|
|
event.accepted = true;
|
|
|
|
return
|
|
|
|
}
|
2023-09-22 14:25:38 +00:00
|
|
|
if (messageLength <= messageLimit) {
|
2023-04-06 16:36:25 +00:00
|
|
|
checkForInlineEmojis(true);
|
2023-09-22 14:25:38 +00:00
|
|
|
control.sendMessage(event);
|
2020-12-07 14:59:24 +00:00
|
|
|
control.hideExtendedArea();
|
2023-09-22 14:25:38 +00:00
|
|
|
event.accepted = true;
|
2020-09-29 09:06:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-09-22 14:25:38 +00:00
|
|
|
else {
|
|
|
|
// pop-up a warning message when trying to send a message over the limit
|
|
|
|
messageLengthLimitTooltip.open();
|
|
|
|
event.accepted = true;
|
|
|
|
return;
|
2022-02-15 21:00:05 +00:00
|
|
|
}
|
2023-09-22 14:25:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (event.key === Qt.Key_Escape && control.isReply) {
|
|
|
|
control.isReply = false;
|
|
|
|
event.accepted = true;
|
|
|
|
return;
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
|
|
|
|
2022-09-06 09:45:16 +00:00
|
|
|
const symbolPressed = event.text.length > 0 &&
|
|
|
|
event.key !== Qt.Key_Backspace &&
|
|
|
|
event.key !== Qt.Key_Delete &&
|
|
|
|
event.key !== Qt.Key_Escape
|
2023-01-18 20:21:25 +00:00
|
|
|
if ((mentionsPos.length > 0) && symbolPressed && (messageInputField.selectedText.length === 0)) {
|
2022-09-06 09:45:16 +00:00
|
|
|
for (var i = 0; i < mentionsPos.length; i++) {
|
|
|
|
if (messageInputField.cursorPosition === mentionsPos[i].leftIndex) {
|
|
|
|
d.leftOfMentionIndex = i
|
|
|
|
event.accepted = true
|
|
|
|
return
|
|
|
|
} else if (messageInputField.cursorPosition === mentionsPos[i].rightIndex) {
|
|
|
|
d.rightOfMentionIndex = i
|
|
|
|
event.accepted = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-21 15:58:36 +00:00
|
|
|
if (event.key === Qt.Key_Tab) {
|
|
|
|
if (checkTextInsert()) {
|
|
|
|
event.accepted = true;
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-10 19:54:21 +00:00
|
|
|
const message = control.extrapolateCursorPosition();
|
|
|
|
|
2020-11-17 03:07:01 +00:00
|
|
|
// handle new line in blockquote
|
2020-12-10 19:54:21 +00:00
|
|
|
if ((event.key === Qt.Key_Enter || event.key === Qt.Key_Return) && (event.modifiers & Qt.ShiftModifier) && message.data.startsWith(">")) {
|
2020-11-17 03:07:01 +00:00
|
|
|
if(message.data.startsWith(">") && !message.data.endsWith("\n\n")) {
|
2021-04-01 17:07:26 +00:00
|
|
|
let newMessage1 = ""
|
2020-11-17 03:07:01 +00:00
|
|
|
if (message.data.endsWith("\n> ")) {
|
2021-04-01 17:07:26 +00:00
|
|
|
newMessage1 = message.data.substr(0, message.data.lastIndexOf("> ")) + "\n\n"
|
2020-11-17 03:07:01 +00:00
|
|
|
} else {
|
2021-04-01 17:07:26 +00:00
|
|
|
newMessage1 = message.data + "\n> ";
|
2020-11-17 03:07:01 +00:00
|
|
|
}
|
|
|
|
messageInputField.remove(0, messageInputField.cursorPosition);
|
2022-03-07 14:56:05 +00:00
|
|
|
insertInTextInput(0, StatusQUtils.Emoji.parse(newMessage1));
|
2020-11-17 03:07:01 +00:00
|
|
|
}
|
|
|
|
event.accepted = true
|
|
|
|
}
|
2022-12-15 10:29:10 +00:00
|
|
|
|
|
|
|
if (event.key === Qt.Key_Delete || event.key === Qt.Key_Backspace) {
|
|
|
|
if(mentionsPos.length > 0) {
|
|
|
|
let anticipatedCursorPosition = messageInputField.cursorPosition
|
|
|
|
anticipatedCursorPosition += event.key === Qt.Key_Backspace ?
|
|
|
|
-1 : 1
|
|
|
|
|
2023-01-25 18:31:00 +00:00
|
|
|
const mention = d.getMentionAtPosition(anticipatedCursorPosition)
|
2022-12-15 10:29:10 +00:00
|
|
|
if(mention) {
|
|
|
|
d.removeMention(mention)
|
|
|
|
event.accepted = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle backspace when entering an existing blockquote
|
2020-11-17 03:07:01 +00:00
|
|
|
if(message.data.startsWith(">") && message.data.endsWith("\n\n")) {
|
|
|
|
const newMessage = message.data.substr(0, message.data.lastIndexOf("\n")) + "> ";
|
|
|
|
messageInputField.remove(0, messageInputField.cursorPosition);
|
2022-03-07 14:56:05 +00:00
|
|
|
insertInTextInput(0, StatusQUtils.Emoji.parse(newMessage));
|
2020-11-17 03:07:01 +00:00
|
|
|
event.accepted = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-29 20:04:30 +00:00
|
|
|
if (event.matches(StandardKey.Copy) || event.matches(StandardKey.Cut)) {
|
2022-02-24 21:41:37 +00:00
|
|
|
if (messageInputField.selectedText !== "") {
|
2022-08-22 09:54:19 +00:00
|
|
|
d.copiedTextPlain = messageInputField.getText(
|
|
|
|
messageInputField.selectionStart, messageInputField.selectionEnd)
|
|
|
|
d.copiedTextFormatted = messageInputField.getFormattedText(
|
|
|
|
messageInputField.selectionStart, messageInputField.selectionEnd)
|
2022-09-29 20:04:30 +00:00
|
|
|
d.copyMentions(messageInputField.selectionStart, messageInputField.selectionEnd)
|
2022-02-24 21:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-29 20:04:30 +00:00
|
|
|
if (event.matches(StandardKey.Paste)) {
|
2024-08-27 13:42:45 +00:00
|
|
|
if (ClipboardUtils.hasImage) {
|
|
|
|
const clipboardImage = ClipboardUtils.imageBase64
|
2023-03-27 17:53:17 +00:00
|
|
|
validateImagesAndShowImageArea([clipboardImage])
|
2022-11-25 14:08:12 +00:00
|
|
|
event.accepted = true
|
2024-08-27 13:42:45 +00:00
|
|
|
} else if (ClipboardUtils.hasText) {
|
2024-10-08 11:20:50 +00:00
|
|
|
const clipboardText = StatusQUtils.StringUtils.plainText(ClipboardUtils.text)
|
2023-09-22 14:25:38 +00:00
|
|
|
// prevent repetitive & huge clipboard paste, where huge is total char count > than messageLimitHard
|
|
|
|
const selectionLength = messageInputField.selectionEnd - messageInputField.selectionStart;
|
|
|
|
if ((messageLength + clipboardText.length - selectionLength) > control.messageLimitHard)
|
|
|
|
{
|
|
|
|
messageLengthLimitTooltip.open();
|
|
|
|
event.accepted = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-25 14:08:12 +00:00
|
|
|
messageInputField.remove(messageInputField.selectionStart, messageInputField.selectionEnd)
|
2022-08-22 09:54:19 +00:00
|
|
|
|
2022-11-25 14:08:12 +00:00
|
|
|
// cursor position must be stored in a helper property because setting readonly to true causes change
|
|
|
|
// of the cursor position to the end of the input
|
|
|
|
d.copyTextStart = messageInputField.cursorPosition
|
|
|
|
messageInputField.readOnly = true
|
2022-08-22 09:54:19 +00:00
|
|
|
|
2024-10-08 11:20:50 +00:00
|
|
|
const copiedText = StatusQUtils.StringUtils.plainText(d.copiedTextPlain)
|
2022-11-25 14:08:12 +00:00
|
|
|
if (copiedText === clipboardText) {
|
2023-01-05 13:15:54 +00:00
|
|
|
if (d.copiedTextPlain.includes("@")) {
|
|
|
|
d.copiedTextFormatted = d.copiedTextFormatted.replace(/span style="/g, "span style=\" text-decoration:none;")
|
|
|
|
|
|
|
|
let lastFoundIndex = -1
|
|
|
|
for (let j = 0; j < d.copiedMentionsPos.length; j++) {
|
|
|
|
const name = d.copiedMentionsPos[j].name
|
|
|
|
const indexOfName = d.copiedTextPlain.indexOf(name, lastFoundIndex)
|
|
|
|
lastFoundIndex += name.length
|
|
|
|
|
|
|
|
if (indexOfName === d.copiedMentionsPos[j].leftIndex + 1) {
|
|
|
|
const mention = {
|
|
|
|
name: name,
|
|
|
|
pubKey: d.copiedMentionsPos[j].pubKey,
|
|
|
|
leftIndex: (d.copiedMentionsPos[j].leftIndex + d.copyTextStart - 1),
|
|
|
|
rightIndex: (d.copiedMentionsPos[j].leftIndex + d.copyTextStart + name.length)
|
|
|
|
}
|
|
|
|
mentionsPos.push(mention)
|
|
|
|
d.sortMentions()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
insertInTextInput(d.copyTextStart, d.copiedTextFormatted)
|
2022-11-25 14:08:12 +00:00
|
|
|
} else {
|
|
|
|
d.copiedTextPlain = ""
|
|
|
|
d.copiedTextFormatted = ""
|
|
|
|
d.copiedMentionsPos = []
|
2023-02-23 14:11:01 +00:00
|
|
|
messageInputField.insert(d.copyTextStart, ((d.nbEmojisInClipboard === 0) ?
|
2024-08-27 13:42:45 +00:00
|
|
|
("<div style='white-space: pre-wrap'>" + StatusQUtils.StringUtils.escapeHtml(ClipboardUtils.text) + "</div>")
|
|
|
|
: StatusQUtils.Emoji.deparse(ClipboardUtils.html)));
|
2022-11-25 14:08:12 +00:00
|
|
|
}
|
2023-09-22 14:25:38 +00:00
|
|
|
event.accepted = true
|
2022-02-24 21:41:37 +00:00
|
|
|
}
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
|
|
|
|
2020-11-17 03:07:01 +00:00
|
|
|
// ⌘⇧U
|
|
|
|
if (isUploadFilePressed(event)) {
|
2022-11-15 17:20:08 +00:00
|
|
|
imageBtn.clicked(null)
|
2020-11-17 03:07:01 +00:00
|
|
|
event.accepted = true
|
|
|
|
}
|
|
|
|
|
2022-11-21 09:24:57 +00:00
|
|
|
if (event.key === Qt.Key_Down && emojiSuggestions.visible) {
|
|
|
|
event.accepted = true
|
2020-10-20 15:32:03 +00:00
|
|
|
return emojiSuggestions.listView.incrementCurrentIndex()
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
2022-11-21 09:24:57 +00:00
|
|
|
if (event.key === Qt.Key_Up && emojiSuggestions.visible) {
|
|
|
|
event.accepted = true
|
2020-10-20 15:32:03 +00:00
|
|
|
return emojiSuggestions.listView.decrementCurrentIndex()
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
|
|
|
|
2022-12-15 18:19:34 +00:00
|
|
|
isColonPressed = event.key === Qt.Key_Colon;
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
|
|
|
|
2022-08-26 13:18:30 +00:00
|
|
|
function getLineStartPosition(selectionStart) {
|
|
|
|
const text = getPlainText()
|
|
|
|
const lastNewLinePos = text.lastIndexOf("\n\n", messageInputField.selectionStart)
|
|
|
|
return lastNewLinePos === -1 ? 0 : lastNewLinePos + 2
|
|
|
|
}
|
|
|
|
|
|
|
|
function prefixSelectedLine(prefix) {
|
|
|
|
const selectedLinePosition = getLineStartPosition(messageInputField.selectionStart)
|
|
|
|
insertInTextInput(selectedLinePosition, prefix)
|
|
|
|
}
|
|
|
|
|
|
|
|
function unprefixSelectedLine(prefix) {
|
|
|
|
if( isSelectedLinePrefixedBy(messageInputField.selectionStart, prefix) ) {
|
|
|
|
const selectedLinePosition = getLineStartPosition(messageInputField.selectionStart)
|
|
|
|
messageInputField.remove(selectedLinePosition, selectedLinePosition + prefix.length)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function isSelectedLinePrefixedBy(selectionStart, prefix) {
|
|
|
|
const selectedLinePosition = getLineStartPosition(selectionStart)
|
|
|
|
const text = getPlainText()
|
|
|
|
const selectedLine = text.substring(selectedLinePosition)
|
|
|
|
return selectedLine.startsWith(prefix)
|
|
|
|
}
|
|
|
|
|
2020-11-17 03:07:01 +00:00
|
|
|
function wrapSelection(wrapWith) {
|
|
|
|
if (messageInputField.selectionStart - messageInputField.selectionEnd === 0) return
|
2021-05-06 20:29:22 +00:00
|
|
|
|
2021-08-24 16:34:24 +00:00
|
|
|
// calulate the new selection start and end positions
|
|
|
|
var newSelectionStart = messageInputField.selectionStart + wrapWith.length
|
|
|
|
var newSelectionEnd = messageInputField.selectionEnd - messageInputField.selectionStart + newSelectionStart
|
|
|
|
|
2021-04-22 15:55:11 +00:00
|
|
|
insertInTextInput(messageInputField.selectionStart, wrapWith);
|
|
|
|
insertInTextInput(messageInputField.selectionEnd, wrapWith);
|
2021-03-03 15:13:41 +00:00
|
|
|
|
2021-08-24 16:34:24 +00:00
|
|
|
messageInputField.select(newSelectionStart, newSelectionEnd)
|
2021-02-17 11:31:37 +00:00
|
|
|
}
|
2021-08-24 16:34:24 +00:00
|
|
|
|
2021-04-21 19:46:58 +00:00
|
|
|
function unwrapSelection(unwrapWith, selectedTextWithFormationChars) {
|
2022-07-05 10:12:27 +00:00
|
|
|
if (messageInputField.selectionStart - messageInputField.selectionEnd === 0) return
|
2021-08-24 16:34:24 +00:00
|
|
|
|
2023-09-22 14:25:38 +00:00
|
|
|
// Calculate the new selection start and end positions
|
2022-07-05 10:12:27 +00:00
|
|
|
var newSelectionStart = messageInputField.selectionStart - unwrapWith.length
|
|
|
|
var newSelectionEnd = messageInputField.selectionEnd-messageInputField.selectionStart + newSelectionStart
|
2021-08-24 16:34:24 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
selectedTextWithFormationChars = selectedTextWithFormationChars.trim()
|
|
|
|
// Check if the selectedTextWithFormationChars has formation chars and if so, calculate how many so we can adapt the start and end pos
|
|
|
|
const selectTextDiff = (selectedTextWithFormationChars.length - messageInputField.selectedText.length) / 2
|
2021-04-21 18:18:52 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
// Remove the deselected option from the before and after the selected text
|
|
|
|
const prefixChars = messageInputField.getText((messageInputField.selectionStart - selectTextDiff), messageInputField.selectionStart)
|
|
|
|
const updatedPrefixChars = prefixChars.replace(unwrapWith, '')
|
|
|
|
const postfixChars = messageInputField.getText(messageInputField.selectionEnd, (messageInputField.selectionEnd + selectTextDiff))
|
|
|
|
const updatedPostfixChars = postfixChars.replace(unwrapWith, '')
|
2021-04-21 19:46:58 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
// Create updated selected string with pre and post formatting characters
|
|
|
|
const updatedSelectedStringWithFormatChars = updatedPrefixChars + messageInputField.selectedText + updatedPostfixChars
|
2021-04-21 19:46:58 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
messageInputField.remove(messageInputField.selectionStart - selectTextDiff, messageInputField.selectionEnd + selectTextDiff)
|
2021-04-21 19:46:58 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
insertInTextInput(messageInputField.selectionStart, updatedSelectedStringWithFormatChars)
|
2021-04-21 18:18:52 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
messageInputField.select(newSelectionStart, newSelectionEnd)
|
2021-04-21 18:18:52 +00:00
|
|
|
}
|
2021-02-17 11:31:37 +00:00
|
|
|
|
2021-03-19 20:13:12 +00:00
|
|
|
function getPlainText() {
|
|
|
|
const textWithoutMention = messageInputField.text.replace(/<span style="[ :#0-9a-z;\-\.,\(\)]+">(@([a-z\.]+(\ ?[a-z]+\ ?[a-z]+)?))<\/span>/ig, "\[\[mention\]\]$1\[\[mention\]\]")
|
|
|
|
|
2022-03-07 14:56:05 +00:00
|
|
|
const deparsedEmoji = StatusQUtils.Emoji.deparse(textWithoutMention);
|
2021-03-19 20:13:12 +00:00
|
|
|
|
2024-10-08 11:20:50 +00:00
|
|
|
return StatusQUtils.StringUtils.plainText(deparsedEmoji)
|
2021-03-19 20:13:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function removeMentions(currentText) {
|
|
|
|
return currentText.replace(/\[\[mention\]\]/g, '')
|
|
|
|
}
|
|
|
|
|
2021-05-06 20:29:22 +00:00
|
|
|
function parseMarkdown(markdownText) {
|
|
|
|
const htmlText = markdownText
|
2021-07-13 07:34:13 +00:00
|
|
|
.replace(/\~\~([^*]+)\~\~/gim, '~~<span style="text-decoration: line-through">$1</span>~~')
|
|
|
|
.replace(/\*\*([^*]+)\*\*/gim, ':asterisk::asterisk:<b>$1</b>:asterisk::asterisk:')
|
|
|
|
.replace(/\`([^*]+)\`/gim, '`<code>$1</code>`')
|
|
|
|
.replace(/\*([^*]+)\*/gim, ':asterisk:<i>$1</i>:asterisk:')
|
2021-05-06 20:29:22 +00:00
|
|
|
return htmlText.replace(/\:asterisk\:/gim, "*")
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFormattedText(start, end) {
|
|
|
|
start = start || 0
|
|
|
|
end = end || messageInputField.length
|
2021-03-19 20:13:12 +00:00
|
|
|
|
2021-05-06 20:29:22 +00:00
|
|
|
const oldFormattedText = messageInputField.getFormattedText(start, end)
|
|
|
|
|
|
|
|
const found = oldFormattedText.match(/<!--StartFragment-->([\w\W\s]*)<!--EndFragment-->/m);
|
|
|
|
|
|
|
|
return found[1]
|
|
|
|
}
|
|
|
|
|
2022-09-20 15:26:54 +00:00
|
|
|
function getTextWithPublicKeys() {
|
2022-09-28 14:12:11 +00:00
|
|
|
let result = messageInputField.text
|
2022-09-20 15:26:54 +00:00
|
|
|
|
|
|
|
if (mentionsPos.length > 0) {
|
2022-09-28 14:12:11 +00:00
|
|
|
for (var k = 0; k < mentionsPos.length; k++) {
|
|
|
|
let leftIndex = result.indexOf(mentionsPos[k].name)
|
|
|
|
let rightIndex = leftIndex + mentionsPos[k].name.length
|
|
|
|
result = result.substring(0, leftIndex)
|
|
|
|
+ mentionsPos[k].pubKey
|
|
|
|
+ result.substring(rightIndex, result.length)
|
2022-09-20 15:26:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2020-09-29 09:06:57 +00:00
|
|
|
function onRelease(event) {
|
2023-01-25 18:31:22 +00:00
|
|
|
if ((event.modifiers & Qt.ControlModifier) || (event.modifiers & Qt.MetaModifier)) // these are likely shortcuts with no meaningful text
|
|
|
|
return
|
|
|
|
|
2023-06-08 18:35:18 +00:00
|
|
|
if (event.key === Qt.Key_Backspace && (!!d.textFormatMenu && d.textFormatMenu.opened)) {
|
2023-06-07 13:18:29 +00:00
|
|
|
d.textFormatMenu.close()
|
2021-03-03 16:04:03 +00:00
|
|
|
}
|
2020-09-29 09:06:57 +00:00
|
|
|
// the text doesn't get registered to the textarea fast enough
|
|
|
|
// we can only get it in the `released` event
|
2022-02-24 21:41:37 +00:00
|
|
|
|
2022-09-06 09:45:16 +00:00
|
|
|
let eventText = event.text
|
|
|
|
if(event.key === Qt.Key_Space) {
|
|
|
|
eventText = " "
|
|
|
|
}
|
|
|
|
|
|
|
|
if(d.rightOfMentionIndex !== -1) {
|
2022-12-15 10:29:10 +00:00
|
|
|
//make sure to add an extra space between mention and text
|
|
|
|
let mentionSeparator = event.key === Qt.Key_Space ? "" : " "
|
|
|
|
messageInputField.insert(mentionsPos[d.rightOfMentionIndex].rightIndex, mentionSeparator + eventText)
|
2022-09-06 09:45:16 +00:00
|
|
|
|
|
|
|
d.rightOfMentionIndex = -1
|
|
|
|
}
|
|
|
|
|
|
|
|
if(d.leftOfMentionIndex !== -1) {
|
|
|
|
messageInputField.insert(mentionsPos[d.leftOfMentionIndex].leftIndex, eventText)
|
|
|
|
|
|
|
|
d.leftOfMentionIndex = -1
|
|
|
|
}
|
|
|
|
|
2020-11-18 17:14:29 +00:00
|
|
|
if (event.key !== Qt.Key_Escape) {
|
2022-08-19 08:46:48 +00:00
|
|
|
emojiEvent = emojiHandler(event)
|
2020-11-18 17:14:29 +00:00
|
|
|
if (!emojiEvent) {
|
|
|
|
emojiSuggestions.close()
|
|
|
|
}
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
2023-01-05 13:15:54 +00:00
|
|
|
|
|
|
|
if (messageInputField.readOnly) {
|
|
|
|
messageInputField.readOnly = false;
|
2024-08-27 13:42:45 +00:00
|
|
|
messageInputField.cursorPosition = (d.copyTextStart + ClipboardUtils.text.length + d.nbEmojisInClipboard);
|
2023-01-05 13:15:54 +00:00
|
|
|
}
|
2023-04-07 19:30:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (suggestionsBox.visible) {
|
|
|
|
let aliasName = suggestionsBox.formattedPlainTextFilter;
|
|
|
|
let lastCursorPosition = suggestionsBox.suggestionFilter.cursorPosition;
|
|
|
|
let lastAtPosition = suggestionsBox.suggestionFilter.lastAtPosition;
|
|
|
|
let suggestionItem = suggestionsBox.suggestionsModel.get(suggestionsBox.listView.currentIndex);
|
|
|
|
if (aliasName !== "" && aliasName.toLowerCase() === suggestionItem.name.toLowerCase()
|
|
|
|
&& (event.key !== Qt.Key_Backspace) && (event.key !== Qt.Key_Delete)) {
|
|
|
|
|
|
|
|
d.insertMention(aliasName, suggestionItem.publicKey, lastAtPosition, lastCursorPosition);
|
|
|
|
} else if (event.key === Qt.Key_Space) {
|
|
|
|
var plainTextToReplace = messageInputField.getText(lastAtPosition, lastCursorPosition);
|
|
|
|
messageInputField.remove(lastAtPosition, lastCursorPosition);
|
|
|
|
messageInputField.insert(lastAtPosition, plainTextToReplace);
|
|
|
|
suggestionsBox.hide();
|
|
|
|
}
|
|
|
|
}
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// since emoji length is not 1 we need to match that position that TextArea returns
|
2021-05-06 20:29:22 +00:00
|
|
|
// to the actual position in the string.
|
2020-09-29 09:06:57 +00:00
|
|
|
function extrapolateCursorPosition() {
|
|
|
|
// we need only the message part to be html
|
2021-03-19 20:13:12 +00:00
|
|
|
const text = getPlainText()
|
|
|
|
const completelyPlainText = removeMentions(text)
|
2022-03-07 14:56:05 +00:00
|
|
|
const plainText = StatusQUtils.Emoji.parse(text);
|
2020-09-29 09:06:57 +00:00
|
|
|
|
|
|
|
var bracketEvent = false;
|
2021-03-19 20:13:12 +00:00
|
|
|
var almostMention = false;
|
|
|
|
var mentionEvent = false;
|
2020-09-29 09:06:57 +00:00
|
|
|
var length = 0;
|
|
|
|
|
2021-03-19 20:13:12 +00:00
|
|
|
// This loop calculates the cursor position inside the plain text which contains the image tags (<img>) and the mention tags ([[mention]])
|
|
|
|
const cursorPos = messageInputField.cursorPosition
|
2021-05-06 20:29:22 +00:00
|
|
|
let character = ""
|
|
|
|
for (var i = 0; i < plainText.length; i++) {
|
2021-03-19 20:13:12 +00:00
|
|
|
if (length >= cursorPos) break;
|
2020-09-29 09:06:57 +00:00
|
|
|
|
2021-05-06 20:29:22 +00:00
|
|
|
character = plainText.charAt(i)
|
|
|
|
if (!bracketEvent && character !== '<' && !mentionEvent && character !== '[') {
|
2020-09-29 09:06:57 +00:00
|
|
|
length++;
|
2021-05-06 20:29:22 +00:00
|
|
|
} else if (!bracketEvent && character === '<') {
|
2020-09-29 09:06:57 +00:00
|
|
|
bracketEvent = true;
|
2021-05-06 20:29:22 +00:00
|
|
|
} else if (bracketEvent && character === '>') {
|
2020-09-29 09:06:57 +00:00
|
|
|
bracketEvent = false;
|
|
|
|
length++;
|
2021-03-19 20:13:12 +00:00
|
|
|
} else if (!mentionEvent && almostMention && plainText.charAt(i) === '[') {
|
|
|
|
almostMention = false
|
|
|
|
mentionEvent = true
|
|
|
|
} else if (!mentionEvent && !almostMention && plainText.charAt(i) === '[') {
|
|
|
|
almostMention = true
|
|
|
|
} else if (!mentionEvent && almostMention && plainText.charAt(i) !== '[') {
|
|
|
|
almostMention = false
|
|
|
|
} else if (mentionEvent && !almostMention && plainText.charAt(i) === ']') {
|
|
|
|
almostMention = true
|
|
|
|
} else if (mentionEvent && almostMention && plainText.charAt(i) === ']') {
|
|
|
|
almostMention = false
|
|
|
|
mentionEvent = false
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-14 08:18:56 +00:00
|
|
|
let textBeforeCursor = StatusQUtils.Emoji.deparse(plainText.substr(0, i));
|
2021-03-19 20:13:12 +00:00
|
|
|
|
2020-09-29 09:06:57 +00:00
|
|
|
return {
|
2021-03-19 20:13:12 +00:00
|
|
|
cursor: countEmojiLengths(plainText.substr(0, i)) + messageInputField.cursorPosition + text.length - completelyPlainText.length,
|
|
|
|
data: textBeforeCursor,
|
2020-09-29 09:06:57 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function emojiHandler(event) {
|
|
|
|
let message = extrapolateCursorPosition();
|
|
|
|
pollEmojiEvent(message);
|
|
|
|
|
|
|
|
// state machine to handle different forms of the emoji event state
|
|
|
|
if (!emojiEvent && isColonPressed) {
|
|
|
|
return (message.data.length <= 1 || Utils.isSpace(message.data.charAt(message.cursor - 1))) ? true : false;
|
|
|
|
} else if (emojiEvent && isColonPressed) {
|
|
|
|
const index = message.data.lastIndexOf(':', message.cursor - 2);
|
|
|
|
if (index >= 0 && message.cursor > 0) {
|
|
|
|
const shortname = message.data.substr(index, message.cursor);
|
2022-03-07 14:56:05 +00:00
|
|
|
const codePoint = StatusQUtils.Emoji.getEmojiUnicode(shortname);
|
2020-09-29 09:06:57 +00:00
|
|
|
if (codePoint !== undefined) {
|
|
|
|
replaceWithEmoji(message, shortname, codePoint);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else if (emojiEvent && isKeyValid(event.key) && !isColonPressed) {
|
|
|
|
// popup
|
|
|
|
const index2 = message.data.lastIndexOf(':', message.cursor - 1);
|
|
|
|
if (index2 >= 0 && message.cursor > 0) {
|
|
|
|
const emojiPart = message.data.substr(index2, message.cursor);
|
|
|
|
if (emojiPart.length > 2) {
|
2022-08-22 09:54:19 +00:00
|
|
|
const emojis = StatusQUtils.Emoji.emojiJSON.emoji_json.filter(function (emoji) {
|
2020-09-29 09:06:57 +00:00
|
|
|
return emoji.name.includes(emojiPart) ||
|
|
|
|
emoji.shortname.includes(emojiPart) ||
|
2024-08-26 08:16:59 +00:00
|
|
|
emoji.aliases.some(a => a.includes(emojiPart)) ||
|
|
|
|
emoji.keywords.some(k => k.includes(emojiPart))
|
2020-09-29 09:06:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
emojiSuggestions.openPopup(emojis, emojiPart)
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (emojiEvent && !isKeyValid(event.key) && !isColonPressed) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function countEmojiLengths(value) {
|
2022-03-07 14:56:05 +00:00
|
|
|
const match = StatusQUtils.Emoji.getEmojis(value);
|
2020-09-29 09:06:57 +00:00
|
|
|
var length = 0;
|
|
|
|
|
|
|
|
if (match && match.length > 0) {
|
|
|
|
for (var i = 0; i < match.length; i++) {
|
2023-04-14 08:18:56 +00:00
|
|
|
length += StatusQUtils.Emoji.deparse(match[i]).length;
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
|
|
|
length = length - match.length;
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2023-04-06 16:36:25 +00:00
|
|
|
function checkForInlineEmojis(force = false) {
|
|
|
|
// trigger inline emoji replacements after space, or always (force==true) when sending the message
|
|
|
|
if (force || messageInputField.getText(messageInputField.cursorPosition, messageInputField.cursorPosition - 1) === " ") {
|
|
|
|
// figure out last word (between spaces), max length of 5
|
|
|
|
var lastWord = ""
|
|
|
|
const cursorPos = messageInputField.cursorPosition - (force ? 1 : 2) // just before the last non-space character
|
|
|
|
for (let i = cursorPos; i > cursorPos - 6; i--) { // go back until we found a space or start of line
|
|
|
|
const lastChar = messageInputField.getText(i, i+1)
|
|
|
|
if (i < 0 || lastChar === " ") { // reached start of line or a space
|
|
|
|
break
|
|
|
|
} else {
|
|
|
|
lastWord = lastChar + lastWord // collect the last word
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the word contains any of the trigger chars (emojiReplacementSymbols)
|
|
|
|
if (!!lastWord && Array.prototype.some.call(d.emojiReplacementSymbols, (trigger) => lastWord.includes(trigger))) {
|
|
|
|
// search the ASCII aliases for a possible match
|
|
|
|
const emojiFound = StatusQUtils.Emoji.emojiJSON.emoji_json.find(emoji => emoji.aliases_ascii.includes(lastWord))
|
|
|
|
if (emojiFound) {
|
|
|
|
replaceWithEmoji("", lastWord, emojiFound.unicode, force ? 0 : 1 /*offset*/);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function replaceWithEmoji(message, shortname, codePoint, offset = 0) {
|
2022-03-07 14:56:05 +00:00
|
|
|
const encodedCodePoint = StatusQUtils.Emoji.getEmojiCodepoint(codePoint)
|
2023-04-06 16:36:25 +00:00
|
|
|
messageInputField.remove(messageInputField.cursorPosition - shortname.length - offset, messageInputField.cursorPosition);
|
2022-03-07 14:56:05 +00:00
|
|
|
insertInTextInput(messageInputField.cursorPosition, StatusQUtils.Emoji.parse(encodedCodePoint) + " ");
|
2020-09-29 09:06:57 +00:00
|
|
|
emojiSuggestions.close()
|
|
|
|
emojiEvent = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if user has placed cursor near valid emoji colon token
|
|
|
|
function pollEmojiEvent(message) {
|
|
|
|
const index = message.data.lastIndexOf(':', message.cursor);
|
|
|
|
if (index >= 0) {
|
|
|
|
emojiEvent = validSubstr(message.data.substr(index, message.cursor - index));
|
2021-05-05 17:54:35 +00:00
|
|
|
}
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function validSubstr(substr) {
|
|
|
|
for(var i = 0; i < substr.length; i++) {
|
|
|
|
var c = substr.charAt(i);
|
2022-11-25 13:29:12 +00:00
|
|
|
if (Utils.isSpace(c) || Utils.isPunct(c))
|
2020-09-29 09:06:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isKeyValid(key) {
|
|
|
|
if (key === Qt.Key_Space || key === Qt.Key_Tab ||
|
2021-07-13 07:34:13 +00:00
|
|
|
(key >= Qt.Key_Exclam && key <= Qt.Key_Slash) ||
|
|
|
|
(key >= Qt.Key_Semicolon && key <= Qt.Key_Question) ||
|
|
|
|
(key >= Qt.Key_BracketLeft && key <= Qt.Key_hyphen))
|
2020-09-29 09:06:57 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-06-07 13:18:29 +00:00
|
|
|
function resetImageArea() {
|
2020-09-29 09:06:57 +00:00
|
|
|
isImage = false;
|
2022-11-25 14:08:12 +00:00
|
|
|
control.fileUrlsAndSources = []
|
2021-03-10 04:59:01 +00:00
|
|
|
for (let i=0; i<validators.children.length; i++) {
|
|
|
|
const validator = validators.children[i]
|
|
|
|
validator.images = []
|
|
|
|
}
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
|
|
|
|
2023-06-07 13:18:29 +00:00
|
|
|
function resetReplyArea() {
|
2023-06-28 20:19:00 +00:00
|
|
|
isReply = false
|
|
|
|
replyArea.messageId = ""
|
2023-06-07 13:18:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function hideExtendedArea() {
|
|
|
|
resetImageArea()
|
|
|
|
resetReplyArea()
|
|
|
|
}
|
|
|
|
|
2024-08-29 15:36:38 +00:00
|
|
|
function validateImages(imagePaths = []) {
|
2023-09-26 14:16:53 +00:00
|
|
|
// needed because control.fileUrlsAndSources is not a normal js array
|
|
|
|
const existing = (control.fileUrlsAndSources || []).map(x => x.toString())
|
2021-03-10 04:59:01 +00:00
|
|
|
let validImages = Utils.deduplicate(existing.concat(imagePaths))
|
|
|
|
for (let i=0; i<validators.children.length; i++) {
|
|
|
|
const validator = validators.children[i]
|
|
|
|
validator.images = validImages
|
|
|
|
validImages = validImages.filter(validImage => validator.validImages.includes(validImage))
|
|
|
|
}
|
|
|
|
return validImages
|
|
|
|
}
|
|
|
|
|
2022-11-25 14:08:12 +00:00
|
|
|
function showImageArea(imagePathsOrData) {
|
2023-06-07 13:18:29 +00:00
|
|
|
isImage = imagePathsOrData.length > 0
|
2023-09-26 14:16:53 +00:00
|
|
|
control.fileUrlsAndSources = imagePathsOrData
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
|
|
|
|
2023-09-22 14:25:38 +00:00
|
|
|
// Use this to validate and show the images. The concatenation of previous selected images is done automatically
|
2023-03-27 17:53:17 +00:00
|
|
|
// Returns true if the images were valid and added
|
|
|
|
function validateImagesAndShowImageArea(imagePaths) {
|
|
|
|
const validImages = validateImages(imagePaths)
|
2023-06-07 13:18:29 +00:00
|
|
|
showImageArea(validImages)
|
|
|
|
return isImage
|
2023-03-27 17:53:17 +00:00
|
|
|
}
|
|
|
|
|
2023-04-27 12:35:16 +00:00
|
|
|
function showReplyArea(messageId, userName, message, contentType, image, album, albumCount, sticker) {
|
2020-09-29 09:06:57 +00:00
|
|
|
isReply = true
|
|
|
|
replyArea.userName = userName
|
|
|
|
replyArea.message = message
|
2021-08-30 12:42:11 +00:00
|
|
|
replyArea.contentType = contentType
|
|
|
|
replyArea.image = image
|
2021-11-09 16:46:18 +00:00
|
|
|
replyArea.stickerData = sticker
|
2022-01-12 12:55:26 +00:00
|
|
|
replyArea.messageId = messageId
|
2023-04-27 12:35:16 +00:00
|
|
|
replyArea.album = album
|
|
|
|
replyArea.albumCount = albumCount
|
2020-11-23 15:49:30 +00:00
|
|
|
messageInputField.forceActiveFocus();
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
|
|
|
|
2022-01-27 17:14:21 +00:00
|
|
|
function forceInputActiveFocus() {
|
|
|
|
messageInputField.forceActiveFocus();
|
|
|
|
}
|
|
|
|
|
2024-10-07 12:31:53 +00:00
|
|
|
DropAreaPanel {
|
|
|
|
enabled: control.visible && control.enabled
|
|
|
|
parent: Overlay.overlay
|
|
|
|
anchors.fill: parent
|
|
|
|
onDroppedOnValidScreen: (drop) => {
|
2023-06-07 16:03:38 +00:00
|
|
|
let dropUrls = drop.urls
|
|
|
|
if (!drop.hasUrls) {
|
|
|
|
console.warn("Trying to drop, list of URLs is empty tho; formats:", drop.formats)
|
|
|
|
if (drop.formats.includes("text/x-moz-url")) { // Chrome uses a non-standard MIME type
|
|
|
|
dropUrls = drop.getDataAsString("text/x-moz-url")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (validateImagesAndShowImageArea(dropUrls)) {
|
2023-01-25 18:31:00 +00:00
|
|
|
drop.acceptProposedAction()
|
|
|
|
}
|
|
|
|
}
|
2021-03-10 04:59:01 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 18:31:00 +00:00
|
|
|
// This is used by Squish tests to not have to access the file dialog
|
2022-08-19 14:57:09 +00:00
|
|
|
function selectImageString(filePath) {
|
2023-03-27 17:53:17 +00:00
|
|
|
validateImagesAndShowImageArea([filePath])
|
2022-08-19 14:57:09 +00:00
|
|
|
messageInputField.forceActiveFocus();
|
|
|
|
}
|
|
|
|
|
2023-06-07 13:18:29 +00:00
|
|
|
Component {
|
|
|
|
id: imageDialogComponent
|
|
|
|
|
|
|
|
FileDialog {
|
|
|
|
title: qsTr("Please choose an image")
|
|
|
|
folder: shortcuts.pictures
|
|
|
|
selectMultiple: true
|
|
|
|
nameFilters: [
|
|
|
|
qsTr("Image files (%1)").arg(Constants.acceptedDragNDropImageExtensions.map(img => "*" + img).join(" "))
|
|
|
|
]
|
|
|
|
onAccepted: {
|
|
|
|
imageBtn.highlighted = false
|
|
|
|
validateImagesAndShowImageArea(fileUrls)
|
|
|
|
messageInputField.forceActiveFocus()
|
|
|
|
}
|
|
|
|
onRejected: {
|
|
|
|
imageBtn.highlighted = false
|
|
|
|
}
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-20 15:32:03 +00:00
|
|
|
StatusEmojiSuggestionPopup {
|
2020-09-29 09:06:57 +00:00
|
|
|
id: emojiSuggestions
|
2021-12-08 21:20:43 +00:00
|
|
|
messageInput: messageInput
|
2022-02-09 20:50:38 +00:00
|
|
|
onClicked: function (index) {
|
|
|
|
if (index === undefined) {
|
|
|
|
index = emojiSuggestions.listView.currentIndex
|
|
|
|
}
|
|
|
|
|
2024-08-26 08:16:59 +00:00
|
|
|
const unicode = emojiSuggestions.modelList[index].unicode
|
2022-02-09 20:50:38 +00:00
|
|
|
replaceWithEmoji(extrapolateCursorPosition(), emojiSuggestions.shortname, unicode);
|
|
|
|
}
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
|
|
|
|
2021-10-01 15:58:36 +00:00
|
|
|
SuggestionBoxPanel {
|
2020-10-20 17:38:48 +00:00
|
|
|
id: suggestionsBox
|
2022-08-10 06:57:34 +00:00
|
|
|
objectName: "suggestionsBox"
|
2024-09-06 13:11:47 +00:00
|
|
|
model: control.usersModel ?? []
|
2020-10-20 17:38:48 +00:00
|
|
|
x : messageInput.x
|
2024-10-15 19:26:12 +00:00
|
|
|
y: -height - Theme.smallPadding
|
2020-10-20 17:38:48 +00:00
|
|
|
width: messageInput.width
|
|
|
|
filter: messageInputField.text
|
|
|
|
cursorPosition: messageInputField.cursorPosition
|
2023-04-18 11:46:04 +00:00
|
|
|
property: ["nickname", "ensName", "name"]
|
2022-02-21 19:51:41 +00:00
|
|
|
inputField: messageInputField
|
2020-10-20 17:38:48 +00:00
|
|
|
onItemSelected: function (item, lastAtPosition, lastCursorPosition) {
|
2022-02-21 19:51:41 +00:00
|
|
|
messageInputField.forceActiveFocus();
|
2023-01-06 13:09:47 +00:00
|
|
|
const name = item[suggestionsBox.property.find(p => !!item[p])].replace("@", "")
|
2022-12-15 10:29:10 +00:00
|
|
|
d.insertMention(name, item.publicKey, lastAtPosition, lastCursorPosition)
|
2020-10-20 17:38:48 +00:00
|
|
|
suggestionsBox.suggestionsModel.clear()
|
|
|
|
}
|
2022-02-21 19:51:41 +00:00
|
|
|
onVisibleChanged: {
|
|
|
|
if (!visible) {
|
|
|
|
messageInputField.forceActiveFocus();
|
|
|
|
}
|
|
|
|
}
|
2020-10-20 17:38:48 +00:00
|
|
|
}
|
|
|
|
|
2023-06-07 13:18:29 +00:00
|
|
|
Component {
|
|
|
|
id: gifPopupComponent
|
|
|
|
|
|
|
|
StatusGifPopup {
|
|
|
|
readonly property point relativePosition: d.getCommonPopupRelativePosition(this, parent)
|
|
|
|
|
2024-09-04 14:27:24 +00:00
|
|
|
gifStore: control.sharedStore.gifStore
|
|
|
|
gifUnfurlingEnabled: control.sharedStore.gifUnfurlingEnabled
|
|
|
|
|
2023-06-07 13:18:29 +00:00
|
|
|
width: 360
|
|
|
|
height: 440
|
|
|
|
x: relativePosition.x
|
|
|
|
y: relativePosition.y
|
|
|
|
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
|
|
|
|
|
|
|
|
gifSelected: function (event, url) {
|
|
|
|
messageInputField.text += "\n" + url
|
|
|
|
control.sendMessage(event)
|
|
|
|
control.isReply = false
|
|
|
|
messageInputField.forceActiveFocus()
|
|
|
|
if (control.closeGifPopupAfterSelection)
|
|
|
|
close()
|
|
|
|
}
|
|
|
|
onClosed: {
|
|
|
|
gifBtn.popup = null
|
|
|
|
destroy()
|
|
|
|
}
|
2021-07-21 08:26:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
RowLayout {
|
|
|
|
id: layout
|
|
|
|
anchors.fill: parent
|
|
|
|
spacing: 4
|
|
|
|
|
|
|
|
StatusQ.StatusFlatRoundButton {
|
|
|
|
id: imageBtn
|
|
|
|
Layout.preferredWidth: 32
|
|
|
|
Layout.preferredHeight: 32
|
|
|
|
Layout.alignment: Qt.AlignBottom
|
|
|
|
Layout.bottomMargin: 4
|
|
|
|
icon.name: "image"
|
|
|
|
type: StatusQ.StatusFlatRoundButton.Type.Tertiary
|
2023-01-20 19:01:32 +00:00
|
|
|
visible: !isEdit
|
2022-07-05 10:12:27 +00:00
|
|
|
onClicked: {
|
|
|
|
highlighted = true
|
2023-06-07 13:18:29 +00:00
|
|
|
const popup = imageDialogComponent.createObject(control)
|
|
|
|
popup.open()
|
2021-07-13 07:34:13 +00:00
|
|
|
}
|
2021-03-10 04:59:01 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 09:06:57 +00:00
|
|
|
Rectangle {
|
2022-07-05 10:12:27 +00:00
|
|
|
id: messageInput
|
2021-07-13 07:34:13 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
implicitHeight: inputLayout.implicitHeight + inputLayout.anchors.topMargin + inputLayout.anchors.bottomMargin
|
|
|
|
implicitWidth: inputLayout.implicitWidth + inputLayout.anchors.leftMargin + inputLayout.anchors.rightMargin
|
|
|
|
|
2024-10-15 19:26:12 +00:00
|
|
|
color: isEdit ? Theme.palette.statusChatInput.secondaryBackgroundColor : Theme.palette.baseColor2
|
2022-07-05 10:12:27 +00:00
|
|
|
radius: 20
|
|
|
|
|
2023-09-22 14:25:38 +00:00
|
|
|
StatusQ.StatusToolTip {
|
|
|
|
id: messageLengthLimitTooltip
|
|
|
|
text: messageInputField.length >= control.messageLimitHard ? qsTr("Please reduce the message length")
|
|
|
|
: qsTr("Maximum message character count is %n", "", control.messageLimit)
|
|
|
|
orientation: StatusQ.StatusToolTip.Orientation.Top
|
|
|
|
timeout: 3000 // show for 3 seconds
|
|
|
|
}
|
|
|
|
|
2023-06-07 13:18:29 +00:00
|
|
|
Component {
|
|
|
|
id: textFormatMenuComponent
|
|
|
|
|
|
|
|
StatusTextFormatMenu {
|
|
|
|
onClosed: {
|
|
|
|
messageInputField.deselect()
|
|
|
|
destroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusChatInputTextFormationAction {
|
|
|
|
wrapper: "**"
|
|
|
|
icon.name: "bold"
|
|
|
|
text: qsTr("Bold")
|
2024-09-03 15:02:02 +00:00
|
|
|
selectedTextWithFormationChars: d.getSelectedTextWithFormationChars(messageInputField)
|
2023-06-07 13:18:29 +00:00
|
|
|
onActionTriggered: checked ?
|
2024-09-03 15:02:02 +00:00
|
|
|
unwrapSelection(wrapper, d.getSelectedTextWithFormationChars(messageInputField)) :
|
2023-06-07 13:18:29 +00:00
|
|
|
wrapSelection(wrapper)
|
|
|
|
}
|
|
|
|
StatusChatInputTextFormationAction {
|
|
|
|
wrapper: "*"
|
|
|
|
icon.name: "italic"
|
|
|
|
text: qsTr("Italic")
|
2024-09-03 15:02:02 +00:00
|
|
|
selectedTextWithFormationChars: d.getSelectedTextWithFormationChars(messageInputField)
|
2023-06-07 13:18:29 +00:00
|
|
|
checked: (surroundedBy("*") && !surroundedBy("**")) || surroundedBy("***")
|
|
|
|
onActionTriggered: checked ?
|
2024-09-03 15:02:02 +00:00
|
|
|
unwrapSelection(wrapper, d.getSelectedTextWithFormationChars(messageInputField)) :
|
2023-06-07 13:18:29 +00:00
|
|
|
wrapSelection(wrapper)
|
|
|
|
}
|
|
|
|
StatusChatInputTextFormationAction {
|
|
|
|
wrapper: "~~"
|
|
|
|
icon.name: "strikethrough"
|
|
|
|
text: qsTr("Strikethrough")
|
2024-09-03 15:02:02 +00:00
|
|
|
selectedTextWithFormationChars: d.getSelectedTextWithFormationChars(messageInputField)
|
2023-06-07 13:18:29 +00:00
|
|
|
onActionTriggered: checked ?
|
2024-09-03 15:02:02 +00:00
|
|
|
unwrapSelection(wrapper, d.getSelectedTextWithFormationChars(messageInputField)) :
|
2023-06-07 13:18:29 +00:00
|
|
|
wrapSelection(wrapper)
|
|
|
|
}
|
|
|
|
StatusChatInputTextFormationAction {
|
|
|
|
wrapper: "`"
|
|
|
|
icon.name: "code"
|
|
|
|
text: qsTr("Code")
|
2024-09-03 15:02:02 +00:00
|
|
|
selectedTextWithFormationChars: d.getSelectedTextWithFormationChars(messageInputField)
|
2023-06-07 13:18:29 +00:00
|
|
|
onActionTriggered: checked ?
|
2024-09-03 15:02:02 +00:00
|
|
|
unwrapSelection(wrapper, d.getSelectedTextWithFormationChars(messageInputField)) :
|
2023-06-07 13:18:29 +00:00
|
|
|
wrapSelection(wrapper)
|
|
|
|
}
|
|
|
|
StatusChatInputTextFormationAction {
|
|
|
|
wrapper: "> "
|
|
|
|
icon.name: "quote"
|
|
|
|
text: qsTr("Quote")
|
|
|
|
checked: messageInputField.selectedText && isSelectedLinePrefixedBy(messageInputField.selectionStart, wrapper)
|
|
|
|
|
|
|
|
onActionTriggered: checked
|
|
|
|
? unprefixSelectedLine(wrapper)
|
|
|
|
: prefixSelectedLine(wrapper)
|
|
|
|
}
|
2022-10-05 11:03:58 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-07 13:18:29 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
ColumnLayout {
|
|
|
|
id: validators
|
|
|
|
anchors.bottom: control.imageErrorMessageLocation === StatusChatInput.ImageErrorMessageLocation.Top ? parent.top : undefined
|
|
|
|
anchors.bottomMargin: control.imageErrorMessageLocation === StatusChatInput.ImageErrorMessageLocation.Top ? -4 : undefined
|
|
|
|
anchors.top: control.imageErrorMessageLocation === StatusChatInput.ImageErrorMessageLocation.Bottom ? parent.bottom : undefined
|
|
|
|
anchors.topMargin: control.imageErrorMessageLocation === StatusChatInput.ImageErrorMessageLocation.Bottom ? (isImage ? -4 : 4) : undefined
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
width: parent.width
|
|
|
|
z: 1
|
|
|
|
|
|
|
|
StatusChatImageExtensionValidator {
|
2024-08-29 15:36:38 +00:00
|
|
|
id: imageExtValidator
|
2022-07-05 10:12:27 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
}
|
|
|
|
StatusChatImageSizeValidator {
|
2024-08-29 15:36:38 +00:00
|
|
|
id: imageSizeValidator
|
2022-07-05 10:12:27 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
}
|
|
|
|
StatusChatImageQtyValidator {
|
2024-08-29 15:36:38 +00:00
|
|
|
id: imageQtyValidator
|
2022-07-05 10:12:27 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2021-07-13 07:34:13 +00:00
|
|
|
}
|
2024-08-29 15:36:38 +00:00
|
|
|
|
|
|
|
Timer {
|
|
|
|
interval: 3000
|
|
|
|
repeat: true
|
|
|
|
running: !imageQtyValidator.isValid || !imageSizeValidator.isValid || !imageExtValidator.isValid
|
|
|
|
onTriggered: validateImages(control.fileUrlsAndSources)
|
|
|
|
}
|
2020-12-04 11:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
2022-07-05 10:12:27 +00:00
|
|
|
// Bottom right corner has different radius
|
2020-12-04 11:11:49 +00:00
|
|
|
color: parent.color
|
2022-07-05 10:12:27 +00:00
|
|
|
anchors.bottom: parent.bottom
|
2020-12-04 11:11:49 +00:00
|
|
|
anchors.right: parent.right
|
2022-07-05 10:12:27 +00:00
|
|
|
height: parent.height / 2
|
|
|
|
width: 32
|
2024-10-15 19:26:12 +00:00
|
|
|
radius: Theme.radius
|
2020-12-04 11:11:49 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
ColumnLayout {
|
|
|
|
id: inputLayout
|
2023-02-14 15:13:03 +00:00
|
|
|
width: parent.width
|
2022-07-05 10:12:27 +00:00
|
|
|
spacing: 4
|
|
|
|
|
|
|
|
StatusChatInputReplyArea {
|
|
|
|
id: replyArea
|
|
|
|
visible: isReply
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.margins: 2
|
|
|
|
onCloseButtonClicked: {
|
|
|
|
isReply = false
|
2021-03-10 04:59:01 +00:00
|
|
|
}
|
2020-12-04 11:11:49 +00:00
|
|
|
}
|
|
|
|
|
2023-09-26 14:16:53 +00:00
|
|
|
ChatInputLinksPreviewArea {
|
|
|
|
id: linkPreviewArea
|
2022-07-05 10:12:27 +00:00
|
|
|
Layout.fillWidth: true
|
2023-10-09 08:45:16 +00:00
|
|
|
visible: hasContent
|
2023-09-26 14:16:53 +00:00
|
|
|
horizontalPadding: 12
|
|
|
|
topPadding: 12
|
2023-10-09 08:45:16 +00:00
|
|
|
imagePreviewArray: control.fileUrlsAndSources
|
2023-09-26 14:16:53 +00:00
|
|
|
linkPreviewModel: control.linkPreviewModel
|
2023-10-09 08:45:16 +00:00
|
|
|
showLinkPreviewSettings: control.askToEnableLinkPreview
|
2023-09-26 14:16:53 +00:00
|
|
|
onImageRemoved: (index) => {
|
|
|
|
//Just do a copy and replace the whole thing because it's a plain JS array and thre's no signal when a single item is removed
|
|
|
|
let urls = control.fileUrlsAndSources
|
|
|
|
if (urls.length > index && urls[index]) {
|
|
|
|
urls.splice(index, 1)
|
2022-07-05 10:12:27 +00:00
|
|
|
}
|
2023-09-26 14:16:53 +00:00
|
|
|
control.fileUrlsAndSources = urls
|
2024-08-29 15:36:38 +00:00
|
|
|
validateImages(control.fileUrlsAndSources)
|
2022-07-05 10:12:27 +00:00
|
|
|
}
|
2024-05-15 09:36:56 +00:00
|
|
|
onImageClicked: (chatImage) => Global.openImagePopup(chatImage, "", false)
|
2023-09-26 14:16:53 +00:00
|
|
|
onLinkReload: (link) => control.linkPreviewReloaded(link)
|
|
|
|
onLinkClicked: (link) => Global.openLink(link)
|
2023-10-09 08:45:16 +00:00
|
|
|
onEnableLinkPreview: () => control.enableLinkPreview()
|
|
|
|
onEnableLinkPreviewForThisMessage: () => control.enableLinkPreviewForThisMessage()
|
|
|
|
onDisableLinkPreview: () => control.disableLinkPreview()
|
|
|
|
onDismissLinkPreviewSettings: () => control.dismissLinkPreviewSettings()
|
|
|
|
onDismissLinkPreview: (index) => control.dismissLinkPreview(index)
|
2020-12-04 11:11:49 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
RowLayout {
|
|
|
|
Layout.fillWidth: true
|
2023-02-14 15:13:03 +00:00
|
|
|
Layout.minimumHeight: (messageInputField.contentHeight + messageInputField.topPadding + messageInputField.bottomPadding)
|
2023-09-22 14:25:38 +00:00
|
|
|
Layout.maximumHeight: 200
|
2024-10-15 19:26:12 +00:00
|
|
|
spacing: Theme.radius
|
2022-07-05 10:12:27 +00:00
|
|
|
StatusScrollView {
|
|
|
|
id: inputScrollView
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.leftMargin: 12
|
|
|
|
Layout.rightMargin: 12
|
|
|
|
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
|
|
|
|
|
|
|
|
padding: 0
|
2022-12-14 15:40:00 +00:00
|
|
|
contentWidth: availableWidth
|
2022-07-05 10:12:27 +00:00
|
|
|
|
|
|
|
TextArea {
|
|
|
|
id: messageInputField
|
2023-01-18 20:21:25 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
objectName: "messageInputField"
|
|
|
|
|
2024-03-04 09:59:52 +00:00
|
|
|
property double lastClick: 0
|
2022-07-05 10:12:27 +00:00
|
|
|
property int cursorWhenPressed: 0
|
2022-12-15 10:29:10 +00:00
|
|
|
property int previousCursorPosition: 0
|
2022-07-05 10:12:27 +00:00
|
|
|
|
|
|
|
width: inputScrollView.availableWidth
|
|
|
|
|
|
|
|
textFormat: Text.RichText
|
|
|
|
font.pixelSize: 15
|
2024-10-15 19:26:12 +00:00
|
|
|
font.family: Theme.baseFont.name
|
2022-07-05 10:12:27 +00:00
|
|
|
wrapMode: TextArea.Wrap
|
|
|
|
placeholderText: control.chatInputPlaceholder
|
2024-10-15 19:26:12 +00:00
|
|
|
placeholderTextColor: Theme.palette.secondaryText
|
2022-07-05 10:12:27 +00:00
|
|
|
selectByMouse: true
|
2024-10-15 19:26:12 +00:00
|
|
|
color: isEdit ? Theme.palette.directColor1 : Theme.palette.textColor
|
2022-07-05 10:12:27 +00:00
|
|
|
topPadding: 9
|
|
|
|
bottomPadding: 9
|
|
|
|
leftPadding: 0
|
|
|
|
padding: 0
|
2023-11-02 12:17:03 +00:00
|
|
|
// This is needed to make sure the text area is disabled when the input is disabled
|
|
|
|
Binding on enabled {
|
2024-03-04 09:59:52 +00:00
|
|
|
value: control.enabled
|
2023-11-02 12:17:03 +00:00
|
|
|
}
|
2023-03-06 16:09:10 +00:00
|
|
|
Keys.onUpPressed: {
|
2023-04-05 11:00:14 +00:00
|
|
|
if (isEdit && !activeFocus) {
|
2023-03-06 16:09:10 +00:00
|
|
|
forceActiveFocus();
|
|
|
|
} else {
|
|
|
|
if (messageInputField.length === 0) {
|
|
|
|
control.keyUpPress();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (emojiSuggestions.visible) {
|
|
|
|
emojiSuggestions.listView.decrementCurrentIndex();
|
|
|
|
}
|
2023-04-05 11:00:14 +00:00
|
|
|
event.accepted = false
|
2023-03-06 16:09:10 +00:00
|
|
|
}
|
2022-07-05 10:12:27 +00:00
|
|
|
Keys.onPressed: {
|
|
|
|
keyEvent = event;
|
|
|
|
onKeyPress(event)
|
|
|
|
cursorWhenPressed = cursorPosition;
|
|
|
|
}
|
|
|
|
Keys.onReleased: onRelease(event) // gives much more up to date cursorPosition
|
|
|
|
Keys.onShortcutOverride: event.accepted = isUploadFilePressed(event)
|
2024-10-15 19:26:12 +00:00
|
|
|
selectionColor: Theme.palette.primaryColor2
|
2022-07-05 10:12:27 +00:00
|
|
|
persistentSelection: true
|
|
|
|
property var keyEvent
|
|
|
|
|
|
|
|
Component.onDestruction: {
|
|
|
|
// NOTE: Without losing focus the app crashes on apply/cancel message editing.
|
|
|
|
control.forceActiveFocus();
|
|
|
|
}
|
2021-12-01 12:46:21 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
onCursorPositionChanged: {
|
2023-01-18 20:21:25 +00:00
|
|
|
if(mentionsPos.length > 0 && ((keyEvent.key === Qt.Key_Left) || (keyEvent.key === Qt.Key_Right)
|
|
|
|
|| (selectedText.length>0))) {
|
2022-12-15 10:29:10 +00:00
|
|
|
const mention = d.getMentionAtPosition(cursorPosition)
|
2023-01-18 20:21:25 +00:00
|
|
|
if (mention) {
|
|
|
|
const cursorMovingLeft = (cursorPosition < previousCursorPosition);
|
2022-12-15 10:29:10 +00:00
|
|
|
const newCursorPosition = cursorMovingLeft ?
|
2023-01-18 20:21:25 +00:00
|
|
|
mention.leftIndex :
|
|
|
|
mention.rightIndex
|
|
|
|
const isSelection = (selectedText.length>0);
|
2022-12-15 10:29:10 +00:00
|
|
|
isSelection ? moveCursorSelection(newCursorPosition, TextEdit.SelectCharacters) :
|
|
|
|
cursorPosition = newCursorPosition
|
2022-07-05 10:12:27 +00:00
|
|
|
}
|
2022-02-24 21:41:37 +00:00
|
|
|
}
|
2022-08-25 13:06:32 +00:00
|
|
|
|
|
|
|
inputScrollView.ensureVisible(cursorRectangle)
|
2022-12-15 10:29:10 +00:00
|
|
|
previousCursorPosition = cursorPosition
|
2022-02-24 21:41:37 +00:00
|
|
|
}
|
2021-07-09 16:11:17 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
onTextChanged: {
|
|
|
|
if (length <= control.messageLimit) {
|
2022-09-20 15:26:54 +00:00
|
|
|
if (length === 0) {
|
2022-07-05 10:12:27 +00:00
|
|
|
mentionsPos = [];
|
2023-04-06 16:36:25 +00:00
|
|
|
} else {
|
|
|
|
checkForInlineEmojis()
|
2022-07-05 10:12:27 +00:00
|
|
|
}
|
2023-09-22 14:25:38 +00:00
|
|
|
} else if (length > control.messageLimitHard) {
|
|
|
|
const removeFrom = (cursorPosition < messageLimitHard) ? cursorWhenPressed : messageLimitHard;
|
2022-07-05 10:12:27 +00:00
|
|
|
remove(removeFrom, cursorPosition);
|
2023-09-22 14:25:38 +00:00
|
|
|
messageLengthLimitTooltip.open();
|
2022-07-05 10:12:27 +00:00
|
|
|
}
|
2022-09-06 09:45:16 +00:00
|
|
|
|
|
|
|
d.updateMentionsPositions()
|
2022-12-15 10:29:10 +00:00
|
|
|
d.cleanMentionsPos()
|
2022-09-06 09:45:16 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
messageLengthLimit.remainingChars = (messageLimit - length);
|
|
|
|
}
|
2021-02-11 15:50:59 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
onReleased: function (event) {
|
|
|
|
const now = Date.now()
|
|
|
|
if (messageInputField.selectedText.trim() !== "") {
|
|
|
|
// If it's a double click, just check the mouse position
|
|
|
|
// If it's a mouse select, use the start and end position average)
|
2023-06-07 13:18:29 +00:00
|
|
|
const x = now < messageInputField.lastClick + 500
|
|
|
|
? event.x
|
|
|
|
: (messageInputField.cursorRectangle.x + event.x) / 2
|
|
|
|
let menu = Global.openMenu(textFormatMenuComponent, messageInput, {})
|
|
|
|
menu.x = x - menu.width / 2
|
|
|
|
menu.y = messageInputField.y - menu.height - 5
|
|
|
|
d.textFormatMenu = menu
|
|
|
|
messageInputField.forceActiveFocus()
|
2022-07-05 10:12:27 +00:00
|
|
|
}
|
|
|
|
lastClick = now
|
|
|
|
}
|
2021-02-15 12:45:08 +00:00
|
|
|
|
2022-12-15 10:29:10 +00:00
|
|
|
onLinkActivated: {
|
|
|
|
const mention = d.getMentionAtPosition(cursorPosition - 1)
|
|
|
|
if(mention) {
|
|
|
|
select(mention.leftIndex, mention.rightIndex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-20 09:59:53 +00:00
|
|
|
onEnabledChanged: {
|
|
|
|
if (!enabled) {
|
2023-04-05 10:29:25 +00:00
|
|
|
clear()
|
2023-03-20 09:59:53 +00:00
|
|
|
control.hideExtendedArea()
|
|
|
|
}
|
|
|
|
}
|
2023-03-15 08:00:18 +00:00
|
|
|
|
2023-04-05 14:27:43 +00:00
|
|
|
cursorDelegate: StatusCursorDelegate {
|
|
|
|
cursorVisible: messageInputField.cursorVisible
|
2022-07-05 10:12:27 +00:00
|
|
|
}
|
2021-02-15 12:45:08 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
StatusSyntaxHighlighter {
|
|
|
|
quickTextDocument: messageInputField.textDocument
|
2024-10-15 19:26:12 +00:00
|
|
|
codeBackgroundColor: Theme.palette.baseColor4
|
|
|
|
codeForegroundColor: Theme.palette.textColor
|
2023-11-07 11:32:21 +00:00
|
|
|
hyperlinks: control.urlsList
|
|
|
|
hyperlinkColor: Theme.palette.primaryColor1
|
|
|
|
highlightedHyperlink: linkPreviewArea.hoveredUrl
|
|
|
|
hyperlinkHoverColor: Theme.palette.primaryColor3
|
2022-07-05 10:12:27 +00:00
|
|
|
}
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
acceptedButtons: Qt.NoButton
|
|
|
|
enabled: parent.hoveredLink
|
|
|
|
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.IBeamCursor
|
|
|
|
}
|
|
|
|
}
|
2020-09-29 09:06:57 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
Shortcut {
|
|
|
|
enabled: messageInputField.activeFocus
|
|
|
|
sequence: StandardKey.Bold
|
|
|
|
onActivated: wrapSelection("**")
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
enabled: messageInputField.activeFocus
|
|
|
|
sequence: StandardKey.Italic
|
|
|
|
onActivated: wrapSelection("*")
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
enabled: messageInputField.activeFocus
|
|
|
|
sequence: "Ctrl+Shift+Alt+C"
|
|
|
|
onActivated: wrapSelection("```")
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
enabled: messageInputField.activeFocus
|
|
|
|
sequence: "Ctrl+Shift+C"
|
|
|
|
onActivated: wrapSelection("`")
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
enabled: messageInputField.activeFocus
|
|
|
|
sequence: "Ctrl+Alt+-"
|
|
|
|
onActivated: wrapSelection("~~")
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
enabled: messageInputField.activeFocus
|
|
|
|
sequence: "Ctrl+Shift+X"
|
|
|
|
onActivated: wrapSelection("~~")
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
enabled: messageInputField.activeFocus
|
|
|
|
sequence: "Ctrl+Meta+Space"
|
|
|
|
onActivated: emojiBtn.clicked(null)
|
|
|
|
}
|
|
|
|
}
|
2020-09-29 09:06:57 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
Column {
|
|
|
|
Layout.alignment: Qt.AlignBottom
|
|
|
|
Layout.bottomMargin: 3
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: messageLengthLimit
|
|
|
|
property int remainingChars: -1
|
2024-10-15 19:26:12 +00:00
|
|
|
leftPadding: Theme.halfPadding
|
|
|
|
rightPadding: Theme.halfPadding
|
2023-09-22 14:25:38 +00:00
|
|
|
visible: messageInputField.length >= control.messageLimit - control.messageLimitSoft
|
|
|
|
color: {
|
|
|
|
if (remainingChars >= 0)
|
2024-10-15 19:26:12 +00:00
|
|
|
return Theme.palette.textColor
|
2023-09-22 14:25:38 +00:00
|
|
|
else
|
2024-10-15 19:26:12 +00:00
|
|
|
return Theme.palette.dangerColor1
|
2023-09-22 14:25:38 +00:00
|
|
|
}
|
2022-07-05 10:12:27 +00:00
|
|
|
text: visible ? remainingChars.toString() : ""
|
2023-09-22 14:25:38 +00:00
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: mouseArea
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
|
|
|
onEntered: {
|
|
|
|
messageLengthLimitTooltip.open()
|
|
|
|
}
|
|
|
|
onExited: {
|
|
|
|
messageLengthLimitTooltip.hide()
|
|
|
|
}
|
|
|
|
}
|
2022-07-05 10:12:27 +00:00
|
|
|
}
|
2021-12-01 12:46:21 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
Row {
|
|
|
|
id: actions
|
|
|
|
spacing: 2
|
|
|
|
|
|
|
|
StatusQ.StatusFlatRoundButton {
|
|
|
|
id: emojiBtn
|
|
|
|
objectName: "statusChatInputEmojiButton"
|
|
|
|
implicitHeight: 32
|
|
|
|
implicitWidth: 32
|
|
|
|
icon.name: "emojis"
|
|
|
|
icon.color: (hovered || highlighted) ? Theme.palette.primaryColor1
|
|
|
|
: Theme.palette.baseColor1
|
|
|
|
type: StatusQ.StatusFlatRoundButton.Type.Tertiary
|
|
|
|
color: "transparent"
|
2023-06-07 13:18:29 +00:00
|
|
|
highlighted: d.emojiPopupOpened
|
2022-07-05 10:12:27 +00:00
|
|
|
onClicked: {
|
2023-06-07 13:18:29 +00:00
|
|
|
if (d.emojiPopupOpened) {
|
|
|
|
emojiPopup.close()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
d.emojiPopupOpened = true
|
|
|
|
emojiPopup.open()
|
2022-07-05 10:12:27 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-01 12:46:21 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
StatusQ.StatusFlatRoundButton {
|
|
|
|
id: gifBtn
|
2023-06-07 13:18:29 +00:00
|
|
|
|
|
|
|
property Popup popup
|
|
|
|
|
2022-08-12 12:11:57 +00:00
|
|
|
objectName: "gifPopupButton"
|
2022-07-05 10:12:27 +00:00
|
|
|
implicitHeight: 32
|
|
|
|
implicitWidth: 32
|
2023-10-18 09:03:32 +00:00
|
|
|
visible: !isEdit
|
2022-07-05 10:12:27 +00:00
|
|
|
icon.name: "gif"
|
|
|
|
icon.color: (hovered || highlighted) ? Theme.palette.primaryColor1
|
|
|
|
: Theme.palette.baseColor1
|
|
|
|
type: StatusQ.StatusFlatRoundButton.Type.Tertiary
|
|
|
|
color: "transparent"
|
2023-06-07 13:18:29 +00:00
|
|
|
highlighted: popup && popup.opened
|
|
|
|
onClicked: {
|
|
|
|
if (popup) {
|
|
|
|
popup.close()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
popup = gifPopupComponent.createObject(gifBtn)
|
|
|
|
popup.open()
|
|
|
|
}
|
2022-07-05 10:12:27 +00:00
|
|
|
}
|
2021-12-01 12:46:21 +00:00
|
|
|
|
2022-07-05 10:12:27 +00:00
|
|
|
StatusQ.StatusFlatRoundButton {
|
|
|
|
id: stickersBtn
|
2022-08-11 19:16:59 +00:00
|
|
|
objectName: "statusChatInputStickersButton"
|
2022-07-05 10:12:27 +00:00
|
|
|
implicitHeight: 32
|
|
|
|
implicitWidth: 32
|
|
|
|
width: visible ? 32 : 0
|
|
|
|
icon.name: "stickers"
|
|
|
|
icon.color: (hovered || highlighted) ? Theme.palette.primaryColor1
|
|
|
|
: Theme.palette.baseColor1
|
|
|
|
type: StatusQ.StatusFlatRoundButton.Type.Tertiary
|
|
|
|
visible: !isEdit && emojiBtn.visible
|
|
|
|
color: "transparent"
|
2023-06-07 13:18:29 +00:00
|
|
|
highlighted: d.stickersPopupOpened
|
2022-11-14 20:21:00 +00:00
|
|
|
onClicked: {
|
2023-06-07 13:18:29 +00:00
|
|
|
if (d.stickersPopupOpened) {
|
|
|
|
control.stickersPopup.close()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
d.stickersPopupOpened = true
|
|
|
|
control.stickersPopup.open()
|
2022-11-14 20:21:00 +00:00
|
|
|
}
|
2022-07-05 10:12:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-07 14:56:05 +00:00
|
|
|
}
|
2021-07-21 08:26:31 +00:00
|
|
|
}
|
2022-07-05 10:12:27 +00:00
|
|
|
}
|
2020-09-29 09:06:57 +00:00
|
|
|
}
|
2022-08-22 09:54:19 +00:00
|
|
|
}
|