Re: how to implement requestsendmessage

2008-12-09 Thread Adam Winer
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, something like:

opensocial.Container.prototype.requestSendMessage = function(recipients,
message, opt_callback, opt_params) {
  // Save for later invocation (not shown here...)
  this.sendMessageCallback _ = opt_callback;
  gadgets.rpc.call(null, request_send_message, null, recipients,
message, opt_params);
}



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.
 What we want to do is just send a message as soon as a gadget asks us with
 the requestSendMessage method.

 However, in container.js this returns a not-implemented response. How do we
 redirect it to use the createMessage function in MessagesService on the
 server side ?

 Thanks!



Re: how to implement requestsendmessage

2008-12-09 Thread Rodrigo Gallardo
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.