Skip to content

Commit 05badbf

Browse files
committed
Changed types in UpgradedGift and UserGift, according to Layer 197.
1 parent 74ab511 commit 05badbf

File tree

7 files changed

+70
-23
lines changed

7 files changed

+70
-23
lines changed

docs/source/releases/changes-in-this-fork.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Changes in this Fork
2626
| Scheme layer used: 198 |
2727
+------------------------+
2828

29+
- Changed types in :obj:`~pyrogram.types.UpgradedGift`, :obj:`~pyrogram.types.UserGift`.
2930
- PR from upstream: `701 <https://github.com/pyrogram/pyrogram/pull/701>`_
3031
- View `new and changed <https://telegramplayground.github.io/TG-APIs/TL/diff/tdlib.html?from=196&to=198>`__ `raw API methods <https://telegramplayground.github.io/TG-APIs/TL/diff/tdesktop.html?from=196&to=198>`__.
3132

pyrogram/methods/business/get_available_gifts.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@ async def get_available_gifts(
4242
raw.functions.payments.GetStarGifts(hash=0)
4343
)
4444

45-
return types.List([await types.Gift._parse(self, gift) for gift in r.gifts])
45+
return types.List([
46+
await types.Gift._parse(self, gift, {})
47+
for gift in r.gifts
48+
])

pyrogram/methods/business/get_user_gifts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ async def get_user_gifts(
7272
)
7373

7474
users = {u.id: u for u in r.users}
75-
# TODO
75+
chats = {c.id: c for c in r.chats}
7676

7777
user_gifts = [
78-
await types.UserGift._parse(self, gift, users)
78+
await types.UserGift._parse(self, gift, users, chats)
7979
for gift in r.gifts
8080
]
8181

pyrogram/types/messages_and_media/gift.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ def __init__(
102102
async def _parse(
103103
client,
104104
star_gift: "raw.base.StarGift",
105+
users: dict
105106
) -> Union["Gift", "types.UpgradedGift"]:
106107
if isinstance(star_gift, raw.types.StarGiftUnique):
107-
return types.UpgradedGift._parse(client, star_gift)
108+
return types.UpgradedGift._parse(client, star_gift, users)
108109

109110
doc = star_gift.sticker
110111
attributes = {type(i): i for i in doc.attributes}

pyrogram/types/messages_and_media/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ async def _parse(
10131013
isinstance(action, raw.types.MessageActionStarGift) or
10141014
isinstance(action, raw.types.MessageActionStarGiftUnique)
10151015
):
1016-
user_gift = await types.UserGift._parse_action(client, message, users)
1016+
user_gift = await types.UserGift._parse_action(client, message, users, chats)
10171017
service_type = enums.MessageServiceType.USER_GIFT
10181018

10191019
parsed_message = Message(

pyrogram/types/messages_and_media/upgraded_gift.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from typing import Optional
2020

2121
import pyrogram
22-
from pyrogram import raw, utils
22+
from pyrogram import raw, types, utils
2323
from ..object import Object
2424

2525

@@ -33,6 +33,9 @@ class UpgradedGift(Object):
3333
title (``str``):
3434
The title of the upgraded gift.
3535
36+
name (``str``):
37+
Unique name of the upgraded gift.
38+
3639
number (``int``):
3740
Unique number of the upgraded gift among gifts upgraded from the same gift.
3841
@@ -42,11 +45,17 @@ class UpgradedGift(Object):
4245
max_upgraded_count (``int``):
4346
The maximum number of gifts that can be upgraded from the same gift.
4447
45-
owner_user_id (``int``, *optional*):
46-
User identifier of the user that owns the upgraded gift.
48+
owner_id (:obj:`~pyrogram.types.User`, *optional*):
49+
User identifier of the user or the chat that owns the upgraded gift; may be None if unknown.
50+
51+
owner_address (``str``, *optional*):
52+
Address of the gift NFT owner in TON blockchain.
4753
48-
owner_user_name (``str``, *optional*):
49-
User name of the user that owns the upgraded gift.
54+
owner_name (``str``, *optional*):
55+
Name of the owner for the case when owner identifier and address aren't known.
56+
57+
link (``str``, *property*):
58+
The link is a link to an upgraded gift.
5059
5160
"""
5261

@@ -56,38 +65,53 @@ def __init__(
5665
client: "pyrogram.Client" = None,
5766
id: int,
5867
title: str,
68+
name: str,
5969
number: int,
6070
total_upgraded_count: int,
6171
max_upgraded_count: int,
62-
owner_user_id: Optional[int] = None,
63-
owner_user_name: Optional[str] = None,
72+
owner_id: Optional["types.Chat"] = None,
73+
owner_address: Optional[str] = None,
74+
owner_name: Optional[str] = None,
6475
_raw: "raw.types.StarGiftUnique" = None,
6576
):
6677
super().__init__(client)
6778

6879
self.id = id
6980
self.title = title
81+
self.name = name
7082
self.number = number
7183
self.total_upgraded_count = total_upgraded_count
7284
self.max_upgraded_count = max_upgraded_count
73-
self.owner_user_id = owner_user_id
74-
self.owner_user_name = owner_user_name
85+
self.owner_id = owner_id
86+
self.owner_address = owner_address
87+
self.owner_name = owner_name
7588
self._raw = _raw # TODO
7689

7790

7891
@staticmethod
7992
def _parse(
8093
client,
81-
star_gift: "raw.types.StarGiftUnique"
94+
star_gift: "raw.types.StarGiftUnique",
95+
users: dict
8296
) -> "UpgradedGift":
97+
owner_id = utils.get_raw_peer_id(getattr(star_gift, "owner_id", None))
8398
return UpgradedGift(
8499
id=star_gift.id,
85100
title=star_gift.title,
101+
name=star_gift.slug,
86102
number=star_gift.num,
87103
total_upgraded_count=star_gift.availability_issued,
88104
max_upgraded_count=star_gift.availability_total,
89-
owner_user_id=utils.get_raw_peer_id(getattr(star_gift, "owner_id", None)),
90-
owner_user_name=getattr(star_gift, "owner_name", None),
105+
owner_id=types.Chat._parse_user_chat(
106+
client,
107+
users.get(owner_id, owner_id)
108+
),
109+
owner_address=getattr(star_gift, "owner_address", None),
110+
owner_name=getattr(star_gift, "owner_name", None),
91111
_raw=star_gift,
92112
client=client
93113
)
114+
115+
@property
116+
def link(self) -> str:
117+
return f"https://t.me/nft/{self.name}"

pyrogram/types/messages_and_media/user_gift.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,29 @@ def __init__(
124124
async def _parse(
125125
client,
126126
saved_star_gift: "raw.types.SavedStarGift",
127-
users: dict
127+
users: dict,
128+
chats: dict
128129
) -> "UserGift":
129130
text, entities = None, None
130131
if getattr(saved_star_gift, "message", None):
131132
text = saved_star_gift.message.text or None
132133
entities = [types.MessageEntity._parse(client, entity, users) for entity in saved_star_gift.message.entities]
133134
entities = types.List(filter(lambda x: x is not None, entities))
134135
# TODO refunded:flags.9?true can_upgrade:flags.10?true msg_id:flags.3?int saved_id:flags.11?long upgrade_stars:flags.6?long can_export_at:flags.7?int transfer_stars:flags.8?long
136+
sender_user = utils.get_raw_peer_id(saved_star_gift.from_id)
135137
return UserGift(
136138
date=utils.timestamp_to_datetime(saved_star_gift.date),
137-
gift=await types.Gift._parse(client, saved_star_gift.gift),
139+
gift=await types.Gift._parse(
140+
client,
141+
saved_star_gift.gift,
142+
users
143+
),
138144
is_private=getattr(saved_star_gift, "name_hidden", None),
139145
is_saved=not saved_star_gift.unsaved if getattr(saved_star_gift, "unsaved", None) else None,
140-
sender_user=types.User._parse(client, users.get(saved_star_gift.from_id)) if getattr(saved_star_gift, "from_id", None) else None,
146+
sender_user=types.User._parse(
147+
client,
148+
users.get(sender_user)
149+
) if sender_user else None,
141150
message_id=getattr(saved_star_gift, "msg_id", None),
142151
sell_star_count=getattr(saved_star_gift, "convert_stars", None),
143152
text=Str(text).init(entities) if text else None,
@@ -149,7 +158,8 @@ async def _parse(
149158
async def _parse_action(
150159
client,
151160
message: "raw.base.Message",
152-
users: dict
161+
users: dict,
162+
chats: dict
153163
) -> "UserGift":
154164
action = message.action
155165

@@ -161,7 +171,11 @@ async def _parse_action(
161171
# TODO
162172
if isinstance(action, raw.types.MessageActionStarGift):
163173
return UserGift(
164-
gift=await types.Gift._parse(client, action.gift),
174+
gift=await types.Gift._parse(
175+
client,
176+
action.gift,
177+
users
178+
),
165179
date=utils.timestamp_to_datetime(message.date),
166180
is_private=getattr(action, "name_hidden", None),
167181
is_saved=getattr(action, "saved", None),
@@ -179,7 +193,11 @@ async def _parse_action(
179193

180194
if isinstance(action, raw.types.MessageActionStarGiftUnique):
181195
return UserGift(
182-
gift=await types.Gift._parse(client, action.gift),
196+
gift=await types.Gift._parse(
197+
client,
198+
action.gift,
199+
users
200+
),
183201
date=utils.timestamp_to_datetime(message.date),
184202
sender_user=types.User._parse(client, users.get(utils.get_raw_peer_id(message.peer_id))),
185203
message_id=message.id,

0 commit comments

Comments
 (0)