2018-10-31 05:27:48 +00:00
|
|
|
package activity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/aerogo/aero"
|
2019-06-03 09:32:43 +00:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
2018-10-31 05:27:48 +00:00
|
|
|
)
|
|
|
|
|
2021-11-23 06:47:25 +00:00
|
|
|
// Posts activity page.
|
|
|
|
func Posts(ctx aero.Context) error {
|
2019-11-17 07:59:34 +00:00
|
|
|
user := arn.GetUserFromContext(ctx)
|
2021-11-23 06:47:25 +00:00
|
|
|
activities := fetchCreateActivities(user)
|
2018-11-12 06:05:46 +00:00
|
|
|
return render(ctx, activities)
|
2018-11-12 05:24:00 +00:00
|
|
|
}
|
|
|
|
|
2021-11-23 06:47:25 +00:00
|
|
|
// Watch activity page.
|
|
|
|
func Watch(ctx aero.Context) error {
|
2019-11-17 07:59:34 +00:00
|
|
|
user := arn.GetUserFromContext(ctx)
|
2021-11-23 06:47:25 +00:00
|
|
|
activities := fetchConsumeActivities(user)
|
2018-11-12 06:05:46 +00:00
|
|
|
return render(ctx, activities)
|
2018-11-12 05:24:00 +00:00
|
|
|
}
|
|
|
|
|
2021-11-23 06:47:25 +00:00
|
|
|
// fetchCreateActivities filters the activities by the given filters.
|
|
|
|
func fetchCreateActivities(user *arn.User) []arn.Activity {
|
2021-11-23 07:08:54 +00:00
|
|
|
followedOnly := user != nil && user.Settings().Activity.ShowFollowedOnly
|
2021-11-23 06:47:25 +00:00
|
|
|
|
2019-08-27 06:03:29 +00:00
|
|
|
activities := arn.FilterActivityCreates(func(activity arn.Activity) bool {
|
2019-11-19 04:51:54 +00:00
|
|
|
if followedOnly && user != nil && !user.IsFollowing(activity.GetCreatedBy()) {
|
2018-11-12 05:24:00 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-11-12 16:21:45 +00:00
|
|
|
if !activity.Creator().HasNick() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-08-27 06:03:29 +00:00
|
|
|
obj := activity.(*arn.ActivityCreate).Object()
|
2018-10-31 05:27:48 +00:00
|
|
|
|
2019-08-27 06:03:29 +00:00
|
|
|
if obj == nil {
|
|
|
|
return false
|
2018-11-12 01:41:46 +00:00
|
|
|
}
|
2018-10-31 05:27:48 +00:00
|
|
|
|
2019-08-27 06:03:29 +00:00
|
|
|
draft, isDraftable := obj.(arn.Draftable)
|
|
|
|
return !isDraftable || !draft.GetIsDraft()
|
2018-11-12 01:41:46 +00:00
|
|
|
})
|
2018-10-31 05:27:48 +00:00
|
|
|
|
2018-11-12 01:41:46 +00:00
|
|
|
arn.SortActivitiesLatestFirst(activities)
|
2018-11-12 05:24:00 +00:00
|
|
|
return activities
|
2018-10-31 05:27:48 +00:00
|
|
|
}
|
2021-11-23 06:47:25 +00:00
|
|
|
|
|
|
|
// fetchConsumeActivities filters the consume activities by the given filters.
|
|
|
|
func fetchConsumeActivities(user *arn.User) []arn.Activity {
|
2021-11-23 07:08:54 +00:00
|
|
|
followedOnly := user != nil && user.Settings().Activity.ShowFollowedOnly
|
2021-11-23 06:47:25 +00:00
|
|
|
|
|
|
|
activities := arn.FilterActivitiesConsumeAnime(func(activity arn.Activity) bool {
|
|
|
|
if followedOnly && user != nil && !user.IsFollowing(activity.GetCreatedBy()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if !activity.Creator().HasNick() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
arn.SortActivitiesLatestFirst(activities)
|
|
|
|
return activities
|
|
|
|
}
|