doSend always doSendWithCallback

The goal of this change is to provide only one way of sending
messages. By default, a callback will always be returned, and
the caller will decide if it needs to use it.
This commit is contained in:
David Cormier 2013-10-27 12:03:45 -04:00
parent 8c51ab18d3
commit a3ea312773

View file

@ -203,12 +203,13 @@ weechat.factory('connection', ['$q', '$rootScope', '$log', '$store', 'handlers',
cb: defer cb: defer
} }
callBackIdString = "(" + currentCallBackId + ")"; callBackIdString = "(" + currentCallBackId + ")";
doSend(callBackIdString + " " + message);
return defer; return defer;
} }
var doSendWithCallback = function(message) { var doSendWithCallback = function(message) {
message.replace(/[\r\n]+$/g, "").split("\n");
var cb = createCallback(message); var cb = createCallback(message);
websocket.send(callBackIdString + " " + message);
return cb.promise; return cb.promise;
} }
@ -223,20 +224,15 @@ weechat.factory('connection', ['$q', '$rootScope', '$log', '$store', 'handlers',
var doSendAllWithCallback = function(messages) { var doSendAllWithCallback = function(messages) {
var promises = []; var promises = [];
for(i in messages) { for(i in messages) {
var cb = createCallback(messages[i]); var promise = doSendWithCallback(messages[i]);
promises.push(cb.promise); promises.push(promise);
}; };
return $q.all(promises); return $q.all(promises);
}; };
// Sanitizes messages to be sent to the weechat relay // Sanitizes messages to be sent to the weechat relay
var doSend = function(message) { var doSend = function(message) {
msgs = message.replace(/[\r\n]+$/g, "").split("\n"); doSendWithCallback(message);
for (var i = 0; i < msgs.length; i++) {
$log.log('=' + msgs[i] + '=');
$rootScope.commands.push("SENT: " + msgs[i]);
}
websocket.send(message);
} }
// Takes care of the connection and websocket hooks // Takes care of the connection and websocket hooks