Update to Telegram API layer 138
This commit is contained in:
+20
-13
@@ -118,8 +118,8 @@ from telethon.tl.types import (
|
|||||||
MessageMediaPoll,
|
MessageMediaPoll,
|
||||||
MessageMediaUnsupported,
|
MessageMediaUnsupported,
|
||||||
MessageMediaVenue,
|
MessageMediaVenue,
|
||||||
|
MessagePeerReaction,
|
||||||
MessageReactions,
|
MessageReactions,
|
||||||
MessageUserReaction,
|
|
||||||
PeerChannel,
|
PeerChannel,
|
||||||
PeerChat,
|
PeerChat,
|
||||||
PeerUser,
|
PeerUser,
|
||||||
@@ -2757,31 +2757,33 @@ class Portal(DBPortal, BasePortal):
|
|||||||
count += 1
|
count += 1
|
||||||
return count
|
return count
|
||||||
|
|
||||||
def _split_dm_reaction_counts(self, counts: list[ReactionCount]) -> list[MessageUserReaction]:
|
def _split_dm_reaction_counts(self, counts: list[ReactionCount]) -> list[MessagePeerReaction]:
|
||||||
if len(counts) == 1:
|
if len(counts) == 1:
|
||||||
item = counts[0]
|
item = counts[0]
|
||||||
if item.count == 2:
|
if item.count == 2:
|
||||||
return [
|
return [
|
||||||
MessageUserReaction(reaction=item.reaction, user_id=self.tgid),
|
MessagePeerReaction(reaction=item.reaction, peer_id=PeerUser(self.tgid)),
|
||||||
MessageUserReaction(reaction=item.reaction, user_id=self.tg_receiver),
|
MessagePeerReaction(
|
||||||
|
reaction=item.reaction, peer_id=PeerUser(self.tg_receiver)
|
||||||
|
),
|
||||||
]
|
]
|
||||||
elif item.count == 1:
|
elif item.count == 1:
|
||||||
return [
|
return [
|
||||||
MessageUserReaction(
|
MessagePeerReaction(
|
||||||
reaction=item.reaction,
|
reaction=item.reaction,
|
||||||
user_id=self.tg_receiver if item.chosen else self.tgid,
|
peer_id=PeerUser(self.tg_receiver if item.chosen else self.tgid),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
elif len(counts) == 2:
|
elif len(counts) == 2:
|
||||||
item1, item2 = counts
|
item1, item2 = counts
|
||||||
return [
|
return [
|
||||||
MessageUserReaction(
|
MessagePeerReaction(
|
||||||
reaction=item1.reaction,
|
reaction=item1.reaction,
|
||||||
user_id=self.tg_receiver if item1.chosen else self.tgid,
|
peer_id=PeerUser(self.tg_receiver if item1.chosen else self.tgid),
|
||||||
),
|
),
|
||||||
MessageUserReaction(
|
MessagePeerReaction(
|
||||||
reaction=item2.reaction,
|
reaction=item2.reaction,
|
||||||
user_id=self.tg_receiver if item2.chosen else self.tgid,
|
peer_id=PeerUser(self.tg_receiver if item2.chosen else self.tgid),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
return []
|
return []
|
||||||
@@ -2816,7 +2818,7 @@ class Portal(DBPortal, BasePortal):
|
|||||||
return
|
return
|
||||||
|
|
||||||
total_count = sum(item.count for item in data.results)
|
total_count = sum(item.count for item in data.results)
|
||||||
recent_reactions = data.recent_reactons or []
|
recent_reactions = data.recent_reactions or []
|
||||||
if not recent_reactions and total_count > 0:
|
if not recent_reactions and total_count > 0:
|
||||||
if self.peer_type == "user":
|
if self.peer_type == "user":
|
||||||
recent_reactions = self._split_dm_reaction_counts(data.results)
|
recent_reactions = self._split_dm_reaction_counts(data.results)
|
||||||
@@ -2835,9 +2837,14 @@ class Portal(DBPortal, BasePortal):
|
|||||||
await self._handle_telegram_reactions_locked(dbm, recent_reactions, total_count)
|
await self._handle_telegram_reactions_locked(dbm, recent_reactions, total_count)
|
||||||
|
|
||||||
async def _handle_telegram_reactions_locked(
|
async def _handle_telegram_reactions_locked(
|
||||||
self, msg: DBMessage, reaction_list: list[MessageUserReaction], total_count: int
|
self, msg: DBMessage, reaction_list: list[MessagePeerReaction], total_count: int
|
||||||
) -> None:
|
) -> None:
|
||||||
reactions = {reaction.user_id: reaction.reaction for reaction in reaction_list}
|
reactions = {
|
||||||
|
reaction.peer_id.user_id: reaction.reaction
|
||||||
|
for reaction in reaction_list
|
||||||
|
# TODO allow PeerChannel once channel senders are properly supported
|
||||||
|
if isinstance(reaction.peer_id, PeerUser)
|
||||||
|
}
|
||||||
is_full = len(reactions) == total_count
|
is_full = len(reactions) == total_count
|
||||||
|
|
||||||
existing_reactions = await DBReaction.get_all_by_message(msg.mxid, msg.mx_room)
|
existing_reactions = await DBReaction.get_all_by_message(msg.mxid, msg.mx_room)
|
||||||
|
|||||||
+2
-2
@@ -5,8 +5,8 @@ aiohttp>=3,<4
|
|||||||
yarl>=1,<2
|
yarl>=1,<2
|
||||||
mautrix>=0.14.8,<0.15
|
mautrix>=0.14.8,<0.15
|
||||||
#telethon>=1.24,<1.25
|
#telethon>=1.24,<1.25
|
||||||
# Fork to make session storage async and update to layer 137
|
# Fork to make session storage async and update to layer 138
|
||||||
tulir-telethon==1.25.0a3
|
tulir-telethon==1.25.0a4
|
||||||
asyncpg>=0.20,<0.26
|
asyncpg>=0.20,<0.26
|
||||||
mako>=1,<2
|
mako>=1,<2
|
||||||
setuptools
|
setuptools
|
||||||
|
|||||||
Reference in New Issue
Block a user