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,6 +724,10 @@ func (channel *Channel) Join(client *Client, key string, isSajoin bool, rb *Resp
724 724
 
725 725
 	client.addChannel(channel)
726 726
 
727
+	if rb == nil {
728
+		return
729
+	}
730
+
727 731
 	var modestr string
728 732
 	if givenMode != 0 {
729 733
 		modestr = fmt.Sprintf("+%v", givenMode)
@@ -731,7 +735,7 @@ func (channel *Channel) Join(client *Client, key string, isSajoin bool, rb *Resp
731 735
 
732 736
 	for _, member := range channel.Members() {
733 737
 		for _, session := range member.Sessions() {
734
-			if rb != nil && session == rb.session {
738
+			if session == rb.session {
735 739
 				continue
736 740
 			} else if client == session.client {
737 741
 				channel.playJoinForSession(session)
@@ -748,13 +752,13 @@ func (channel *Channel) Join(client *Client, key string, isSajoin bool, rb *Resp
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 756
 		rb.AddFromClient(message.Time, message.Msgid, details.nickMask, details.accountName, nil, "JOIN", chname, details.accountName, details.realname)
753 757
 	} else {
754 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 762
 		// don't send topic and names for a SAJOIN of a different client
759 763
 		channel.SendTopic(client, rb, false)
760 764
 		channel.Names(client, rb)
@@ -763,9 +767,7 @@ func (channel *Channel) Join(client *Client, key string, isSajoin bool, rb *Resp
763 767
 	// TODO #259 can be implemented as Flush(false) (i.e., nonblocking) while holding joinPartMutex
764 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 773
 func (channel *Channel) autoReplayHistory(client *Client, rb *ResponseBuffer, skipMsgid string) {

+ 0
- 40
irc/responsebuffer.go View File

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

Loading…
Cancel
Save