mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
clean up nil checks relevant to always-on join
This commit is contained in:
parent
282e7a4d57
commit
8031085c26
@ -724,6 +724,10 @@ func (channel *Channel) Join(client *Client, key string, isSajoin bool, rb *Resp
|
|||||||
|
|
||||||
client.addChannel(channel)
|
client.addChannel(channel)
|
||||||
|
|
||||||
|
if rb == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var modestr string
|
var modestr string
|
||||||
if givenMode != 0 {
|
if givenMode != 0 {
|
||||||
modestr = fmt.Sprintf("+%v", givenMode)
|
modestr = fmt.Sprintf("+%v", givenMode)
|
||||||
@ -731,7 +735,7 @@ func (channel *Channel) Join(client *Client, key string, isSajoin bool, rb *Resp
|
|||||||
|
|
||||||
for _, member := range channel.Members() {
|
for _, member := range channel.Members() {
|
||||||
for _, session := range member.Sessions() {
|
for _, session := range member.Sessions() {
|
||||||
if rb != nil && session == rb.session {
|
if session == rb.session {
|
||||||
continue
|
continue
|
||||||
} else if client == session.client {
|
} else if client == session.client {
|
||||||
channel.playJoinForSession(session)
|
channel.playJoinForSession(session)
|
||||||
@ -748,13 +752,13 @@ func (channel *Channel) Join(client *Client, key string, isSajoin bool, rb *Resp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if rb != nil && rb.session.capabilities.Has(caps.ExtendedJoin) {
|
if rb.session.capabilities.Has(caps.ExtendedJoin) {
|
||||||
rb.AddFromClient(message.Time, message.Msgid, details.nickMask, details.accountName, nil, "JOIN", chname, details.accountName, details.realname)
|
rb.AddFromClient(message.Time, message.Msgid, details.nickMask, details.accountName, nil, "JOIN", chname, details.accountName, details.realname)
|
||||||
} else {
|
} else {
|
||||||
rb.AddFromClient(message.Time, message.Msgid, details.nickMask, details.accountName, nil, "JOIN", chname)
|
rb.AddFromClient(message.Time, message.Msgid, details.nickMask, details.accountName, nil, "JOIN", chname)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rb != nil && rb.session.client == client {
|
if rb.session.client == client {
|
||||||
// don't send topic and names for a SAJOIN of a different client
|
// don't send topic and names for a SAJOIN of a different client
|
||||||
channel.SendTopic(client, rb, false)
|
channel.SendTopic(client, rb, false)
|
||||||
channel.Names(client, rb)
|
channel.Names(client, rb)
|
||||||
@ -763,10 +767,8 @@ func (channel *Channel) Join(client *Client, key string, isSajoin bool, rb *Resp
|
|||||||
// TODO #259 can be implemented as Flush(false) (i.e., nonblocking) while holding joinPartMutex
|
// TODO #259 can be implemented as Flush(false) (i.e., nonblocking) while holding joinPartMutex
|
||||||
rb.Flush(true)
|
rb.Flush(true)
|
||||||
|
|
||||||
if rb != nil {
|
|
||||||
channel.autoReplayHistory(client, rb, message.Msgid)
|
channel.autoReplayHistory(client, rb, message.Msgid)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (channel *Channel) autoReplayHistory(client *Client, rb *ResponseBuffer, skipMsgid string) {
|
func (channel *Channel) autoReplayHistory(client *Client, rb *ResponseBuffer, skipMsgid string) {
|
||||||
// autoreplay any messages as necessary
|
// autoreplay any messages as necessary
|
||||||
|
@ -58,10 +58,6 @@ func NewResponseBuffer(session *Session) *ResponseBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rb *ResponseBuffer) AddMessage(msg ircmsg.IrcMessage) {
|
func (rb *ResponseBuffer) AddMessage(msg ircmsg.IrcMessage) {
|
||||||
if rb == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if rb.finalized {
|
if rb.finalized {
|
||||||
rb.target.server.logger.Error("internal", "message added to finalized ResponseBuffer, undefined behavior")
|
rb.target.server.logger.Error("internal", "message added to finalized ResponseBuffer, undefined behavior")
|
||||||
debug.PrintStack()
|
debug.PrintStack()
|
||||||
@ -84,20 +80,12 @@ func (rb *ResponseBuffer) setNestedBatchTag(msg *ircmsg.IrcMessage) {
|
|||||||
|
|
||||||
// Add adds a standard new message to our queue.
|
// Add adds a standard new message to our queue.
|
||||||
func (rb *ResponseBuffer) Add(tags map[string]string, prefix string, command string, params ...string) {
|
func (rb *ResponseBuffer) Add(tags map[string]string, prefix string, command string, params ...string) {
|
||||||
if rb == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
rb.AddMessage(ircmsg.MakeMessage(tags, prefix, command, params...))
|
rb.AddMessage(ircmsg.MakeMessage(tags, prefix, command, params...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast adds a standard new message to our queue, then sends an unlabeled copy
|
// Broadcast adds a standard new message to our queue, then sends an unlabeled copy
|
||||||
// to all other sessions.
|
// to all other sessions.
|
||||||
func (rb *ResponseBuffer) Broadcast(tags map[string]string, prefix string, command string, params ...string) {
|
func (rb *ResponseBuffer) Broadcast(tags map[string]string, prefix string, command string, params ...string) {
|
||||||
if rb == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// can't reuse the IrcMessage object because of tag pollution :-\
|
// can't reuse the IrcMessage object because of tag pollution :-\
|
||||||
rb.Add(tags, prefix, command, params...)
|
rb.Add(tags, prefix, command, params...)
|
||||||
for _, session := range rb.session.client.Sessions() {
|
for _, session := range rb.session.client.Sessions() {
|
||||||
@ -109,10 +97,6 @@ func (rb *ResponseBuffer) Broadcast(tags map[string]string, prefix string, comma
|
|||||||
|
|
||||||
// AddFromClient adds a new message from a specific client to our queue.
|
// AddFromClient adds a new message from a specific client to our queue.
|
||||||
func (rb *ResponseBuffer) AddFromClient(time time.Time, msgid string, fromNickMask string, fromAccount string, tags map[string]string, command string, params ...string) {
|
func (rb *ResponseBuffer) AddFromClient(time time.Time, msgid string, fromNickMask string, fromAccount string, tags map[string]string, command string, params ...string) {
|
||||||
if rb == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
msg := ircmsg.MakeMessage(nil, fromNickMask, command, params...)
|
msg := ircmsg.MakeMessage(nil, fromNickMask, command, params...)
|
||||||
if rb.session.capabilities.Has(caps.MessageTags) {
|
if rb.session.capabilities.Has(caps.MessageTags) {
|
||||||
msg.UpdateTags(tags)
|
msg.UpdateTags(tags)
|
||||||
@ -134,10 +118,6 @@ func (rb *ResponseBuffer) AddFromClient(time time.Time, msgid string, fromNickMa
|
|||||||
|
|
||||||
// AddSplitMessageFromClient adds a new split message from a specific client to our queue.
|
// AddSplitMessageFromClient adds a new split message from a specific client to our queue.
|
||||||
func (rb *ResponseBuffer) AddSplitMessageFromClient(fromNickMask string, fromAccount string, tags map[string]string, command string, target string, message utils.SplitMessage) {
|
func (rb *ResponseBuffer) AddSplitMessageFromClient(fromNickMask string, fromAccount string, tags map[string]string, command string, target string, message utils.SplitMessage) {
|
||||||
if rb == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if message.Is512() {
|
if message.Is512() {
|
||||||
rb.AddFromClient(message.Time, message.Msgid, fromNickMask, fromAccount, tags, command, target, message.Message)
|
rb.AddFromClient(message.Time, message.Msgid, fromNickMask, fromAccount, tags, command, target, message.Message)
|
||||||
} else {
|
} else {
|
||||||
@ -185,10 +165,6 @@ func (rb *ResponseBuffer) sendBatchEnd(blocking bool) {
|
|||||||
// Starts a nested batch (see the ResponseBuffer struct definition for a description of
|
// Starts a nested batch (see the ResponseBuffer struct definition for a description of
|
||||||
// how this works)
|
// how this works)
|
||||||
func (rb *ResponseBuffer) StartNestedBatch(batchType string, params ...string) (batchID string) {
|
func (rb *ResponseBuffer) StartNestedBatch(batchType string, params ...string) (batchID string) {
|
||||||
if rb == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
batchID = rb.session.generateBatchID()
|
batchID = rb.session.generateBatchID()
|
||||||
msgParams := make([]string, len(params)+2)
|
msgParams := make([]string, len(params)+2)
|
||||||
msgParams[0] = "+" + batchID
|
msgParams[0] = "+" + batchID
|
||||||
@ -218,10 +194,6 @@ func (rb *ResponseBuffer) EndNestedBatch(batchID string) {
|
|||||||
// Convenience to start a nested batch for history lines, at the highest level
|
// Convenience to start a nested batch for history lines, at the highest level
|
||||||
// supported by the client (`history`, `chathistory`, or no batch, in descending order).
|
// supported by the client (`history`, `chathistory`, or no batch, in descending order).
|
||||||
func (rb *ResponseBuffer) StartNestedHistoryBatch(params ...string) (batchID string) {
|
func (rb *ResponseBuffer) StartNestedHistoryBatch(params ...string) (batchID string) {
|
||||||
if rb == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var batchType string
|
var batchType string
|
||||||
if rb.session.capabilities.Has(caps.EventPlayback) {
|
if rb.session.capabilities.Has(caps.EventPlayback) {
|
||||||
batchType = "history"
|
batchType = "history"
|
||||||
@ -238,10 +210,6 @@ func (rb *ResponseBuffer) StartNestedHistoryBatch(params ...string) (batchID str
|
|||||||
// Afterwards, the buffer is in an undefined state and MUST NOT be used further.
|
// Afterwards, the buffer is in an undefined state and MUST NOT be used further.
|
||||||
// If `blocking` is true you MUST be sending to the client from its own goroutine.
|
// If `blocking` is true you MUST be sending to the client from its own goroutine.
|
||||||
func (rb *ResponseBuffer) Send(blocking bool) error {
|
func (rb *ResponseBuffer) Send(blocking bool) error {
|
||||||
if rb == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return rb.flushInternal(true, blocking)
|
return rb.flushInternal(true, blocking)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,10 +218,6 @@ func (rb *ResponseBuffer) Send(blocking bool) error {
|
|||||||
// to ensure that the final `BATCH -` message is sent.
|
// to ensure that the final `BATCH -` message is sent.
|
||||||
// If `blocking` is true you MUST be sending to the client from its own goroutine.
|
// If `blocking` is true you MUST be sending to the client from its own goroutine.
|
||||||
func (rb *ResponseBuffer) Flush(blocking bool) error {
|
func (rb *ResponseBuffer) Flush(blocking bool) error {
|
||||||
if rb == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return rb.flushInternal(false, blocking)
|
return rb.flushInternal(false, blocking)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,9 +292,5 @@ func (rb *ResponseBuffer) flushInternal(final bool, blocking bool) error {
|
|||||||
|
|
||||||
// Notice sends the client the given notice from the server.
|
// Notice sends the client the given notice from the server.
|
||||||
func (rb *ResponseBuffer) Notice(text string) {
|
func (rb *ResponseBuffer) Notice(text string) {
|
||||||
if rb == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
rb.Add(nil, rb.target.server.name, "NOTICE", rb.target.Nick(), text)
|
rb.Add(nil, rb.target.server.name, "NOTICE", rb.target.Nick(), text)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user