feat: update privacy data
This commit is contained in:
@@ -8,7 +8,7 @@ from time import sleep
|
|||||||
from requests.exceptions import ConnectionError, HTTPError
|
from requests.exceptions import ConnectionError, HTTPError
|
||||||
from sseclient import SSEClient
|
from sseclient import SSEClient
|
||||||
|
|
||||||
from itd.routes.users import get_user, update_profile, follow, unfollow, get_followers, get_following, update_privacy
|
from itd.routes.users import get_user, update_profile, follow, unfollow, get_followers, get_following, update_privacy, update_privacy_new
|
||||||
from itd.routes.etc import get_top_clans, get_who_to_follow, get_platform_status
|
from itd.routes.etc import get_top_clans, get_who_to_follow, get_platform_status
|
||||||
from itd.routes.comments import get_comments, add_comment, delete_comment, like_comment, unlike_comment, add_reply_comment, get_replies
|
from itd.routes.comments import get_comments, add_comment, delete_comment, like_comment, unlike_comment, add_reply_comment, get_replies
|
||||||
from itd.routes.hashtags import get_hashtags, get_posts_by_hashtag
|
from itd.routes.hashtags import get_hashtags, get_posts_by_hashtag
|
||||||
@@ -26,7 +26,7 @@ from itd.models.notification import Notification
|
|||||||
from itd.models.post import Post, NewPost, PollData, Poll
|
from itd.models.post import Post, NewPost, PollData, Poll
|
||||||
from itd.models.clan import Clan
|
from itd.models.clan import Clan
|
||||||
from itd.models.hashtag import Hashtag
|
from itd.models.hashtag import Hashtag
|
||||||
from itd.models.user import User, UserProfileUpdate, UserPrivacy, UserFollower, UserWhoToFollow
|
from itd.models.user import User, UserProfileUpdate, UserPrivacy, UserFollower, UserWhoToFollow, UserPrivacyData
|
||||||
from itd.models.pagination import Pagination, PostsPagintaion, LikedPostsPagintaion
|
from itd.models.pagination import Pagination, PostsPagintaion, LikedPostsPagintaion
|
||||||
from itd.models.verification import Verification, VerificationStatus
|
from itd.models.verification import Verification, VerificationStatus
|
||||||
from itd.models.report import NewReport
|
from itd.models.report import NewReport
|
||||||
@@ -194,7 +194,7 @@ class Client:
|
|||||||
|
|
||||||
@refresh_on_error
|
@refresh_on_error
|
||||||
def update_privacy(self, wall_closed: bool = False, private: bool = False) -> UserPrivacy:
|
def update_privacy(self, wall_closed: bool = False, private: bool = False) -> UserPrivacy:
|
||||||
"""Обновить настройки приватности
|
"""(УСТАРЕЛО! Используйте update_privacy_new) настройки приватности
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
wall_closed (bool, optional): Закрыть стену. Defaults to False.
|
wall_closed (bool, optional): Закрыть стену. Defaults to False.
|
||||||
@@ -208,6 +208,21 @@ class Client:
|
|||||||
|
|
||||||
return UserPrivacy.model_validate(res.json())
|
return UserPrivacy.model_validate(res.json())
|
||||||
|
|
||||||
|
@refresh_on_error
|
||||||
|
def update_privacy_new(self, privacy: UserPrivacyData) -> UserPrivacy:
|
||||||
|
"""Обновить настройки приватности
|
||||||
|
|
||||||
|
Args:
|
||||||
|
privacy (UserPrivacyData): Данные приватности
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
UserPrivacy: Обновленные данные приватности
|
||||||
|
"""
|
||||||
|
res = update_privacy_new(self.token, privacy)
|
||||||
|
res.raise_for_status()
|
||||||
|
|
||||||
|
return UserPrivacy.model_validate(res.json())
|
||||||
|
|
||||||
@refresh_on_error
|
@refresh_on_error
|
||||||
def follow(self, username: str) -> int:
|
def follow(self, username: str) -> int:
|
||||||
"""Подписаться на пользователя
|
"""Подписаться на пользователя
|
||||||
@@ -615,7 +630,6 @@ class Client:
|
|||||||
res = mark_all_as_read(self.token)
|
res = mark_all_as_read(self.token)
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
|
|
||||||
|
|
||||||
@refresh_on_error
|
@refresh_on_error
|
||||||
def get_unread_notifications_count(self) -> int:
|
def get_unread_notifications_count(self) -> int:
|
||||||
"""Получить количество непрочитанных уведомлений
|
"""Получить количество непрочитанных уведомлений
|
||||||
|
|||||||
@@ -33,3 +33,10 @@ class AttachType(Enum):
|
|||||||
class PostsTab(Enum):
|
class PostsTab(Enum):
|
||||||
FOLLOWING = 'following'
|
FOLLOWING = 'following'
|
||||||
POPULAR = 'popular'
|
POPULAR = 'popular'
|
||||||
|
|
||||||
|
class AccessType(Enum):
|
||||||
|
"""Типы разрешений для видимости лайков и записей на стене"""
|
||||||
|
NOBODY = 'nobody' # никто
|
||||||
|
MUTUAL = 'mutual' # взаимные
|
||||||
|
FOLLOWERS = 'followers' # подписчики
|
||||||
|
EVERYONE = 'everyone' # все
|
||||||
@@ -74,6 +74,7 @@ class _Post(_PostShort):
|
|||||||
is_reposted: bool = Field(False, alias='isReposted')
|
is_reposted: bool = Field(False, alias='isReposted')
|
||||||
is_viewed: bool = Field(False, alias='isViewed')
|
is_viewed: bool = Field(False, alias='isViewed')
|
||||||
is_owner: bool = Field(False, alias='isOwner')
|
is_owner: bool = Field(False, alias='isOwner')
|
||||||
|
is_pinned: bool = Field(False, alias='isPinned') # only for user wall
|
||||||
|
|
||||||
attachments: list[PostAttach] = []
|
attachments: list[PostAttach] = []
|
||||||
comments: list[Comment] = []
|
comments: list[Comment] = []
|
||||||
|
|||||||
@@ -4,13 +4,41 @@ from datetime import datetime
|
|||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from itd.models.pin import ShortPin
|
from itd.models.pin import ShortPin
|
||||||
|
from itd.enums import AccessType
|
||||||
|
|
||||||
|
|
||||||
class UserPrivacy(BaseModel):
|
class _UserPrivacy(BaseModel):
|
||||||
private: bool | None = Field(None, alias='isPrivate') # none for not me
|
private: bool | None = Field(None, alias='isPrivate') # none for not me
|
||||||
wall_closed: bool = Field(False, alias='wallClosed')
|
wall_closed: bool | None = Field(None, alias='wallClosed', deprecated=True)
|
||||||
|
wall_access: AccessType = Field(AccessType.EVERYONE, alias='wallAccess')
|
||||||
|
likes_visibility: AccessType = Field(AccessType.EVERYONE, alias='likesVisibility')
|
||||||
|
|
||||||
model_config = {'populate_by_name': True}
|
model_config = {'serialize_by_alias': True}
|
||||||
|
|
||||||
|
|
||||||
|
class UserPrivacy(_UserPrivacy):
|
||||||
|
show_last_seen: bool = Field(True, alias='showLastSeen')
|
||||||
|
|
||||||
|
|
||||||
|
class UserPrivacyData:
|
||||||
|
def __init__(self, private: bool | None = None, wall_access: AccessType | None = None, likes_visibility: AccessType | None = None, show_last_seen: bool | None = None) -> None:
|
||||||
|
self.private = private
|
||||||
|
self.wall_access = wall_access
|
||||||
|
self.likes_visibility = likes_visibility
|
||||||
|
self.show_last_seen = show_last_seen
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
data = {}
|
||||||
|
if self.private is not None:
|
||||||
|
data['isPrivate'] = self.private
|
||||||
|
if self.wall_access is not None:
|
||||||
|
data['wallAccess'] = self.wall_access.value
|
||||||
|
if self.likes_visibility is not None:
|
||||||
|
data['likesVisibility'] = self.likes_visibility.value
|
||||||
|
if self.show_last_seen is not None:
|
||||||
|
data['showLastSeen'] = self.show_last_seen
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
class UserProfileUpdate(BaseModel):
|
class UserProfileUpdate(BaseModel):
|
||||||
@@ -51,7 +79,7 @@ class UserSearch(UserFollower, UserWhoToFollow):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class User(UserSearch, UserPrivacy):
|
class User(UserSearch, _UserPrivacy):
|
||||||
banner: str | None = None
|
banner: str | None = None
|
||||||
bio: str | None = None
|
bio: str | None = None
|
||||||
pinned_post_id: UUID | None = Field(None, alias='pinnedPostId')
|
pinned_post_id: UUID | None = Field(None, alias='pinnedPostId')
|
||||||
@@ -62,3 +90,5 @@ class User(UserSearch, UserPrivacy):
|
|||||||
is_followed: bool | None = Field(None, alias='isFollowedBy') # none for me
|
is_followed: bool | None = Field(None, alias='isFollowedBy') # none for me
|
||||||
|
|
||||||
created_at: datetime = Field(alias='createdAt')
|
created_at: datetime = Field(alias='createdAt')
|
||||||
|
last_seen_at: datetime | None = Field(None, alias='lastSeen')
|
||||||
|
online: bool = False
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from itd.request import fetch
|
from itd.request import fetch
|
||||||
|
from itd.models.user import UserPrivacyData
|
||||||
|
|
||||||
|
|
||||||
def get_user(token: str, username: str):
|
def get_user(token: str, username: str):
|
||||||
@@ -26,6 +27,9 @@ def update_privacy(token: str, wall_closed: bool = False, private: bool = False)
|
|||||||
data['isPrivate'] = private
|
data['isPrivate'] = private
|
||||||
return fetch(token, 'put', 'users/me/privacy', data)
|
return fetch(token, 'put', 'users/me/privacy', data)
|
||||||
|
|
||||||
|
def update_privacy_new(token: str, privacy: UserPrivacyData):
|
||||||
|
return fetch(token, 'put', 'users/me/privacy', privacy.to_dict())
|
||||||
|
|
||||||
def follow(token: str, username: str):
|
def follow(token: str, username: str):
|
||||||
return fetch(token, 'post', f'users/{username}/follow')
|
return fetch(token, 'post', f'users/{username}/follow')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user