Browse Source

fix #831

tags/v2.0.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
85dfebce43
3 changed files with 27 additions and 19 deletions
  1. 6
    5
      irc/channel.go
  2. 1
    1
      irc/client.go
  3. 20
    13
      irc/znc.go

+ 6
- 5
irc/channel.go View File

772
 	// autoreplay any messages as necessary
772
 	// autoreplay any messages as necessary
773
 	var items []history.Item
773
 	var items []history.Item
774
 
774
 
775
-	var after, before time.Time
775
+	var start, end time.Time
776
 	if rb.session.zncPlaybackTimes.ValidFor(channel.NameCasefolded()) {
776
 	if rb.session.zncPlaybackTimes.ValidFor(channel.NameCasefolded()) {
777
-		after, before = rb.session.zncPlaybackTimes.after, rb.session.zncPlaybackTimes.before
777
+		start, end = rb.session.zncPlaybackTimes.start, rb.session.zncPlaybackTimes.end
778
 	} else if !rb.session.autoreplayMissedSince.IsZero() {
778
 	} else if !rb.session.autoreplayMissedSince.IsZero() {
779
 		// we already checked for history caps in `playReattachMessages`
779
 		// we already checked for history caps in `playReattachMessages`
780
-		after = rb.session.autoreplayMissedSince
780
+		start = time.Now().UTC()
781
+		end = rb.session.autoreplayMissedSince
781
 	}
782
 	}
782
 
783
 
783
-	if !after.IsZero() || !before.IsZero() {
784
+	if !start.IsZero() || !end.IsZero() {
784
 		_, seq, _ := channel.server.GetHistorySequence(channel, client, "")
785
 		_, seq, _ := channel.server.GetHistorySequence(channel, client, "")
785
 		if seq != nil {
786
 		if seq != nil {
786
 			zncMax := channel.server.Config().History.ZNCMax
787
 			zncMax := channel.server.Config().History.ZNCMax
787
-			items, _, _ = seq.Between(history.Selector{Time: after}, history.Selector{Time: before}, zncMax)
788
+			items, _, _ = seq.Between(history.Selector{Time: start}, history.Selector{Time: end}, zncMax)
788
 		}
789
 		}
789
 	} else if !rb.session.HasHistoryCaps() {
790
 	} else if !rb.session.HasHistoryCaps() {
790
 		var replayLimit int
791
 		var replayLimit int

+ 1
- 1
irc/client.go View File

668
 	}
668
 	}
669
 	if !session.autoreplayMissedSince.IsZero() && !hasHistoryCaps {
669
 	if !session.autoreplayMissedSince.IsZero() && !hasHistoryCaps {
670
 		rb := NewResponseBuffer(session)
670
 		rb := NewResponseBuffer(session)
671
-		zncPlayPrivmsgs(client, rb, "*", session.autoreplayMissedSince, time.Time{})
671
+		zncPlayPrivmsgs(client, rb, "*", time.Now().UTC(), session.autoreplayMissedSince)
672
 		rb.Send(true)
672
 		rb.Send(true)
673
 	}
673
 	}
674
 	session.autoreplayMissedSince = time.Time{}
674
 	session.autoreplayMissedSince = time.Time{}

+ 20
- 13
irc/znc.go View File

54
 }
54
 }
55
 
55
 
56
 type zncPlaybackTimes struct {
56
 type zncPlaybackTimes struct {
57
-	after   time.Time
58
-	before  time.Time
57
+	start   time.Time
58
+	end     time.Time
59
 	targets StringSet // nil for "*" (everything), otherwise the channel names
59
 	targets StringSet // nil for "*" (everything), otherwise the channel names
60
 	setAt   time.Time
60
 	setAt   time.Time
61
 }
61
 }
80
 // PRIVMSG *playback :play <target> [lower_bound] [upper_bound]
80
 // PRIVMSG *playback :play <target> [lower_bound] [upper_bound]
81
 // e.g., PRIVMSG *playback :play * 1558374442
81
 // e.g., PRIVMSG *playback :play * 1558374442
82
 func zncPlaybackHandler(client *Client, command string, params []string, rb *ResponseBuffer) {
82
 func zncPlaybackHandler(client *Client, command string, params []string, rb *ResponseBuffer) {
83
-	if len(params) < 2 {
83
+	if len(params) < 2 || len(params) > 4 {
84
 		return
84
 		return
85
 	} else if strings.ToLower(params[0]) != "play" {
85
 	} else if strings.ToLower(params[0]) != "play" {
86
 		return
86
 		return
87
 	}
87
 	}
88
 	targetString := params[1]
88
 	targetString := params[1]
89
 
89
 
90
-	var after, before time.Time
91
-	if 2 < len(params) {
92
-		after = zncWireTimeToTime(params[2])
93
-	}
94
-	if 3 < len(params) {
95
-		before = zncWireTimeToTime(params[3])
90
+	now := time.Now().UTC()
91
+	var start, end time.Time
92
+	switch len(params) {
93
+	case 3:
94
+		// #831: this should have the same semantics as `LATEST timestamp=qux`,
95
+		// or equivalently `BETWEEN timestamp=$now timestamp=qux`, as opposed to
96
+		// `AFTER timestamp=qux` (this matters in the case where there are
97
+		// more than znc-maxmessages available)
98
+		start = now
99
+		end = zncWireTimeToTime(params[2])
100
+	case 4:
101
+		start = zncWireTimeToTime(params[2])
102
+		end = zncWireTimeToTime(params[3])
96
 	}
103
 	}
97
 
104
 
98
 	var targets StringSet
105
 	var targets StringSet
115
 	//          channels; redundant JOIN is a complete no-op so we won't replay twice
122
 	//          channels; redundant JOIN is a complete no-op so we won't replay twice
116
 
123
 
117
 	if params[1] == "*" {
124
 	if params[1] == "*" {
118
-		zncPlayPrivmsgs(client, rb, "*", after, before)
125
+		zncPlayPrivmsgs(client, rb, "*", start, end)
119
 	} else {
126
 	} else {
120
 		targets = make(StringSet)
127
 		targets = make(StringSet)
121
 		for _, targetName := range strings.Split(targetString, ",") {
128
 		for _, targetName := range strings.Split(targetString, ",") {
132
 	}
139
 	}
133
 
140
 
134
 	rb.session.zncPlaybackTimes = &zncPlaybackTimes{
141
 	rb.session.zncPlaybackTimes = &zncPlaybackTimes{
135
-		after:   after,
136
-		before:  before,
142
+		start:   start,
143
+		end:     end,
137
 		targets: targets,
144
 		targets: targets,
138
 		setAt:   time.Now().UTC(),
145
 		setAt:   time.Now().UTC(),
139
 	}
146
 	}
146
 	}
153
 	}
147
 
154
 
148
 	for _, cfNick := range nickTargets {
155
 	for _, cfNick := range nickTargets {
149
-		zncPlayPrivmsgs(client, rb, cfNick, after, before)
156
+		zncPlayPrivmsgs(client, rb, cfNick, start, end)
150
 		rb.Flush(true)
157
 		rb.Flush(true)
151
 	}
158
 	}
152
 }
159
 }

Loading…
Cancel
Save