61 lines
1.4 KiB
Go
Raw Normal View History

2018-10-31 05:27:48 +00:00
package activity
import (
"github.com/aerogo/aero"
2018-11-12 01:41:46 +00:00
"github.com/animenotifier/arn"
2018-10-31 05:27:48 +00:00
"github.com/animenotifier/notify.moe/utils"
)
// Global activity page.
func Global(ctx *aero.Context) string {
2018-10-31 05:27:48 +00:00
user := utils.GetUser(ctx)
activities := fetchActivities(user, false)
2018-11-12 06:05:46 +00:00
return render(ctx, activities)
}
// Followed activity page.
func Followed(ctx *aero.Context) string {
user := utils.GetUser(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 {
var followedUserIDs []string
if followedOnly && user != nil {
followedUserIDs = user.Follows().Items
}
2018-10-31 05:27:48 +00:00
2018-11-12 01:41:46 +00:00
activities := arn.FilterActivities(func(activity arn.Activity) bool {
if followedOnly && !arn.Contains(followedUserIDs, activity.GetCreatedBy()) {
return false
}
if !activity.Creator().HasNick() {
return false
}
2018-11-12 01:41:46 +00:00
if activity.Type() == "ActivityCreate" {
obj := activity.(*arn.ActivityCreate).Object()
2018-10-31 05:27:48 +00:00
2018-11-12 01:41:46 +00:00
if obj == nil {
return false
}
2018-11-05 04:19:42 +00:00
draft, isDraftable := obj.(arn.Draftable)
return !isDraftable || !draft.GetIsDraft()
2018-11-12 02:40:46 +00:00
}
2018-11-05 04:19:42 +00:00
2018-11-12 02:40:46 +00:00
if activity.Type() == "ActivityConsumeAnime" {
return activity.(*arn.ActivityConsumeAnime).Anime() != nil
2018-11-12 01:41:46 +00:00
}
2018-10-31 05:27:48 +00:00
2018-11-12 02:40:46 +00:00
return false
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
}