summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authordelthas <delthas@dille.cc>2022-02-10 15:44:05 +0100
committerdelthas <delthas@dille.cc>2022-02-11 12:18:45 +0100
commitb46a755bfc2afbce7276a2ce075d956ab7dc5b01 (patch)
treecad716b91edbcf5382ef131defc6728cbc25f8b3 /ui
parentRename ColorGrey to ColorGray for consistency (diff)
Add support for the soju.im/read capability and READ command
See: https://github.com/emersion/soju/blob/c7f0634ec8ee94425547b159bc36705582151012/doc/read.md
Diffstat (limited to 'ui')
-rw-r--r--ui/buffers.go34
-rw-r--r--ui/ui.go9
2 files changed, 43 insertions, 0 deletions
diff --git a/ui/buffers.go b/ui/buffers.go
index 4cc0b45..4c40e19 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -182,6 +182,7 @@ type buffer struct {
title string
highlights int
unread bool
+ read time.Time
lines []Line
topic string
@@ -389,6 +390,39 @@ func (bs *BufferList) SetTopic(netID, title string, topic string) {
b.topic = topic
}
+func (bs *BufferList) SetRead(netID, title string, timestamp time.Time) {
+ idx := bs.idx(netID, title)
+ if idx < 0 {
+ return
+ }
+ b := &bs.list[idx]
+ if len(b.lines) > 0 && !b.lines[len(b.lines)-1].At.After(timestamp) {
+ b.highlights = 0
+ b.unread = false
+ }
+ if b.read.Before(timestamp) {
+ b.read = timestamp
+ }
+}
+
+func (bs *BufferList) UpdateRead() (netID, title string, timestamp time.Time) {
+ b := &bs.list[bs.current]
+ var line *Line
+ y := 0
+ for i := len(b.lines) - 1; 0 <= i; i-- {
+ line = &b.lines[i]
+ if y >= b.scrollAmt {
+ break
+ }
+ y += len(line.NewLines(bs.tlInnerWidth)) + 1
+ }
+ if line != nil && line.At.After(b.read) {
+ b.read = line.At
+ return b.netID, b.title, b.read
+ }
+ return "", "", time.Time{}
+}
+
func (bs *BufferList) Current() (netID, title string) {
b := &bs.list[bs.current]
return b.netID, b.title
diff --git a/ui/ui.go b/ui/ui.go
index 750644c..9f0b13d 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -3,6 +3,7 @@ package ui
import (
"strings"
"sync/atomic"
+ "time"
"git.sr.ht/~taiite/senpai/irc"
@@ -236,6 +237,14 @@ func (ui *UI) SetTopic(netID, buffer string, topic string) {
ui.bs.SetTopic(netID, buffer, topic)
}
+func (ui *UI) SetRead(netID, buffer string, timestamp time.Time) {
+ ui.bs.SetRead(netID, buffer, timestamp)
+}
+
+func (ui *UI) UpdateRead() (netID, buffer string, timestamp time.Time) {
+ return ui.bs.UpdateRead()
+}
+
func (ui *UI) SetStatus(status string) {
ui.status = status
}