diff options
author | delthas <delthas@dille.cc> | 2021-07-13 19:26:24 +0200 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-07-13 21:38:53 +0200 |
commit | 93005741f2fa5c16bed3d7bc325c7d09a6a507da (patch) | |
tree | 2373fbf66cc6987ab7f3c6f1a1f4b0238fea9049 | |
parent | Clear the input on CTRL+C instead of quitting (diff) |
Switch to the buffer of a new user-requested channel join
Diffstat (limited to '')
-rw-r--r-- | app.go | 5 | ||||
-rw-r--r-- | irc/events.go | 3 | ||||
-rw-r--r-- | irc/session.go | 51 | ||||
-rw-r--r-- | ui/buffers.go | 9 | ||||
-rw-r--r-- | ui/ui.go | 12 |
5 files changed, 50 insertions, 30 deletions
@@ -511,10 +511,13 @@ func (app *App) handleIRCEvent(ev interface{}) { }) } case irc.SelfJoinEvent: - app.win.AddBuffer(ev.Channel) + i := app.win.AddBuffer(ev.Channel) app.s.NewHistoryRequest(ev.Channel). WithLimit(200). Before(msg.TimeOrNow()) + if ev.Requested { + app.win.JumpBufferIndex(i) + } case irc.UserJoinEvent: body := new(ui.StyledStringBuilder) body.Grow(len(ev.User) + 1) diff --git a/irc/events.go b/irc/events.go index bdd6914..0451a80 100644 --- a/irc/events.go +++ b/irc/events.go @@ -22,7 +22,8 @@ type UserNickEvent struct { } type SelfJoinEvent struct { - Channel string + Channel string + Requested bool // whether we recently requested to join that channel } type UserJoinEvent struct { diff --git a/irc/session.go b/irc/session.go index 376015f..33d52fc 100644 --- a/irc/session.go +++ b/irc/session.go @@ -130,30 +130,33 @@ type Session struct { channels map[string]Channel // joined channels. chBatches map[string]HistoryEvent // channel history batches being processed. chReqs map[string]struct{} // set of targets for which history is currently requested. + + pendingChannels map[string]time.Time // set of join requests stamps for channels. } func NewSession(out chan<- Message, params SessionParams) *Session { s := &Session{ - out: out, - typings: NewTypings(), - typingStamps: map[string]typingStamp{}, - nick: params.Nickname, - nickCf: CasemapASCII(params.Nickname), - user: params.Username, - real: params.RealName, - auth: params.Auth, - availableCaps: map[string]string{}, - enabledCaps: map[string]struct{}{}, - casemap: CasemapRFC1459, - chantypes: "#&", - linelen: 512, - historyLimit: 100, - prefixSymbols: "@+", - prefixModes: "ov", - users: map[string]*User{}, - channels: map[string]Channel{}, - chBatches: map[string]HistoryEvent{}, - chReqs: map[string]struct{}{}, + out: out, + typings: NewTypings(), + typingStamps: map[string]typingStamp{}, + nick: params.Nickname, + nickCf: CasemapASCII(params.Nickname), + user: params.Username, + real: params.RealName, + auth: params.Auth, + availableCaps: map[string]string{}, + enabledCaps: map[string]struct{}{}, + casemap: CasemapRFC1459, + chantypes: "#&", + linelen: 512, + historyLimit: 100, + prefixSymbols: "@+", + prefixModes: "ov", + users: map[string]*User{}, + channels: map[string]Channel{}, + chBatches: map[string]HistoryEvent{}, + chReqs: map[string]struct{}{}, + pendingChannels: map[string]time.Time{}, } s.out <- NewMessage("CAP", "LS", "302") @@ -272,6 +275,8 @@ func (s *Session) SendRaw(raw string) { } func (s *Session) Join(channel, key string) { + channelCf := s.Casemap(channel) + s.pendingChannels[channelCf] = time.Now() if key == "" { s.out <- NewMessage("JOIN", channel) } else { @@ -685,9 +690,13 @@ func (s *Session) handleRegistered(msg Message) Event { if c, ok := s.channels[channelCf]; ok && !c.complete { c.complete = true s.channels[channelCf] = c - return SelfJoinEvent{ + ev := SelfJoinEvent{ Channel: c.Name, } + if stamp, ok := s.pendingChannels[channelCf]; ok && time.Now().Sub(stamp) < 5*time.Second { + ev.Requested = true + } + return ev } case rplTopic: channelCf := s.Casemap(msg.Params[1]) diff --git a/ui/buffers.go b/ui/buffers.go index 297f70e..6de3923 100644 --- a/ui/buffers.go +++ b/ui/buffers.go @@ -224,17 +224,16 @@ func (bs *BufferList) Previous() { bs.list[bs.current].unread = false } -func (bs *BufferList) Add(title string) (ok bool) { +func (bs *BufferList) Add(title string) int { lTitle := strings.ToLower(title) - for _, b := range bs.list { + for i, b := range bs.list { if strings.ToLower(b.title) == lTitle { - return + return i } } - ok = true bs.list = append(bs.list, buffer{title: title}) - return + return len(bs.list) - 1 } func (bs *BufferList) Remove(title string) (ok bool) { @@ -128,8 +128,8 @@ func (ui *UI) IsAtTop() bool { return ui.bs.IsAtTop() } -func (ui *UI) AddBuffer(title string) { - _ = ui.bs.Add(title) +func (ui *UI) AddBuffer(title string) int { + return ui.bs.Add(title) } func (ui *UI) RemoveBuffer(title string) { @@ -156,6 +156,14 @@ func (ui *UI) JumpBuffer(sub string) bool { return false } +func (ui *UI) JumpBufferIndex(i int) bool { + if i >= 0 && i < len(ui.bs.list) { + ui.bs.To(i) + return true + } + return false +} + func (ui *UI) SetStatus(status string) { ui.status = status } |