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"
|
|
|
|
)
|
|
|
|
|
2018-11-12 05:24:00 +00:00
|
|
|
// Global activity page.
|
|
|
|
func Global(ctx *aero.Context) string {
|
2018-10-31 05:27:48 +00:00
|
|
|
user := utils.GetUser(ctx)
|
2018-11-12 05:24:00 +00:00
|
|
|
activities := fetchActivities(user, false)
|
2018-11-12 06:05:46 +00:00
|
|
|
return render(ctx, activities)
|
2018-11-12 05:24:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2018-11-12 05:24:00 +00: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 05:27:48 +00:00
|
|
|
|
2018-11-12 01:41:46 +00:00
|
|
|
activities := arn.FilterActivities(func(activity arn.Activity) bool {
|
2018-11-12 05:24:00 +00:00
|
|
|
if followedOnly && !arn.Contains(followedUserIDs, activity.GetCreatedBy()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-11-12 16:21:45 +00:00
|
|
|
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
|
|
|
|
2018-11-12 05:24:00 +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)
|
2018-11-12 05:24:00 +00:00
|
|
|
return activities
|
2018-10-31 05:27:48 +00:00
|
|
|
}
|