From df1be01f54634c69bfcb84ac2884bfe0afdb9832 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Sun, 14 Jun 2020 13:52:29 -0400 Subject: [PATCH] simplify lastSeen handling --- irc/client.go | 11 +++++------ irc/getters.go | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/irc/client.go b/irc/client.go index 669016dd..d733ee23 100644 --- a/irc/client.go +++ b/irc/client.go @@ -307,7 +307,6 @@ func (server *Server) RunClient(conn IRCConn) { // give them 1k of grace over the limit: socket := NewSocket(conn, config.Server.MaxSendQBytes) client := &Client{ - lastSeen: make(map[string]time.Time), lastActive: now, channels: make(ChannelSet), ctime: now, @@ -369,11 +368,8 @@ func (server *Server) RunClient(conn IRCConn) { func (server *Server) AddAlwaysOnClient(account ClientAccount, chnames []string, lastSeen map[string]time.Time, uModes modes.Modes) { now := time.Now().UTC() config := server.Config() - if lastSeen == nil { - lastSeen = make(map[string]time.Time) - if account.Settings.AutoreplayMissed { - lastSeen[""] = now - } + if lastSeen == nil && account.Settings.AutoreplayMissed { + lastSeen = map[string]time.Time{"": now} } client := &Client{ @@ -746,6 +742,9 @@ func (client *Client) Touch(active bool, session *Session) { } func (client *Client) setLastSeen(now time.Time, deviceID string) { + if client.lastSeen == nil { + client.lastSeen = make(map[string]time.Time) + } client.lastSeen[deviceID] = now // evict the least-recently-used entry if necessary if maxDeviceIDsPerClient < len(client.lastSeen) { diff --git a/irc/getters.go b/irc/getters.go index 8041134e..1d2038f3 100644 --- a/irc/getters.go +++ b/irc/getters.go @@ -334,7 +334,7 @@ func (client *Client) SetAccountSettings(settings AccountSettings) { becameAlwaysOn = (!client.alwaysOn && alwaysOn) client.alwaysOn = alwaysOn if autoreplayMissedDisabled { - client.lastSeen = make(map[string]time.Time) + client.lastSeen = nil } } client.accountSettings = settings