diff options
author | delthas <delthas@dille.cc> | 2022-02-10 15:44:05 +0100 |
---|---|---|
committer | delthas <delthas@dille.cc> | 2022-02-11 12:18:45 +0100 |
commit | b46a755bfc2afbce7276a2ce075d956ab7dc5b01 (patch) | |
tree | cad716b91edbcf5382ef131defc6728cbc25f8b3 /irc/session.go | |
parent | Rename 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 'irc/session.go')
-rw-r--r-- | irc/session.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/irc/session.go b/irc/session.go index 96632bf..ca2c2d9 100644 --- a/irc/session.go +++ b/irc/session.go @@ -60,6 +60,7 @@ var SupportedCapabilities = map[string]struct{}{ "draft/chathistory": {}, "draft/event-playback": {}, "soju.im/bouncer-networks": {}, + "soju.im/read": {}, } // Values taken by the "@+typing=" client tag. TypingUnspec means the value or @@ -426,6 +427,18 @@ func (s *Session) TypingStop(target string) { s.out <- NewMessage("TAGMSG", target).WithTag("+typing", "done") } +func (s *Session) ReadGet(target string) { + if _, ok := s.enabledCaps["soju.im/read"]; ok { + s.out <- NewMessage("READ", target) + } +} + +func (s *Session) ReadSet(target string, timestamp time.Time) { + if _, ok := s.enabledCaps["soju.im/read"]; ok { + s.out <- NewMessage("READ", target, formatTimestamp(timestamp)) + } +} + func (s *Session) MonitorAdd(target string) { targetCf := s.casemap(target) if _, ok := s.monitors[targetCf]; !ok { @@ -1237,6 +1250,26 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er Time: msg.TimeOrNow(), }, nil } + case "READ": + if len(msg.Params) < 2 { + break + } + var target, timestamp string + if err := msg.ParseParams(&target, ×tamp); err != nil { + return nil, err + } + if !strings.HasPrefix(timestamp, "timestamp=") { + return nil, nil + } + timestamp = strings.TrimPrefix(timestamp, "timestamp=") + t, ok := parseTimestamp(timestamp) + if !ok { + return nil, nil + } + return ReadEvent{ + Target: target, + Timestamp: t, + }, nil case "BOUNCER": if len(msg.Params) < 3 { break |