Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ def get_title_list(s: str) -> list:
VideoChatScheduled
VideoChatStarted
RtmpUrl
ChatBackground
""",
)

Expand Down
2 changes: 2 additions & 0 deletions pyrogram/types/user_and_chats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from .video_chat_scheduled import VideoChatScheduled
from .video_chat_started import VideoChatStarted
from .rtmp_url import RtmpUrl
from .chat_background import ChatBackground

__all__ = [
"Birthdate",
Expand Down Expand Up @@ -76,4 +77,5 @@
"VideoChatScheduled",
"VideoChatStarted",
"RtmpUrl",
"ChatBackground"
]
9 changes: 9 additions & 0 deletions pyrogram/types/user_and_chats/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class Chat(Object):
emoji_status (:obj:`~pyrogram.types.EmojiStatus`, *optional*):
Emoji status.

background (:obj:`~pyrogram.types.ChatBackground`, *optional*):
A chat background.

bio (``str``, *optional*):
Bio of the other party in a private chat.
Returned only in :meth:`~pyrogram.Client.get_chat`.
Expand Down Expand Up @@ -254,6 +257,7 @@ def __init__(
accent_color: "types.ChatColor" = None,
profile_color: "types.ChatColor" = None,
emoji_status: "types.EmojiStatus" = None,
background: "types.ChatBackground" = None,
has_visible_history: bool = None,
has_hidden_members: bool = None,
has_aggressive_anti_spam_enabled: bool = None,
Expand Down Expand Up @@ -308,6 +312,7 @@ def __init__(
self.accent_color = accent_color
self.profile_color = profile_color
self.emoji_status = emoji_status
self.background = background
self.has_visible_history = has_visible_history
self.has_hidden_members = has_hidden_members
self.has_aggressive_anti_spam_enabled = has_aggressive_anti_spam_enabled
Expand All @@ -326,6 +331,7 @@ def __init__(
self.business_location = business_location
self.business_opening_hours = business_opening_hours
self.active_usernames = active_usernames
self.max_reaction_count = max_reaction_count
self._raw = _raw

@staticmethod
Expand Down Expand Up @@ -609,6 +615,9 @@ async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw.
if isinstance(full_chat.exported_invite, raw.types.ChatInviteExported):
parsed_chat.invite_link = full_chat.exported_invite.link

if hasattr(full_chat, "wallpaper") and getattr(full_chat, "wallpaper"):
parsed_chat.background = types.ChatBackground._parse(client, full_chat.wallpaper)

parsed_chat.available_reactions = types.ChatReactions._parse(
client,
full_chat.available_reactions,
Expand Down
113 changes: 113 additions & 0 deletions pyrogram/types/user_and_chats/chat_background.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from datetime import datetime
from typing import List

import pyrogram
from pyrogram import raw, utils
from pyrogram import types
from pyrogram.file_id import (
FileId,
FileType,
FileUniqueId,
FileUniqueType,
ThumbnailSource,
)
from ..object import Object


class ChatBackground(Object):
"""Describes a background set for a specific chat.

Parameters:
file_id (``str``):
Identifier for this file, which can be used to download the file.

file_unique_id (``str``):
Unique identifier for this file, which is supposed to be the same over time and for different accounts.
Can't be used to download or reuse the file.

file_size (``int``):
File size.

date (:py:obj:`~datetime.datetime`):
Date the background was setted.

slug (``str``):
Identifier of the background code.
You can combine it with `https://t.me/bg/{slug}`
to get link for this background.

thumbs (List of :obj:`~pyrogram.types.Thumbnail`, *optional*):
Available thumbnails of this background.

link (``str``, *property*):
Generate a link to this background code.
"""

def __init__(
self,
*,
client: "pyrogram.Client" = None,
file_id: str,
file_unique_id: str,
file_size: int,
date: datetime,
slug: str,
thumbs: List["types.Thumbnail"] = None,
):
super().__init__(client)

self.file_id = file_id
self.file_unique_id = file_unique_id
self.file_size = file_size
self.date = date
self.slug = slug
self.thumbs = thumbs

@property
def link(self) -> str:
return f"https://t.me/bg/{self.slug}"

@staticmethod
def _parse(
client,
wallpaper: "raw.types.Wallpaper",
) -> "ChatBackground":
return ChatBackground(
file_id=FileId(
dc_id=wallpaper.document.dc_id,
file_reference=wallpaper.document.file_reference,
access_hash=wallpaper.document.access_hash,
file_type=FileType.BACKGROUND,
media_id=wallpaper.document.id,
volume_id=0,
local_id=0,
thumbnail_source=ThumbnailSource.THUMBNAIL,
thumbnail_file_type=FileType.BACKGROUND,
).encode(),
file_unique_id=FileUniqueId(
file_unique_type=FileUniqueType.DOCUMENT, media_id=wallpaper.document.id
).encode(),
file_size=wallpaper.document.size,
slug=wallpaper.slug,
date=utils.timestamp_to_datetime(wallpaper.document.date),
thumbs=types.Thumbnail._parse(client, wallpaper.document),
client=client,
)