pyrofork: Remove state when leaving chat

Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
wulan17 2024-07-23 22:28:20 +07:00
parent 6ba25aa4f5
commit 4bbbd5c460
No known key found for this signature in database
GPG key ID: 318CD6CD3A6AC0A5
3 changed files with 11 additions and 0 deletions

View file

@ -53,6 +53,8 @@ class LeaveChat:
await app.leave_chat(chat_id, delete=True) await app.leave_chat(chat_id, delete=True)
""" """
peer = await self.resolve_peer(chat_id) peer = await self.resolve_peer(chat_id)
if not self.skip_updates:
await self.storage.remove_state(chat_id)
if isinstance(peer, raw.types.InputPeerChannel): if isinstance(peer, raw.types.InputPeerChannel):
return await self.invoke( return await self.invoke(

View file

@ -178,6 +178,9 @@ class MongoStorage(Storage):
else: else:
await self._states.update_one({'_id': value[0]}, {'$set': {'pts': value[1], 'qts': value[2], 'date': value[3], 'seq': value[4]}}, upsert=True) await self._states.update_one({'_id': value[0]}, {'$set': {'pts': value[1], 'qts': value[2], 'date': value[3], 'seq': value[4]}}, upsert=True)
async def remove_state(self, chat_id):
await self._states.delete_one({'_id': chat_id})
async def get_peer_by_id(self, peer_id: int): async def get_peer_by_id(self, peer_id: int):
# id, access_hash, type # id, access_hash, type
r = await self._peer.find_one({'_id': peer_id}, {'_id': 1, 'access_hash': 1, 'type': 1}) r = await self._peer.find_one({'_id': peer_id}, {'_id': 1, 'access_hash': 1, 'type': 1})

View file

@ -194,6 +194,12 @@ class SQLiteStorage(Storage):
value value
) )
async def remove_state(self, chat_id):
self.conn.execute(
"DELETE FROM update_state WHERE id = ?",
(chat_id,)
)
async def get_peer_by_id(self, peer_id: int): async def get_peer_by_id(self, peer_id: int):
r = self.conn.execute( r = self.conn.execute(
"SELECT id, access_hash, type FROM peers WHERE id = ?", "SELECT id, access_hash, type FROM peers WHERE id = ?",