Skip to content

Commit

Permalink
chore: FollowActions.add メソッドを非推奨に、代わりにcreateメソッドを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Feb 21, 2024
1 parent dc00a0e commit 69c89a7
Showing 1 changed file with 21 additions and 37 deletions.
58 changes: 21 additions & 37 deletions mipac/actions/follow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from mipac.models.follow import FollowRequest
from mipac.models.user import PartialUser
from mipac.types.follow import IFollowRequest
from mipac.utils.format import remove_dict_missing
from mipac.utils.util import MISSING, deprecated

if TYPE_CHECKING:
from mipac.manager.client import ClientManager
Expand All @@ -18,23 +20,28 @@ def __init__(self, *, session: HTTPClient, client: ClientManager):
self._session = session
self._client = client

async def create(self, with_replies: bool = MISSING, *, user_id: str) -> PartialUser:
data = remove_dict_missing({"userId": user_id, "withReplies": with_replies})

res: IPartialUser = await self._session.request(
Route("POST", "/api/following/create"),
json=data,
)
return PartialUser(res, client=self._client)

@deprecated
async def add(self, *, user_id: str) -> PartialUser:
"""
Follow a user
"""対象のユーザーをフォローします
.. deprecated:: 0.6.1
Use :meth:`mipac.actions.follow.SharedFollowActions.create` instead.
Returns
-------
UserLite:
The user that you followed
"""
data = {"userId": user_id}
res: IPartialUser = await self._session.request(
Route("POST", "/api/following/create"),
json=data,
auth=True,
lower=True,
)
return PartialUser(res, client=self._client)
return await self.create(user_id=user_id)

async def remove(self, *, user_id: str) -> PartialUser:
"""
Expand Down Expand Up @@ -73,46 +80,23 @@ def __init__(self, user_id: str, *, session: HTTPClient, client: ClientManager):
self.__user_id: str = user_id

@override
async def add(self, *, user_id: str | None = None) -> PartialUser:
"""
Follow a user
Returns
-------
UserLite:
The user that you followed
"""
async def create(self, with_replies: bool = MISSING, *, user_id: str) -> PartialUser:
return await super().create(with_replies, user_id=user_id)

@override
async def add(self, *, user_id: str | None = None) -> PartialUser:
user_id = user_id or self.__user_id

return await super().add(user_id=user_id)

@override
async def remove(self, *, user_id: str | None = None) -> PartialUser:
"""
Unfollow a user
Returns
-------
PartialUser
The user that you unfollowed
"""

user_id = user_id or self.__user_id

return await super().remove(user_id=user_id)

@override
async def invalidate(self, *, user_id: str | None = None) -> PartialUser:
"""
Make the user unfollows you
Returns
-------
PartialUser
The user that followed you
"""

user_id = user_id or self.__user_id

return await super().invalidate(user_id=user_id)
Expand Down

0 comments on commit 69c89a7

Please sign in to comment.