telegram: As messages are referenced by peer and id (in "get" and future
patch 72bb23b64e2392ff01f7e060670e98093cfe0839
Author: E. Bosch <presidev@AT@gmail.com>
Date: Mon May 15 21:27:05 CEST 2023
* telegram: As messages are referenced by peer and id (in "get" and future
commands), make the compact IDs more compact with offsets relative to peers
(users or channels)
hunk ./irc.py 412
- mid = self.tg.mid.num_to_id_offset(tg_msg.id)
+ mid = self.tg.mid.num_to_id_offset(telegram_id, tg_msg.id)
hunk ./service.py 121
- id = self.tg.mid.id_to_num_offset(mid)
hunk ./service.py 124
+ id = self.tg.mid.id_to_num_offset(peer_id, mid)
hunk ./telegram.py 377
- mid = self.mid.num_to_id_offset(id)
+ mid = self.mid.num_to_id_offset(event.message.peer_id, id)
hunk ./telegram.py 441
- mid = self.mid.num_to_id_offset(deleted_id)
- text = 'Message id {} deleted not in cache'.format(mid)
+ text = 'Message id {} deleted not in cache'.format(deleted_id)
hunk ./telegram.py 458
- mid = self.mid.num_to_id_offset(msg.id)
+ mid = self.mid.num_to_id_offset(msg.peer_id, msg.id)
hunk ./telegram.py 557
- replied_msg = '[{}]'.format(self.mid.num_to_id_offset(replied.id))
+ replied_msg = '[{}]'.format(self.mid.num_to_id_offset(replied.peer_id, replied.id))
hunk ./telegram.py 740
- self.mesg_base = None
+ self.mesg_base = {}
hunk ./telegram.py 751
- def num_to_id_offset(self, num):
- if self.mesg_base is None:
- self.mesg_base = num
- return self.num_to_id(num - self.mesg_base)
+ def num_to_id_offset(self, peer, num):
+ peer_id = self.get_peer_id(peer)
+ if peer_id not in self.mesg_base:
+ self.mesg_base[peer_id] = num
+ return self.num_to_id(num - self.mesg_base[peer_id])
hunk ./telegram.py 766
- def id_to_num_offset(self, mid):
- if self.mesg_base is not None:
+ def id_to_num_offset(self, peer, mid):
+ peer_id = self.get_peer_id(peer)
+ if peer_id in self.mesg_base:
hunk ./telegram.py 770
- id = id_rel + self.mesg_base
+ id = id_rel + self.mesg_base[peer_id]
hunk ./telegram.py 773
+ return id
+
+ def get_peer_id(self, peer):
+ if isinstance(peer, tgty.PeerChannel):
+ id = peer.channel_id
+ elif isinstance(peer, tgty.PeerChat):
+ id = peer.chat_id
+ elif isinstance(peer, tgty.PeerUser):
+ id = peer.user_id
+ else:
+ id = peer