3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-23 03:02:48 +01:00

Merge pull request #1199 from slingamn/issue1198_awaynotify.1

fix #1198
This commit is contained in:
Shivaram Lingamneni 2020-07-17 02:36:56 -07:00 committed by GitHub
commit b5855e6194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 24 deletions

View File

@ -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)
}
}

View File

@ -1054,29 +1054,32 @@ func (client *Client) ModeString() (str string) {
}
// Friends refers to clients that share a channel with this client.
func (client *Client) Friends(capabs ...caps.Capability) (result map[*Session]bool) {
result = make(map[*Session]bool)
func (client *Client) Friends(capabs ...caps.Capability) (result map[*Session]empty) {
result = make(map[*Session]empty)
// look at the client's own sessions
for _, session := range client.Sessions() {
if session.capabilities.HasAll(capabs...) {
result[session] = true
}
}
addFriendsToSet(result, client, capabs...)
for _, channel := range client.Channels() {
for _, member := range channel.Members() {
for _, session := range member.Sessions() {
if session.capabilities.HasAll(capabs...) {
result[session] = true
}
}
addFriendsToSet(result, member, capabs...)
}
}
return
}
// helper for Friends
func addFriendsToSet(set map[*Session]empty, client *Client, capabs ...caps.Capability) {
client.stateMutex.RLock()
defer client.stateMutex.RUnlock()
for _, session := range client.sessions {
if session.capabilities.HasAll(capabs...) {
set[session] = empty{}
}
}
}
func (client *Client) SetOper(oper *Oper) {
client.stateMutex.Lock()
defer client.stateMutex.Unlock()

View File

@ -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
}

View File

@ -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

View File

@ -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)
}
}
}

View File

@ -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)
}
}