blob: 80590b09969414acc05b7ceb4e89239c0c190ac6 [file]
#summary 'Sandworm' Newsfeed Module
#labels Importance-Useful,Phase-Requirements,Contents-Draft
[http://github.com/jamslevy/Melange/tree/master Source Code Repository]
<wiki:toc max_depth="3" />
= Introduction =
A framework for customizable news feeds for various entity kinds that can be formatted on various site pages. Each newsfeed includes a subscription link, and through a 'subscribe' url pattern is used to render XML feeds.
Because of the relatively simple nature of the initial project, some of the post-midterm development will include an auxiliary open source pubsub component meant to be deployed separately, and act as a hub allowing Melange instances to host chat, Google Wave updates, and other real-time activity.
= NewsFeed Model =
An individual FeedItem entity is created for each news feed update. A garbage collection task will delete old feed items, so they don't take over the datastore.
The FeedItem model contains the following properties:
* *sender* (db.Key) - The sender is the entity that was updated
* *receivers* (db.Key) - A list of entities whose news feed is being updated.
* *update_type* (created, deleted, modified)
* *created* (datetime)
A FeedItem is created for each sender-receiver pair. For instance, if a document is created and saved, it is the sender while its associated project and program and user could all be receivers.
= Logic =
Newsfeed logic consists of two public methods:
* *addToFeed* takes a sender entity, a list of receiver entities, an update type, and an optional payload (like a text preview of a document). It adds all the receivers to a FeedItem with the specified payload:
{{{
for receiver in receivers:
new_feed_item = soc.models.news_feed.FeedItem(
sender_key= str(sender.key()),
receiver_key = str(receiver.key()),
user = user,
update_type = update_type
)
}}}
* *retrieveFeed* takes a receiever entity, and retrieves it's latest news feed updates, with an optional count kwarg. This method is cached, with a cache handler in the /cache folder.
{{{
def retrieveFeed(self, entity, count=10):
""" Retrieves feed for a given entity
"""
feed_items = soc.models.news_feed.FeedItem.all().filter(
"receiver_key =", str(entity.key())).fetch(1000)
return feed_items[:count]
}}}
= Views =
The newsfeed template itself is simply a table modeled after the blog template that lists each news feed update, which is added to the context dict through the retrieveFeed method.
= Subscribe via RSS =
I've added a new url_path 'subscribe', so that a URL for requesting an ATOM feed would look like this:
http://melange.appspot.com/site/subscribe/somesite
The new URL pattern is configured in soc.views.helper.params:
{{{
if params.get('subscribe'):
new_params['django_patterns_defaults'] += [
(r'^%(url_name)s/(?P<access_type>subscribe)/%(key_fields)s$',
'%(module_package)s.%(module_name)s.subscribe',
'Subscribe to %(name_plural)s')]
}}}
This address is added to pages with a meta tag:
<link rel="alternate" type="application/rss+xml" title="RSS" href="{{ feed_url }}"/>
There is also a graphic subscribe icon on the corner of the newsfeed GUI module.
The 'subscribe' path will also be the interface for any PubSub interactions, but those will only be activated on POST requests with a callback URL, otherwise the ATOM feed will be returned as normal.
== E-mail Notification Task ==
When a feed item is created, it schedules a handler to send out e-mail notification. This handler calls the sendFeedItemEmailNotifications method that fetches a list of users who are subscribed to the sender entity and e-mails them.
(This results in an OverQuota Error for more than a few people, and since it's in a task, it refreshes and starts e-mailing people again! The solution is to put the mail_dispatcher sendMessage method into a task, so all e-mails are sent via tasks and don't risk mass-spamming when a request fails.)
== User Subscriptions ==
The subscriptions model contains a relational index entity for the user, containing a list of entity keys that the user is subscribed to. From their edit_profile page, the user can set a global preference for whether they are accepting e-mail notifications, and the user can also configure individual entity preferences from those pages using the subscribe-by-star UI pattern.
== PubSubHubbub Support ==
<wiki:video url="http://www.youtube.com/watch?v=ewQBgbysSOQ"/>
This demo demonstrates Google Reader updating in seconds after a blog is updated.
It should be fairly trivial to integrate push notification support, and abstract it so that it could also be accessed by other Melange features.
= Feedback =
** Before I continue to develop detailed specs and continue coding, I'd like to get some feedback about what Melange users would like to see from a news feed. Specifically, the following types of feedback:
* Which entity types would you most like to have a newsfeed (for instance, programs, organizations, clubs, users, etc.)
* What's more important to you - having the news feed contain detailed information about updates, or having an easy way to export the newsfeed to an external feed reader?
* Are there any things you'd like to see in a news feed aside from updates about recently updated entities?