diff options
author | Hubert Hirtz <hubert@hirtz.pm> | 2021-11-29 09:35:45 +0100 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-11-29 09:35:45 +0100 |
commit | 3904c9190d94f273c0ae9937d3161b9fe4adf856 (patch) | |
tree | d6739e47198810e4b01f4906fbf739cbf429a8a9 /app.go | |
parent | Fetch history for queries (diff) |
Use second precision for bound computation
Should solve duplicates on servers that don't store message stamps with
the full millisecond precision offered by the time tag (e.g. soju)
Diffstat (limited to 'app.go')
-rw-r--r-- | app.go | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -34,16 +34,17 @@ type bound struct { // Compare returns 0 if line is within bounds, -1 if before, 1 if after. func (b *bound) Compare(line *ui.Line) int { - if line.At.Before(b.first) { + at := line.At.Truncate(time.Second) + if at.Before(b.first) { return -1 } - if line.At.After(b.last) { + if at.After(b.last) { return 1 } - if line.At.Equal(b.first) && line.Body.String() != b.firstMessage { + if at.Equal(b.first) && line.Body.String() != b.firstMessage { return -1 } - if line.At.Equal(b.last) && line.Body.String() != b.lastMessage { + if at.Equal(b.last) && line.Body.String() != b.lastMessage { return -1 } return 0 @@ -54,11 +55,12 @@ func (b *bound) Update(line *ui.Line) { if line.At.IsZero() { return } - if b.first.IsZero() || line.At.Before(b.first) { - b.first = line.At + at := line.At.Truncate(time.Second) + if b.first.IsZero() || at.Before(b.first) { + b.first = at b.firstMessage = line.Body.String() - } else if b.last.IsZero() || line.At.After(b.last) { - b.last = line.At + } else if b.last.IsZero() || at.After(b.last) { + b.last = at b.lastMessage = line.Body.String() } } |