commit 32bf7bf

Hugo Osvaldo Barrera  ·  2023-07-02 22:55:15 +0000 UTC
parent 2a9fc6e
Process "last seen" markers of joined channels

Previously, senpai received MARKREAD events of newly joined channels but
dropped them, because they were received before the RPL_ENDOFNAMES which
marks the ends of the initial channel join batch.

This fixes the issue by storing the read marker, then using it in the
channel join event so that it can be set in the channel.
3 files changed,  +16, -0
M app.go
M app.go
+3, -0
 1@@ -792,6 +792,9 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
 2 		}
 3 	case irc.SelfJoinEvent:
 4 		i, added := app.win.AddBuffer(netID, "", ev.Channel)
 5+		if !ev.Read.IsZero() {
 6+			app.win.SetRead(netID, ev.Channel, ev.Read)
 7+		}
 8 		bounds, ok := app.messageBounds[boundKey{netID, ev.Channel}]
 9 		if added || !ok {
10 			if t, ok := msg.Time(); ok {
+1, -0
1@@ -26,6 +26,7 @@ type SelfJoinEvent struct {
2 	Channel   string
3 	Requested bool // whether we recently requested to join that channel
4 	Topic     string
5+	Read      time.Time
6 }
7 
8 type UserJoinEvent struct {
+12, -0
 1@@ -95,6 +95,7 @@ type Channel struct {
 2 	Topic     string           // the topic of the channel, or "" if absent.
 3 	TopicWho  *Prefix          // the name of the last user who set the topic.
 4 	TopicTime time.Time        // the last time the topic has been changed.
 5+	Read      time.Time        // the time until which messages were read.
 6 
 7 	complete bool // whether this structure is fully initialized.
 8 }
 9@@ -1045,6 +1046,7 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er
10 			ev := SelfJoinEvent{
11 				Channel: c.Name,
12 				Topic:   c.Topic,
13+				Read:    c.Read,
14 			}
15 			if stamp, ok := s.pendingChannels[channelCf]; ok && time.Since(stamp) < 5*time.Second {
16 				ev.Requested = true
17@@ -1367,6 +1369,16 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er
18 		if !ok {
19 			return nil, nil
20 		}
21+
22+		channelCf := s.Casemap(target)
23+		if c, ok := s.channels[channelCf]; ok {
24+			c.Read = t
25+			s.channels[channelCf] = c
26+			if !c.complete {
27+				return nil, nil
28+			}
29+		}
30+
31 		return ReadEvent{
32 			Target:    target,
33 			Timestamp: t,