Attempt to load and save MessageBox state

This commit is contained in:
Lonami Exo
2022-05-13 17:40:03 +02:00
parent 053a0052c8
commit a5c3df2743
7 changed files with 60 additions and 8 deletions

View File

@@ -97,6 +97,12 @@ class Session(ABC):
"""
raise NotImplementedError
@abstractmethod
async def get_update_states(self):
"""
Returns an iterable over all known pairs of ``(entity ID, update state)``.
"""
@abstractmethod
async def close(self):
"""

View File

@@ -77,6 +77,9 @@ class MemorySession(Session):
async def set_update_state(self, entity_id, state):
self._update_states[entity_id] = state
async def get_update_states(self):
return self._update_states.items()
async def close(self):
pass

View File

@@ -215,6 +215,14 @@ class SQLiteSession(MemorySession):
entity_id, state.pts, state.qts,
state.date.timestamp(), state.seq)
async def get_update_states(self):
c = self._cursor()
try:
rows = c.execute('select id, pts, qts, date, seq from update_state').fetchall()
return ((row[0], types.updates.State(*row[1:], unread_count=0)) for row in rows)
finally:
c.close()
async def save(self):
"""Saves the current session object as session_user_id.session"""
# This is a no-op if there are no changes to commit, so there's