feat: reactionのactionsとmanagerをclientで分けた

pull/125/head
yupix 9 months ago
parent d55f88c0a3
commit 36026a7079
No known key found for this signature in database
GPG Key ID: 2FF705F5C56D9C06

@ -1,6 +1,6 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING, override
from mipac.abstract.action import AbstractAction from mipac.abstract.action import AbstractAction
from mipac.http import HTTPClient, Route from mipac.http import HTTPClient, Route
@ -15,13 +15,13 @@ if TYPE_CHECKING:
from mipac.manager.client import ClientManager from mipac.manager.client import ClientManager
class ReactionActions(AbstractAction): class ClientReactionActions(AbstractAction):
def __init__(self, note_id: str | None = None, *, session: HTTPClient, client: ClientManager): def __init__(self, note_id: str | None = None, *, session: HTTPClient, client: ClientManager):
self.__note_id: str | None = note_id self.__note_id: str | None = note_id
self.__session: HTTPClient = session self.__session: HTTPClient = session
self.__client: ClientManager = client self.__client: ClientManager = client
async def add(self, reaction: str, note_id: str | None = None) -> bool: async def add(self, reaction: str, *, note_id: str | None = None) -> bool:
"""Add reaction to note """Add reaction to note
Endpoint: `/api/notes/reactions/create` Endpoint: `/api/notes/reactions/create`
@ -46,7 +46,7 @@ class ReactionActions(AbstractAction):
res: bool = await self.__session.request(route, json=data, auth=True, lower=True) res: bool = await self.__session.request(route, json=data, auth=True, lower=True)
return bool(res) return bool(res)
async def remove(self, note_id: str | None = None) -> bool: async def remove(self, *, note_id: str | None = None) -> bool:
"""Remove reaction from note """Remove reaction from note
Endpoint: `/api/notes/reactions/delete` Endpoint: `/api/notes/reactions/delete`
@ -71,12 +71,12 @@ class ReactionActions(AbstractAction):
@cache(group="get_note_reaction") @cache(group="get_note_reaction")
async def get_reactions( async def get_reactions(
self, self,
note_id: str | None = None, type: str | None = None,
reaction: str | None = None,
*,
limit: int = 10, limit: int = 10,
since_id: str | None = None, since_id: str | None = None,
until_id: str | None = None, until_id: str | None = None,
*,
note_id: str | None = None,
) -> list[NoteReaction]: ) -> list[NoteReaction]:
note_id = note_id or self.__note_id note_id = note_id or self.__note_id
@ -87,7 +87,7 @@ class ReactionActions(AbstractAction):
{ {
"noteId": note_id, "noteId": note_id,
"limit": limit, "limit": limit,
"type": reaction, "type": type,
"sinceId": since_id, "sinceId": since_id,
"untilId": until_id, "untilId": until_id,
} }
@ -103,15 +103,54 @@ class ReactionActions(AbstractAction):
@cache(group="get_note_reaction", override=True) @cache(group="get_note_reaction", override=True)
async def fetch_reactions( async def fetch_reactions(
self, self,
reaction: str | None = None, type: str | None = None,
note_id: str | None = None,
*,
limit: int = 10, limit: int = 10,
since_id: str | None = None, since_id: str | None = None,
until_id: str | None = None, until_id: str | None = None,
*,
note_id: str | None = None,
) -> list[NoteReaction]: ) -> list[NoteReaction]:
return await self.get_reactions( return await self.get_reactions(
reaction, note_id, limit=limit, since_id=since_id, until_id=until_id type=type, note_id=note_id, limit=limit, since_id=since_id, until_id=until_id
)
class ReactionActions(ClientReactionActions):
def __init__(self, *, session: HTTPClient, client: ClientManager):
super().__init__(session=session, client=client)
@override
async def add(self, note_id: str, reaction: str):
return await super().add(reaction=reaction, note_id=note_id)
@override
async def remove(self, note_id: str):
return await super().remove(note_id=note_id)
@override
async def get_reactions(
self,
note_id: str,
type: str | None = None,
limit: int = 10,
since_id: str | None = None,
until_id: str | None = None,
):
return await super().get_reactions(
type=type, limit=limit, since_id=since_id, until_id=until_id, note_id=note_id
)
@override
async def fetch_reactions(
self,
note_id: str,
type: str | None = None,
limit: int = 10,
since_id: str | None = None,
until_id: str | None = None,
):
return await super().fetch_reactions(
type=type, limit=limit, since_id=since_id, until_id=until_id, note_id=note_id
) )
async def get_emoji_list(self) -> list[CustomEmoji]: async def get_emoji_list(self) -> list[CustomEmoji]:

@ -7,7 +7,7 @@ from mipac.actions.note import ClientNoteActions, NoteActions
from mipac.http import HTTPClient from mipac.http import HTTPClient
from mipac.manager.favorite import ClientFavoriteManager, FavoriteManager from mipac.manager.favorite import ClientFavoriteManager, FavoriteManager
from mipac.manager.poll import ClientPollManager, PollManager from mipac.manager.poll import ClientPollManager, PollManager
from mipac.manager.reaction import ReactionManager from mipac.manager.reaction import ClientReactionManager, ReactionManager
if TYPE_CHECKING: if TYPE_CHECKING:
from mipac.manager.client import ClientManager from mipac.manager.client import ClientManager
@ -18,7 +18,7 @@ class ClientNoteManager(AbstractManager):
self.__note_id = note_id self.__note_id = note_id
self.__session: HTTPClient = session self.__session: HTTPClient = session
self.__client: ClientManager = client self.__client: ClientManager = client
self.reaction: ReactionManager = ReactionManager( self.reaction: ClientReactionManager = ClientReactionManager(
note_id=note_id, session=session, client=client note_id=note_id, session=session, client=client
) )
self.favorite = ClientFavoriteManager(note_id=note_id, session=session, client=client) self.favorite = ClientFavoriteManager(note_id=note_id, session=session, client=client)
@ -42,9 +42,7 @@ class NoteManager(AbstractManager):
self.__note_id: str | None = note_id self.__note_id: str | None = note_id
self.__session: HTTPClient = session self.__session: HTTPClient = session
self.__client: ClientManager = client self.__client: ClientManager = client
self.reaction: ReactionManager = ReactionManager( self.reaction: ReactionManager = ReactionManager(session=session, client=client)
note_id=note_id, session=session, client=client
)
self.favorite = FavoriteManager(note_id=note_id, session=session, client=client) self.favorite = FavoriteManager(note_id=note_id, session=session, client=client)
self.poll: PollManager = PollManager(note_id=note_id, session=session, client=client) self.poll: PollManager = PollManager(note_id=note_id, session=session, client=client)
self.__action: NoteActions = NoteActions( self.__action: NoteActions = NoteActions(

@ -3,20 +3,41 @@ from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from mipac.abstract.manager import AbstractManager from mipac.abstract.manager import AbstractManager
from mipac.actions.reaction import ReactionActions from mipac.actions.reaction import ClientReactionActions, ReactionActions
from mipac.http import HTTPClient from mipac.http import HTTPClient
if TYPE_CHECKING: if TYPE_CHECKING:
from mipac.client import ClientManager from mipac.client import ClientManager
class ClientReactionManager(AbstractManager):
def __init__(self, note_id: str | None = None, *, session: HTTPClient, client: ClientManager):
self.__note_id: str | None = note_id
self.__session: HTTPClient = session
self.__client: ClientManager = client
self.__action = ClientReactionActions(
session=self.__session,
client=self.__client,
)
@property
def action(self) -> ClientReactionActions:
"""リアクションに関するアクション
Returns
-------
ClientReactionActions
Reactionに対するアクションを行うクラス
"""
return self.__action
class ReactionManager(AbstractManager): class ReactionManager(AbstractManager):
def __init__(self, note_id: str | None = None, *, session: HTTPClient, client: ClientManager): def __init__(self, note_id: str | None = None, *, session: HTTPClient, client: ClientManager):
self.__note_id: str | None = note_id self.__note_id: str | None = note_id
self.__session: HTTPClient = session self.__session: HTTPClient = session
self.__client: ClientManager = client self.__client: ClientManager = client
self.__action = ReactionActions( self.__action = ReactionActions(
note_id=self.__note_id,
session=self.__session, session=self.__session,
client=self.__client, client=self.__client,
) )

Loading…
Cancel
Save