46 lines
1.1 KiB
Go
Raw Normal View History

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
)
// Global activity page.
2019-06-01 04:55:49 +00:00
func Global(ctx aero.Context) error {
2019-11-17 07:59:34 +00:00
user := arn.GetUserFromContext(ctx)
activities := fetchActivities(user, false)
2018-11-12 06:05:46 +00:00
return render(ctx, activities)
}
// Followed activity page.
2019-06-01 04:55:49 +00:00
func Followed(ctx aero.Context) error {
2019-11-17 07:59:34 +00:00
user := arn.GetUserFromContext(ctx)
activities := fetchActivities(user, true)
2018-11-12 06:05:46 +00:00
return render(ctx, activities)
}
// fetchActivities filters the activities by the given filters.
func fetchActivities(user *arn.User, followedOnly bool) []arn.Activity {
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()) {
return false
}
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)
return activities
2018-10-31 05:27:48 +00:00
}