Shivaram Lingamneni 4 лет назад
Родитель
Сommit
621df31577
2 измененных файлов: 27 добавлений и 6 удалений
  1. 23
    5
      irc/channel.go
  2. 4
    1
      irc/server.go

+ 23
- 5
irc/channel.go Просмотреть файл

@@ -211,6 +211,8 @@ func (channel *Channel) MarkDirty(dirtyBits uint) {
211 211
 // ChannelManager's lock (that way, no one can join and make the channel dirty again
212 212
 // between this method exiting and the actual deletion).
213 213
 func (channel *Channel) IsClean() bool {
214
+	config := channel.server.Config()
215
+
214 216
 	if !channel.writerSemaphore.TryAcquire() {
215 217
 		// a database write (which may fail) is in progress, the channel cannot be cleaned up
216 218
 		return false
@@ -219,8 +221,16 @@ func (channel *Channel) IsClean() bool {
219 221
 
220 222
 	channel.stateMutex.RLock()
221 223
 	defer channel.stateMutex.RUnlock()
222
-	// the channel must be empty, and either be unregistered or fully written to the DB
223
-	return len(channel.members) == 0 && (channel.registeredFounder == "" || channel.dirtyBits == 0)
224
+	if len(channel.members) != 0 {
225
+		return false
226
+	}
227
+	if channel.registeredFounder == "" {
228
+		return true
229
+	}
230
+	// a registered channel must be fully written to the DB,
231
+	// and not set to ephemeral history (#704)
232
+	return channel.dirtyBits == 0 &&
233
+		channelHistoryStatus(config, true, channel.settings.History) != HistoryEphemeral
224 234
 }
225 235
 
226 236
 func (channel *Channel) wakeWriter() {
@@ -599,15 +609,23 @@ func (channel *Channel) historyStatus(config *Config) (status HistoryStatus, tar
599 609
 	registered := channel.registeredFounder != ""
600 610
 	channel.stateMutex.RUnlock()
601 611
 
612
+	return channelHistoryStatus(config, registered, historyStatus), target
613
+}
614
+
615
+func channelHistoryStatus(config *Config, registered bool, storedStatus HistoryStatus) (result HistoryStatus) {
616
+	if !config.History.Enabled {
617
+		return HistoryDisabled
618
+	}
619
+
602 620
 	// ephemeral history: either the channel owner explicitly set the ephemeral preference,
603 621
 	// or persistent history is disabled for unregistered channels
604 622
 	if registered {
605
-		return historyEnabled(config.History.Persistent.RegisteredChannels, historyStatus), target
623
+		return historyEnabled(config.History.Persistent.RegisteredChannels, storedStatus)
606 624
 	} else {
607 625
 		if config.History.Persistent.UnregisteredChannels {
608
-			return HistoryPersistent, target
626
+			return HistoryPersistent
609 627
 		} else {
610
-			return HistoryEphemeral, target
628
+			return HistoryEphemeral
611 629
 		}
612 630
 	}
613 631
 }

+ 4
- 1
irc/server.go Просмотреть файл

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

Загрузка…
Отмена
Сохранить