Skip to content

Commit

Permalink
pyrofork: Remove state when leaving chat
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Jul 23, 2024
1 parent 0b1a05d commit 875a941
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pyrogram/methods/chats/leave_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ async def leave_chat(
await app.leave_chat(chat_id, delete=True)
"""
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):
return await self.invoke(
Expand Down
3 changes: 3 additions & 0 deletions pyrogram/storage/mongo_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ async def update_state(self, value: Tuple[int, int, int, int, int] = object):
else:
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):
# id, access_hash, type
r = await self._peer.find_one({'_id': peer_id}, {'_id': 1, 'access_hash': 1, 'type': 1})
Expand Down
6 changes: 6 additions & 0 deletions pyrogram/storage/sqlite_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ async def update_state(self, value: Tuple[int, int, int, int, int] = object):
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):
r = self.conn.execute(
"SELECT id, access_hash, type FROM peers WHERE id = ?",
Expand Down

0 comments on commit 875a941

Please sign in to comment.