Implement multi-account writing for sendbox

This commit is contained in:
miruka 2019-07-18 23:50:23 -04:00
parent 93bc2ff5a9
commit 2cf0864b18
3 changed files with 64 additions and 16 deletions

View File

@ -1,6 +1,9 @@
- Don't send a formatted_text if it's just `<p>plaintext</p>`
- 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

View File

@ -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()
})

View File

@ -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) {