~taiite/public-inbox

senpai: Switch to the buffer of a new user-requested channel join v1 SUPERSEDED

delthas: 1
 Switch to the buffer of a new user-requested channel join

 5 files changed, 40 insertions(+), 26 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~taiite/public-inbox/patches/23790/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH senpai] Switch to the buffer of a new user-requested channel join Export this patch

---
 app.go         |  3 +++
 commands.go    |  2 +-
 irc/events.go  |  3 ++-
 irc/session.go | 51 +++++++++++++++++++++++++++++---------------------
 ui/ui.go       |  7 ++++---
 5 files changed, 40 insertions(+), 26 deletions(-)

diff --git a/app.go b/app.go
index 57c12de..9bcd739 100644
--- a/app.go
+++ b/app.go
@@ -514,6 +514,9 @@ func (app *App) handleIRCEvent(ev interface{}) {
		app.s.NewHistoryRequest(ev.Channel).
			WithLimit(200).
			Before(msg.TimeOrNow())
		if ev.Requested {
			app.win.JumpBuffer(ev.Channel, true)
		}
	case irc.UserJoinEvent:
		body := new(ui.StyledStringBuilder)
		body.Grow(len(ev.User) + 1)
diff --git a/commands.go b/commands.go
index b9ac392..998b696 100644
--- a/commands.go
+++ b/commands.go
@@ -491,7 +491,7 @@ func (app *App) handleInput(buffer, content string) error {

func commandDoBuffer(app *App, buffer string, args []string) error {
	name := args[0]
	if !app.win.JumpBuffer(args[0]) {
	if !app.win.JumpBuffer(args[0], false) {
		return fmt.Errorf("none of the buffers match %q", name)
	}

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 dabec03..c46f0b2 100644
--- a/irc/session.go
+++ b/irc/session.go
@@ -128,30 +128,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]time.Time{},
		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]time.Time{},
		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")
@@ -270,6 +273,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 {
@@ -658,9 +663,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/ui.go b/ui/ui.go
index 0b45a3c..61c7ef3 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -144,10 +144,11 @@ func (ui *UI) AddLines(buffer string, lines []Line) {
	ui.bs.AddLines(buffer, lines)
}

func (ui *UI) JumpBuffer(sub string) bool {
	subLower := strings.ToLower(sub)
func (ui *UI) JumpBuffer(pattern string, exact bool) bool {
	subLower := strings.ToLower(pattern)
	for i, b := range ui.bs.list {
		if strings.Contains(strings.ToLower(b.title), subLower) {
		if (exact && strings.ToLower(b.title) == subLower) ||
			(!exact && strings.Contains(strings.ToLower(b.title), subLower)) {
			ui.bs.To(i)
			return true
		}
-- 
2.30.0