[polari/wip/fmuellner/misc-cleanups: 4/12] accountsMonitor: Add enabledAccounts convenience getter
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/fmuellner/misc-cleanups: 4/12] accountsMonitor: Add enabledAccounts convenience getter
- Date: Sun, 7 Aug 2016 01:51:03 +0000 (UTC)
commit bca01d865ba5557145987534c2e4b4e3990cb0d5
Author: Florian Müllner <fmuellner gnome org>
Date: Thu Aug 4 01:53:24 2016 +0200
accountsMonitor: Add enabledAccounts convenience getter
It is common enough to filter out disabled accounts to add a convenience
getter function that takes care of the filtering.
https://bugzilla.gnome.org/show_bug.cgi?id=769582
src/accountsMonitor.js | 4 ++++
src/application.js | 5 +----
src/joinDialog.js | 9 +++------
src/mainWindow.js | 11 ++++-------
4 files changed, 12 insertions(+), 17 deletions(-)
---
diff --git a/src/accountsMonitor.js b/src/accountsMonitor.js
index 71ecb9c..6e466d5 100644
--- a/src/accountsMonitor.js
+++ b/src/accountsMonitor.js
@@ -37,6 +37,10 @@ const AccountsMonitor = new Lang.Class({
return [...this._accounts.values()];
},
+ get enabledAccounts() {
+ return [...this._accounts.values()].filter(a => a.enabled);
+ },
+
get accountManager() {
return this._accountManager;
},
diff --git a/src/application.js b/src/application.js
index 6254fbc..2968589 100644
--- a/src/application.js
+++ b/src/application.js
@@ -177,10 +177,7 @@ const Application = new Lang.Class({
_openURIs: function(uris, time) {
let map = {};
- this._accountsMonitor.accounts.forEach(function(a) {
- if (!a.enabled)
- return;
-
+ this._accountsMonitor.enabledAccounts.forEach(a => {
let params = a.dup_parameters_vardict().deep_unpack();
map[a.get_object_path()] = {
server: params.server.deep_unpack(),
diff --git a/src/joinDialog.js b/src/joinDialog.js
index 6e23c2a..9e6e2b4 100644
--- a/src/joinDialog.js
+++ b/src/joinDialog.js
@@ -61,12 +61,9 @@ const JoinDialog = new Lang.Class({
this._roomManager = ChatroomManager.getDefault();
this._accounts = {};
- this._accountsMonitor.accounts.forEach(Lang.bind(this,
- function(a) {
- if (!a.enabled)
- return;
- this._accounts[a.display_name] = a;
- }));
+ this._accountsMonitor.enabledAccounts.forEach(a => {
+ this._accounts[a.display_name] = a;
+ });
this._accountAddedId =
this._accountsMonitor.connect('account-added', Lang.bind(this,
function(am, account) {
diff --git a/src/mainWindow.js b/src/mainWindow.js
index bd9a664..f8088d9 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -154,13 +154,10 @@ const MainWindow = new Lang.Class({
}));
this._accountsMonitor = AccountsMonitor.getDefault();
- this._accountsMonitor.connect('accounts-changed', Lang.bind(this,
- function(am) {
- let accounts = am.accounts;
- this._roomListRevealer.reveal_child = accounts.some(function(a) {
- return a.enabled;
- });
- }));
+ this._accountsMonitor.connect('accounts-changed', () => {
+ let hasAccounts = this._accountsMonitor.enabledAccounts.length > 0;
+ this._roomListRevealer.reveal_child = hasAccounts;
+ });
this._roomManager = ChatroomManager.getDefault();
this._roomManager.connect('active-changed',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]