fixes for follows, initial follow event code

This commit is contained in:
Kyle Drake 2014-05-08 08:47:28 -07:00
parent 2097350a1c
commit 070d8df1db
6 changed files with 24 additions and 9 deletions

View file

@ -1,6 +1,6 @@
language: ruby language: ruby
rvm: rvm:
- "2.1.0" - "2.1.1"
addons: addons:
postgresql: "9.3" postgresql: "9.3"
before_script: before_script:

View file

@ -2,13 +2,15 @@ class Event < Sequel::Model
include Sequel::ParanoidDelete include Sequel::ParanoidDelete
many_to_one :site many_to_one :site
one_to_one :follow many_to_one :follow
one_to_one :tip one_to_one :tip
one_to_one :tag one_to_one :tag
one_to_one :site_change one_to_one :site_change
many_to_one :profile_comment many_to_one :profile_comment
one_to_many :likes one_to_many :likes
one_to_many :comments one_to_many :comments
many_to_one :site
many_to_one :actioning_site, key: :actioning_site_id, class: :Site
def created_by?(site) def created_by?(site)
return true if profile_comment && profile_comment.actioning_site_id == site.id return true if profile_comment && profile_comment.actioning_site_id == site.id
@ -44,4 +46,4 @@ class Event < Sequel::Model
true true
end end
end end
end end

View file

@ -1,4 +1,5 @@
class Follow < Sequel::Model class Follow < Sequel::Model
many_to_one :site many_to_one :site
many_to_one :actioning_site, :class => :Site many_to_one :actioning_site, :class => :Site
end one_to_one :event
end

View file

@ -4,6 +4,6 @@ class ProfileComment < Sequel::Model
many_to_one :actioning_site, :class => :Site many_to_one :actioning_site, :class => :Site
def after_create def after_create
self.event = Event.create site_id: site.id self.event = Event.create site_id: site.id, actioning_site_id: actioning_site.id
end end
end end

View file

@ -105,10 +105,16 @@ class Site < Sequel::Model
def toggle_follow(site) def toggle_follow(site)
if is_following? site if is_following? site
followings_dataset.filter(site_id: site.id).delete follow = followings_dataset.filter(site_id: site.id).first
site.events_dataset.filter(follow_id: follow.id).delete
follow.delete
false false
else else
add_following site_id: site.id DB.transaction do
follow = add_following site_id: site.id
Event.create site_id: site.id, actioning_site_id: self.id, follow_id: follow.id
end
true true
end end
end end

View file

@ -9,6 +9,12 @@
<% if event.profile_comment_id %> <% if event.profile_comment_id %>
<div class="news-item comment for-me" id="event_<%= event.id %>"> <div class="news-item comment for-me" id="event_<%= event.id %>">
<%== erb :'_news_profile_comment', layout: false, locals: {profile_comment: event.profile_comment} %> <%== erb :'_news_profile_comment', layout: false, locals: {profile_comment: event.profile_comment} %>
<% elsif event.follow_id %>
<div class="news-item follow">
<div class="title">
<div class="icon"></div>
<a href="/site/<%= event.actioning_site.username %>" class="user"><%= event.actioning_site.username %></a> followed <a href="/site/<%= event.site.username %>" class="user"><%= event.site.username %>'s</a> website<span class="date">7h</span>
</div>
<% end %> <% end %>
<%== erb :'_news_actions', layout: false, locals: {event: event} %> <%== erb :'_news_actions', layout: false, locals: {event: event} %>
@ -19,7 +25,7 @@
<% event.comments.each do |comment| %> <% event.comments.each do |comment| %>
<div class="comment" id="comment_<%= comment.id %>"> <div class="comment" id="comment_<%= comment.id %>">
<img class="avatar" src="<%= comment.actioning_site.screenshot_url('index.html', '82x62') %>"> <img class="avatar" src="<%= comment.actioning_site.screenshot_url('index.html', '82x62') %>">
<a href="" class="user"><%= comment.actioning_site.username %></a> <a href="/site/<%= comment.actioning_site.username %>" class="user"><%= comment.actioning_site.username %></a>
<span class="date"><%= comment.created_at.ago %></span> <span class="date"><%= comment.created_at.ago %></span>
<p><%= comment.message %></p> <p><%= comment.message %></p>
</div> </div>