Create helper functions for initialization methods

This commit is contained in:
David Cormier 2014-02-17 21:15:10 -05:00
parent 3a5dfd5e94
commit 8c386f7553

View file

@ -269,12 +269,8 @@ function($rootScope,
var onopen = function () { var onopen = function () {
$log.info("Connected to relay"); var _initializeConnection = function(passwd) {
return ngWebsockets.sendAll([
// First command asks for the password and issues
// a version command. If it fails, it means the we
// did not provide the proper password.
ngWebsockets.sendAll([
weeChat.Protocol.formatInit({ weeChat.Protocol.formatInit({
password: passwd, password: passwd,
compression: noCompression ? 'off' : 'zlib' compression: noCompression ? 'off' : 'zlib'
@ -283,7 +279,46 @@ function($rootScope,
weeChat.Protocol.formatInfo({ weeChat.Protocol.formatInfo({
name: 'version' name: 'version'
}) })
]).then( ])
};
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({
path: 'buffer:gui_buffers(*)',
keys: ['local_variables,notify,number,full_name,short_name,title']
})
);
};
var _requestSync = function() {
return ngWebsockets.send(
weeChat.Protocol.formatSync({})
);
};
$log.info("Connected to relay");
// 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(
null, null,
function() { function() {
// Connection got closed, lets check if we ever was connected successfully // Connection got closed, lets check if we ever was connected successfully
@ -292,12 +327,7 @@ function($rootScope,
} }
); );
ngWebsockets.send( _requestBufferInfos().then(function(bufinfo) {
weeChat.Protocol.formatHdata({
path: 'buffer:gui_buffers(*)',
keys: ['local_variables,notify,number,full_name,short_name,title']
})
).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++) {
@ -311,25 +341,15 @@ function($rootScope,
}); });
// Send all the other commands required for initialization // Send all the other commands required for initialization
ngWebsockets.send( _requestHotlist().then(function(hotlist) {
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; $rootScope.connected = true;