[polari/wip/fmuellner/misc-cleanups: 5/12] accountsMonitor: Provide lookup function
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/fmuellner/misc-cleanups: 5/12] accountsMonitor: Provide lookup function
- Date: Sun, 7 Aug 2016 01:51:08 +0000 (UTC)
commit 8b7b65401a74a84cfdd3927a844148fbf3bcb822
Author: Florian Müllner <fmuellner gnome org>
Date: Sat Jul 30 17:02:47 2016 +0200
accountsMonitor: Provide lookup function
We are currently using TpSimpleClientFactory.ensure_account()
when we need to look up accounts, which is slightly dodgy as it
bypasses the account filtering in AccountsMonitor. To address
this, add a small wrapper around Map.get().
https://bugzilla.gnome.org/show_bug.cgi?id=769582
src/accountsMonitor.js | 4 ++++
src/application.js | 21 +++++++++------------
src/chatroomManager.js | 24 ++++++++----------------
3 files changed, 21 insertions(+), 28 deletions(-)
---
diff --git a/src/accountsMonitor.js b/src/accountsMonitor.js
index 6e466d5..30dc870 100644
--- a/src/accountsMonitor.js
+++ b/src/accountsMonitor.js
@@ -45,6 +45,10 @@ const AccountsMonitor = new Lang.Class({
return this._accountManager;
},
+ lookupAccount: function(accountPath) {
+ return this._accounts.get(accountPath);
+ },
+
_onPrepared: function(am, res) {
try {
am.prepare_finish(res);
diff --git a/src/application.js b/src/application.js
index 2968589..051a3c2 100644
--- a/src/application.js
+++ b/src/application.js
@@ -350,15 +350,13 @@ const Application = new Lang.Class({
},
_requestChannel: function(accountPath, targetType, targetId, time, callback) {
- // have this in AccountMonitor?
- let factory = Tp.AccountManager.dup().get_factory();
- let account = factory.ensure_account(accountPath, []);
+ let account = this._accountsMonitor.lookupAccount(accountPath);
- if (!account.enabled) {
+ if (!account || !account.enabled) {
// if we are requesting a channel for a disabled account, we
// are restoring saved channels; if the account has also never
// been online, it was removed since the channel was saved
- if (!account.has_been_online)
+ if (account && !account.has_been_online)
this._removeSavedChannelsForAccount(account);
return;
}
@@ -482,11 +480,12 @@ const Application = new Lang.Class({
_onJoinRoom: function(action, parameter) {
let [accountPath, channelName, time] = parameter.deep_unpack();
+ let account = this._accountsMonitor.lookupAccount(accountPath);
+ if (!account)
+ return;
+
this._requestChannel(accountPath, Tp.HandleType.ROOM,
channelName, time);
-
- let factory = Tp.AccountManager.dup().get_factory();
- let account = factory.ensure_account(accountPath, []);
this._addSavedChannel(account, channelName);
},
@@ -551,8 +550,7 @@ const Application = new Lang.Class({
_onRemoveConnection: function(action, parameter){
let accountPath = parameter.deep_unpack();
- let factory = Tp.AccountManager.dup().get_factory();
- let account = factory.ensure_account(accountPath, []);
+ let account = this._accountsMonitor.lookupAccount(accountPath);
account.set_enabled_async(false, Lang.bind(this,
function() {
let label = _("%s removed.").format(account.display_name);
@@ -574,8 +572,7 @@ const Application = new Lang.Class({
_onEditConnection: function(action, parameter) {
let accountPath = parameter.deep_unpack();
- let factory = Tp.AccountManager.dup().get_factory();
- let account = factory.ensure_account(accountPath, []);
+ let account = this._accountsMonitor.lookupAccount(accountPath);
let dialog = new Connections.ConnectionProperties(account);
dialog.transient_for = this._window;
dialog.connect('response', Lang.bind(this,
diff --git a/src/chatroomManager.js b/src/chatroomManager.js
index 3fe7726..8f9479f 100644
--- a/src/chatroomManager.js
+++ b/src/chatroomManager.js
@@ -283,8 +283,7 @@ const _ChatroomManager = new Lang.Class({
_onConnectAccountActivated: function(action, parameter) {
let accountPath = parameter.deep_unpack();
- let factory = Tp.AccountManager.dup().get_factory();
- let account = factory.ensure_account(accountPath, []);
+ let account = this._accountsMonitor.lookupAccount(accountPath);
account.request_presence_async(Tp.ConnectionPresenceType.AVAILABLE,
'available',
account.requested_status_message,
@@ -293,18 +292,13 @@ const _ChatroomManager = new Lang.Class({
_onReconnectAccountActivated: function(action, parameter) {
let accountPath = parameter.deep_unpack();
- let factory = Tp.AccountManager.dup().get_factory();
- let account = factory.ensure_account(accountPath, []);
- account.reconnect_async(Lang.bind(this,
- function (a, res){
- a.reconnect_finish(res);
- }));
+ let account = this._accountsMonitor.lookupAccount(accountPath);
+ account.reconnect_async((a, res) => { a.reconnect_finish(res); });
},
_onAuthenticateAccountActivated: function(action, parameter) {
let [accountPath, password] = parameter.deep_unpack();
- let factory = Tp.AccountManager.dup().get_factory();
- let account = factory.ensure_account(accountPath, []);
+ let account = this._accountsMonitor.lookupAccount(accountPath);
let prompt = new GLib.Variant('b', password.length > 0);
let params = GLib.Variant.new('a{sv}', { 'password-prompt': prompt });
@@ -320,10 +314,9 @@ const _ChatroomManager = new Lang.Class({
_onJoinActivated: function(action, parameter) {
let [accountPath, channelName, time] = parameter.deep_unpack();
- let factory = Tp.AccountManager.dup().get_factory();
- let account = factory.ensure_account(accountPath, []);
+ let account = this._accountsMonitor.lookupAccount(accountPath);
- if (!account.enabled)
+ if (!account || !account.enabled)
return;
let room = this._ensureRoom(account, channelName, Tp.HandleType.ROOM);
@@ -334,10 +327,9 @@ const _ChatroomManager = new Lang.Class({
_onQueryActivated: function(action, parameter) {
let [accountPath, channelName, message, time] = parameter.deep_unpack();
- let factory = Tp.AccountManager.dup().get_factory();
- let account = factory.ensure_account(accountPath, []);
+ let account = this._accountsMonitor.lookupAccount(accountPath);
- if (!account.enabled)
+ if (!account || !account.enabled)
return;
let room = this._ensureRoom(account, channelName, Tp.HandleType.CONTACT);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]