Send init commands when connection is successful

Initialization commands are sent when we are sure that
the password has been accepted and that the init has been
processed by the weechat relay
This commit is contained in:
David Cormier 2014-02-17 21:18:33 -05:00
parent 8c386f7553
commit ba20a79c72

View file

@ -269,6 +269,8 @@ function($rootScope,
var onopen = function () { var onopen = function () {
// Helper methods for initialization commands
var _initializeConnection = function(passwd) { var _initializeConnection = function(passwd) {
return ngWebsockets.sendAll([ return ngWebsockets.sendAll([
weeChat.Protocol.formatInit({ weeChat.Protocol.formatInit({
@ -313,20 +315,14 @@ function($rootScope,
); );
}; };
$log.info("Connected to relay");
// First command asks for the password and issues // First command asks for the password and issues
// a version command. If it fails, it means the we // a version command. If it fails, it means the we
// did not provide the proper password. // did not provide the proper password.
_initializeConnection(passwd).then( _initializeConnection(passwd).then(
null,
function() { function() {
// Connection got closed, lets check if we ever was connected successfully // Connection is successful
if(!$rootScope.waseverconnected) // Send all the other commands required for initialization
$rootScope.passwordError = true;
}
);
_requestBufferInfos().then(function(bufinfo) { _requestBufferInfos().then(function(bufinfo) {
var bufferInfos = bufinfo.objects[0].content; var bufferInfos = bufinfo.objects[0].content;
// buffers objects // buffers objects
@ -340,7 +336,6 @@ function($rootScope,
} }
}); });
// Send all the other commands required for initialization
_requestHotlist().then(function(hotlist) { _requestHotlist().then(function(hotlist) {
handlers.handleHotlistInfo(hotlist); handlers.handleHotlistInfo(hotlist);
}); });
@ -350,8 +345,15 @@ function($rootScope,
}); });
_requestSync(); _requestSync();
$log.info("Connected to relay");
$rootScope.connected = true; $rootScope.connected = true;
},
function() {
// Connection got closed, lets check if we ever was connected successfully
if(!$rootScope.waseverconnected)
$rootScope.passwordError = true;
}
);
}; };