43 lines
941 B
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/components"
"github.com/animenotifier/notify.moe/utils"
)
const maxActivitiesPerPage = 40
// Get activity page.
func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
2018-11-12 01:41:46 +00:00
activities := arn.FilterActivities(func(activity arn.Activity) bool {
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
2018-11-12 01:41:46 +00:00
draft, isDraftable := obj.(arn.HasDraft)
2018-11-12 02:40:46 +00:00
return !isDraftable || !draft.IsDraft
}
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)
2018-10-31 05:27:48 +00:00
2018-11-12 01:41:46 +00:00
if len(activities) > maxActivitiesPerPage {
activities = activities[:maxActivitiesPerPage]
}
return ctx.HTML(components.ActivityFeed(activities, user))
2018-10-31 05:27:48 +00:00
}