Bladeren bron

clean up nested batch logic

tags/v2.12.0-rc1
Shivaram Lingamneni 11 maanden geleden
bovenliggende
commit
38a6d17ee5
5 gewijzigde bestanden met toevoegingen van 9 en 19 verwijderingen
  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 Bestand weergeven

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

+ 1
- 1
irc/channel.go Bestand weergeven

1059
 		}
1059
 		}
1060
 	}
1060
 	}
1061
 
1061
 
1062
-	batchID := rb.StartNestedHistoryBatch(chname)
1062
+	batchID := rb.StartNestedBatch(chname, "chathistory")
1063
 	defer rb.EndNestedBatch(batchID)
1063
 	defer rb.EndNestedBatch(batchID)
1064
 
1064
 
1065
 	for _, item := range items {
1065
 	for _, item := range items {

+ 1
- 1
irc/client.go Bestand weergeven

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

+ 2
- 4
irc/handlers.go Bestand weergeven

655
 		} else {
655
 		} else {
656
 			// successful responses are sent as a chathistory or history batch
656
 			// successful responses are sent as a chathistory or history batch
657
 			if listTargets {
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
 				for _, target := range targets {
660
 				for _, target := range targets {
663
 					name := server.UnfoldName(target.CfName)
661
 					name := server.UnfoldName(target.CfName)
664
 					rb.Add(nil, server.name, "CHATHISTORY", "TARGETS", name,
662
 					rb.Add(nil, server.name, "CHATHISTORY", "TARGETS", name,

+ 3
- 13
irc/responsebuffer.go Bestand weergeven

193
 // Starts a nested batch (see the ResponseBuffer struct definition for a description of
193
 // Starts a nested batch (see the ResponseBuffer struct definition for a description of
194
 // how this works)
194
 // how this works)
195
 func (rb *ResponseBuffer) StartNestedBatch(batchType string, params ...string) (batchID string) {
195
 func (rb *ResponseBuffer) StartNestedBatch(batchType string, params ...string) (batchID string) {
196
+	if !rb.session.capabilities.Has(caps.Batch) {
197
+		return
198
+	}
196
 	batchID = rb.session.generateBatchID()
199
 	batchID = rb.session.generateBatchID()
197
 	msgParams := make([]string, len(params)+2)
200
 	msgParams := make([]string, len(params)+2)
198
 	msgParams[0] = "+" + batchID
201
 	msgParams[0] = "+" + batchID
219
 	rb.AddMessage(ircmsg.MakeMessage(nil, rb.target.server.name, "BATCH", "-"+batchID))
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
 // Send sends all messages in the buffer to the client.
225
 // Send sends all messages in the buffer to the client.
236
 // Afterwards, the buffer is in an undefined state and MUST NOT be used further.
226
 // Afterwards, the buffer is in an undefined state and MUST NOT be used further.
237
 // If `blocking` is true you MUST be sending to the client from its own goroutine.
227
 // If `blocking` is true you MUST be sending to the client from its own goroutine.

Laden…
Annuleren
Opslaan