Move message handling in RPC responses out of individual commands and to a general property of the response.
This commit is contained in:
16
api.py
16
api.py
@@ -94,11 +94,21 @@ class APIWrapper(webapp2.RequestHandler):
|
||||
@security.weak_security_checks
|
||||
@session.session_required
|
||||
def post(self):
|
||||
ret = []
|
||||
ret = {
|
||||
'status': 'ok',
|
||||
'responses': [],
|
||||
'messages': [],
|
||||
}
|
||||
for command in self.request_json['commands']:
|
||||
callback = self._COMMANDS[command['command']]
|
||||
result = callback(self.verified_google_user, self.client, command.get('arguments', {}))
|
||||
ret.append(result)
|
||||
result = callback(
|
||||
self.verified_google_user,
|
||||
self.client,
|
||||
command.get('arguments', {}))
|
||||
# Magic: if result contains "messages", haul them up a level so the
|
||||
# client can see them as a single stream.
|
||||
ret['messages'].extend(result.pop('messages', []))
|
||||
ret['responses'].append(result)
|
||||
return ret
|
||||
|
||||
|
||||
|
||||
@@ -75,10 +75,7 @@ def session_required(handler):
|
||||
else:
|
||||
self.client = models.Client.FromGoogleUser(self.verified_google_user)
|
||||
|
||||
ret = {
|
||||
'status': 'ok',
|
||||
'responses': handler(self),
|
||||
}
|
||||
ret = handler(self)
|
||||
if client_key != self.client.key():
|
||||
# Tell the client that this changed
|
||||
ret['client_id'] = auth.Sign(self.client.key())
|
||||
|
||||
@@ -136,6 +136,9 @@ cosmopolite.Client.prototype.sendRPCs_ = function(commands, delay) {
|
||||
this.$.proxy(commands[i]['onSuccess'], this)(data.responses[i]);
|
||||
}
|
||||
}
|
||||
// Handle messages that were immediately available as if they came over the
|
||||
// channel.
|
||||
data['messages'].forEach(this.onServerMessage_, this);
|
||||
})
|
||||
.fail(function(xhr) {
|
||||
var intDelay =
|
||||
@@ -181,9 +184,6 @@ cosmopolite.Client.prototype.onCreateChannel_ = function(data) {
|
||||
onmessage: this.$.proxy(this.onSocketMessage_, this),
|
||||
onerror: this.$.proxy(this.onSocketError_, this),
|
||||
});
|
||||
// Handle messages that were immediately available as if they came over the
|
||||
// channel.
|
||||
data['messages'].forEach(this.onServerMessage_, this);
|
||||
};
|
||||
|
||||
cosmopolite.Client.prototype.onSocketOpen_ = function() {
|
||||
|
||||
Reference in New Issue
Block a user