Skip to content

Commit 79c3882

Browse files
committed
fix: added missing entities
1 parent 4c7621d commit 79c3882

File tree

1 file changed

+49
-11
lines changed

1 file changed

+49
-11
lines changed

userbot/src/db_session.py

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from telethon.sessions.abstract import Session
66
from telethon.crypto import AuthKey
7+
from telethon.tl.types import InputPhoto, InputDocument, PeerUser, PeerChat, PeerChannel
78

89
import userbot.src.db_manager as db_manager
910
from userbot.src.db.session import get_db
@@ -137,13 +138,11 @@ def set_dc(self, dc_id: int, server_address: str, port: int):
137138
self._port = port
138139

139140
def get_update_state(self, entity_id: int) -> Optional[Tuple[int, int, int, int, int]]:
140-
"""Note: This implementation is global, not per-entity."""
141141
if self._pts is None:
142142
return None
143143
return self._pts, self._qts, self._date, self._seq, 0
144144

145145
def set_update_state(self, entity_id: int, state: Any):
146-
"""Note: This implementation is global, not per-entity."""
147146
if isinstance(state.date, datetime):
148147
date_ts = int(state.date.replace(tzinfo=timezone.utc).timestamp())
149148
else:
@@ -155,18 +154,57 @@ def set_update_state(self, entity_id: int, state: Any):
155154
self._seq = state.seq
156155

157156
async def close(self) -> None:
158-
"""No action needed for DB sessions as the pool is managed globally."""
159157
pass
160158

161-
# --- Deprecated/Legacy Abstract Methods (from older Telethon versions) ---
162-
163159
def get_update_states(self) -> List[Tuple[int, int, int, int, int, int]]:
164-
"""
165-
Returns all update states.
166-
Since we store only one global state, we return it for the "self" user entity.
167-
The entity ID 0 is a placeholder for "self".
168-
"""
169160
if self._pts is None:
170161
return []
171-
# entity_id, pts, qts, date, seq, unread_count
172162
return [(0, self._pts, self._qts, self._date, self._seq, 0)]
163+
164+
# --- New Stubs for Entity and File Caching ---
165+
166+
def process_entities(self, tlo: object) -> None:
167+
"""
168+
This session does not cache entities, so this method does nothing.
169+
170+
Args:
171+
tlo (object): A TLObject containing entities.
172+
"""
173+
pass
174+
175+
def get_input_entity(self, key: Any) -> Any:
176+
"""
177+
This session does not cache entities, so this method always fails.
178+
179+
Args:
180+
key (Any): The key to look up an entity.
181+
182+
Raises:
183+
KeyError: Always, as no entities are cached.
184+
"""
185+
raise KeyError("Entity not found in DbSession cache (caching is not implemented).")
186+
187+
def cache_file(self, md5_digest: bytes, file_size: int, instance: Any) -> None:
188+
"""
189+
This session does not cache files, so this method does nothing.
190+
191+
Args:
192+
md5_digest (bytes): The MD5 digest of the file.
193+
file_size (int): The size of the file.
194+
instance (Any): The InputFile or InputPhoto instance.
195+
"""
196+
pass
197+
198+
def get_file(self, md5_digest: bytes, file_size: int, exact: bool = True) -> Optional[Any]:
199+
"""
200+
This session does not cache files, so this method always returns None.
201+
202+
Args:
203+
md5_digest (bytes): The MD5 digest of the file.
204+
file_size (int): The size of the file.
205+
exact (bool): Whether the file size must be exact.
206+
207+
Returns:
208+
None: Always, as no files are cached.
209+
"""
210+
return None

0 commit comments

Comments
 (0)