summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Hirtz <hubert@hirtz.pm>2021-11-29 09:35:45 +0100
committerHubert Hirtz <hubert@hirtz.pm>2021-11-29 09:35:45 +0100
commit3904c9190d94f273c0ae9937d3161b9fe4adf856 (patch)
treed6739e47198810e4b01f4906fbf739cbf429a8a9
parentFetch 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)
-rw-r--r--app.go18
1 files changed, 10 insertions, 8 deletions
diff --git a/app.go b/app.go
index 5d5cf7e..2b0ba82 100644
--- a/app.go
+++ b/app.go
@@ -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()
}
}