mirror of
https://github.com/neocities/neocities.git
synced 2025-08-01 23:31:52 +02:00
fixes for follows, initial follow event code
This commit is contained in:
parent
2097350a1c
commit
070d8df1db
6 changed files with 24 additions and 9 deletions
|
@ -2,13 +2,15 @@ class Event < Sequel::Model
|
|||
include Sequel::ParanoidDelete
|
||||
|
||||
many_to_one :site
|
||||
one_to_one :follow
|
||||
many_to_one :follow
|
||||
one_to_one :tip
|
||||
one_to_one :tag
|
||||
one_to_one :site_change
|
||||
many_to_one :profile_comment
|
||||
one_to_many :likes
|
||||
one_to_many :comments
|
||||
many_to_one :site
|
||||
many_to_one :actioning_site, key: :actioning_site_id, class: :Site
|
||||
|
||||
def created_by?(site)
|
||||
return true if profile_comment && profile_comment.actioning_site_id == site.id
|
||||
|
@ -44,4 +46,4 @@ class Event < Sequel::Model
|
|||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Follow < Sequel::Model
|
||||
many_to_one :site
|
||||
many_to_one :actioning_site, :class => :Site
|
||||
end
|
||||
one_to_one :event
|
||||
end
|
||||
|
|
|
@ -4,6 +4,6 @@ class ProfileComment < Sequel::Model
|
|||
many_to_one :actioning_site, :class => :Site
|
||||
|
||||
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
|
||||
|
|
|
@ -105,10 +105,16 @@ class Site < Sequel::Model
|
|||
|
||||
def toggle_follow(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
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue