ソースを参照

Merge pull request #2069 from slingamn/nestedbatch.1

some cleanups
tags/v2.12.0-rc1
Shivaram Lingamneni 1年前
コミット
2aded271c5
コミッターのメールアドレスに関連付けられたアカウントが存在しません
8個のファイルの変更35行の追加39行の削除
  1. 2
    0
      irc/caps/constants.go
  2. 1
    1
      irc/channel.go
  3. 16
    16
      irc/client.go
  4. 2
    4
      irc/handlers.go
  5. 2
    4
      irc/message_cache.go
  6. 3
    13
      irc/responsebuffer.go
  7. 8
    0
      irc/utils/types.go
  8. 1
    1
      irctest

+ 2
- 0
irc/caps/constants.go ファイルの表示

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 ファイルの表示

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 {

+ 16
- 16
irc/client.go ファイルの表示

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
1425
 }
1425
 }
1426
 
1426
 
1427
 var (
1427
 var (
1428
-	// these are all the output commands that MUST have their last param be a trailing.
1429
-	// this is needed because dumb clients like to treat trailing params separately from the
1430
-	// other params in messages.
1431
-	commandsThatMustUseTrailing = map[string]bool{
1432
-		"PRIVMSG": true,
1433
-		"NOTICE":  true,
1434
-
1435
-		RPL_WHOISCHANNELS: true,
1436
-		RPL_USERHOST:      true,
1437
-
1428
+	// in practice, many clients require that the final parameter be a trailing
1429
+	// (prefixed with `:`) even when this is not syntactically necessary.
1430
+	// by default, force the following commands to use a trailing:
1431
+	commandsThatMustUseTrailing = utils.SetLiteral(
1432
+		"PRIVMSG",
1433
+		"NOTICE",
1434
+		RPL_WHOISCHANNELS,
1435
+		RPL_USERHOST,
1438
 		// mirc's handling of RPL_NAMREPLY is broken:
1436
 		// mirc's handling of RPL_NAMREPLY is broken:
1439
 		// https://forums.mirc.com/ubbthreads.php/topics/266939/re-nick-list
1437
 		// https://forums.mirc.com/ubbthreads.php/topics/266939/re-nick-list
1440
-		RPL_NAMREPLY: true,
1441
-	}
1438
+		RPL_NAMREPLY,
1439
+	)
1442
 )
1440
 )
1443
 
1441
 
1442
+func forceTrailing(config *Config, command string) bool {
1443
+	return config.Server.Compatibility.forceTrailing && commandsThatMustUseTrailing.Has(command)
1444
+}
1445
+
1444
 // SendRawMessage sends a raw message to the client.
1446
 // SendRawMessage sends a raw message to the client.
1445
 func (session *Session) SendRawMessage(message ircmsg.Message, blocking bool) error {
1447
 func (session *Session) SendRawMessage(message ircmsg.Message, blocking bool) error {
1446
-	// use dumb hack to force the last param to be a trailing param if required
1447
-	config := session.client.server.Config()
1448
-	if config.Server.Compatibility.forceTrailing && commandsThatMustUseTrailing[message.Command] {
1448
+	if forceTrailing(session.client.server.Config(), message.Command) {
1449
 		message.ForceTrailing()
1449
 		message.ForceTrailing()
1450
 	}
1450
 	}
1451
 
1451
 

+ 2
- 4
irc/handlers.go ファイルの表示

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,

+ 2
- 4
irc/message_cache.go ファイルの表示

79
 	m.params = params
79
 	m.params = params
80
 
80
 
81
 	var msg ircmsg.Message
81
 	var msg ircmsg.Message
82
-	config := server.Config()
83
-	if config.Server.Compatibility.forceTrailing && commandsThatMustUseTrailing[command] {
82
+	if forceTrailing(server.Config(), command) {
84
 		msg.ForceTrailing()
83
 		msg.ForceTrailing()
85
 	}
84
 	}
86
 	msg.Source = nickmask
85
 	msg.Source = nickmask
111
 	m.target = target
110
 	m.target = target
112
 	m.splitMessage = message
111
 	m.splitMessage = message
113
 
112
 
114
-	config := server.Config()
115
-	forceTrailing := config.Server.Compatibility.forceTrailing && commandsThatMustUseTrailing[command]
113
+	forceTrailing := forceTrailing(server.Config(), command)
116
 
114
 
117
 	if message.Is512() {
115
 	if message.Is512() {
118
 		isTagmsg := command == "TAGMSG"
116
 		isTagmsg := command == "TAGMSG"

+ 3
- 13
irc/responsebuffer.go ファイルの表示

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.

+ 8
- 0
irc/utils/types.go ファイルの表示

20
 	delete(s, elem)
20
 	delete(s, elem)
21
 }
21
 }
22
 
22
 
23
+func SetLiteral[T comparable](elems ...T) HashSet[T] {
24
+	result := make(HashSet[T], len(elems))
25
+	for _, elem := range elems {
26
+		result.Add(elem)
27
+	}
28
+	return result
29
+}
30
+
23
 func CopyMap[K comparable, V any](input map[K]V) (result map[K]V) {
31
 func CopyMap[K comparable, V any](input map[K]V) (result map[K]V) {
24
 	result = make(map[K]V, len(input))
32
 	result = make(map[K]V, len(input))
25
 	for key, value := range input {
33
 	for key, value := range input {

+ 1
- 1
irctest

1
-Subproject commit 22c6743b24f2a85bf79a92fb0c7fab325c047a6c
1
+Subproject commit 5a5dbdb50dda3dc9e5ed3d542ab75b1b87fccac9

読み込み中…
キャンセル
保存