mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-23 03:02:48 +01:00
Cleanup message sending
This commit is contained in:
parent
a81ccd68c5
commit
522001d4f6
@ -376,16 +376,6 @@ func (channel *Channel) TagMsg(msgid string, minPrefix *ChannelMode, clientOnlyT
|
|||||||
channel.sendMessage(msgid, "TAGMSG", []Capability{MessageTags}, minPrefix, clientOnlyTags, client, nil)
|
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) {
|
func (channel *Channel) sendMessage(msgid, cmd string, requiredCaps []Capability, minPrefix *ChannelMode, clientOnlyTags *map[string]ircmsg.TagValue, client *Client, message *string) {
|
||||||
if !channel.CanSpeak(client) {
|
if !channel.CanSpeak(client) {
|
||||||
client.Send(nil, client.server.name, ERR_CANNOTSENDTOCHAN, channel.name, "Cannot send to channel")
|
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 {
|
if message == nil {
|
||||||
member.SendFromClient(msgid, client, messageTagsToUse, client.nickMaskString, cmd, channel.name)
|
member.SendFromClient(msgid, client, messageTagsToUse, cmd, channel.name)
|
||||||
} else {
|
} 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.
|
// 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) {
|
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.
|
// 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) {
|
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) {
|
if !channel.CanSpeak(client) {
|
||||||
client.Send(nil, client.server.name, ERR_CANNOTSENDTOCHAN, channel.name, "Cannot send to channel")
|
client.Send(nil, client.server.name, ERR_CANNOTSENDTOCHAN, channel.name, "Cannot send to channel")
|
||||||
return
|
return
|
||||||
@ -464,10 +454,15 @@ func (channel *Channel) sendSplitMessage(msgid, cmd string, minPrefix *ChannelMo
|
|||||||
if member == client && !client.capabilities[EchoMessage] {
|
if member == client && !client.capabilities[EchoMessage] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
var tagsToUse *map[string]ircmsg.TagValue
|
||||||
if member.capabilities[MessageTags] {
|
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 {
|
} else {
|
||||||
member.SendSplitMsgFromClient(msgid, client, nil, cmd, channel.name, message)
|
member.SendSplitMsgFromClient(msgid, client, tagsToUse, cmd, channel.name, *message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -510,7 +510,7 @@ func (client *Client) SendSplitMsgFromClient(msgid string, from *Client, tags *m
|
|||||||
|
|
||||||
// SendFromClient sends an IRC line coming from a specific client.
|
// SendFromClient sends an IRC line coming from a specific client.
|
||||||
// Adds account-tag to the line as well.
|
// 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
|
// attach account-tag
|
||||||
if client.capabilities[AccountTag] && from.account != &NoAccount {
|
if client.capabilities[AccountTag] && from.account != &NoAccount {
|
||||||
if tags == nil {
|
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.
|
// Send sends an IRC line to the client.
|
||||||
|
@ -16,7 +16,7 @@ func (client *Client) alertMonitors() {
|
|||||||
for _, mClient := range client.server.monitoring[client.nickCasefolded] {
|
for _, mClient := range client.server.monitoring[client.nickCasefolded] {
|
||||||
// don't have to notify ourselves
|
// don't have to notify ourselves
|
||||||
if &mClient != client {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -900,12 +900,12 @@ type SplitMessage struct {
|
|||||||
ForMaxLine string
|
ForMaxLine string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) splitMessage(original string) SplitMessage {
|
func (server *Server) splitMessage(original string, origIs512 bool) SplitMessage {
|
||||||
var newSplit SplitMessage
|
var newSplit SplitMessage
|
||||||
|
|
||||||
newSplit.ForMaxLine = original
|
newSplit.ForMaxLine = original
|
||||||
|
|
||||||
if len(original) > 400 {
|
if !origIs512 && len(original) > 400 {
|
||||||
newSplit.For512 = wordWrap(original, 400)
|
newSplit.For512 = wordWrap(original, 400)
|
||||||
} else {
|
} else {
|
||||||
newSplit.For512 = []string{original}
|
newSplit.For512 = []string{original}
|
||||||
@ -921,7 +921,7 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
|
|||||||
message := msg.Params[1]
|
message := msg.Params[1]
|
||||||
|
|
||||||
// split privmsg
|
// split privmsg
|
||||||
splitMsg := server.splitMessage(message)
|
splitMsg := server.splitMessage(message, !client.capabilities[MaxLine])
|
||||||
|
|
||||||
for i, targetString := range targets {
|
for i, targetString := range targets {
|
||||||
// max of four targets per privmsg
|
// 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
|
// push new vhost if one is set
|
||||||
if len(server.operators[name].Vhost) > 0 {
|
if len(server.operators[name].Vhost) > 0 {
|
||||||
originalHost := client.nickMaskString
|
|
||||||
client.vhost = server.operators[name].Vhost
|
|
||||||
for fClient := range client.Friends(ChgHost) {
|
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()
|
client.updateNickMask()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1461,9 +1461,9 @@ func awayHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
// dispatch away-notify
|
// dispatch away-notify
|
||||||
for friend := range client.Friends(AwayNotify) {
|
for friend := range client.Friends(AwayNotify) {
|
||||||
if client.flags[Away] {
|
if client.flags[Away] {
|
||||||
friend.SendFromClient("", client, nil, client.nickMaskString, "AWAY", client.awayMessage)
|
friend.SendFromClient("", client, nil, "AWAY", client.awayMessage)
|
||||||
} else {
|
} 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]
|
message := msg.Params[1]
|
||||||
|
|
||||||
// split privmsg
|
// split privmsg
|
||||||
splitMsg := server.splitMessage(message)
|
splitMsg := server.splitMessage(message, !client.capabilities[MaxLine])
|
||||||
|
|
||||||
for i, targetString := range targets {
|
for i, targetString := range targets {
|
||||||
// max of four targets per privmsg
|
// max of four targets per privmsg
|
||||||
|
Loading…
Reference in New Issue
Block a user