@ -5,12 +5,13 @@ from typing import TYPE_CHECKING
from mipac . abstract . action import AbstractAction
from mipac . abstract . action import AbstractAction
from mipac . http import Route
from mipac . http import Route
from mipac . models . follow import FollowRequest
from mipac . models . follow import FollowRequest
from mipac . models . user import UserDetailed
from mipac . models . user import UserDetailed , LiteUser
from mipac . types . follow import IFollowRequest
from mipac . types . follow import IFollowRequest
if TYPE_CHECKING :
if TYPE_CHECKING :
from mipac . http import HTTPClient
from mipac . http import HTTPClient
from mipac . manager . client import ClientActions
from mipac . manager . client import ClientActions
from mipac . types . user import ILiteUser
class FollowActions ( AbstractAction ) :
class FollowActions ( AbstractAction ) :
@ -25,52 +26,62 @@ class FollowActions(AbstractAction):
self . __session = session
self . __session = session
self . __client = client
self . __client = client
async def add ( self , user_id : str | None = None ) - > tuple [ bool , str | None ] :
async def add ( self , user_id : str | None = None ) - > LiteUser :
"""
"""
ユーザーをフォローします
Follow a user
Returns
Returns
- - - - - - -
- - - - - - -
bool
UserLite :
成功ならTrue , 失敗ならFalse
The user that you followed
str
実行に失敗した際のエラーコード
"""
"""
user_id = user_id or self . __user_id
user_id = user_id or self . __user_id
data = { ' userId ' : user_id }
data = { ' userId ' : user_id }
res = await self . __session . request (
res : ILiteUser = await self . __session . request (
Route ( ' POST ' , ' /api/following/create ' ) ,
Route ( ' POST ' , ' /api/following/create ' ) ,
json = data ,
json = data ,
auth = True ,
auth = True ,
lower = True ,
lower = True ,
)
)
if res . get ( ' error ' ) :
return LiteUser ( res , client = self . __client )
code = res [ ' error ' ] [ ' code ' ]
status = False
async def remove ( self , user_id : str | None = None ) - > LiteUser :
else :
code = None
status = True
return status , code
async def remove ( self , user_id : str | None = None ) - > bool :
"""
"""
ユーザーのフォローを解除します
Unfollow a user
Returns
Returns
- - - - - - -
- - - - - - -
bool
LiteUser
成功ならTrue, 失敗ならFalse
The user that you unfollowed
"""
"""
user_id = user_id or self . __user_id
user_id = user_id or self . __user_id
data = { ' userId ' : user_id }
data = { ' userId ' : user_id }
res : bool = await self . __session . request (
res = await self . __session . request (
Route ( ' POST ' , ' /api/following/delete ' ) , json = data , auth = True
Route ( ' POST ' , ' /api/following/delete ' ) , json = data , auth = True
)
)
return res
return LiteUser ( res , client = self . __client )
async def invalidate ( self , user_id : str | None = None ) - > LiteUser :
"""
Make the user unfollows you
Returns
- - - - - - -
LiteUser
The user that followed you
"""
user_id = user_id or self . __user_id
data = { ' userId ' : user_id }
res : ILiteUser = await self . __session . request (
Route ( ' POST ' , ' /api/following/invalidate ' ) , json = data , auth = True
)
return LiteUser ( res , client = self . __client )
class FollowRequestActions ( AbstractAction ) :
class FollowRequestActions ( AbstractAction ) :
@ -87,7 +98,12 @@ class FollowRequestActions(AbstractAction):
async def get_all ( self ) - > list [ FollowRequest ] :
async def get_all ( self ) - > list [ FollowRequest ] :
"""
"""
未承認のフォローリクエストを取得します
Get all follow requests
Returns
- - - - - - -
list [ FollowRequest ]
List of follow requests
"""
"""
res : list [ IFollowRequest ] = await self . __session . request (
res : list [ IFollowRequest ] = await self . __session . request (
@ -99,27 +115,45 @@ class FollowRequestActions(AbstractAction):
FollowRequest ( follow_request = i , client = self . __client ) for i in res
FollowRequest ( follow_request = i , client = self . __client ) for i in res
]
]
async def get_user ( self , user_id : str | None = None ) - > UserDetailed :
async def accept ( self , user_id : str | None = None ) - > bool :
"""
"""
フォローリクエスト元のユーザーを取得します
Accept a follow request
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
user_id : str | None , default = None
user_id : str
ユーザーID
The user ID to accept
Returns
Returns
- - - - - - -
- - - - - - -
UserDetailed
bool
フォローリクエスト元のユーザー
Whether the request was accepted
"""
"""
user_id = user_id or self . __user_id
user_id = user_id or self . __user_id
return await self . __client . user . action . get ( user_id )
data = { ' userId ' : user_id }
return bool (
await self . __session . request (
Route ( ' POST ' , ' /api/following/requests/accept ' ) ,
json = data ,
auth = True ,
)
)
async def accept ( self , user_id : str | None = None ) - > bool :
async def rejec t( self , user_id : str | None = None ) - > bool :
"""
"""
与えられたIDのユーザーのフォローリクエストを承認します
Reject a follow request
Parameters
- - - - - - - - - -
user_id : str
The user ID to reject
Returns
- - - - - - -
bool
Whether the request was rejected
"""
"""
user_id = user_id or self . __user_id
user_id = user_id or self . __user_id
@ -127,24 +161,34 @@ class FollowRequestActions(AbstractAction):
data = { ' userId ' : user_id }
data = { ' userId ' : user_id }
return bool (
return bool (
await self . __session . request (
await self . __session . request (
Route ( ' POST ' , ' /api/following/requests/ accep t' ) ,
Route ( ' POST ' , ' /api/following/requests/ rejec t' ) ,
json = data ,
json = data ,
auth = True ,
auth = True ,
)
)
)
)
async def reject( self , user_id : str | None ) - > bool :
async def cancel( self , user_id : str | None = None ) - > LiteUser :
"""
"""
与えられたIDのユーザーのフォローリクエストを拒否します
Cancel a follow request
Parameters
- - - - - - - - - -
user_id : str
The user ID to cancel
Returns
- - - - - - -
LiteUser
The user that you canceled to follow
"""
"""
user_id = user_id or self . __user_id
user_id = user_id or self . __user_id
data = { ' userId ' : user_id }
data = { ' userId ' : user_id }
return bool (
res : ILiteUser = await self . __session . request (
await self . __session . request (
Route ( ' POST ' , ' /api/following/requests/cancel ' ) ,
Route ( ' POST ' , ' /api/following/requests/reject ' ) ,
json = data ,
json = data ,
auth = True ,
auth = True ,
lower = True ,
)
)
)
return LiteUser ( res , client = self . __client )