On Tue, Dec 09, 2008 at 10:34:01AM -0800, Adam Winer wrote:
On Tue, Dec 9, 2008 at 7:46 AM, jochen delqi [EMAIL PROTECTED] wrote:
Hi guys,
I'm wondering about how to implement the
opensocial.Container.prototype.requestSendMessage service.
At the moment, you'd need to override requestSendMessage() in a custom
subclass.
I think, though, the default implementation should really be to send
an RPC to the containing page
Given the place the message service has in the spec, pretty much
side to side with the people, activities and app data services, I
think it's much more likely that most containers will want to
implement the javascript side of it by way of a data request call,
just as all calls to the other services are done.
And that in turn means something more along the lines of
--
JsonRpcContainer.prototype.requestSendMessage = function(recipients, message,
opt_callback, opt_params) {
opt_callback = opt_callback || function(){};
opt_params = opt_params || {};
var req = opensocial.newDataRequest();
var viewer = new opensocial.IdSpec({'userId' : 'VIEWER'});
req.add(this.newCreateMessageRequest(viewer, recipients, message,
opt_params), 'key');
req.send(function(response) {
opt_callback(response.get('key'));
});
}
JsonRpcContainer.prototype.newCreateMessageRequest = function(idSpec,
recipients, message, params) {
var rpc = { method : message.post };
rpc.params = this.translateIdSpec(idSpec);
rpc.params.appId = @app;
if (idSpec.getField('networkDistance')) {
rpc.params.networkDistance = idSpec.getField('networkDistance');
}
rpc.params.message = message.toJsonObject();
rpc.params.message[recipients] =
this.translateIdSpec(this.makeIdSpec(recipients))[userId];
return new JsonRpcRequestItem(rpc);
};
--
But don't just apply that as a patch to jsconcontainer.js, because it
depends on the not-yet-ready changes to the message object.