Implement multi-account writing for sendbox
This commit is contained in:
parent
93bc2ff5a9
commit
2cf0864b18
3
TODO.md
3
TODO.md
|
@ -1,6 +1,9 @@
|
||||||
|
- Don't send a formatted_text if it's just `<p>plaintext</p>`
|
||||||
- Set Qt.application.* stuff from C++
|
- Set Qt.application.* stuff from C++
|
||||||
- Devices and client settings in edit account page
|
- Devices and client settings in edit account page
|
||||||
- Multiaccount aliases
|
- Multiaccount aliases
|
||||||
|
- Warn when overwriting another alias
|
||||||
|
- Add an explanation tooltip
|
||||||
- If avatar is set, name color from average color?
|
- If avatar is set, name color from average color?
|
||||||
- Accent color from background
|
- Accent color from background
|
||||||
- Reduce messages ListView cacheBuffer height once http thumbnails
|
- Reduce messages ListView cacheBuffer height once http thumbnails
|
||||||
|
|
|
@ -8,6 +8,12 @@ import "../Base"
|
||||||
HRectangle {
|
HRectangle {
|
||||||
function setFocus() { textArea.forceActiveFocus() }
|
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
|
id: sendBox
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.minimumHeight: theme.baseElementsHeight
|
Layout.minimumHeight: theme.baseElementsHeight
|
||||||
|
@ -21,7 +27,7 @@ HRectangle {
|
||||||
|
|
||||||
HUserAvatar {
|
HUserAvatar {
|
||||||
id: avatar
|
id: avatar
|
||||||
userId: chatPage.userId
|
userId: writingUserId
|
||||||
}
|
}
|
||||||
|
|
||||||
HScrollableTextArea {
|
HScrollableTextArea {
|
||||||
|
@ -34,20 +40,58 @@ HRectangle {
|
||||||
backgroundColor: "transparent"
|
backgroundColor: "transparent"
|
||||||
area.focus: true
|
area.focus: true
|
||||||
|
|
||||||
property bool textChangedSinceLostFocus: false
|
|
||||||
|
|
||||||
function setTyping(typing) {
|
function setTyping(typing) {
|
||||||
py.callClientCoro(
|
py.callClientCoro(
|
||||||
chatPage.userId,
|
writingUserId,
|
||||||
"room_typing",
|
"room_typing",
|
||||||
[chatPage.roomId, typing, 5000]
|
[chatPage.roomId, typing, 5000]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
setTyping(Boolean(text))
|
let foundAlias = null
|
||||||
textChangedSinceLostFocus = true
|
|
||||||
|
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
|
area.onEditingFinished: { // when lost focus
|
||||||
if (text && textChangedSinceLostFocus) {
|
if (text && textChangedSinceLostFocus) {
|
||||||
setTyping(false)
|
setTyping(false)
|
||||||
|
@ -68,8 +112,9 @@ HRectangle {
|
||||||
|
|
||||||
if (textArea.text === "") { return }
|
if (textArea.text === "") { return }
|
||||||
|
|
||||||
let args = [chatPage.roomId, textArea.text]
|
let args = [chatPage.roomId, toSend]
|
||||||
py.callClientCoro(chatPage.userId, "send_markdown", args)
|
py.callClientCoro(writingUserId, "send_markdown", args)
|
||||||
|
|
||||||
area.clear()
|
area.clear()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -73,18 +73,18 @@ Item {
|
||||||
id: initialRoomTimer
|
id: initialRoomTimer
|
||||||
interval: 4000
|
interval: 4000
|
||||||
repeat: false
|
repeat: false
|
||||||
// onTriggered: pageStack.showRoom(
|
onTriggered: pageStack.showRoom(
|
||||||
// "@test_mary:matrix.org",
|
"@test_mary:matrix.org",
|
||||||
// "Rooms",
|
"Rooms",
|
||||||
// "!TSXGsbBbdwsdylIOJZ:matrix.org" // st
|
// "!TSXGsbBbdwsdylIOJZ:matrix.org" // st
|
||||||
// "!VDSsFIzQnXARSCVNxS:matrix.org" // hs
|
"!VDSsFIzQnXARSCVNxS:matrix.org" // hs
|
||||||
// "Invites",
|
// "Invites",
|
||||||
// "!xjqvLOGhMVutPXpAqi:matrix.org"
|
// "!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) {
|
onCurrentItemChanged: if (currentItem) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user