consolidate sending DMs to targets with sending copies to non-originating sessions

This commit is contained in:
Shivaram Lingamneni 2020-02-20 01:15:11 -05:00
parent ef161c47ed
commit 5892680f60
1 changed files with 21 additions and 25 deletions

View File

@ -1911,11 +1911,23 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi
details := client.Details()
nickMaskString := details.nickMask
accountName := details.accountName
var deliverySessions []*Session
// restrict messages appropriately when +R is set
// intentionally make the sending user think the message went through fine
allowedPlusR := !user.HasMode(modes.RegisteredOnly) || details.account != ""
if allowedPlusR {
for _, session := range user.Sessions() {
deliverySessions = append(deliverySessions, user.Sessions()...)
}
// all sessions of the sender, except the originating session, get a copy as well:
if client != user {
for _, session := range client.Sessions() {
if session != rb.session {
deliverySessions = append(deliverySessions, session)
}
}
}
for _, session := range deliverySessions {
hasTagsCap := session.capabilities.Has(caps.MessageTags)
// don't send TAGMSG at all if they don't have the tags cap
if histType == history.Tagmsg && hasTagsCap {
@ -1928,8 +1940,8 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi
session.sendSplitMsgFromClientInternal(false, nickMaskString, accountName, tagsToSend, command, tnick, message)
}
}
}
// an echo-message may need to be included in the response:
// the originating session may get an echo message:
if rb.session.capabilities.Has(caps.EchoMessage) {
if histType == history.Tagmsg && rb.session.capabilities.Has(caps.MessageTags) {
rb.AddFromClient(message.Time, message.Msgid, nickMaskString, accountName, tags, command, tnick)
@ -1937,22 +1949,6 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi
rb.AddSplitMessageFromClient(nickMaskString, accountName, tags, command, tnick, message)
}
}
// an echo-message may need to go out to other client sessions:
for _, session := range client.Sessions() {
if session == rb.session {
continue
}
hasTagsCap := session.capabilities.Has(caps.MessageTags)
if histType == history.Tagmsg && hasTagsCap {
session.sendFromClientInternal(false, message.Time, message.Msgid, nickMaskString, accountName, tags, command, tnick)
} else if histType != history.Tagmsg {
tagsToSend := tags
if !hasTagsCap {
tagsToSend = nil
}
session.sendSplitMsgFromClientInternal(false, nickMaskString, accountName, tagsToSend, command, tnick, message)
}
}
if histType != history.Notice && user.Away() {
//TODO(dan): possibly implement cooldown of away notifications to users
rb.Add(nil, server.name, RPL_AWAY, client.Nick(), tnick, user.AwayMessage())