Skip to content

Commit

Permalink
add event creation policy to user following
Browse files Browse the repository at this point in the history
  • Loading branch information
aajjbb committed Aug 21, 2017
1 parent 20f9167 commit 6bd7539
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions applications/user.moon
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ class MoonRocksUser extends lapis.Application
"You can't follow yourself"

@flow("followings")\follow_object followed_user, "subscription"
@flow("events")\create_event_and_deliver followed_user, "subscription"

redirect_to: @url_for followed_user

Expand All @@ -372,5 +373,6 @@ class MoonRocksUser extends lapis.Application
"Invalid User"

@flow("followings")\unfollow_object unfollowed_user, "subscription"
@flow("events")\remove_from_timeline unfollowed_user, "subscription"

redirect_to: @url_for unfollowed_user
8 changes: 4 additions & 4 deletions flows/events.moon
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EventsFlow extends Flow

create_event_and_deliver: (object, event_type) =>
import preload from require "lapis.db.model"

-- Creates the primary event
event = Events\create({
user: @current_user
Expand All @@ -22,7 +22,7 @@ class EventsFlow extends Flow
})

-- Adds the new event to the timeline of every subscriber of @current_user
do
do
user_followers = Followings\select "where object_type = ? and object_id = ? and type = ?", Followings\object_type_for_object(@current_user), @current_user.id, Followings.types.subscription
preload user_followers, "source_user"

Expand All @@ -33,7 +33,7 @@ class EventsFlow extends Flow
user_id: follower_user.id
event_id: event.id
})

-- If the event is a update, then every follower of the module should see the event
if Events.event_types.update == Events.event_types\for_db(event_type)
followers = Followings\select "where object_id = ? and object_type = ? and type = ?", event.object_id, event.object_type, Followings.types.subscription
Expand All @@ -52,7 +52,7 @@ class EventsFlow extends Flow
timeline_events = if Events\object_type_for_object(object) == Events\object_type_for_model(Users)
-- If we are removing the subscription from an use
db.select "user_id, event_id from timeline_events join events on timeline_events.event_id = events.id and events.source_user_id = ?", object.id
else
else
-- If we are removing the subscription from Module
db.select "user_id, event_id from timeline_events join events on timeline_events.event_id = events.id and events.source_user_id = ? and events.object_type = ? and object_id = ?", object.user_id, Events\object_type_for_object(object), object.id

Expand Down

0 comments on commit 6bd7539

Please sign in to comment.