mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-06 09:34:13 -04:00
An initial hack at storing presence state-change mtimes in database and presenting age durations to clients/federation events
This commit is contained in:
parent
a6a9b71da0
commit
d05aa651f8
7 changed files with 101 additions and 29 deletions
|
@ -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.
|
||||
|
|
|
@ -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"],
|
||||
)
|
||||
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue