Skip to content

Commit

Permalink
feat: now vkontakte images returned are largest accessible; bumped ve…
Browse files Browse the repository at this point in the history
…rsion
  • Loading branch information
michaelkryukov committed May 24, 2021
1 parent d8103c4 commit 583b4f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
> Changes to public API are marked as `^`. Possible changes
> to public API are marked as `^?`.
- v5.0.5
- ^(VKontakte) Attachments with type `image` now returns largest image.
- Added support for expect_sender for telegram 'callback_query'.

- v5.0.4
- Fixed issue with incorrect merge of multiple `PayloadRouter`.
- Renamed `alike` method to `can_merge` in routers.
Expand Down
9 changes: 8 additions & 1 deletion kutana/backends/vkontakte/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,16 @@ def _make_attachment(self, raw_attachment):
id = None

if t == "photo":
def get_largest_image(sizes):
def key(size):
width = size.get("width") or 0
height = size.get("height") or 0
return width * height
return sorted(sizes, key=key)[-1]["url"]

return Attachment._existing_full(
id=id, type="image", title=d["text"], file_name=id,
getter=self._make_getter(d["sizes"][-1]["url"]), raw=d,
getter=self._make_getter(get_largest_image(d["sizes"])), raw=d,
)

elif t == "doc":
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import setuptools


VERSION = "5.0.4"
VERSION = "5.0.5"


with open("README.md", "r") as fh:
Expand Down

0 comments on commit 583b4f7

Please sign in to comment.