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.
This commit is contained in:
parent
57b26240fc
commit
740862efa2
2 changed files with 7 additions and 7 deletions
2
main.go
2
main.go
|
@ -85,7 +85,7 @@ func main() {
|
||||||
// ok then...
|
// ok then...
|
||||||
logger.error("Couldn't query notices from API endpoint '" + a.Id + "'")
|
logger.error("Couldn't query notices from API endpoint '" + a.Id + "'")
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
} else {
|
} else if len(n) > 0 {
|
||||||
newNotices = append(newNotices, n...)
|
newNotices = append(newNotices, n...)
|
||||||
persistent.data.(PersistentData).LastPublished[a.Id] = t
|
persistent.data.(PersistentData).LastPublished[a.Id] = t
|
||||||
persistent.save()
|
persistent.save()
|
||||||
|
|
12
widapi.go
12
widapi.go
|
@ -41,7 +41,7 @@ type ApiEndpoint struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ApiEndpoint) getNotices(since time.Time) ([]WidNotice, time.Time, error) {
|
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 notices []WidNotice = []WidNotice{}
|
||||||
var err error
|
var err error
|
||||||
params := defaultParams
|
params := defaultParams
|
||||||
|
@ -58,19 +58,19 @@ func (e ApiEndpoint) getNotices(since time.Time) ([]WidNotice, time.Time, error)
|
||||||
if res.StatusCode == 200 {
|
if res.StatusCode == 200 {
|
||||||
resBody, err := io.ReadAll(res.Body)
|
resBody, err := io.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, time.Time{}, err
|
return []WidNotice{}, since, err
|
||||||
}
|
}
|
||||||
var decodedData map[string]interface{}
|
var decodedData map[string]interface{}
|
||||||
if err = json.Unmarshal(resBody, &decodedData); err != nil {
|
if err = json.Unmarshal(resBody, &decodedData); err != nil {
|
||||||
return nil, time.Time{}, err
|
return []WidNotice{}, since, err
|
||||||
}
|
}
|
||||||
notices = parseApiResponse(decodedData, e)
|
notices = parseApiResponse(decodedData, e)
|
||||||
} else {
|
} else {
|
||||||
logger.error(fmt.Sprintf("Get \"%v\": %v\n", url, res.Status))
|
logger.error(fmt.Sprintf("Get \"%v\": %v\n", url, res.Status))
|
||||||
return nil, time.Time{}, err
|
return []WidNotice{}, since, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, time.Time{}, err
|
return []WidNotice{}, since, err
|
||||||
}
|
}
|
||||||
if len(notices) > 0 {
|
if len(notices) > 0 {
|
||||||
// And here the filtering begins. yay -.-
|
// 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
|
return noticesFiltered, lastPublished, nil
|
||||||
} else {
|
} else {
|
||||||
return nil, time.Time{}, nil
|
return []WidNotice{}, since, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue