Merge connection initialization method

with-route-provider
David Cormier 12 years ago
commit 518d56299b
  1. 96
      js/glowingbear.js

@ -272,35 +272,68 @@ function($rootScope,
var onopen = function () { var onopen = function () {
$log.info("Connected to relay");
// First command asks for the password and issues // Helper methods for initialization commands
// a version command. If it fails, it means the we var _initializeConnection = function(passwd) {
// did not provide the proper password.
ngWebsockets.sendAll([ // This is not the proper way to do this.
// WeeChat does not send a confirmation for the init.
// Until it does, We need to "assume" that formatInit
// will be received before formatInfo
ngWebsockets.send(
weeChat.Protocol.formatInit({ weeChat.Protocol.formatInit({
password: passwd, password: passwd,
compression: noCompression ? 'off' : 'zlib' compression: noCompression ? 'off' : 'zlib'
}), })
);
return ngWebsockets.send(
weeChat.Protocol.formatInfo({ weeChat.Protocol.formatInfo({
name: 'version' name: 'version'
}) })
]).then(
null,
function() {
// Connection got closed, lets check if we ever was connected successfully
if(!$rootScope.waseverconnected)
$rootScope.passwordError = true;
}
); );
};
ngWebsockets.send( var _requestHotlist = function() {
return ngWebsockets.send(
weeChat.Protocol.formatHdata({
path: "hotlist:gui_hotlist(*)",
keys: []
})
);
};
var _requestNicklist = function() {
return ngWebsockets.send(
weeChat.Protocol.formatNicklist({
})
);
};
var _requestBufferInfos = function() {
return ngWebsockets.send(
weeChat.Protocol.formatHdata({ weeChat.Protocol.formatHdata({
path: 'buffer:gui_buffers(*)', path: 'buffer:gui_buffers(*)',
keys: ['local_variables,notify,number,full_name,short_name,title'] keys: ['local_variables,notify,number,full_name,short_name,title']
}) })
).then(function(bufinfo) { );
};
var _requestSync = function() {
return ngWebsockets.send(
weeChat.Protocol.formatSync({})
);
};
// First command asks for the password and issues
// a version command. If it fails, it means the we
// did not provide the proper password.
_initializeConnection(passwd).then(
function() {
// Connection is successful
// Send all the other commands required for initialization
_requestBufferInfos().then(function(bufinfo) {
var bufferInfos = bufinfo.objects[0].content; var bufferInfos = bufinfo.objects[0].content;
// buffers objects // buffers objects
for (var i = 0; i < bufferInfos.length ; i++) { for (var i = 0; i < bufferInfos.length ; i++) {
@ -309,36 +342,31 @@ function($rootScope,
// Switch to first buffer on startup // Switch to first buffer on startup
if (i === 0) { if (i === 0) {
models.setActiveBuffer(buffer.id); models.setActiveBuffer(buffer.id);
// Set setActiveBuffer emits a signal (activeBufferChanged)
// The $rootScope.$on('activeBuffer...' should take care of
// changing the buffer. However, and for a reason that I ignore
// this signal is not sent on initialization
$rootScope.connected = true;
$location.path(buffer.fullName); $location.path(buffer.fullName);
} }
} }
}); });
// Send all the other commands required for initialization _requestHotlist().then(function(hotlist) {
ngWebsockets.send(
weeChat.Protocol.formatHdata({
path: "hotlist:gui_hotlist(*)",
keys: []
})
).then(function(hotlist) {
handlers.handleHotlistInfo(hotlist); handlers.handleHotlistInfo(hotlist);
}); });
ngWebsockets.send( _requestNicklist().then(function(nicklist) {
weeChat.Protocol.formatNicklist({
})
).then(function(nicklist) {
handlers.handleNicklist(nicklist); handlers.handleNicklist(nicklist);
}); });
ngWebsockets.send( _requestSync();
weeChat.Protocol.formatSync({})
$rootScope.connected = true;
},
function() {
// Connection got closed, lets check if we ever was connected successfully
if(!$rootScope.waseverconnected)
$rootScope.passwordError = true;
}
); );
}; };

Loading…
Cancel
Save