commit 31b8f90

Hubert Hirtz  ·  2020-06-03 21:05:44 +0000 UTC
parent 7824063
Show JOIN and PARTs
5 files changed,  +47, -12
+9, -3
 1@@ -34,7 +34,7 @@ func main() {
 2 	defer app.Close()
 3 
 4 	addr := cfg.Addr
 5-	app.AddLine("home", fmt.Sprintf("Connecting to %s...", addr), time.Now())
 6+	app.AddLine("home", fmt.Sprintf("Connecting to %s...", addr), time.Now(), false)
 7 
 8 	conn, err := tls.Dial("tcp", addr, nil)
 9 	if err != nil {
10@@ -57,14 +57,20 @@ func main() {
11 		case ev := <-s.Poll():
12 			switch ev := ev.(type) {
13 			case irc.RegisteredEvent:
14-				app.AddLine("home", "Connected to the server", time.Now())
15+				app.AddLine("home", "Connected to the server", time.Now(), false)
16 			case irc.SelfJoinEvent:
17 				app.AddBuffer(ev.Channel)
18+			case irc.UserJoinEvent:
19+				line := fmt.Sprintf("\x033+\x0314%s", ev.Nick)
20+				app.AddLine(ev.Channel, line, ev.Time, true)
21 			case irc.SelfPartEvent:
22 				app.RemoveBuffer(ev.Channel)
23+			case irc.UserPartEvent:
24+				line := fmt.Sprintf("\x034-\x0314%s", ev.Nick)
25+				app.AddLine(ev.Channel, line, ev.Time, true)
26 			case irc.ChannelMessageEvent:
27 				line := formatIRCMessage(ev.Nick, ev.Content)
28-				app.AddLine(ev.Channel, line, ev.Time)
29+				app.AddLine(ev.Channel, line, ev.Time, false)
30 			case error:
31 				log.Panicln(ev)
32 			}
+2, -0
 1@@ -32,6 +32,7 @@ func (c ChannelEvent) ChannelMapped() (channel string) {
 2 type UserJoinEvent struct {
 3 	UserEvent
 4 	ChannelEvent
 5+	Time time.Time
 6 }
 7 
 8 type SelfPartEvent struct {
 9@@ -41,6 +42,7 @@ type SelfPartEvent struct {
10 type UserPartEvent struct {
11 	UserEvent
12 	ChannelEvent
13+	Time time.Time
14 }
15 
16 type SelfJoinEvent struct {
+22, -2
 1@@ -527,7 +527,17 @@ func (s *Session) handle(msg Message) (ev Event, err error) {
 2 				s.users[lNick] = User{Nick: nick}
 3 			}
 4 			c.Members[lNick] = ""
 5-			ev = UserJoinEvent{ChannelEvent: channelEv, UserEvent: UserEvent{Nick: nick}}
 6+
 7+			t, ok := msg.Time()
 8+			if !ok {
 9+				t = time.Now()
10+			}
11+
12+			ev = UserJoinEvent{
13+				ChannelEvent: channelEv,
14+				UserEvent:    UserEvent{Nick: nick},
15+				Time:         t,
16+			}
17 		}
18 	case "PART":
19 		nick, _, _ := FullMask(msg.Prefix)
20@@ -540,7 +550,17 @@ func (s *Session) handle(msg Message) (ev Event, err error) {
21 			ev = SelfPartEvent{ChannelEvent: channelEv}
22 		} else if c, ok := s.channels[channel]; ok {
23 			delete(c.Members, lNick)
24-			ev = UserPartEvent{ChannelEvent: channelEv, UserEvent: UserEvent{Nick: nick}}
25+
26+			t, ok := msg.Time()
27+			if !ok {
28+				t = time.Now()
29+			}
30+
31+			ev = UserPartEvent{
32+				ChannelEvent: channelEv,
33+				UserEvent:    UserEvent{Nick: nick},
34+				Time:         t,
35+			}
36 		}
37 	case "353": // RPL_NAMREPLY
38 		channel := strings.ToLower(msg.Params[2])
+12, -5
 1@@ -99,9 +99,16 @@ func (bs *BufferList) Idx(title string) (idx int) {
 2 	return
 3 }
 4 
 5-func (bs *BufferList) AddLine(idx int, line string, t time.Time) {
 6-	bs.List[idx].Content = append(bs.List[idx].Content, Line{
 7-		Time:    t,
 8-		Content: line,
 9-	})
10+func (bs *BufferList) AddLine(idx int, line string, t time.Time, isStatus bool) {
11+	n := len(bs.List[idx].Content)
12+
13+	if isStatus && n != 0 && bs.List[idx].Content[n-1].IsStatus {
14+		bs.List[idx].Content[n-1].Content += " " + line
15+	} else {
16+		bs.List[idx].Content = append(bs.List[idx].Content, Line{
17+			Time:     t,
18+			IsStatus: isStatus,
19+			Content:  line,
20+		})
21+	}
22 }
+2, -2
 1@@ -112,13 +112,13 @@ func (ui *UI) RemoveBuffer(title string) {
 2 	}
 3 }
 4 
 5-func (ui *UI) AddLine(buffer string, line string, t time.Time) {
 6+func (ui *UI) AddLine(buffer string, line string, t time.Time, isStatus bool) {
 7 	idx := ui.bufferList.Idx(buffer)
 8 	if idx < 0 {
 9 		return
10 	}
11 
12-	ui.bufferList.AddLine(idx, line, t)
13+	ui.bufferList.AddLine(idx, line, t, isStatus)
14 
15 	if idx == ui.bufferList.Current {
16 		ui.drawBuffer()