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

channel: Give founder mode if channel already exists and founder joins

This commit is contained in:
Daniel Oaks 2017-03-27 14:52:34 +10:00
parent 127d0ff681
commit 013635a827

View File

@ -269,8 +269,9 @@ func (channel *Channel) Join(client *Client, key string) {
client.channels.Add(channel) client.channels.Add(channel)
channel.members.Add(client) channel.members.Add(client)
// give channel mode if necessary
var givenMode *Mode var givenMode *Mode
if len(channel.members) == 1 {
client.server.registeredChannelsMutex.Lock() client.server.registeredChannelsMutex.Lock()
defer client.server.registeredChannelsMutex.Unlock() defer client.server.registeredChannelsMutex.Unlock()
client.server.store.Update(func(tx *buntdb.Tx) error { client.server.store.Update(func(tx *buntdb.Tx) error {
@ -286,6 +287,8 @@ func (channel *Channel) Join(client *Client, key string) {
channel.members[client][ChannelFounder] = true channel.members[client][ChannelFounder] = true
givenMode = &ChannelFounder givenMode = &ChannelFounder
} }
if len(channel.members) == 1 {
// apply other details if new channel
channel.topic = chanReg.Topic channel.topic = chanReg.Topic
channel.topicSetBy = chanReg.TopicSetBy channel.topicSetBy = chanReg.TopicSetBy
channel.topicSetTime = chanReg.TopicSetTime channel.topicSetTime = chanReg.TopicSetTime
@ -301,9 +304,9 @@ func (channel *Channel) Join(client *Client, key string) {
channel.lists[InviteMask].Add(mask) channel.lists[InviteMask].Add(mask)
} }
} }
}
return nil return nil
}) })
}
if client.capabilities[ExtendedJoin] { if client.capabilities[ExtendedJoin] {
client.Send(nil, client.nickMaskString, "JOIN", channel.name, client.account.Name, client.realname) client.Send(nil, client.nickMaskString, "JOIN", channel.name, client.account.Name, client.realname)
@ -313,7 +316,9 @@ func (channel *Channel) Join(client *Client, key string) {
channel.getTopicNoMutex(client) // we already have Lock channel.getTopicNoMutex(client) // we already have Lock
channel.namesNoMutex(client) channel.namesNoMutex(client)
if givenMode != nil { if givenMode != nil {
client.Send(nil, client.server.name, "MODE", channel.name, fmt.Sprintf("+%v", *givenMode), client.nick) for member := range channel.members {
member.Send(nil, client.server.name, "MODE", channel.name, fmt.Sprintf("+%v", *givenMode), client.nick)
}
} }
} }