32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
class SyncToken(object):
|
|
"""A SyncToken is an instance of a sync token, which is a token retrieved from a matrix
|
|
homeserver. It is given to the /sync endpoint in order to specify at which point in the
|
|
event timeline you would like to receive messages after
|
|
"""
|
|
|
|
def __init__(self, store):
|
|
"""
|
|
Args:
|
|
store (Storage): An object to access the storage layer
|
|
"""
|
|
self.store = store
|
|
|
|
# Attempt to load a token from the provided storage layer
|
|
self._load()
|
|
|
|
def _load(self):
|
|
"""Load the latest sync token from the database"""
|
|
self.store.cursor.execute("SELECT token FROM sync_token")
|
|
rows = self.store.cursor.fetchone()
|
|
|
|
if rows:
|
|
self.token = rows[0]
|
|
|
|
def update(self, token):
|
|
"""Update the sync token in the database
|
|
|
|
Args:
|
|
token (str): A sync token from a sync response sent by a matrix homeserver
|
|
"""
|
|
self.store.cursor.execute("INSERT OR REPLACE INTO sync_token "
|
|
"(token) VALUES (?)", (token,))
|