-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adapt classes to use \create method with opts arguments
- Loading branch information
Showing
4 changed files
with
65 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,46 @@ | ||
db = require "lapis.db" | ||
import Model from require "lapis.db.model" | ||
import Events, Followings, Users from require "models" | ||
|
||
|
||
class TimelineEvents extends Model | ||
@primary_key: { "user_id", "event_id" } | ||
|
||
@create: (user, event) => | ||
@create: (opts={}) => | ||
assert opts.user_id, "user id not specified" | ||
assert opts.event_id, "event id not specified" | ||
|
||
super { | ||
user_id: user.id | ||
event_id: event.id | ||
user_id: opts.user_id | ||
event_id: opts.event_id | ||
} | ||
|
||
@delete: (user, event) => | ||
db.delete @table_name!, { user_id: user.id, event_id: event.id } | ||
|
||
@deliver: (user, event) => | ||
import Events, Followings, Users from require "models" | ||
|
||
switch event.event_type | ||
when Events.event_types.update | ||
followers = Followings\select "where object_id = ?", event.object_object_id | ||
followers = Followings\select "where object_id = ? and object_type = ?", event.object_object_id, event.object_object_type | ||
|
||
for users in *followers | ||
follower_user = Users\find users.source_user_id | ||
@@create(follower_user, event) | ||
@@create({ | ||
user_id: follower_user.id | ||
event_id: event | ||
}) | ||
else | ||
@@create(user, event) | ||
@@create({ | ||
user_id: user.id | ||
event_id: event.id | ||
}) | ||
|
||
if Events\model_for_object_type(event.object_object_type) == Users | ||
@@create(Users\find(event.object_object_id), event) | ||
@@create({ | ||
user_id: Users\find(event.object_object_id).id | ||
event_id: event.id | ||
}) | ||
|
||
@user_timeline: (user) => | ||
@@select "where user_id = ?", user.id |
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