Browse Source

clean up nested batch logic

tags/v2.12.0-rc1
Shivaram Lingamneni 11 months ago
parent
commit
38a6d17ee5
5 changed files with 9 additions and 19 deletions
  1. 2
    0
      irc/caps/constants.go
  2. 1
    1
      irc/channel.go
  3. 1
    1
      irc/client.go
  4. 2
    4
      irc/handlers.go
  5. 3
    13
      irc/responsebuffer.go

+ 2
- 0
irc/caps/constants.go View File

@@ -62,6 +62,8 @@ const (
62 62
 	RelaymsgTagName = "draft/relaymsg"
63 63
 	// BOT mode: https://ircv3.net/specs/extensions/bot-mode
64 64
 	BotTagName = "bot"
65
+	// https://ircv3.net/specs/extensions/chathistory
66
+	ChathistoryTargetsBatchType = "draft/chathistory-targets"
65 67
 )
66 68
 
67 69
 func init() {

+ 1
- 1
irc/channel.go View File

@@ -1059,7 +1059,7 @@ func (channel *Channel) replayHistoryItems(rb *ResponseBuffer, items []history.I
1059 1059
 		}
1060 1060
 	}
1061 1061
 
1062
-	batchID := rb.StartNestedHistoryBatch(chname)
1062
+	batchID := rb.StartNestedBatch(chname, "chathistory")
1063 1063
 	defer rb.EndNestedBatch(batchID)
1064 1064
 
1065 1065
 	for _, item := range items {

+ 1
- 1
irc/client.go View File

@@ -850,7 +850,7 @@ func (client *Client) replayPrivmsgHistory(rb *ResponseBuffer, items []history.I
850 850
 	if target == "" {
851 851
 		target = nick
852 852
 	}
853
-	batchID = rb.StartNestedHistoryBatch(target)
853
+	batchID = rb.StartNestedBatch(target, "chathistory")
854 854
 
855 855
 	isSelfMessage := func(item *history.Item) bool {
856 856
 		// XXX: Params[0] is the message target. if the source of this message is an in-memory

+ 2
- 4
irc/handlers.go View File

@@ -655,10 +655,8 @@ func chathistoryHandler(server *Server, client *Client, msg ircmsg.Message, rb *
655 655
 		} else {
656 656
 			// successful responses are sent as a chathistory or history batch
657 657
 			if listTargets {
658
-				if rb.session.capabilities.Has(caps.Batch) { // #2066
659
-					batchID := rb.StartNestedBatch("draft/chathistory-targets")
660
-					defer rb.EndNestedBatch(batchID)
661
-				}
658
+				batchID := rb.StartNestedBatch(caps.ChathistoryTargetsBatchType)
659
+				defer rb.EndNestedBatch(batchID)
662 660
 				for _, target := range targets {
663 661
 					name := server.UnfoldName(target.CfName)
664 662
 					rb.Add(nil, server.name, "CHATHISTORY", "TARGETS", name,

+ 3
- 13
irc/responsebuffer.go View File

@@ -193,6 +193,9 @@ func (rb *ResponseBuffer) sendBatchEnd(blocking bool) {
193 193
 // Starts a nested batch (see the ResponseBuffer struct definition for a description of
194 194
 // how this works)
195 195
 func (rb *ResponseBuffer) StartNestedBatch(batchType string, params ...string) (batchID string) {
196
+	if !rb.session.capabilities.Has(caps.Batch) {
197
+		return
198
+	}
196 199
 	batchID = rb.session.generateBatchID()
197 200
 	msgParams := make([]string, len(params)+2)
198 201
 	msgParams[0] = "+" + batchID
@@ -219,19 +222,6 @@ func (rb *ResponseBuffer) EndNestedBatch(batchID string) {
219 222
 	rb.AddMessage(ircmsg.MakeMessage(nil, rb.target.server.name, "BATCH", "-"+batchID))
220 223
 }
221 224
 
222
-// Convenience to start a nested batch for history lines, at the highest level
223
-// supported by the client (`history`, `chathistory`, or no batch, in descending order).
224
-func (rb *ResponseBuffer) StartNestedHistoryBatch(params ...string) (batchID string) {
225
-	var batchType string
226
-	if rb.session.capabilities.Has(caps.Batch) {
227
-		batchType = "chathistory"
228
-	}
229
-	if batchType != "" {
230
-		batchID = rb.StartNestedBatch(batchType, params...)
231
-	}
232
-	return
233
-}
234
-
235 225
 // Send sends all messages in the buffer to the client.
236 226
 // Afterwards, the buffer is in an undefined state and MUST NOT be used further.
237 227
 // If `blocking` is true you MUST be sending to the client from its own goroutine.

Loading…
Cancel
Save