Browse Source

simplify lastSeen handling

tags/v2.2.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
df1be01f54
2 changed files with 6 additions and 7 deletions
  1. 5
    6
      irc/client.go
  2. 1
    1
      irc/getters.go

+ 5
- 6
irc/client.go View File

307
 	// give them 1k of grace over the limit:
307
 	// give them 1k of grace over the limit:
308
 	socket := NewSocket(conn, config.Server.MaxSendQBytes)
308
 	socket := NewSocket(conn, config.Server.MaxSendQBytes)
309
 	client := &Client{
309
 	client := &Client{
310
-		lastSeen:   make(map[string]time.Time),
311
 		lastActive: now,
310
 		lastActive: now,
312
 		channels:   make(ChannelSet),
311
 		channels:   make(ChannelSet),
313
 		ctime:      now,
312
 		ctime:      now,
369
 func (server *Server) AddAlwaysOnClient(account ClientAccount, chnames []string, lastSeen map[string]time.Time, uModes modes.Modes) {
368
 func (server *Server) AddAlwaysOnClient(account ClientAccount, chnames []string, lastSeen map[string]time.Time, uModes modes.Modes) {
370
 	now := time.Now().UTC()
369
 	now := time.Now().UTC()
371
 	config := server.Config()
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
 	client := &Client{
375
 	client := &Client{
746
 }
742
 }
747
 
743
 
748
 func (client *Client) setLastSeen(now time.Time, deviceID string) {
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
 	client.lastSeen[deviceID] = now
748
 	client.lastSeen[deviceID] = now
750
 	// evict the least-recently-used entry if necessary
749
 	// evict the least-recently-used entry if necessary
751
 	if maxDeviceIDsPerClient < len(client.lastSeen) {
750
 	if maxDeviceIDsPerClient < len(client.lastSeen) {

+ 1
- 1
irc/getters.go View File

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

Loading…
Cancel
Save