3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

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

View File

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