Skip to content

Commit

Permalink
Pyrofork: Stories: Disable allowed_chats privacy for now
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <[email protected]>
  • Loading branch information
wulan17 committed Oct 5, 2023
1 parent 8036da6 commit da9c45a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 61 deletions.
16 changes: 6 additions & 10 deletions pyrogram/methods/users/edit_story.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ async def edit_story(
privacy: "enums.StoriesPrivacyRules" = None,
allowed_users: List[int] = None,
denied_users: List[int] = None,
allowed_chats: List[int] = None,
denied_chats: List[int] = None,
#allowed_chats: List[int] = None,
#denied_chats: List[int] = None,
animation: str = None,
photo: str = None,
video: str = None,
Expand Down Expand Up @@ -79,12 +79,6 @@ async def edit_story(
privacy (:obj:`~pyrogram.enums.StoriesPrivacyRules`, *optional*):
Story privacy.
allowed_chats (List of ``int``, *optional*):
List of chat_id which participant allowed to view the story.
denied_chats (List of ``int``, *optional*):
List of chat_id which participant denied to view the story.
allowed_users (List of ``int``, *optional*):
List of user_id whos allowed to view the story.
Expand Down Expand Up @@ -225,12 +219,14 @@ async def edit_story(
if caption:
text, entities = self._split(**await utils.parse_text_entities(self, caption, parse_mode, caption_entities))

'''
if allowed_chats and len(allowed_chats) > 0:
chats = [await self.resolve_peer(chat_id) for chat_id in allowed_chats]
chats = [int(str(chat_id)[3:]) if str(chat_id).startswith("-100") else chat_id for chat_id in allowed_chats]
privacy_rules.append(raw.types.InputPrivacyValueAllowChatParticipants(chats=chats))
if denied_chats and len(denied_chats) > 0:
chats = [await self.resolve_peer(chat_id) for chat_id in denied_chats]
chats = [int(str(chat_id)[3:]) if str(chat_id).startswith("-100") else chat_id for chat_id in denied_chats]
privacy_rules.append(raw.types.InputPrivacyValueDisallowChatParticipants(chats=chats))
'''
if allowed_users and len(allowed_users) > 0:
users = [await self.resolve_peer(user_id) for user_id in allowed_users]
privacy_rules.append(raw.types.InputPrivacyValueAllowUsers(users=users))
Expand Down
12 changes: 4 additions & 8 deletions pyrogram/methods/users/send_story.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ async def send_story(
privacy: "enums.StoriesPrivacyRules" = None,
allowed_users: List[int] = None,
denied_users: List[int] = None,
allowed_chats: List[int] = None,
denied_chats: List[int] = None,
#allowed_chats: List[int] = None,
#denied_chats: List[int] = None,
animation: str = None,
photo: str = None,
video: str = None,
Expand Down Expand Up @@ -81,12 +81,6 @@ async def send_story(
Story privacy.
Defaults to :obj:`~pyrogram.enums.StoriesPrivacyRules.PUBLIC`
allowed_chats (List of ``int``, *optional*):
List of chat_id which participant allowed to view the story.
denied_chats (List of ``int``, *optional*):
List of chat_id which participant denied to view the story.
allowed_users (List of ``int``, *optional*):
List of user_id whos allowed to view the story.
Expand Down Expand Up @@ -237,12 +231,14 @@ async def send_story(

text, entities = self._split(**await utils.parse_text_entities(self, caption, parse_mode, caption_entities))

'''
if allowed_chats and len(allowed_chats) > 0:
chats = [await self.resolve_peer(chat_id) for chat_id in allowed_chats]
privacy_rules.append(raw.types.InputPrivacyValueAllowChatParticipants(chats=chats))
if denied_chats and len(denied_chats) > 0:
chats = [await self.resolve_peer(chat_id) for chat_id in denied_chats]
privacy_rules.append(raw.types.InputPrivacyValueDisallowChatParticipants(chats=chats))
'''
if allowed_users and len(allowed_users) > 0:
users = [await self.resolve_peer(user_id) for user_id in allowed_users]
privacy_rules.append(raw.types.InputPrivacyValueAllowUsers(users=users))
Expand Down
69 changes: 26 additions & 43 deletions pyrogram/types/messages_and_media/story.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,14 @@ class Story(Object, Update):
privacy (:obj:`~pyrogram.enums.StoryPrivacy`, *optional*):
Story privacy.
allowed_chats (List of ``int``, *optional*):
List of chat_id which participant allowed to view the story.
denied_chats (List of ``int``, *optional*):
List of chat_id which participant denied to view the story.
allowed_users (List of ``int``, *optional*):
List of user_id whos allowed to view the story.
denied_users (List of ``int``, *optional*):
List of user_id whos denied to view the story.
"""

# TODO: Add Media Areas
# TODO: Add Media Areas, fix Allowed Chats

def __init__(
self,
Expand Down Expand Up @@ -131,8 +125,8 @@ def __init__(
privacy: "enums.StoryPrivacy" = None,
allowed_users: List[int] = None,
denied_users: List[int] = None,
allowed_chats: List[int] = None,
denied_chats: List[int] = None
#allowed_chats: List[int] = None,
#denied_chats: List[int] = None
):
super().__init__(client)

Expand All @@ -158,8 +152,8 @@ def __init__(
self.privay = privacy
self.allowed_users = allowed_users
self.denied_users = denied_users
self.allowed_chats = allowed_chats
self.denied_chats = denied_chats
#self.allowed_chats = allowed_chats
#self.denied_chats = denied_chats

@staticmethod
async def _parse(
Expand All @@ -179,9 +173,9 @@ async def _parse(
from_user = None
sender_chat = None
privacy = None
allowed_chats = None
#allowed_chats = None
allowed_users = None
denied_chats = None
#denied_chats = None
denied_users = None
if stories.media:
if isinstance(stories.media, raw.types.MessageMediaPhoto):
Expand Down Expand Up @@ -223,14 +217,15 @@ async def _parse(
privacy = enums.StoryPrivacy.PRIVATE
elif isinstance(priv, raw.types.PrivacyValueDisallowContacts):
privacy = enums.StoryPrivacy.NO_CONTACTS
if isinstance(priv, raw.types.PrivacyValueAllowChatParticipants):
allowed_chats = []
for chat in priv.chats:
allowed_chats.append(f"-100{chat}")
if isinstance(priv, raw.types.PrivacyValueDisallowChatParticipants):
denied_chats = []
for chat in priv.chats:
denied_chats.append(f"-100{chat}")

'''
if allowed_chats and len(allowed_chats) > 0:
chats = [int(str(chat_id)[3:]) if str(chat_id).startswith("-100") else chat_id for chat_id in allowed_chats]
privacy_rules.append(raw.types.InputPrivacyValueAllowChatParticipants(chats=chats))
if denied_chats and len(denied_chats) > 0:
chats = [int(str(chat_id)[3:]) if str(chat_id).startswith("-100") else chat_id for chat_id in denied_chats]
privacy_rules.append(raw.types.InputPrivacyValueDisallowChatParticipants(chats=chats))
'''
if isinstance(priv, raw.types.PrivacyValueAllowUsers):
allowed_users = priv.users
if isinstance(priv, raw.types.PrivacyValueDisallowUsers):
Expand All @@ -257,8 +252,8 @@ async def _parse(
caption_entities=entities or None,
views=types.StoryViews._parse(stories.views),
privacy=privacy,
allowed_chats=allowed_chats,
denied_chats=denied_chats,
#allowed_chats=allowed_chats,
#denied_chats=denied_chats,
allowed_users=allowed_users,
denied_users=denied_users,
client=client
Expand Down Expand Up @@ -1426,8 +1421,8 @@ async def edit(
privacy: "enums.StoriesPrivacyRules" = None,
allowed_users: List[int] = None,
denied_users: List[int] = None,
allowed_chats: List[int] = None,
denied_chats: List[int] = None,
#allowed_chats: List[int] = None,
#denied_chats: List[int] = None,
animation: str = None,
photo: str = None,
video: str = None,
Expand Down Expand Up @@ -1480,12 +1475,6 @@ async def edit(
privacy (:obj:`~pyrogram.enums.StoriesPrivacyRules`, *optional*):
Story privacy.
allowed_chats (List of ``int``, *optional*):
List of chat_id which participant allowed to view the story.
denied_chats (List of ``int``, *optional*):
List of chat_id which participant denied to view the story.
allowed_users (List of ``int``, *optional*):
List of user_id whos allowed to view the story.
Expand All @@ -1512,8 +1501,8 @@ async def edit(
channel_id=self.sender_chat.id if self.sender_chat else None,
story_id=self.id,
privacy=privacy,
allowed_chats=allowed_chats,
denied_chats=denied_chats,
#allowed_chats=allowed_chats,
#denied_chats=denied_chats,
allowed_users=allowed_users,
denied_users=denied_users,
animation=animation,
Expand Down Expand Up @@ -1610,8 +1599,8 @@ async def edit_privacy(
privacy: "enums.StoriesPrivacyRules" = None,
allowed_users: List[int] = None,
denied_users: List[int] = None,
allowed_chats: List[int] = None,
denied_chats: List[int] = None
#allowed_chats: List[int] = None,
#denied_chats: List[int] = None
) -> "types.Story":
"""Bound method *edit_privacy* of :obj:`~pyrogram.types.Story`.
Expand All @@ -1633,12 +1622,6 @@ async def edit_privacy(
privacy (:obj:`~pyrogram.enums.StoriesPrivacyRules`, *optional*):
Story privacy.
allowed_chats (List of ``int``, *optional*):
List of chat_id which participant allowed to view the story.
denied_chats (List of ``int``, *optional*):
List of chat_id which participant denied to view the story.
allowed_users (List of ``int``, *optional*):
List of user_id whos allowed to view the story.
Expand All @@ -1655,8 +1638,8 @@ async def edit_privacy(
channel_id=self.sender_chat.id if self.sender_chat else None,
story_id=self.id,
privacy=privacy,
allowed_chats=allowed_chats,
denied_chats=denied_chats,
#allowed_chats=allowed_chats,
#denied_chats=denied_chats,
allowed_users=allowed_users,
denied_users=denied_users
)
Expand Down

0 comments on commit da9c45a

Please sign in to comment.