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

View File

@ -301,6 +301,13 @@ type PartCommand struct {
message string message string
} }
func (cmd *PartCommand) Message() string {
if cmd.message == "" {
return cmd.Source().Nick()
}
return cmd.message
}
func (cmd *PartCommand) String() string { func (cmd *PartCommand) String() string {
return fmt.Sprintf("PART(channels=%s, message=%s)", cmd.channels, cmd.message) 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) 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) 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) return NewStringReply(client, RPL_PART, "%s :%s", channel.name, message)
} }