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

Cleanup message sending

This commit is contained in:
Daniel Oaks 2017-01-14 21:48:57 +10:00
parent a81ccd68c5
commit 522001d4f6
4 changed files with 24 additions and 29 deletions

View File

@ -376,16 +376,6 @@ func (channel *Channel) TagMsg(msgid string, minPrefix *ChannelMode, clientOnlyT
channel.sendMessage(msgid, "TAGMSG", []Capability{MessageTags}, minPrefix, clientOnlyTags, client, nil)
}
// PrivMsg sends a private message to everyone in this channel.
func (channel *Channel) PrivMsg(msgid string, minPrefix *ChannelMode, clientOnlyTags *map[string]ircmsg.TagValue, client *Client, message string) {
channel.sendMessage(msgid, "PRIVMSG", nil, minPrefix, clientOnlyTags, client, &message)
}
// Notice sends a private message to everyone in this channel.
func (channel *Channel) Notice(msgid string, minPrefix *ChannelMode, clientOnlyTags *map[string]ircmsg.TagValue, client *Client, message string) {
channel.sendMessage(msgid, "NOTICE", nil, minPrefix, clientOnlyTags, client, &message)
}
func (channel *Channel) sendMessage(msgid, cmd string, requiredCaps []Capability, minPrefix *ChannelMode, clientOnlyTags *map[string]ircmsg.TagValue, client *Client, message *string) {
if !channel.CanSpeak(client) {
client.Send(nil, client.server.name, ERR_CANNOTSENDTOCHAN, channel.name, "Cannot send to channel")
@ -425,24 +415,24 @@ func (channel *Channel) sendMessage(msgid, cmd string, requiredCaps []Capability
}
if message == nil {
member.SendFromClient(msgid, client, messageTagsToUse, client.nickMaskString, cmd, channel.name)
member.SendFromClient(msgid, client, messageTagsToUse, cmd, channel.name)
} else {
member.SendFromClient(msgid, client, messageTagsToUse, client.nickMaskString, cmd, channel.name, *message)
member.SendFromClient(msgid, client, messageTagsToUse, cmd, channel.name, *message)
}
}
}
// SplitPrivMsg sends a private message to everyone in this channel.
func (channel *Channel) SplitPrivMsg(msgid string, minPrefix *ChannelMode, clientOnlyTags *map[string]ircmsg.TagValue, client *Client, message SplitMessage) {
channel.sendSplitMessage(msgid, "PRIVMSG", minPrefix, clientOnlyTags, client, message)
channel.sendSplitMessage(msgid, "PRIVMSG", minPrefix, clientOnlyTags, client, &message)
}
// SplitNotice sends a private message to everyone in this channel.
func (channel *Channel) SplitNotice(msgid string, minPrefix *ChannelMode, clientOnlyTags *map[string]ircmsg.TagValue, client *Client, message SplitMessage) {
channel.sendSplitMessage(msgid, "NOTICE", minPrefix, clientOnlyTags, client, message)
channel.sendSplitMessage(msgid, "NOTICE", minPrefix, clientOnlyTags, client, &message)
}
func (channel *Channel) sendSplitMessage(msgid, cmd string, minPrefix *ChannelMode, clientOnlyTags *map[string]ircmsg.TagValue, client *Client, message SplitMessage) {
func (channel *Channel) sendSplitMessage(msgid, cmd string, minPrefix *ChannelMode, clientOnlyTags *map[string]ircmsg.TagValue, client *Client, message *SplitMessage) {
if !channel.CanSpeak(client) {
client.Send(nil, client.server.name, ERR_CANNOTSENDTOCHAN, channel.name, "Cannot send to channel")
return
@ -464,10 +454,15 @@ func (channel *Channel) sendSplitMessage(msgid, cmd string, minPrefix *ChannelMo
if member == client && !client.capabilities[EchoMessage] {
continue
}
var tagsToUse *map[string]ircmsg.TagValue
if member.capabilities[MessageTags] {
member.SendSplitMsgFromClient(msgid, client, clientOnlyTags, cmd, channel.name, message)
tagsToUse = clientOnlyTags
}
if message == nil {
member.SendFromClient(msgid, client, tagsToUse, cmd, channel.name)
} else {
member.SendSplitMsgFromClient(msgid, client, nil, cmd, channel.name, message)
member.SendSplitMsgFromClient(msgid, client, tagsToUse, cmd, channel.name, *message)
}
}
}

View File

@ -510,7 +510,7 @@ func (client *Client) SendSplitMsgFromClient(msgid string, from *Client, tags *m
// SendFromClient sends an IRC line coming from a specific client.
// Adds account-tag to the line as well.
func (client *Client) SendFromClient(msgid string, from *Client, tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) error {
func (client *Client) SendFromClient(msgid string, from *Client, tags *map[string]ircmsg.TagValue, command string, params ...string) error {
// attach account-tag
if client.capabilities[AccountTag] && from.account != &NoAccount {
if tags == nil {
@ -528,7 +528,7 @@ func (client *Client) SendFromClient(msgid string, from *Client, tags *map[strin
}
}
return client.Send(tags, prefix, command, params...)
return client.Send(tags, from.nickMaskString, command, params...)
}
// Send sends an IRC line to the client.

View File

@ -16,7 +16,7 @@ func (client *Client) alertMonitors() {
for _, mClient := range client.server.monitoring[client.nickCasefolded] {
// don't have to notify ourselves
if &mClient != client {
mClient.SendFromClient("", client, nil, client.server.name, RPL_MONONLINE, mClient.nick, client.nickMaskString)
mClient.SendFromClient("", client, nil, RPL_MONONLINE, mClient.nick, client.nickMaskString)
}
}
}

View File

@ -900,12 +900,12 @@ type SplitMessage struct {
ForMaxLine string
}
func (server *Server) splitMessage(original string) SplitMessage {
func (server *Server) splitMessage(original string, origIs512 bool) SplitMessage {
var newSplit SplitMessage
newSplit.ForMaxLine = original
if len(original) > 400 {
if !origIs512 && len(original) > 400 {
newSplit.For512 = wordWrap(original, 400)
} else {
newSplit.For512 = []string{original}
@ -921,7 +921,7 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
message := msg.Params[1]
// split privmsg
splitMsg := server.splitMessage(message)
splitMsg := server.splitMessage(message, !client.capabilities[MaxLine])
for i, targetString := range targets {
// max of four targets per privmsg
@ -1219,11 +1219,11 @@ func operHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
// push new vhost if one is set
if len(server.operators[name].Vhost) > 0 {
originalHost := client.nickMaskString
client.vhost = server.operators[name].Vhost
for fClient := range client.Friends(ChgHost) {
fClient.SendFromClient("", client, nil, originalHost, "CHGHOST", client.username, client.vhost)
fClient.SendFromClient("", client, nil, "CHGHOST", client.username, server.operators[name].Vhost)
}
// CHGHOST requires prefix nickmask to have original hostname, so do that before updating nickmask
client.vhost = server.operators[name].Vhost
client.updateNickMask()
}
@ -1461,9 +1461,9 @@ func awayHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
// dispatch away-notify
for friend := range client.Friends(AwayNotify) {
if client.flags[Away] {
friend.SendFromClient("", client, nil, client.nickMaskString, "AWAY", client.awayMessage)
friend.SendFromClient("", client, nil, "AWAY", client.awayMessage)
} else {
friend.SendFromClient("", client, nil, client.nickMaskString, "AWAY")
friend.SendFromClient("", client, nil, "AWAY")
}
}
@ -1510,7 +1510,7 @@ func noticeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
message := msg.Params[1]
// split privmsg
splitMsg := server.splitMessage(message)
splitMsg := server.splitMessage(message, !client.capabilities[MaxLine])
for i, targetString := range targets {
// max of four targets per privmsg