From 93530ae3977238a3924c977f881e467986c47fd0 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Fri, 17 Jul 2020 01:55:13 -0400 Subject: [PATCH] fix #1198 --- irc/channel.go | 8 ++++++-- irc/getters.go | 4 ++-- irc/handlers.go | 10 ++++++---- irc/roleplay.go | 4 ++-- irc/server.go | 4 ++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/irc/channel.go b/irc/channel.go index f6b39bc0..4d66ee60 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -767,6 +767,7 @@ func (channel *Channel) Join(client *Client, key string, isSajoin bool, rb *Resp modestr = fmt.Sprintf("+%v", givenMode) } + isAway, awayMessage := client.Away() for _, member := range channel.Members() { for _, session := range member.Sessions() { if session == rb.session { @@ -783,6 +784,9 @@ func (channel *Channel) Join(client *Client, key string, isSajoin bool, rb *Resp if givenMode != 0 { session.Send(nil, client.server.name, "MODE", chname, modestr, details.nick) } + if isAway && session.capabilities.Has(caps.AwayNotify) { + session.sendFromClientInternal(false, time.Time{}, "", details.nickMask, details.account, nil, "AWAY", awayMessage) + } } } @@ -1458,8 +1462,8 @@ func (channel *Channel) Invite(invitee *Client, inviter *Client, rb *ResponseBuf tnick := invitee.Nick() rb.Add(nil, inviter.server.name, RPL_INVITING, cnick, tnick, chname) invitee.Send(nil, inviter.NickMaskString(), "INVITE", tnick, chname) - if invitee.Away() { - rb.Add(nil, inviter.server.name, RPL_AWAY, cnick, tnick, invitee.AwayMessage()) + if away, awayMessage := invitee.Away(); away { + rb.Add(nil, inviter.server.name, RPL_AWAY, cnick, tnick, awayMessage) } } diff --git a/irc/getters.go b/irc/getters.go index 2f9cb848..b7aaae7a 100644 --- a/irc/getters.go +++ b/irc/getters.go @@ -185,9 +185,9 @@ func (client *Client) Hostname() string { return client.hostname } -func (client *Client) Away() (result bool) { +func (client *Client) Away() (result bool, message string) { client.stateMutex.Lock() - result = client.away + result, message = client.away, client.awayMessage client.stateMutex.Unlock() return } diff --git a/irc/handlers.go b/irc/handlers.go index 773fb253..28e576a7 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -2122,9 +2122,11 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi rb.AddSplitMessageFromClient(nickMaskString, accountName, tagsToSend, command, tnick, message) } } - if histType != history.Notice && user.Away() { + if histType != history.Notice { //TODO(dan): possibly implement cooldown of away notifications to users - rb.Add(nil, server.name, RPL_AWAY, client.Nick(), tnick, user.AwayMessage()) + if away, awayMessage := user.Away(); away { + rb.Add(nil, server.name, RPL_AWAY, client.Nick(), tnick, awayMessage) + } } config := server.Config() @@ -2742,7 +2744,7 @@ func userhostHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb * if target.HasMode(modes.Operator) { isOper = "*" } - if target.Away() { + if away, _ := target.Away(); away { isAway = "-" } else { isAway = "+" @@ -2893,7 +2895,7 @@ func (client *Client) rplWhoReply(channel *Channel, target *Client, rb *Response } if fields.Has('f') { // "flags" (away + oper state + channel status prefix + bot) var flags strings.Builder - if target.Away() { + if away, _ := target.Away(); away { flags.WriteRune('G') // Gone } else { flags.WriteRune('H') // Here diff --git a/irc/roleplay.go b/irc/roleplay.go index 3c1f750e..42a87e74 100644 --- a/irc/roleplay.go +++ b/irc/roleplay.go @@ -110,9 +110,9 @@ func sendRoleplayMessage(server *Server, client *Client, source string, targetSt for _, session := range user.Sessions() { session.sendSplitMsgFromClientInternal(false, source, "", nil, "PRIVMSG", tnick, splitMessage) } - if user.Away() { + if away, awayMessage := user.Away(); away { //TODO(dan): possibly implement cooldown of away notifications to users - rb.Add(nil, server.name, RPL_AWAY, cnick, tnick, user.AwayMessage()) + rb.Add(nil, server.name, RPL_AWAY, cnick, tnick, awayMessage) } } } diff --git a/irc/server.go b/irc/server.go index 88a4f078..d12460da 100644 --- a/irc/server.go +++ b/irc/server.go @@ -436,8 +436,8 @@ func (client *Client) getWhoisOf(target *Client, rb *ResponseBuffer) { } } rb.Add(nil, client.server.name, RPL_WHOISIDLE, cnick, tnick, strconv.FormatUint(target.IdleSeconds(), 10), strconv.FormatInt(target.SignonTime(), 10), client.t("seconds idle, signon time")) - if target.Away() { - rb.Add(nil, client.server.name, RPL_AWAY, cnick, tnick, target.AwayMessage()) + if away, awayMessage := target.Away(); away { + rb.Add(nil, client.server.name, RPL_AWAY, cnick, tnick, awayMessage) } }