mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-25 13:29:27 +01:00
(hopefully) fix labeled-response behaviour
This commit is contained in:
parent
e0fa97d344
commit
a70cc6713c
@ -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
|
||||
|
@ -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,13 +642,6 @@ 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)
|
||||
}
|
||||
} else {
|
||||
if message == nil {
|
||||
member.SendFromClient(msgid, client, tagsToUse, cmd, channel.name)
|
||||
} else {
|
||||
@ -629,7 +649,6 @@ func (channel *Channel) sendSplitMessage(msgid, cmd string, minPrefix *modes.Mod
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (channel *Channel) applyModeMemberNoMutex(client *Client, mode modes.Mode, op modes.ModeOp, nick string, rb *ResponseBuffer) *modes.ModeChange {
|
||||
if nick == "" {
|
||||
|
@ -1770,12 +1770,8 @@ 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)
|
||||
}
|
||||
}
|
||||
if client.capabilities.Has(caps.EchoMessage) {
|
||||
rb.AddSplitMessageFromClient(msgid, client, clientOnlyTags, "NOTICE", user.nick, splitMsg)
|
||||
}
|
||||
@ -2002,12 +1998,8 @@ 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)
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
if client.capabilities.Has(caps.EchoMessage) {
|
||||
rb.AddFromClient(msgid, client, clientOnlyTags, "TAGMSG", user.nick)
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user