diff --git a/src/qml/Base/HRateLimiter.qml b/src/qml/Base/HRateLimiter.qml new file mode 100644 index 00000000..217b607b --- /dev/null +++ b/src/qml/Base/HRateLimiter.qml @@ -0,0 +1,46 @@ +import QtQuick 2.12 + +QtObject { + property int cooldown: 250 + property bool extendOnRequestWhileCooldownActive: false + + property bool firePending: false + + readonly property Timer timer: Timer { + property bool extended: false + + interval: cooldown + onTriggered: { + if (firePending) { + if (extendOnRequestWhileCooldownActive && ! extended) { + firePending = false + extended = true + running = true + return + } + + fired() + firePending = false + extended = false + } else if (extended) { + fired() + extended = false + } + } + } + + + signal requestFire() + signal fired() + + onRequestFire: { + if (timer.running) { + firePending = true + return + } + + fired() + firePending = false + timer.running = true + } +} diff --git a/src/qml/SidePane/AccountRoomList.qml b/src/qml/SidePane/AccountRoomList.qml index 1405355a..c1edfb40 100644 --- a/src/qml/SidePane/AccountRoomList.qml +++ b/src/qml/SidePane/AccountRoomList.qml @@ -52,12 +52,13 @@ HListView { function previous() { decrementCurrentIndex() - currentItem.item.activate() + activateLimiter.requestFire() + } function next() { incrementCurrentIndex() - currentItem.item.activate() + activateLimiter.requestFire() } function toggleCollapseAccount() { @@ -91,4 +92,11 @@ HListView { source: "Delegate" + (model.type == "Account" ? "Account.qml" : "Room.qml") } + + + HRateLimiter { + id: activateLimiter + onFired: currentItem.item.activate() + extendOnRequestWhileCooldownActive: true + } }