소스 검색

fix #831

tags/v2.0.0-rc1
Shivaram Lingamneni 4 년 전
부모
커밋
85dfebce43
3개의 변경된 파일27개의 추가작업 그리고 19개의 파일을 삭제
  1. 6
    5
      irc/channel.go
  2. 1
    1
      irc/client.go
  3. 20
    13
      irc/znc.go

+ 6
- 5
irc/channel.go 파일 보기

@@ -772,19 +772,20 @@ func (channel *Channel) autoReplayHistory(client *Client, rb *ResponseBuffer, sk
772 772
 	// autoreplay any messages as necessary
773 773
 	var items []history.Item
774 774
 
775
-	var after, before time.Time
775
+	var start, end time.Time
776 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 778
 	} else if !rb.session.autoreplayMissedSince.IsZero() {
779 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 785
 		_, seq, _ := channel.server.GetHistorySequence(channel, client, "")
785 786
 		if seq != nil {
786 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 790
 	} else if !rb.session.HasHistoryCaps() {
790 791
 		var replayLimit int

+ 1
- 1
irc/client.go 파일 보기

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

+ 20
- 13
irc/znc.go 파일 보기

@@ -54,8 +54,8 @@ func zncWireTimeToTime(str string) (result time.Time) {
54 54
 }
55 55
 
56 56
 type zncPlaybackTimes struct {
57
-	after   time.Time
58
-	before  time.Time
57
+	start   time.Time
58
+	end     time.Time
59 59
 	targets StringSet // nil for "*" (everything), otherwise the channel names
60 60
 	setAt   time.Time
61 61
 }
@@ -80,19 +80,26 @@ func (z *zncPlaybackTimes) ValidFor(target string) bool {
80 80
 // PRIVMSG *playback :play <target> [lower_bound] [upper_bound]
81 81
 // e.g., PRIVMSG *playback :play * 1558374442
82 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 84
 		return
85 85
 	} else if strings.ToLower(params[0]) != "play" {
86 86
 		return
87 87
 	}
88 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 105
 	var targets StringSet
@@ -115,7 +122,7 @@ func zncPlaybackHandler(client *Client, command string, params []string, rb *Res
115 122
 	//          channels; redundant JOIN is a complete no-op so we won't replay twice
116 123
 
117 124
 	if params[1] == "*" {
118
-		zncPlayPrivmsgs(client, rb, "*", after, before)
125
+		zncPlayPrivmsgs(client, rb, "*", start, end)
119 126
 	} else {
120 127
 		targets = make(StringSet)
121 128
 		for _, targetName := range strings.Split(targetString, ",") {
@@ -132,8 +139,8 @@ func zncPlaybackHandler(client *Client, command string, params []string, rb *Res
132 139
 	}
133 140
 
134 141
 	rb.session.zncPlaybackTimes = &zncPlaybackTimes{
135
-		after:   after,
136
-		before:  before,
142
+		start:   start,
143
+		end:     end,
137 144
 		targets: targets,
138 145
 		setAt:   time.Now().UTC(),
139 146
 	}
@@ -146,7 +153,7 @@ func zncPlaybackHandler(client *Client, command string, params []string, rb *Res
146 153
 	}
147 154
 
148 155
 	for _, cfNick := range nickTargets {
149
-		zncPlayPrivmsgs(client, rb, cfNick, after, before)
156
+		zncPlayPrivmsgs(client, rb, cfNick, start, end)
150 157
 		rb.Flush(true)
151 158
 	}
152 159
 }

Loading…
취소
저장