Ver código fonte

simplify lastSeen handling

tags/v2.2.0-rc1
Shivaram Lingamneni 4 anos atrás
pai
commit
df1be01f54
2 arquivos alterados com 6 adições e 7 exclusões
  1. 5
    6
      irc/client.go
  2. 1
    1
      irc/getters.go

+ 5
- 6
irc/client.go Ver arquivo

@@ -307,7 +307,6 @@ func (server *Server) RunClient(conn IRCConn) {
307 307
 	// give them 1k of grace over the limit:
308 308
 	socket := NewSocket(conn, config.Server.MaxSendQBytes)
309 309
 	client := &Client{
310
-		lastSeen:   make(map[string]time.Time),
311 310
 		lastActive: now,
312 311
 		channels:   make(ChannelSet),
313 312
 		ctime:      now,
@@ -369,11 +368,8 @@ func (server *Server) RunClient(conn IRCConn) {
369 368
 func (server *Server) AddAlwaysOnClient(account ClientAccount, chnames []string, lastSeen map[string]time.Time, uModes modes.Modes) {
370 369
 	now := time.Now().UTC()
371 370
 	config := server.Config()
372
-	if lastSeen == nil {
373
-		lastSeen = make(map[string]time.Time)
374
-		if account.Settings.AutoreplayMissed {
375
-			lastSeen[""] = now
376
-		}
371
+	if lastSeen == nil && account.Settings.AutoreplayMissed {
372
+		lastSeen = map[string]time.Time{"": now}
377 373
 	}
378 374
 
379 375
 	client := &Client{
@@ -746,6 +742,9 @@ func (client *Client) Touch(active bool, session *Session) {
746 742
 }
747 743
 
748 744
 func (client *Client) setLastSeen(now time.Time, deviceID string) {
745
+	if client.lastSeen == nil {
746
+		client.lastSeen = make(map[string]time.Time)
747
+	}
749 748
 	client.lastSeen[deviceID] = now
750 749
 	// evict the least-recently-used entry if necessary
751 750
 	if maxDeviceIDsPerClient < len(client.lastSeen) {

+ 1
- 1
irc/getters.go Ver arquivo

@@ -334,7 +334,7 @@ func (client *Client) SetAccountSettings(settings AccountSettings) {
334 334
 		becameAlwaysOn = (!client.alwaysOn && alwaysOn)
335 335
 		client.alwaysOn = alwaysOn
336 336
 		if autoreplayMissedDisabled {
337
-			client.lastSeen = make(map[string]time.Time)
337
+			client.lastSeen = nil
338 338
 		}
339 339
 	}
340 340
 	client.accountSettings = settings

Carregando…
Cancelar
Salvar