travis-ci/travis-core — pull request #121 by svenfuchs (2012-10-17 21:57:46+00:00)
Title: Introducing broadcasts

this is the foundation for a broadcasts feature which allows to send notify people about certain events manually

the ui might look like this, basically re-using the new flash messages, but with some twists:

![](http://s3itch.svenfuchs.com/feature_broadcasts-20121017-234713.jpg)

the schema looks like this:

```
create_table "broadcasts", :force => true do |t|
t.integer "recipient_id"
t.string "recipient_type"
t.string "message"
t.boolean "expired"
t.datetime "created_at"
end
```

i.e. broadcasts **can** have a recipient but do not need to. they also can be manually expired, but do not need to.

when the client loads the current_user (i.e. the user either signs in or still is signed in and is re-loaded) then the client will check for broadcasts that are adressed at this user.

a broadcast is addressed at a user when:

* it does not have a recipient (i.e. global broadcasts)
* it is addressed at the user itself
* it is addressed at an organization where the user is a member
* it is addressed at a repository where the user has any permissions
* it is not expired
* it is not older than 2 weeks

broadcasts that are addressed at the user will be displayed as flash-message-style messages.

if the user clicks on the [x] close icon then the client takes a note about that in the browser's localStorage (i.e. saved on the disk, but not shared across computers, this is a compromise) and won't display the broadcast again. this is similar to how github broadcasts work.

further improvements:

* add pusher messages so that broadcasts will be sent to users who currently are signed in and visiting the site
* add an admin UI to travis-admin so that we can manage broadcasts conveniently
* re-use the same functionality in emails, i.e. add the last active broadcast to email notifications (this only works well for global broadcasts and broadcasts where the recipient is a repository, because we can't map comitter/author emails to users reliably)
* possibly add a feature to "refresh" broadcasts periodically (e.g. "please remember to donate" ;)