3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

properly implement join/part

This commit is contained in:
Jeremy Latt 2014-02-08 17:53:06 -08:00
parent c4f457705a
commit a0eed1d687
3 changed files with 21 additions and 15 deletions

View File

@ -109,7 +109,8 @@ func (channel *Channel) String() string {
func (channel *Channel) Join(client *Client) {
channel.members[client] = true
client.channels[channel] = true
reply := RplJoin(channel, client)
reply := RplJoin(client, channel)
client.replies <- reply
channel.replies <- reply
channel.GetTopic(client)
channel.GetUsers(client)
@ -134,24 +135,22 @@ func (m *JoinCommand) HandleChannel(channel *Channel) {
}
func (m *PartCommand) HandleChannel(channel *Channel) {
c := m.Client()
client := m.Client()
if !channel.HasMember(c) {
c.replies <- ErrNotOnChannel(channel)
if !channel.HasMember(client) {
client.replies <- ErrNotOnChannel(channel)
return
}
msg := m.message
if msg == "" {
msg = c.Nick()
}
reply := RplPart(client, channel, m.Message())
client.replies <- reply
channel.replies <- reply
channel.replies <- RplPart(channel, c, msg)
delete(channel.members, client)
delete(client.channels, channel)
delete(channel.members, c)
delete(c.channels, channel)
if channel.IsEmpty() { // TODO persistent channels
// TODO persistent channels
if channel.IsEmpty() {
channel.server.DeleteChannel(channel)
}
}

View File

@ -301,6 +301,13 @@ type PartCommand struct {
message string
}
func (cmd *PartCommand) Message() string {
if cmd.message == "" {
return cmd.Source().Nick()
}
return cmd.message
}
func (cmd *PartCommand) String() string {
return fmt.Sprintf("PART(channels=%s, message=%s)", cmd.channels, cmd.message)
}

View File

@ -145,11 +145,11 @@ func RplNick(source Identifier, newNick string) Reply {
return NewStringReply(source, RPL_NICK, newNick)
}
func RplJoin(channel *Channel, client *Client) Reply {
func RplJoin(client *Client, channel *Channel) Reply {
return NewStringReply(client, RPL_JOIN, channel.name)
}
func RplPart(channel *Channel, client *Client, message string) Reply {
func RplPart(client *Client, channel *Channel, message string) Reply {
return NewStringReply(client, RPL_PART, "%s :%s", channel.name, message)
}