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"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2018-10-31 05:27:48 +00:00
"github.com/animenotifier/notify.moe/utils"
)
// Global activity page.
2019-06-01 04:55:49 +00:00
func Global(ctx aero.Context) error {
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.
2019-06-01 04:55:49 +00:00
func Followed(ctx aero.Context) error {
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-15 11:19:40 +00:00
if activity.TypeName() == "ActivityCreate" {
2018-11-12 01:41:46 +00:00
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-15 11:19:40 +00:00
if activity.TypeName() == "ActivityConsumeAnime" {
2018-11-12 02:40:46 +00:00
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
}