summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2014-08-13 19:18:55 +0100
committerPaul "LeoNerd" Evans <paul@matrix.org>2014-08-13 19:19:15 +0100
commitd05aa651f80b604428c003a13a03c4f6f61c317d (patch)
tree655502cdd01fe89c0ab56a3b0d27cc9faf95b2e9 /synapse/storage
parentAllow advancing the MockClock's time (diff)
downloadsynapse-d05aa651f80b604428c003a13a03c4f6f61c317d.tar.xz
An initial hack at storing presence state-change mtimes in database and presenting age durations to clients/federation events
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/_base.py1
-rw-r--r--synapse/storage/presence.py5
-rw-r--r--synapse/storage/schema/presence.sql1
3 files changed, 5 insertions, 2 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index 1b98bdfcef..bf1800f4bf 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -29,6 +29,7 @@ class SQLBaseStore(object):
     def __init__(self, hs):
         self.hs = hs
         self._db_pool = hs.get_db_pool()
+        self._clock = hs.get_clock()
 
     def cursor_to_dict(self, cursor):
         """Converts a SQL cursor into an list of dicts.
diff --git a/synapse/storage/presence.py b/synapse/storage/presence.py
index 6f5b042c25..23b6d1694e 100644
--- a/synapse/storage/presence.py
+++ b/synapse/storage/presence.py
@@ -35,7 +35,7 @@ class PresenceStore(SQLBaseStore):
         return self._simple_select_one(
             table="presence",
             keyvalues={"user_id": user_localpart},
-            retcols=["state", "status_msg"],
+            retcols=["state", "status_msg", "mtime"],
         )
 
     def set_presence_state(self, user_localpart, new_state):
@@ -43,7 +43,8 @@ class PresenceStore(SQLBaseStore):
             table="presence",
             keyvalues={"user_id": user_localpart},
             updatevalues={"state": new_state["state"],
-                          "status_msg": new_state["status_msg"]},
+                          "status_msg": new_state["status_msg"],
+                          "mtime": self._clock.time_msec()},
             retcols=["state"],
         )
 
diff --git a/synapse/storage/schema/presence.sql b/synapse/storage/schema/presence.sql
index b22e3ba863..b1081d3aab 100644
--- a/synapse/storage/schema/presence.sql
+++ b/synapse/storage/schema/presence.sql
@@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS presence(
   user_id INTEGER NOT NULL,
   state INTEGER,
   status_msg TEXT,
+  mtime INTEGER, -- miliseconds since last state change
   FOREIGN KEY(user_id) REFERENCES users(id)
 );