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