diff --git a/TODO.md b/TODO.md index b17a493d..2c20b7b4 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,9 @@ +- Don't send a formatted_text if it's just `

plaintext

` - Set Qt.application.* stuff from C++ - Devices and client settings in edit account page - Multiaccount aliases + - Warn when overwriting another alias + - Add an explanation tooltip - If avatar is set, name color from average color? - Accent color from background - Reduce messages ListView cacheBuffer height once http thumbnails diff --git a/src/qml/Chat/SendBox.qml b/src/qml/Chat/SendBox.qml index e369b8de..5f01502f 100644 --- a/src/qml/Chat/SendBox.qml +++ b/src/qml/Chat/SendBox.qml @@ -8,6 +8,12 @@ import "../Base" HRectangle { function setFocus() { textArea.forceActiveFocus() } + property var aliases: window.settings.write_aliases + property string writingUserId: chatPage.userId + property string toSend: "" + + property bool textChangedSinceLostFocus: false + id: sendBox Layout.fillWidth: true Layout.minimumHeight: theme.baseElementsHeight @@ -21,7 +27,7 @@ HRectangle { HUserAvatar { id: avatar - userId: chatPage.userId + userId: writingUserId } HScrollableTextArea { @@ -34,20 +40,58 @@ HRectangle { backgroundColor: "transparent" area.focus: true - property bool textChangedSinceLostFocus: false - function setTyping(typing) { py.callClientCoro( - chatPage.userId, + writingUserId, "room_typing", [chatPage.roomId, typing, 5000] ) } onTextChanged: { - setTyping(Boolean(text)) - textChangedSinceLostFocus = true + let foundAlias = null + + for (let [user, writing_alias] of Object.entries(aliases)) { + if (text.startsWith(writing_alias + " ")) { + writingUserId = user + foundAlias = new RegExp("^" + writing_alias + " ") + break + } + } + + if (foundAlias) { + toSend = text.replace(foundAlias, "") + setTyping(Boolean(text)) + textChangedSinceLostFocus = true + return + } + + writingUserId = Qt.binding(() => chatPage.userId) + toSend = text + + let vals = Object.values(aliases) + + let longestAlias = + vals.reduce((a, b) => a.length > b.length ? a: b) + + let textNotStartsWithAnyAlias = + ! vals.some(a => text.startsWith(a)) + + let textContainsCharNotInAnyAlias = + vals.every(a => text.split("").some(c => ! a.includes(c))) + + // Only set typing when it's sure that the user will not use + // an alias and has written something + if (toSend && + (text.length > longestAlias.length || + textNotStartsWithAnyAlias || + textContainsCharNotInAnyAlias)) + { + setTyping(Boolean(text)) + textChangedSinceLostFocus = true + } } + area.onEditingFinished: { // when lost focus if (text && textChangedSinceLostFocus) { setTyping(false) @@ -68,8 +112,9 @@ HRectangle { if (textArea.text === "") { return } - let args = [chatPage.roomId, textArea.text] - py.callClientCoro(chatPage.userId, "send_markdown", args) + let args = [chatPage.roomId, toSend] + py.callClientCoro(writingUserId, "send_markdown", args) + area.clear() }) diff --git a/src/qml/UI.qml b/src/qml/UI.qml index 66241bd0..582ca6eb 100644 --- a/src/qml/UI.qml +++ b/src/qml/UI.qml @@ -73,18 +73,18 @@ Item { id: initialRoomTimer interval: 4000 repeat: false - // onTriggered: pageStack.showRoom( - // "@test_mary:matrix.org", - // "Rooms", + onTriggered: pageStack.showRoom( + "@test_mary:matrix.org", + "Rooms", // "!TSXGsbBbdwsdylIOJZ:matrix.org" // st - // "!VDSsFIzQnXARSCVNxS:matrix.org" // hs + "!VDSsFIzQnXARSCVNxS:matrix.org" // hs // "Invites", // "!xjqvLOGhMVutPXpAqi:matrix.org" - // ) - onTriggered: pageStack.showPage( - "EditAccount/EditAccount", - {"userId": "@test_mary:matrix.org"} ) + // onTriggered: pageStack.showPage( + // "EditAccount/EditAccount", + // {"userId": "@test_mary:matrix.org"} + // ) } onCurrentItemChanged: if (currentItem) {