Browse Source

CHATHISTORY with no results SHOULD send an empty batch

tags/v2.0.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
03378da81b
4 changed files with 15 additions and 16 deletions
  1. 4
    5
      irc/channel.go
  2. 8
    8
      irc/client.go
  3. 2
    2
      irc/handlers.go
  4. 1
    1
      irc/znc.go

+ 4
- 5
irc/channel.go View File

@@ -944,7 +944,9 @@ func (channel *Channel) replayHistoryForResume(session *Session, after time.Time
944 944
 		items, complete, _ = seq.Between(afterS, beforeS, channel.server.Config().History.ZNCMax)
945 945
 	}
946 946
 	rb := NewResponseBuffer(session)
947
-	channel.replayHistoryItems(rb, items, false)
947
+	if len(items) != 0 {
948
+		channel.replayHistoryItems(rb, items, false)
949
+	}
948 950
 	if !complete && !session.resumeDetails.HistoryIncomplete {
949 951
 		// warn here if we didn't warn already
950 952
 		rb.Add(nil, histServMask, "NOTICE", channel.Name(), session.client.t("Some additional message history may have been lost"))
@@ -961,10 +963,7 @@ func stripMaskFromNick(nickMask string) (nick string) {
961 963
 }
962 964
 
963 965
 func (channel *Channel) replayHistoryItems(rb *ResponseBuffer, items []history.Item, autoreplay bool) {
964
-	if len(items) == 0 {
965
-		return
966
-	}
967
-
966
+	// send an empty batch if necessary, as per the CHATHISTORY spec
968 967
 	chname := channel.Name()
969 968
 	client := rb.target
970 969
 	eventPlayback := rb.session.capabilities.Has(caps.EventPlayback)

+ 8
- 8
irc/client.go View File

@@ -832,9 +832,11 @@ func (session *Session) playResume() {
832 832
 	if !timestamp.IsZero() && privmsgSeq != nil {
833 833
 		after := history.Selector{Time: timestamp}
834 834
 		items, complete, _ := privmsgSeq.Between(after, history.Selector{}, config.History.ZNCMax)
835
-		rb := NewResponseBuffer(session)
836
-		client.replayPrivmsgHistory(rb, items, "", complete)
837
-		rb.Send(true)
835
+		if len(items) != 0 {
836
+			rb := NewResponseBuffer(session)
837
+			client.replayPrivmsgHistory(rb, items, "", complete)
838
+			rb.Send(true)
839
+		}
838 840
 	}
839 841
 
840 842
 	session.resumeDetails = nil
@@ -844,12 +846,10 @@ func (client *Client) replayPrivmsgHistory(rb *ResponseBuffer, items []history.I
844 846
 	var batchID string
845 847
 	details := client.Details()
846 848
 	nick := details.nick
847
-	if 0 < len(items) {
848
-		if target == "" {
849
-			target = nick
850
-		}
851
-		batchID = rb.StartNestedHistoryBatch(target)
849
+	if target == "" {
850
+		target = nick
852 851
 	}
852
+	batchID = rb.StartNestedHistoryBatch(target)
853 853
 
854 854
 	allowTags := rb.session.capabilities.Has(caps.MessageTags)
855 855
 	for _, item := range items {

+ 2
- 2
irc/handlers.go View File

@@ -525,7 +525,7 @@ func chathistoryHandler(server *Server, client *Client, msg ircmsg.IrcMessage, r
525 525
 	var err error
526 526
 	defer func() {
527 527
 		// successful responses are sent as a chathistory or history batch
528
-		if err == nil && 0 < len(items) {
528
+		if err == nil {
529 529
 			if channel != nil {
530 530
 				channel.replayHistoryItems(rb, items, false)
531 531
 			} else {
@@ -958,7 +958,7 @@ func historyHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R
958 958
 		items, _, err = sequence.Between(start, end, limit)
959 959
 	}
960 960
 
961
-	if err == nil {
961
+	if err == nil && len(items) != 0 {
962 962
 		if channel != nil {
963 963
 			channel.replayHistoryItems(rb, items, false)
964 964
 		} else {

+ 1
- 1
irc/znc.go View File

@@ -124,7 +124,7 @@ func zncPlayPrivmsgs(client *Client, rb *ResponseBuffer, after, before time.Time
124 124
 	}
125 125
 	zncMax := client.server.Config().History.ZNCMax
126 126
 	items, _, err := sequence.Between(history.Selector{Time: after}, history.Selector{Time: before}, zncMax)
127
-	if err == nil {
127
+	if err == nil && len(items) != 0 {
128 128
 		client.replayPrivmsgHistory(rb, items, "", true)
129 129
 	}
130 130
 }

Loading…
Cancel
Save