Add keys for direct room switching (#209)

* Add Keys.Rooms.Direct configuration

Keybinding to jump to specific room id in specific account id, or the
first occurence of specific room id in any account.

* Default binding was a bad idea

This example binding was preventing the user from binding Ctrl+G,Ctrl+M
to something else.

* Use const instead of var

* Use showItemAtIndex for direct room switching

This is a simpler implementation that better fits in the existing
codebase and doesn't really have drawbacks.

* Use existing findIndex

From roomList.model. Instead of reinventing it

* Made example not a real room

Earlier I made it point to the Mirage room

* Add instructions for copying room ID

After noticing that these IDs do not match Matrix room addresses, I felt
it was necessary to explain this here, even if it's already explained in
other parts of the configuration file.

* Use .split(" ") for splitting descriptions

This is a more readable implementation.

* Fix shortcuts breaking on config reload

Wrapping HShortcut in Loader makes it destructible.
See d53978f62bab35cdc7e115c50f0571f736814582

* Cleanup showRoomByDescription method, now showById

- "Room description" is a vague, it sounds like this is about
  the room topic too. Instead of having a function that takes a
  string with a certain format, take explicit arguments for the user and
  room ID, this way we don't need comments to explain what's going on
  either

- Reduce indentations and {} noise to make it simpler to read

* More details for direct room binds config comment

Co-authored-by: miruka <miruka@disroot.org>
This commit is contained in:
Maze 2021-04-15 23:47:08 +02:00 committed by miruka
parent 61996400d0
commit b6773c724e
2 changed files with 42 additions and 0 deletions

View File

@ -376,6 +376,17 @@ class Keys:
9 = [Keys.alt_or_cmd() + "+9"]
10 = [Keys.alt_or_cmd() + "+0"]
class Direct:
# Switch to specific rooms with keybindings.
# An unlimited number of properties can be added, where each
# property maps a room to a list of keybind.
# A room's ID can be copied by right clicking on it in the room list.
"!roomID:example.org" = []
# If you have multiple accounts in the same room, you can also set
# which account should be targeted as "<userId> <roomId>":
"@account:example.org !roomID:example.org" = []
class Chat:
# Keybinds specific to the current chat page.

View File

@ -73,6 +73,27 @@ HListView {
keepListCentered = true
}
function showById(roomId, accountId=null) {
// If only a room ID is passed, first account with this room is used
if (accountId === null) {
const roomIndex = model.findIndex(roomId)
roomIndex === null ?
console.warn("No account with such room ID:", roomId) :
showItemAtIndex(roomIndex)
return
}
if (! (accountId in accountIndice)) {
console.warn("No such account:", accountId)
return
}
pageLoader.showRoom(accountId, roomId)
startCorrectItemSearch()
}
function showAccountRoomAtIndex(index) {
const item = model.get(currentIndex === -1 ? 0 : currentIndex)
@ -284,6 +305,16 @@ HListView {
}
}
Instantiator {
model: Object.keys(window.settings.Keys.Rooms.Direct)
delegate: Loader {
sourceComponent: HShortcut {
sequences: window.settings.Keys.Rooms.Direct[modelData]
onActivated: showById(...modelData.split(/\s+/).reverse())
}
}
}
Rectangle {
anchors.fill: parent
z: -100