Skip to content

Commit

Permalink
Add keydown listeners for ctrl/alt + up/down to switch conversations
Browse files Browse the repository at this point in the history
This is related to some issues: signalapp#512, signalapp#1104, signalapp#3154.
This work is based on an existing closed PR (signalapp#2042) by @colefranz.
  • Loading branch information
Hyask committed Jul 26, 2019
1 parent cd8421c commit ab4f4c7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
48 changes: 48 additions & 0 deletions js/views/inbox_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
},
events: {
click: 'onClick',
keyup: 'switchConversation',
},
setupLeftPane() {
this.leftPaneView = new Whisper.ReactWrapperView({
Expand Down Expand Up @@ -206,6 +207,53 @@
onClick(e) {
this.closeRecording(e);
},
// switches the conversation with ctrl/alt + up/down
switchConversation(e) {
const keyCode = e.which || e.keyCode;
const conversations = getInboxCollection().models;
const currentConversation =
this.conversation_stack.lastConversation || conversations[0];
let currentConversationIndex = -1;

if (!e.ctrlKey && !e.altKey) {
return;
}

function _compare(a, b) {
if (a.cachedProps.lastUpdated < b.cachedProps.lastUpdated) {
return 1;
} else if (a.cachedProps.lastUpdated > b.cachedProps.lastUpdated) {
return -1;
} else if (a.cachedProps.name < b.cachedProps.name) {
return -1;
} else if (a.cachedProps.name > b.cachedProps.name) {
return 1;
}
return 0;
}
conversations.sort(_compare);

currentConversationIndex = conversations.findIndex(
conversation => conversation.id === currentConversation.id
);

// down key
if (
keyCode === 40 &&
currentConversationIndex + 1 < conversations.length
) {
this.openConversation(
conversations[currentConversationIndex + 1].id,
'Down key'
);
// up key
} else if (keyCode === 38 && currentConversationIndex > 0) {
this.openConversation(
conversations[currentConversationIndex - 1].id,
'Up key'
);
}
},
});

Whisper.ExpiredAlertBanner = Whisper.View.extend({
Expand Down
18 changes: 9 additions & 9 deletions ts/util/lint/exceptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@
"rule": "jQuery-$(",
"path": "js/views/inbox_view.js",
"line": " this.$('.left-pane-placeholder').append(this.leftPaneView.el);",
"lineNumber": 130,
"lineNumber": 131,
"reasonCategory": "usageTrusted",
"updated": "2019-03-08T23:49:08.796Z",
"reasonDetail": "Protected from arbitrary input"
Expand All @@ -558,7 +558,7 @@
"rule": "jQuery-append(",
"path": "js/views/inbox_view.js",
"line": " this.$('.left-pane-placeholder').append(this.leftPaneView.el);",
"lineNumber": 130,
"lineNumber": 131,
"reasonCategory": "usageTrusted",
"updated": "2019-03-08T23:49:08.796Z",
"reasonDetail": "Protected from arbitrary input"
Expand All @@ -567,7 +567,7 @@
"rule": "jQuery-$(",
"path": "js/views/inbox_view.js",
"line": " if (e && this.$(e.target).closest('.placeholder').length) {",
"lineNumber": 171,
"lineNumber": 172,
"reasonCategory": "usageTrusted",
"updated": "2019-03-08T23:49:08.796Z",
"reasonDetail": "Protected from arbitrary input"
Expand All @@ -576,7 +576,7 @@
"rule": "jQuery-$(",
"path": "js/views/inbox_view.js",
"line": " this.$('#header, .gutter').addClass('inactive');",
"lineNumber": 175,
"lineNumber": 176,
"reasonCategory": "usageTrusted",
"updated": "2019-03-08T23:49:08.796Z",
"reasonDetail": "Protected from arbitrary input"
Expand All @@ -585,7 +585,7 @@
"rule": "jQuery-$(",
"path": "js/views/inbox_view.js",
"line": " this.$('.conversation-stack').addClass('inactive');",
"lineNumber": 179,
"lineNumber": 180,
"reasonCategory": "usageTrusted",
"updated": "2019-03-08T23:49:08.796Z",
"reasonDetail": "Protected from arbitrary input"
Expand All @@ -594,7 +594,7 @@
"rule": "jQuery-$(",
"path": "js/views/inbox_view.js",
"line": " this.$('.conversation:first .menu').trigger('close');",
"lineNumber": 181,
"lineNumber": 182,
"reasonCategory": "usageTrusted",
"updated": "2019-03-08T23:49:08.796Z",
"reasonDetail": "Protected from arbitrary input"
Expand All @@ -603,7 +603,7 @@
"rule": "jQuery-$(",
"path": "js/views/inbox_view.js",
"line": " if (e && this.$(e.target).closest('.capture-audio').length > 0) {",
"lineNumber": 201,
"lineNumber": 202,
"reasonCategory": "usageTrusted",
"updated": "2019-03-08T23:49:08.796Z",
"reasonDetail": "Protected from arbitrary input"
Expand All @@ -612,7 +612,7 @@
"rule": "jQuery-$(",
"path": "js/views/inbox_view.js",
"line": " this.$('.conversation:first .recorder').trigger('close');",
"lineNumber": 204,
"lineNumber": 205,
"reasonCategory": "usageTrusted",
"updated": "2019-03-08T23:49:08.796Z",
"reasonDetail": "Protected from arbitrary input"
Expand Down Expand Up @@ -7904,4 +7904,4 @@
"reasonCategory": "falseMatch",
"updated": "2019-05-02T20:44:56.470Z"
}
]
]

0 comments on commit ab4f4c7

Please sign in to comment.