3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00
This commit is contained in:
Shivaram Lingamneni 2020-03-19 07:26:17 -04:00
parent 1d228eaa92
commit 621df31577
2 changed files with 27 additions and 6 deletions

View File

@ -211,6 +211,8 @@ func (channel *Channel) MarkDirty(dirtyBits uint) {
// ChannelManager's lock (that way, no one can join and make the channel dirty again // ChannelManager's lock (that way, no one can join and make the channel dirty again
// between this method exiting and the actual deletion). // between this method exiting and the actual deletion).
func (channel *Channel) IsClean() bool { func (channel *Channel) IsClean() bool {
config := channel.server.Config()
if !channel.writerSemaphore.TryAcquire() { if !channel.writerSemaphore.TryAcquire() {
// a database write (which may fail) is in progress, the channel cannot be cleaned up // a database write (which may fail) is in progress, the channel cannot be cleaned up
return false return false
@ -219,8 +221,16 @@ func (channel *Channel) IsClean() bool {
channel.stateMutex.RLock() channel.stateMutex.RLock()
defer channel.stateMutex.RUnlock() defer channel.stateMutex.RUnlock()
// the channel must be empty, and either be unregistered or fully written to the DB if len(channel.members) != 0 {
return len(channel.members) == 0 && (channel.registeredFounder == "" || channel.dirtyBits == 0) return false
}
if channel.registeredFounder == "" {
return true
}
// a registered channel must be fully written to the DB,
// and not set to ephemeral history (#704)
return channel.dirtyBits == 0 &&
channelHistoryStatus(config, true, channel.settings.History) != HistoryEphemeral
} }
func (channel *Channel) wakeWriter() { func (channel *Channel) wakeWriter() {
@ -599,15 +609,23 @@ func (channel *Channel) historyStatus(config *Config) (status HistoryStatus, tar
registered := channel.registeredFounder != "" registered := channel.registeredFounder != ""
channel.stateMutex.RUnlock() channel.stateMutex.RUnlock()
return channelHistoryStatus(config, registered, historyStatus), target
}
func channelHistoryStatus(config *Config, registered bool, storedStatus HistoryStatus) (result HistoryStatus) {
if !config.History.Enabled {
return HistoryDisabled
}
// ephemeral history: either the channel owner explicitly set the ephemeral preference, // ephemeral history: either the channel owner explicitly set the ephemeral preference,
// or persistent history is disabled for unregistered channels // or persistent history is disabled for unregistered channels
if registered { if registered {
return historyEnabled(config.History.Persistent.RegisteredChannels, historyStatus), target return historyEnabled(config.History.Persistent.RegisteredChannels, storedStatus)
} else { } else {
if config.History.Persistent.UnregisteredChannels { if config.History.Persistent.UnregisteredChannels {
return HistoryPersistent, target return HistoryPersistent
} else { } else {
return HistoryEphemeral, target return HistoryEphemeral
} }
} }
} }

View File

@ -979,7 +979,10 @@ func (target *Client) RplList(channel *Channel, rb *ResponseBuffer) {
} }
} }
rb.Add(nil, target.server.name, RPL_LIST, target.nick, channel.name, strconv.Itoa(memberCount), channel.topic) // #704: some channels are kept around even with no members
if memberCount != 0 {
rb.Add(nil, target.server.name, RPL_LIST, target.nick, channel.name, strconv.Itoa(memberCount), channel.topic)
}
} }
var ( var (