Delete on completed and fetch on hold

This commit is contained in:
daru
2022-05-18 21:29:46 +02:00
parent be1419bfa7
commit 95294eb344
3 changed files with 47 additions and 35 deletions

View File

@@ -145,24 +145,37 @@ func SearchAnime(animeId int64) (*Anime, error) {
return anime, err
}
func FetchProgress(animeId, userId int64, username string, progress int) (int, time.Time, error) {
func FetchProgress(animeId, userId int64, username string, progress int) (int, time.Time, string, error) {
// check watching first
list, _, err := GetUserAnimeListData(username, malApiStatusW)
newProgress, updated, err := fetchProgressOnState(animeId, userId, progress, username, malApiStatusW)
if err != nil {
return 0, time.Time{}, err
return newProgress, updated, "", err
}
for _, a := range list.Data {
// check if found
if a.Node.ID == animeId {
// check if progress changed
if progress != a.ListStatus.NumEpisodesWatched {
return a.ListStatus.NumEpisodesWatched, a.ListStatus.UpdatedAt, nil
}
return progress, a.ListStatus.UpdatedAt, nil
}
if newProgress != -1 {
return newProgress, updated, malApiStatusW, err
}
// check on hold
newProgress, updated, err = fetchProgressOnState(animeId, userId, progress, username, malApiStatusH)
if err != nil {
return newProgress, updated, "", err
}
if newProgress != -1 {
return newProgress, updated, malApiStatusH, err
}
// check completed
list, _, err = GetUserAnimeListData(username, malApiStatusC)
newProgress, updated, err = fetchProgressOnState(animeId, userId, progress, username, malApiStatusC)
if err != nil {
return newProgress, updated, "", err
}
if newProgress != -1 {
return newProgress, updated, malApiStatusC, err
}
// has no progress or dropped
return 0, updated, "", nil
}
func fetchProgressOnState(animeId, userId int64, progress int, username, malStatus string) (int, time.Time, error) {
list, _, err := GetUserAnimeListData(username, malStatus)
if err != nil {
return 0, time.Time{}, err
}
@@ -170,14 +183,11 @@ func FetchProgress(animeId, userId int64, username string, progress int) (int, t
// check if found
if a.Node.ID == animeId {
// check if progress changed
if progress != a.ListStatus.NumEpisodesWatched {
return a.ListStatus.NumEpisodesWatched, a.ListStatus.UpdatedAt, nil
}
return progress, a.ListStatus.UpdatedAt, nil
return a.ListStatus.NumEpisodesWatched, a.ListStatus.UpdatedAt, nil
}
}
// has no progress or dropped/hold
return 0, time.Now(), nil
// no progess found
return -1, time.Now(), nil
}
func AddToChat(old, new, user string) string {