2018-10-31 14:27:48 +09:00
|
|
|
package activity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/aerogo/aero"
|
2019-06-03 18:32:43 +09:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
2018-10-31 14:27:48 +09:00
|
|
|
)
|
|
|
|
|
2018-11-12 14:24:00 +09:00
|
|
|
// Global activity page.
|
2019-06-01 13:55:49 +09:00
|
|
|
func Global(ctx aero.Context) error {
|
2019-11-17 16:59:34 +09:00
|
|
|
user := arn.GetUserFromContext(ctx)
|
2018-11-12 14:24:00 +09:00
|
|
|
activities := fetchActivities(user, false)
|
2018-11-12 15:05:46 +09:00
|
|
|
return render(ctx, activities)
|
2018-11-12 14:24:00 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// Followed activity page.
|
2019-06-01 13:55:49 +09:00
|
|
|
func Followed(ctx aero.Context) error {
|
2019-11-17 16:59:34 +09:00
|
|
|
user := arn.GetUserFromContext(ctx)
|
2018-11-12 14:24:00 +09:00
|
|
|
activities := fetchActivities(user, true)
|
2018-11-12 15:05:46 +09:00
|
|
|
return render(ctx, activities)
|
2018-11-12 14:24:00 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// fetchActivities filters the activities by the given filters.
|
|
|
|
func fetchActivities(user *arn.User, followedOnly bool) []arn.Activity {
|
|
|
|
var followedUserIDs []string
|
|
|
|
|
|
|
|
if followedOnly && user != nil {
|
|
|
|
followedUserIDs = user.Follows().Items
|
|
|
|
}
|
2018-10-31 14:27:48 +09:00
|
|
|
|
2019-08-27 15:03:29 +09:00
|
|
|
activities := arn.FilterActivityCreates(func(activity arn.Activity) bool {
|
2018-11-12 14:24:00 +09:00
|
|
|
if followedOnly && !arn.Contains(followedUserIDs, activity.GetCreatedBy()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-11-13 01:21:45 +09:00
|
|
|
if !activity.Creator().HasNick() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-08-27 15:03:29 +09:00
|
|
|
obj := activity.(*arn.ActivityCreate).Object()
|
2018-10-31 14:27:48 +09:00
|
|
|
|
2019-08-27 15:03:29 +09:00
|
|
|
if obj == nil {
|
|
|
|
return false
|
2018-11-12 10:41:46 +09:00
|
|
|
}
|
2018-10-31 14:27:48 +09:00
|
|
|
|
2019-08-27 15:03:29 +09:00
|
|
|
draft, isDraftable := obj.(arn.Draftable)
|
|
|
|
return !isDraftable || !draft.GetIsDraft()
|
2018-11-12 10:41:46 +09:00
|
|
|
})
|
2018-10-31 14:27:48 +09:00
|
|
|
|
2018-11-12 10:41:46 +09:00
|
|
|
arn.SortActivitiesLatestFirst(activities)
|
2018-11-12 14:24:00 +09:00
|
|
|
return activities
|
2018-10-31 14:27:48 +09:00
|
|
|
}
|