forked from sudara/alonetone
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
205 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
class AssetMailer < ActionMailer::Base | |||
|
|||
|
|||
def upload_notification(asset, emails, sent_at = Time.now) | |||
subject "[alonetone] '#{asset.user.name}' uploaded a new track!" | |||
recipients '' | |||
from 'noreply@alonetone.com' | |||
bcc emails.join(', ') | |||
sent_on sent_at | |||
body :track => asset.name, | |||
:name => asset.user.name, | |||
:download_link => download_link_for(asset), | |||
:play_link => play_link_for(asset), | |||
:user_link => user_link_for(asset), | |||
:exclamation => ["Sweet", "Yes", "Oooooh", "Alright", "Booya", "Yum","Celebrate", "OMG"] | |||
end | |||
|
|||
protected | |||
|
|||
def user_link_for(asset) | |||
'http://' + ALONETONE.url + '/' + asset.user.login | |||
end | |||
|
|||
def play_link_for(asset) | |||
user_link_for(asset) + '/tracks/' + asset.id.to_s | |||
end | |||
|
|||
def download_link_for(asset) | |||
play_link_for(asset) + '.mp3?source=email' | |||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
class AssetObserver < ActiveRecord::Observer | |||
def after_create(asset) | |||
if followers_exist_for?(asset) | |||
AssetMailer.deliver_upload_notification(asset,emails_of_followers(asset)) | |||
end | |||
end | |||
|
|||
protected | |||
|
|||
def followers_exist_for?(asset) | |||
emails_of_followers(asset).size > 0 | |||
end | |||
|
|||
def emails_of_followers(asset) | |||
followers_of(asset).inject([]) do |emails, follower| | |||
emails << follower.email if user_wants_email?(follower) | |||
emails | |||
end | |||
end | |||
|
|||
def followers_of(asset) | |||
asset.user.followers | |||
end | |||
|
|||
def user_wants_email?(user) | |||
# anyone who doesn't have it set to false, aka, opt-out | |||
(user.settings == nil) || (user.settings[:email_new_tracks] != "false") | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
class Following < ActiveRecord::Base | |||
|
|||
belongs_to :user, :counter_cache => :followers_count | |||
belongs_to :follower, :class_name => 'User' | |||
|
|||
validates_presence_of :user_id, :follower_id | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
Hi! | |||
|
|||
<%= @name %> just uploaded a new track on alonetone. <%= @exclamation.randomly_pick(1) %>! | |||
|
|||
It's so piping hot we don't even know the juicy details yet. <%= @name %> is still typing them in. | |||
|
|||
Listen to it at alonetone: | |||
<%= @play_link %> | |||
|
|||
Download it directly: | |||
<%= @download_link%> | |||
|
|||
-----8<------------------------- | |||
|
|||
You are getting this email because you decided to follow <%= @name %>. You can change your mind by clicking "un-follow" here: | |||
<%= @user_link %> | |||
|
|||
You can also turn off all emails by editing your profile at alonetone. | |||
|
|||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
db/migrate/20090103235851_replace_stalkings_with_followers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
class ReplaceStalkingsWithFollowers < ActiveRecord::Migration | |||
def self.up | |||
drop_table :stalkings | |||
create_table :followings do |t| | |||
t.integer :user_id | |||
t.integer :follower_id | |||
t.timestamps | |||
end | |||
add_index :followings, :user_id | |||
add_index :followings, :follower_id | |||
end | |||
|
|||
def self.down | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
class AddFollowersCountToUser < ActiveRecord::Migration | |||
def self.up | |||
add_column :users, :followers_count, :integer, :default => 0 | |||
end | |||
|
|||
def self.down | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters