2017-10-20 14:52:07 +00:00
|
|
|
package anime
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/animenotifier/notify.moe/components"
|
2017-12-03 16:21:58 +00:00
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
2017-10-20 14:52:07 +00:00
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Episodes ...
|
|
|
|
func Episodes(ctx *aero.Context) string {
|
2017-12-03 16:21:58 +00:00
|
|
|
user := utils.GetUser(ctx)
|
2017-10-20 14:52:07 +00:00
|
|
|
id := ctx.Get("id")
|
|
|
|
anime, err := arn.GetAnime(id)
|
2018-11-13 22:36:42 +00:00
|
|
|
episodeToFriends := map[int][]*arn.User{}
|
|
|
|
|
|
|
|
if user != nil {
|
2018-11-16 08:57:56 +00:00
|
|
|
ownListItem := user.AnimeList().Find(anime.ID)
|
|
|
|
|
|
|
|
if ownListItem != nil {
|
|
|
|
episodeToFriends[ownListItem.Episodes] = append(episodeToFriends[ownListItem.Episodes], user)
|
|
|
|
}
|
|
|
|
|
2018-11-13 22:36:42 +00:00
|
|
|
for _, friend := range user.Follows().Users() {
|
|
|
|
friendAnimeList := friend.AnimeList()
|
|
|
|
friendAnimeListItem := friendAnimeList.Find(anime.ID)
|
|
|
|
|
|
|
|
if friendAnimeListItem != nil && !friendAnimeListItem.Private && len(episodeToFriends[friendAnimeListItem.Episodes]) < maxFriendsPerEpisode {
|
|
|
|
episodeToFriends[friendAnimeListItem.Episodes] = append(episodeToFriends[friendAnimeListItem.Episodes], friend)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-20 14:52:07 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
|
|
|
}
|
|
|
|
|
2018-11-13 22:36:42 +00:00
|
|
|
return ctx.HTML(components.AnimeEpisodes(anime, anime.Episodes().Items, episodeToFriends, user, true))
|
2017-10-20 14:52:07 +00:00
|
|
|
}
|