summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/buffers.go49
-rw-r--r--ui/ui.go6
2 files changed, 13 insertions, 42 deletions
diff --git a/ui/buffers.go b/ui/buffers.go
index 91d46cd..681918c 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -235,16 +235,16 @@ func (bs *BufferList) Previous() {
bs.list[bs.current].unread = false
}
-func (bs *BufferList) Add(title string) int {
+func (bs *BufferList) Add(title string) (i int, added bool) {
lTitle := strings.ToLower(title)
for i, b := range bs.list {
if strings.ToLower(b.title) == lTitle {
- return i
+ return i, false
}
}
bs.list = append(bs.list, buffer{title: title})
- return len(bs.list) - 1
+ return len(bs.list) - 1, true
}
func (bs *BufferList) Remove(title string) (ok bool) {
@@ -299,49 +299,20 @@ func (bs *BufferList) AddLine(title string, notify NotifyType, line Line) {
}
}
-// "lines" needs to be sorted by their "At" field.
-func (bs *BufferList) AddLines(title string, lines []Line) {
+func (bs *BufferList) AddLines(title string, before, after []Line) {
idx := bs.idx(title)
if idx < 0 {
return
}
b := &bs.list[idx]
- limit := len(lines)
-
- if 0 < len(b.lines) {
- // Compute "limit", the index first line of "lines" that should
- // not be added to the buffer.
- firstLineTime := b.lines[0].At.Unix()
- firstLineBody := b.lines[0].Body
- for i, l := range lines {
- historyLineTime := l.At.Unix()
- if historyLineTime < firstLineTime {
- // This line is behind the first line of the
- // buffer.
- continue
- }
- if historyLineTime > firstLineTime {
- // This line happened after the first line of
- // the buffer.
- limit = i
- break
- }
- if l.Body.string == firstLineBody.string {
- // This line happened at the same millisecond
- // as the first line of the buffer, and has the
- // same contents. Heuristic: it's the same
- // message.
- limit = i
- break
- }
- }
+
+ if len(before) != 0 {
+ b.lines = append(before, b.lines...)
}
- for i := 0; i < limit; i++ {
- lines[i].computeSplitPoints()
+ if len(after) != 0 {
+ b.lines = append(b.lines, after...)
}
-
- b.lines = append(lines[:limit], b.lines...)
}
func (bs *BufferList) Current() (title string) {
@@ -353,7 +324,7 @@ func (bs *BufferList) CurrentOldestTime() (t *time.Time) {
if 0 < len(ls) {
t = &ls[0].At
}
- return
+ return t
}
func (bs *BufferList) ScrollUp(n int) {
diff --git a/ui/ui.go b/ui/ui.go
index 39f936c..8fb6227 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -148,7 +148,7 @@ func (ui *UI) IsAtTop() bool {
return ui.bs.IsAtTop()
}
-func (ui *UI) AddBuffer(title string) int {
+func (ui *UI) AddBuffer(title string) (i int, added bool) {
return ui.bs.Add(title)
}
@@ -161,8 +161,8 @@ func (ui *UI) AddLine(buffer string, notify NotifyType, line Line) {
ui.bs.AddLine(buffer, notify, line)
}
-func (ui *UI) AddLines(buffer string, lines []Line) {
- ui.bs.AddLines(buffer, lines)
+func (ui *UI) AddLines(buffer string, before, after []Line) {
+ ui.bs.AddLines(buffer, before, after)
}
func (ui *UI) JumpBuffer(sub string) bool {