commit 9300574
delthas
·
2021-07-13 17:26:24 +0000 UTC
parent c078fbb
Switch to the buffer of a new user-requested channel join
5 files changed,
+50,
-30
M
app.go
+4,
-1
1@@ -511,10 +511,13 @@ func (app *App) handleIRCEvent(ev interface{}) {
2 })
3 }
4 case irc.SelfJoinEvent:
5- app.win.AddBuffer(ev.Channel)
6+ i := app.win.AddBuffer(ev.Channel)
7 app.s.NewHistoryRequest(ev.Channel).
8 WithLimit(200).
9 Before(msg.TimeOrNow())
10+ if ev.Requested {
11+ app.win.JumpBufferIndex(i)
12+ }
13 case irc.UserJoinEvent:
14 body := new(ui.StyledStringBuilder)
15 body.Grow(len(ev.User) + 1)
+2,
-1
1@@ -22,7 +22,8 @@ type UserNickEvent struct {
2 }
3
4 type SelfJoinEvent struct {
5- Channel string
6+ Channel string
7+ Requested bool // whether we recently requested to join that channel
8 }
9
10 type UserJoinEvent struct {
+30,
-21
1@@ -130,30 +130,33 @@ type Session struct {
2 channels map[string]Channel // joined channels.
3 chBatches map[string]HistoryEvent // channel history batches being processed.
4 chReqs map[string]struct{} // set of targets for which history is currently requested.
5+
6+ pendingChannels map[string]time.Time // set of join requests stamps for channels.
7 }
8
9 func NewSession(out chan<- Message, params SessionParams) *Session {
10 s := &Session{
11- out: out,
12- typings: NewTypings(),
13- typingStamps: map[string]typingStamp{},
14- nick: params.Nickname,
15- nickCf: CasemapASCII(params.Nickname),
16- user: params.Username,
17- real: params.RealName,
18- auth: params.Auth,
19- availableCaps: map[string]string{},
20- enabledCaps: map[string]struct{}{},
21- casemap: CasemapRFC1459,
22- chantypes: "#&",
23- linelen: 512,
24- historyLimit: 100,
25- prefixSymbols: "@+",
26- prefixModes: "ov",
27- users: map[string]*User{},
28- channels: map[string]Channel{},
29- chBatches: map[string]HistoryEvent{},
30- chReqs: map[string]struct{}{},
31+ out: out,
32+ typings: NewTypings(),
33+ typingStamps: map[string]typingStamp{},
34+ nick: params.Nickname,
35+ nickCf: CasemapASCII(params.Nickname),
36+ user: params.Username,
37+ real: params.RealName,
38+ auth: params.Auth,
39+ availableCaps: map[string]string{},
40+ enabledCaps: map[string]struct{}{},
41+ casemap: CasemapRFC1459,
42+ chantypes: "#&",
43+ linelen: 512,
44+ historyLimit: 100,
45+ prefixSymbols: "@+",
46+ prefixModes: "ov",
47+ users: map[string]*User{},
48+ channels: map[string]Channel{},
49+ chBatches: map[string]HistoryEvent{},
50+ chReqs: map[string]struct{}{},
51+ pendingChannels: map[string]time.Time{},
52 }
53
54 s.out <- NewMessage("CAP", "LS", "302")
55@@ -272,6 +275,8 @@ func (s *Session) SendRaw(raw string) {
56 }
57
58 func (s *Session) Join(channel, key string) {
59+ channelCf := s.Casemap(channel)
60+ s.pendingChannels[channelCf] = time.Now()
61 if key == "" {
62 s.out <- NewMessage("JOIN", channel)
63 } else {
64@@ -685,9 +690,13 @@ func (s *Session) handleRegistered(msg Message) Event {
65 if c, ok := s.channels[channelCf]; ok && !c.complete {
66 c.complete = true
67 s.channels[channelCf] = c
68- return SelfJoinEvent{
69+ ev := SelfJoinEvent{
70 Channel: c.Name,
71 }
72+ if stamp, ok := s.pendingChannels[channelCf]; ok && time.Now().Sub(stamp) < 5*time.Second {
73+ ev.Requested = true
74+ }
75+ return ev
76 }
77 case rplTopic:
78 channelCf := s.Casemap(msg.Params[1])
+4,
-5
1@@ -224,17 +224,16 @@ func (bs *BufferList) Previous() {
2 bs.list[bs.current].unread = false
3 }
4
5-func (bs *BufferList) Add(title string) (ok bool) {
6+func (bs *BufferList) Add(title string) int {
7 lTitle := strings.ToLower(title)
8- for _, b := range bs.list {
9+ for i, b := range bs.list {
10 if strings.ToLower(b.title) == lTitle {
11- return
12+ return i
13 }
14 }
15
16- ok = true
17 bs.list = append(bs.list, buffer{title: title})
18- return
19+ return len(bs.list) - 1
20 }
21
22 func (bs *BufferList) Remove(title string) (ok bool) {
M
ui/ui.go
+10,
-2
1@@ -128,8 +128,8 @@ func (ui *UI) IsAtTop() bool {
2 return ui.bs.IsAtTop()
3 }
4
5-func (ui *UI) AddBuffer(title string) {
6- _ = ui.bs.Add(title)
7+func (ui *UI) AddBuffer(title string) int {
8+ return ui.bs.Add(title)
9 }
10
11 func (ui *UI) RemoveBuffer(title string) {
12@@ -156,6 +156,14 @@ func (ui *UI) JumpBuffer(sub string) bool {
13 return false
14 }
15
16+func (ui *UI) JumpBufferIndex(i int) bool {
17+ if i >= 0 && i < len(ui.bs.list) {
18+ ui.bs.To(i)
19+ return true
20+ }
21+ return false
22+}
23+
24 func (ui *UI) SetStatus(status string) {
25 ui.status = status
26 }