summaryrefslogtreecommitdiff
path: root/app.go
diff options
context:
space:
mode:
authordelthas <delthas@dille.cc>2021-11-19 12:33:01 +0100
committerHubert Hirtz <hubert@hirtz.pm>2021-11-19 13:39:04 +0100
commit6014ba12270933c74018f2914713ec6fb2ed4a77 (patch)
treefc7dee4491600afea3ea9ba23177591b3b507738 /app.go
parentAlso write the last buffer on SIGTERM, SIGINT and SIGHUP (diff)
Add support for CHATHISTORY TARGETS
Diffstat (limited to 'app.go')
-rw-r--r--app.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/app.go b/app.go
index db5c776..d652b97 100644
--- a/app.go
+++ b/app.go
@@ -91,6 +91,9 @@ type App struct {
messageBounds map[boundKey]bound
lastNetID string
lastBuffer string
+
+ lastMessageTime time.Time
+ lastCloseTime time.Time
}
func NewApp(cfg Config) (app *App, err error) {
@@ -153,6 +156,9 @@ func (app *App) SwitchToBuffer(netID, buffer string) {
}
func (app *App) Run() {
+ if app.lastCloseTime.IsZero() {
+ app.lastCloseTime = time.Now()
+ }
go app.uiLoop()
go app.ircLoop("")
app.eventLoop()
@@ -167,6 +173,14 @@ func (app *App) CurrentBuffer() (netID, buffer string) {
return app.win.CurrentBuffer()
}
+func (app *App) LastMessageTime() time.Time {
+ return app.lastMessageTime
+}
+
+func (app *App) SetLastClose(t time.Time) {
+ app.lastCloseTime = t
+}
+
// eventLoop retrieves events (in batches) from the event channel and handle
// them, then draws the interface after each batch is handled.
func (app *App) eventLoop() {
@@ -589,6 +603,10 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
})
return
}
+ t := msg.TimeOrNow()
+ if t.After(app.lastMessageTime) {
+ app.lastMessageTime = t
+ }
// Mutate UI state
switch ev := ev.(type) {
@@ -598,6 +616,9 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
// TODO: support autojoining channels with keys
s.Join(channel, "")
}
+ s.NewHistoryRequest("").
+ WithLimit(1000).
+ Targets(app.lastCloseTime, msg.TimeOrNow())
body := "Connected to the server"
if s.Nick() != app.cfg.Nick {
body = fmt.Sprintf("Connected to the server as %s", s.Nick())
@@ -768,6 +789,19 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
bounds := app.messageBounds[boundKey{netID, ev.Target}]
bounds.Update(&line)
app.messageBounds[boundKey{netID, ev.Target}] = bounds
+ case irc.HistoryTargetsEvent:
+ for target, last := range ev.Targets {
+ if s.IsChannel(target) {
+ continue
+ }
+ app.win.AddBuffer(netID, "", target)
+ // CHATHISTORY BEFORE excludes its bound, so add 1ms
+ // (precision of the time tag) to include that last message.
+ last = last.Add(1 * time.Millisecond)
+ s.NewHistoryRequest(target).
+ WithLimit(200).
+ Before(last)
+ }
case irc.HistoryEvent:
var linesBefore []ui.Line
var linesAfter []ui.Line