My favorites | English | Sign in

Faster apps faster - GWT 2.0 with Speed Tracer New!

opensocial.Activity (v0.7)

 SUMMARY     DETAIL

Class opensocial.Activity

Representation of an activity.

Activities are rendered with a title and an optional activity body.

You may set the title and body directly as strings when calling opensocial.createActivity.

However, it is usually beneficial to create activities using Activity Templates for the title and body. Activity Templates support:

  • Internationalization
  • Replacement variables in the message
  • Activity Summaries, which are message variations used to summarize repeated activities that share something in common.

Activity Templates are defined as messages in the gadget specification. To define messages, you create and reference message bundle XML files for each locale you support.

Example module spec in gadget XML:

<ModulePrefs title="ListenToThis">
  <Locale messages="http://www.listentostuff.com/messages.xml"/>
  <Locale lang="de" messages="http://www.listentostuff.com/messages-DE.xml"/>
</ModulePrefs>

Example message bundle:

<messagebundle>
 <msg name="LISTEN_TO_THIS_SONG">
    ${Subject.DisplayName} told ${Owner.DisplayName} to
    listen to a song!
 </msg>
</messagebundle>

You can set custom key/value string pairs when posting an activity. These values will be used for variable substitution in the templates.

Example JS call:

  var owner = ...;
  var viewer = ...;
  var activity = opensocial.newActivity({titleId : 'LISTEN_TO_THIS_SONG',
templateParams : {Song: 'Do That There - (Young Einstein hoo-hoo mix)',
Artist: 'Lyrics Born', Subject: viewer, Owner: owner}});

Associated message:

<msg name="LISTEN_TO_THIS_SONG">
    ${Subject.DisplayName} told ${Owner.DisplayName} to listen
    to ${Song} by ${Artist}
</msg>

People can also be set as values in key/value pairs when posting an activity. You can then reference the following fields on a person:

  • ${Person.DisplayName} The person's name
  • ${Person.Id} The user ID of the person
  • ${Person.ProfileUrl} The profile URL of the person
  • ${Person} This will show the display name, but containers may optionally provide special formatting, such as showing the name as a link

Users will have many activities in their activity streams, and containers will not show every activity that is visible to a user. To help display large numbers of activities, containers will summarize a list of activities from a given source to a single entry.

You can provide Activity Summaries to customize the text shown when multiple activities are summarized. If no customization is provided, a container may ignore your activities altogether or provide default text such as "Bob changed his status message + 20 other events like this."

  • Activity Summaries will always summarize around a specific key in a key/value pair. This is so that the summary can say something concrete (this is clearer in the example below).
  • Other variables will have synthetic "Count" variables created with the total number of items summarized.
  • Message ID of the summary is the message ID of the main template + ":" + the data key

Example summaries:

<messagebundle>
  <msg name="LISTEN_TO_THIS_SONG:Artist">
    ${Subject.Count} of your friends have suggested listening to songs
    by ${Artist}!
  </msg>
  <msg name="LISTEN_TO_THIS_SONG:Song">
    ${Subject.Count} of your friends have suggested listening to ${Song}
  !</msg>
  <msg name="LISTEN_TO_THIS_SONG:Subject">
   ${Subject.DisplayName} has recommended ${Song.Count} songs to you.
  </msg>
</messagebundle>

Activity Templates may only have the following HTML tags: <b>, <i>, <a>, <span>. The container also has the option to strip out these tags when rendering the activity.

See also: opensocial.newActivity(), opensocial.requestCreateActivity()

Method Summary

 String getField(key)
Gets the activity data that's associated with the specified key.
 String getId()
Gets an ID that can be permanently associated with this activity.
setField(key, data)
Sets data for this activity associated with the given key.
 

Method Detail

getField

String getField(key)
    Gets the activity data that's associated with the specified key.
    Parameters:
      String key - The key to get data for; see the Field class for possible values
    Returns:
      String The data

getId

String getId()
    Gets an ID that can be permanently associated with this activity.
    Returns:
      String The ID

setField

setField(key, data)
    Sets data for this activity associated with the given key.
    Parameters:
      String key - The key to set data for
      String data - The data to set

Documentation generated by JsDoc Toolkit 1.3.3