diff --git a/litecord/gateway/websocket.py b/litecord/gateway/websocket.py index 515eac6..e32482e 100644 --- a/litecord/gateway/websocket.py +++ b/litecord/gateway/websocket.py @@ -406,6 +406,13 @@ class GatewayWebsocket: # link the state to the user self.ext.state_manager.insert(self.state) + # update last_session + await self.ext.db.execute(""" + UPDATE users + SET last_session = (now() at time zone 'utc') + WHERE id = $1 + """, user_id) + await self.update_status(presence) await self.subscribe_all() await self.dispatch_ready() diff --git a/schema.sql b/schema.sql index e43ba45..b520d18 100644 --- a/schema.sql +++ b/schema.sql @@ -75,6 +75,9 @@ CREATE TABLE IF NOT EXISTS users ( phone varchar(60) DEFAULT '', password_hash text NOT NULL, + -- store the last time the user logged in via the gateway + last_session timestamp without time zone default (now() at time zone 'utc'), + PRIMARY KEY (id, username, discriminator) );