Browse Source

clean up nil checks relevant to always-on join

tags/v2.0.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
8031085c26
2 changed files with 8 additions and 46 deletions
  1. 8
    6
      irc/channel.go
  2. 0
    40
      irc/responsebuffer.go

+ 8
- 6
irc/channel.go View File

724
 
724
 
725
 	client.addChannel(channel)
725
 	client.addChannel(channel)
726
 
726
 
727
+	if rb == nil {
728
+		return
729
+	}
730
+
727
 	var modestr string
731
 	var modestr string
728
 	if givenMode != 0 {
732
 	if givenMode != 0 {
729
 		modestr = fmt.Sprintf("+%v", givenMode)
733
 		modestr = fmt.Sprintf("+%v", givenMode)
731
 
735
 
732
 	for _, member := range channel.Members() {
736
 	for _, member := range channel.Members() {
733
 		for _, session := range member.Sessions() {
737
 		for _, session := range member.Sessions() {
734
-			if rb != nil && session == rb.session {
738
+			if session == rb.session {
735
 				continue
739
 				continue
736
 			} else if client == session.client {
740
 			} else if client == session.client {
737
 				channel.playJoinForSession(session)
741
 				channel.playJoinForSession(session)
748
 		}
752
 		}
749
 	}
753
 	}
750
 
754
 
751
-	if rb != nil && rb.session.capabilities.Has(caps.ExtendedJoin) {
755
+	if rb.session.capabilities.Has(caps.ExtendedJoin) {
752
 		rb.AddFromClient(message.Time, message.Msgid, details.nickMask, details.accountName, nil, "JOIN", chname, details.accountName, details.realname)
756
 		rb.AddFromClient(message.Time, message.Msgid, details.nickMask, details.accountName, nil, "JOIN", chname, details.accountName, details.realname)
753
 	} else {
757
 	} else {
754
 		rb.AddFromClient(message.Time, message.Msgid, details.nickMask, details.accountName, nil, "JOIN", chname)
758
 		rb.AddFromClient(message.Time, message.Msgid, details.nickMask, details.accountName, nil, "JOIN", chname)
755
 	}
759
 	}
756
 
760
 
757
-	if rb != nil && rb.session.client == client {
761
+	if rb.session.client == client {
758
 		// don't send topic and names for a SAJOIN of a different client
762
 		// don't send topic and names for a SAJOIN of a different client
759
 		channel.SendTopic(client, rb, false)
763
 		channel.SendTopic(client, rb, false)
760
 		channel.Names(client, rb)
764
 		channel.Names(client, rb)
763
 	// TODO #259 can be implemented as Flush(false) (i.e., nonblocking) while holding joinPartMutex
767
 	// TODO #259 can be implemented as Flush(false) (i.e., nonblocking) while holding joinPartMutex
764
 	rb.Flush(true)
768
 	rb.Flush(true)
765
 
769
 
766
-	if rb != nil {
767
-		channel.autoReplayHistory(client, rb, message.Msgid)
768
-	}
770
+	channel.autoReplayHistory(client, rb, message.Msgid)
769
 }
771
 }
770
 
772
 
771
 func (channel *Channel) autoReplayHistory(client *Client, rb *ResponseBuffer, skipMsgid string) {
773
 func (channel *Channel) autoReplayHistory(client *Client, rb *ResponseBuffer, skipMsgid string) {

+ 0
- 40
irc/responsebuffer.go View File

58
 }
58
 }
59
 
59
 
60
 func (rb *ResponseBuffer) AddMessage(msg ircmsg.IrcMessage) {
60
 func (rb *ResponseBuffer) AddMessage(msg ircmsg.IrcMessage) {
61
-	if rb == nil {
62
-		return
63
-	}
64
-
65
 	if rb.finalized {
61
 	if rb.finalized {
66
 		rb.target.server.logger.Error("internal", "message added to finalized ResponseBuffer, undefined behavior")
62
 		rb.target.server.logger.Error("internal", "message added to finalized ResponseBuffer, undefined behavior")
67
 		debug.PrintStack()
63
 		debug.PrintStack()
84
 
80
 
85
 // Add adds a standard new message to our queue.
81
 // Add adds a standard new message to our queue.
86
 func (rb *ResponseBuffer) Add(tags map[string]string, prefix string, command string, params ...string) {
82
 func (rb *ResponseBuffer) Add(tags map[string]string, prefix string, command string, params ...string) {
87
-	if rb == nil {
88
-		return
89
-	}
90
-
91
 	rb.AddMessage(ircmsg.MakeMessage(tags, prefix, command, params...))
83
 	rb.AddMessage(ircmsg.MakeMessage(tags, prefix, command, params...))
92
 }
84
 }
93
 
85
 
94
 // Broadcast adds a standard new message to our queue, then sends an unlabeled copy
86
 // Broadcast adds a standard new message to our queue, then sends an unlabeled copy
95
 // to all other sessions.
87
 // to all other sessions.
96
 func (rb *ResponseBuffer) Broadcast(tags map[string]string, prefix string, command string, params ...string) {
88
 func (rb *ResponseBuffer) Broadcast(tags map[string]string, prefix string, command string, params ...string) {
97
-	if rb == nil {
98
-		return
99
-	}
100
-
101
 	// can't reuse the IrcMessage object because of tag pollution :-\
89
 	// can't reuse the IrcMessage object because of tag pollution :-\
102
 	rb.Add(tags, prefix, command, params...)
90
 	rb.Add(tags, prefix, command, params...)
103
 	for _, session := range rb.session.client.Sessions() {
91
 	for _, session := range rb.session.client.Sessions() {
109
 
97
 
110
 // AddFromClient adds a new message from a specific client to our queue.
98
 // AddFromClient adds a new message from a specific client to our queue.
111
 func (rb *ResponseBuffer) AddFromClient(time time.Time, msgid string, fromNickMask string, fromAccount string, tags map[string]string, command string, params ...string) {
99
 func (rb *ResponseBuffer) AddFromClient(time time.Time, msgid string, fromNickMask string, fromAccount string, tags map[string]string, command string, params ...string) {
112
-	if rb == nil {
113
-		return
114
-	}
115
-
116
 	msg := ircmsg.MakeMessage(nil, fromNickMask, command, params...)
100
 	msg := ircmsg.MakeMessage(nil, fromNickMask, command, params...)
117
 	if rb.session.capabilities.Has(caps.MessageTags) {
101
 	if rb.session.capabilities.Has(caps.MessageTags) {
118
 		msg.UpdateTags(tags)
102
 		msg.UpdateTags(tags)
134
 
118
 
135
 // AddSplitMessageFromClient adds a new split message from a specific client to our queue.
119
 // AddSplitMessageFromClient adds a new split message from a specific client to our queue.
136
 func (rb *ResponseBuffer) AddSplitMessageFromClient(fromNickMask string, fromAccount string, tags map[string]string, command string, target string, message utils.SplitMessage) {
120
 func (rb *ResponseBuffer) AddSplitMessageFromClient(fromNickMask string, fromAccount string, tags map[string]string, command string, target string, message utils.SplitMessage) {
137
-	if rb == nil {
138
-		return
139
-	}
140
-
141
 	if message.Is512() {
121
 	if message.Is512() {
142
 		rb.AddFromClient(message.Time, message.Msgid, fromNickMask, fromAccount, tags, command, target, message.Message)
122
 		rb.AddFromClient(message.Time, message.Msgid, fromNickMask, fromAccount, tags, command, target, message.Message)
143
 	} else {
123
 	} else {
185
 // Starts a nested batch (see the ResponseBuffer struct definition for a description of
165
 // Starts a nested batch (see the ResponseBuffer struct definition for a description of
186
 // how this works)
166
 // how this works)
187
 func (rb *ResponseBuffer) StartNestedBatch(batchType string, params ...string) (batchID string) {
167
 func (rb *ResponseBuffer) StartNestedBatch(batchType string, params ...string) (batchID string) {
188
-	if rb == nil {
189
-		return
190
-	}
191
-
192
 	batchID = rb.session.generateBatchID()
168
 	batchID = rb.session.generateBatchID()
193
 	msgParams := make([]string, len(params)+2)
169
 	msgParams := make([]string, len(params)+2)
194
 	msgParams[0] = "+" + batchID
170
 	msgParams[0] = "+" + batchID
218
 // Convenience to start a nested batch for history lines, at the highest level
194
 // Convenience to start a nested batch for history lines, at the highest level
219
 // supported by the client (`history`, `chathistory`, or no batch, in descending order).
195
 // supported by the client (`history`, `chathistory`, or no batch, in descending order).
220
 func (rb *ResponseBuffer) StartNestedHistoryBatch(params ...string) (batchID string) {
196
 func (rb *ResponseBuffer) StartNestedHistoryBatch(params ...string) (batchID string) {
221
-	if rb == nil {
222
-		return
223
-	}
224
-
225
 	var batchType string
197
 	var batchType string
226
 	if rb.session.capabilities.Has(caps.EventPlayback) {
198
 	if rb.session.capabilities.Has(caps.EventPlayback) {
227
 		batchType = "history"
199
 		batchType = "history"
238
 // Afterwards, the buffer is in an undefined state and MUST NOT be used further.
210
 // Afterwards, the buffer is in an undefined state and MUST NOT be used further.
239
 // If `blocking` is true you MUST be sending to the client from its own goroutine.
211
 // If `blocking` is true you MUST be sending to the client from its own goroutine.
240
 func (rb *ResponseBuffer) Send(blocking bool) error {
212
 func (rb *ResponseBuffer) Send(blocking bool) error {
241
-	if rb == nil {
242
-		return nil
243
-	}
244
-
245
 	return rb.flushInternal(true, blocking)
213
 	return rb.flushInternal(true, blocking)
246
 }
214
 }
247
 
215
 
250
 // to ensure that the final `BATCH -` message is sent.
218
 // to ensure that the final `BATCH -` message is sent.
251
 // If `blocking` is true you MUST be sending to the client from its own goroutine.
219
 // If `blocking` is true you MUST be sending to the client from its own goroutine.
252
 func (rb *ResponseBuffer) Flush(blocking bool) error {
220
 func (rb *ResponseBuffer) Flush(blocking bool) error {
253
-	if rb == nil {
254
-		return nil
255
-	}
256
-
257
 	return rb.flushInternal(false, blocking)
221
 	return rb.flushInternal(false, blocking)
258
 }
222
 }
259
 
223
 
328
 
292
 
329
 // Notice sends the client the given notice from the server.
293
 // Notice sends the client the given notice from the server.
330
 func (rb *ResponseBuffer) Notice(text string) {
294
 func (rb *ResponseBuffer) Notice(text string) {
331
-	if rb == nil {
332
-		return
333
-	}
334
-
335
 	rb.Add(nil, rb.target.server.name, "NOTICE", rb.target.Nick(), text)
295
 	rb.Add(nil, rb.target.server.name, "NOTICE", rb.target.Nick(), text)
336
 }
296
 }

Loading…
Cancel
Save