From 740862efa23c671077cbd0ae4a5bd472afc3a918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller=20=28ChaoticByte=29?= Date: Wed, 18 Oct 2023 20:17:27 +0200 Subject: [PATCH] Fixed a bug where all 1000 last notices where recognized as 'new'. This was caused by ApiEndpoint.getNotices() returning time.Time{} and a nil error in some cases. --- main.go | 2 +- widapi.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index ef85a52..c39f6bc 100644 --- a/main.go +++ b/main.go @@ -85,7 +85,7 @@ func main() { // ok then... logger.error("Couldn't query notices from API endpoint '" + a.Id + "'") logger.error(err) - } else { + } else if len(n) > 0 { newNotices = append(newNotices, n...) persistent.data.(PersistentData).LastPublished[a.Id] = t persistent.save() diff --git a/widapi.go b/widapi.go index 41638a0..f90af7d 100644 --- a/widapi.go +++ b/widapi.go @@ -41,7 +41,7 @@ type ApiEndpoint struct { } func (e ApiEndpoint) getNotices(since time.Time) ([]WidNotice, time.Time, error) { - // returns a slice of WidNotice and the 'published' field of the last notice + // returns a slice of WidNotice and the 'published' field of the last notice, and the error (or nil) var notices []WidNotice = []WidNotice{} var err error params := defaultParams @@ -58,19 +58,19 @@ func (e ApiEndpoint) getNotices(since time.Time) ([]WidNotice, time.Time, error) if res.StatusCode == 200 { resBody, err := io.ReadAll(res.Body) if err != nil { - return nil, time.Time{}, err + return []WidNotice{}, since, err } var decodedData map[string]interface{} if err = json.Unmarshal(resBody, &decodedData); err != nil { - return nil, time.Time{}, err + return []WidNotice{}, since, err } notices = parseApiResponse(decodedData, e) } else { logger.error(fmt.Sprintf("Get \"%v\": %v\n", url, res.Status)) - return nil, time.Time{}, err + return []WidNotice{}, since, err } } else { - return nil, time.Time{}, err + return []WidNotice{}, since, err } if len(notices) > 0 { // And here the filtering begins. yay -.- @@ -87,7 +87,7 @@ func (e ApiEndpoint) getNotices(since time.Time) ([]WidNotice, time.Time, error) } return noticesFiltered, lastPublished, nil } else { - return nil, time.Time{}, nil + return []WidNotice{}, since, nil } }