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

(hopefully) fix labeled-response behaviour

This commit is contained in:
Daniel Oaks 2018-02-11 08:57:15 +10:00
parent e0fa97d344
commit a70cc6713c
4 changed files with 43 additions and 33 deletions

View File

@ -7,6 +7,9 @@ package caps
type Capability string
const (
// LabelTagName is the tag name used for the labeled-response spec.
LabelTagName = "draft/label"
// AccountNotify is this IRCv3 capability: http://ircv3.net/specs/extensions/account-notify-3.1.html
AccountNotify Capability = "account-notify"
// AccountTag is this IRCv3 capability: http://ircv3.net/specs/extensions/account-tag-3.2.html

View File

@ -549,12 +549,26 @@ func (channel *Channel) sendMessage(msgid, cmd string, requiredCaps []caps.Capab
if minPrefix != nil {
minPrefixMode = *minPrefix
}
// send echo-message
if client.capabilities.Has(caps.EchoMessage) {
var messageTagsToUse *map[string]ircmsg.TagValue
if client.capabilities.Has(caps.MessageTags) {
messageTagsToUse = clientOnlyTags
}
if message == nil {
rb.AddFromClient(msgid, client, messageTagsToUse, cmd, channel.name)
} else {
rb.AddFromClient(msgid, client, messageTagsToUse, cmd, channel.name, *message)
}
}
for _, member := range channel.Members() {
if minPrefix != nil && !channel.ClientIsAtLeast(member, minPrefixMode) {
// STATUSMSG
continue
}
if member == client && !client.capabilities.Has(caps.EchoMessage) {
// echo-message is handled above, so skip sending the msg to the user themselves as well
if member == client {
continue
}
@ -574,9 +588,9 @@ func (channel *Channel) sendMessage(msgid, cmd string, requiredCaps []caps.Capab
}
if message == nil {
rb.AddFromClient(msgid, client, messageTagsToUse, cmd, channel.name)
member.SendFromClient(msgid, client, messageTagsToUse, cmd, channel.name)
} else {
rb.AddFromClient(msgid, client, messageTagsToUse, cmd, channel.name, *message)
member.SendFromClient(msgid, client, messageTagsToUse, cmd, channel.name, *message)
}
}
}
@ -602,12 +616,25 @@ func (channel *Channel) sendSplitMessage(msgid, cmd string, minPrefix *modes.Mod
if minPrefix != nil {
minPrefixMode = *minPrefix
}
// send echo-message
if client.capabilities.Has(caps.EchoMessage) {
var tagsToUse *map[string]ircmsg.TagValue
if client.capabilities.Has(caps.MessageTags) {
tagsToUse = clientOnlyTags
}
if message == nil {
rb.AddFromClient(msgid, client, tagsToUse, cmd, channel.name)
} else {
rb.AddSplitMessageFromClient(msgid, client, tagsToUse, cmd, channel.name, *message)
}
}
for _, member := range channel.Members() {
if minPrefix != nil && !channel.ClientIsAtLeast(member, minPrefixMode) {
// STATUSMSG
continue
}
if member == client && !client.capabilities.Has(caps.EchoMessage) {
// echo-message is handled above, so skip sending the msg to the user themselves as well
if member == client {
continue
}
var tagsToUse *map[string]ircmsg.TagValue
@ -615,18 +642,10 @@ func (channel *Channel) sendSplitMessage(msgid, cmd string, minPrefix *modes.Mod
tagsToUse = clientOnlyTags
}
if member == client {
if message == nil {
rb.AddFromClient(msgid, client, tagsToUse, cmd, channel.name)
} else {
rb.AddSplitMessageFromClient(msgid, client, tagsToUse, cmd, channel.name, *message)
}
if message == nil {
member.SendFromClient(msgid, client, tagsToUse, cmd, channel.name)
} else {
if message == nil {
member.SendFromClient(msgid, client, tagsToUse, cmd, channel.name)
} else {
member.SendSplitMsgFromClient(msgid, client, tagsToUse, cmd, channel.name, *message)
}
member.SendSplitMsgFromClient(msgid, client, tagsToUse, cmd, channel.name, *message)
}
}
}

View File

@ -1770,11 +1770,7 @@ func noticeHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
// restrict messages appropriately when +R is set
// intentionally make the sending user think the message went through fine
if !user.flags[modes.RegisteredOnly] || client.registered {
if user == client {
rb.AddSplitMessageFromClient(msgid, client, clientOnlyTags, "NOTICE", user.nick, splitMsg)
} else {
user.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "NOTICE", user.nick, splitMsg)
}
user.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "NOTICE", user.nick, splitMsg)
}
if client.capabilities.Has(caps.EchoMessage) {
rb.AddSplitMessageFromClient(msgid, client, clientOnlyTags, "NOTICE", user.nick, splitMsg)
@ -2002,11 +1998,7 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R
// restrict messages appropriately when +R is set
// intentionally make the sending user think the message went through fine
if !user.flags[modes.RegisteredOnly] || client.registered {
if user == client {
rb.AddSplitMessageFromClient(msgid, client, clientOnlyTags, "PRIVMSG", user.nick, splitMsg)
} else {
user.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "PRIVMSG", user.nick, splitMsg)
}
user.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "PRIVMSG", user.nick, splitMsg)
}
if client.capabilities.Has(caps.EchoMessage) {
rb.AddSplitMessageFromClient(msgid, client, clientOnlyTags, "PRIVMSG", user.nick, splitMsg)
@ -2258,11 +2250,7 @@ func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
if !user.capabilities.Has(caps.MessageTags) {
continue
}
if user == client {
rb.AddFromClient(msgid, client, clientOnlyTags, "TAGMSG", user.nick)
} else {
user.SendFromClient(msgid, client, clientOnlyTags, "TAGMSG", user.nick)
}
user.SendFromClient(msgid, client, clientOnlyTags, "TAGMSG", user.nick)
if client.capabilities.Has(caps.EchoMessage) {
rb.AddFromClient(msgid, client, clientOnlyTags, "TAGMSG", user.nick)
}

View File

@ -23,7 +23,7 @@ type ResponseBuffer struct {
// GetLabel returns the label from the given message.
func GetLabel(msg ircmsg.IrcMessage) string {
return msg.Tags["label"].Value
return msg.Tags[caps.LabelTagName].Value
}
// NewResponseBuffer returns a new ResponseBuffer.
@ -90,13 +90,13 @@ func (rb *ResponseBuffer) Send() error {
// if label but no batch, add label to first message
if useLabel && batch == nil {
message := rb.messages[0]
message.Tags["label"] = ircmsg.MakeTagValue(rb.Label)
message.Tags[caps.LabelTagName] = ircmsg.MakeTagValue(rb.Label)
rb.messages[0] = message
}
// start batch if required
if batch != nil {
batch.Start(rb.target, ircmsg.MakeTags("label", rb.Label))
batch.Start(rb.target, ircmsg.MakeTags(caps.LabelTagName, rb.Label))
}
// send each message out