3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

simplify lastSeen handling

This commit is contained in:
Shivaram Lingamneni 2020-06-14 13:52:29 -04:00
parent 218bea5a3e
commit df1be01f54
2 changed files with 6 additions and 7 deletions

View File

@ -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) {

View File

@ -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