Tell Me More: About the Code to Create Feed Items

In the code for the DeliveryTrakr Web application, the shipment.js file contains the logic to create the various feed items.

Creating a Canvas Feed Item

This code snippet from the onGetPayload function creates a feed item of type CanvasPost. As you can see, it dynamically sets all the post values and retrieves information about the canvas app, such as the namespace and developerName, from the signed request. You can also pass in parameters that are appended to the URL and used in the canvas app feed item.
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17else if ("approval" === action) 
18{
19    p.feedItemType = "CanvasPost";
20    p.auxText = "Please confirm this shipment status: " + 
21        shipments[shipment].description;
22    p.namespace =  sr.context.application.namespace;
23    p.developerName =  sr.context.application.developerName;
24    p.thumbnailUrl = "https://cdn1.iconfinder.com/data/icons/
25        VISTA/project_managment/png/48/deliverables.png";
26    p.parameters =  "{\"shipment\":\"" + shipment + "\"}";
27    p.title = shipments[shipment].description;
28    p.description = "This is a travel shipment for Shipment - " + 
29        shipments[shipment].description + 
30        ".  Click the link to open the canvas app.";
31}

Enabling the Share Button

This code snippet is from the draw function. After this statement is called, the Share button is enabled. This ensures that the user can’t create a feed item until they have selected all the required elements for the canvas app.
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17$$.client.publish(sr.client, {
18    name : 'publisher.setValidForSubmit', 
19    payload : true});

Publishing the Feed Item

When the user clicks the Share button, this code snippet publishes the feed item to the feed. The type of feed item it creates depends on which type you select: text, link, or canvas.
1swfobject.registerObject("clippy.codeblock-2", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17$$.client.publish(sr.client, {name : 'publisher.setPayload', 
18    payload : p});