Skip to content

Commit 51f7714

Browse files
committed
Fix captions not being preserved when editing media
1 parent 15f95a0 commit 51f7714

7 files changed

Lines changed: 23 additions & 12 deletions

File tree

pyrogram/methods/messages/edit_message_media.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ async def edit_message_media(
8080
caption = media.caption
8181
parse_mode = media.parse_mode
8282

83+
message, entities = None, None
84+
85+
if caption is not None:
86+
message, entities = (await self.parser.parse(caption, parse_mode)).values()
87+
8388
if isinstance(media, types.InputMediaPhoto):
8489
if os.path.isfile(media.media):
8590
media = await self.send(
@@ -253,7 +258,8 @@ async def edit_message_media(
253258
id=message_id,
254259
media=media,
255260
reply_markup=reply_markup.write() if reply_markup else None,
256-
**await self.parser.parse(caption, parse_mode)
261+
message=message,
262+
entities=entities
257263
)
258264
)
259265

pyrogram/methods/messages/send_media_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ async def send_media_group(
265265
raw.types.InputSingleMedia(
266266
media=media,
267267
random_id=self.rnd_id(),
268-
**await self.parser.parse(i.caption, i.parse_mode)
268+
**await self.parser.parse(i.caption or "", i.parse_mode)
269269
)
270270
)
271271

pyrogram/types/input_media/input_media_animation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class InputMediaAnimation(InputMedia):
3838
Thumbnails can't be reused and can be only uploaded as a new file.
3939
4040
caption (``str``, *optional*):
41-
Caption of the animation to be sent, 0-1024 characters
41+
Caption of the animation to be sent, 0-1024 characters.
42+
If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
4243
4344
parse_mode (``str``, *optional*):
4445
By default, texts are parsed using both Markdown and HTML styles.
@@ -64,7 +65,7 @@ def __init__(
6465
self,
6566
media: str,
6667
thumb: str = None,
67-
caption: str = "",
68+
caption: str = None,
6869
parse_mode: Optional[str] = object,
6970
caption_entities: List[MessageEntity] = None,
7071
width: int = 0,

pyrogram/types/input_media/input_media_audio.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class InputMediaAudio(InputMedia):
4040
Thumbnails can't be reused and can be only uploaded as a new file.
4141
4242
caption (``str``, *optional*):
43-
Caption of the audio to be sent, 0-1024 characters
43+
Caption of the audio to be sent, 0-1024 characters.
44+
If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
4445
4546
parse_mode (``str``, *optional*):
4647
By default, texts are parsed using both Markdown and HTML styles.
@@ -66,7 +67,7 @@ def __init__(
6667
self,
6768
media: str,
6869
thumb: str = None,
69-
caption: str = "",
70+
caption: str = None,
7071
parse_mode: Optional[str] = object,
7172
caption_entities: List[MessageEntity] = None,
7273
duration: int = 0,

pyrogram/types/input_media/input_media_document.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class InputMediaDocument(InputMedia):
3838
Thumbnails can't be reused and can be only uploaded as a new file.
3939
4040
caption (``str``, *optional*):
41-
Caption of the document to be sent, 0-1024 characters
41+
Caption of the document to be sent, 0-1024 characters.
42+
If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
4243
4344
parse_mode (``str``, *optional*):
4445
By default, texts are parsed using both Markdown and HTML styles.
@@ -55,7 +56,7 @@ def __init__(
5556
self,
5657
media: str,
5758
thumb: str = None,
58-
caption: str = "",
59+
caption: str = None,
5960
parse_mode: Optional[str] = object,
6061
caption_entities: List[MessageEntity] = None
6162
):

pyrogram/types/input_media/input_media_photo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class InputMediaPhoto(InputMedia):
3434
Sending photo by a URL is currently unsupported.
3535
3636
caption (``str``, *optional*):
37-
Caption of the photo to be sent, 0-1024 characters
37+
Caption of the photo to be sent, 0-1024 characters.
38+
If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
3839
3940
parse_mode (``str``, *optional*):
4041
By default, texts are parsed using both Markdown and HTML styles.
@@ -50,7 +51,7 @@ class InputMediaPhoto(InputMedia):
5051
def __init__(
5152
self,
5253
media: str,
53-
caption: str = "",
54+
caption: str = None,
5455
parse_mode: Optional[str] = object,
5556
caption_entities: List[MessageEntity] = None
5657
):

pyrogram/types/input_media/input_media_video.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class InputMediaVideo(InputMedia):
4040
Thumbnails can't be reused and can be only uploaded as a new file.
4141
4242
caption (``str``, *optional*):
43-
Caption of the video to be sent, 0-1024 characters
43+
Caption of the video to be sent, 0-1024 characters.
44+
If not specified, the original caption is kept. Pass "" (empty string) to remove the caption.
4445
4546
parse_mode (``str``, *optional*):
4647
By default, texts are parsed using both Markdown and HTML styles.
@@ -69,7 +70,7 @@ def __init__(
6970
self,
7071
media: str,
7172
thumb: str = None,
72-
caption: str = "",
73+
caption: str = None,
7374
parse_mode: Optional[str] = object,
7475
caption_entities: List[MessageEntity] = None,
7576
width: int = 0,

0 commit comments

Comments
 (0)