diff --git a/mipac/actions/note.py b/mipac/actions/note.py index e825811a..7a8f55f1 100644 --- a/mipac/actions/note.py +++ b/mipac/actions/note.py @@ -104,17 +104,9 @@ async def get_children( *, note_id: str, ) -> list[Note]: - data = { - "noteId": note_id, - "limit": limit, - "sinceId": since_id, - "untilId": untilId, - } - - notes: list[INote] = await self._session.request( - Route("POST", "/api/notes/children"), json=data + return await self.fetch_children( + limit=limit, since_id=since_id, untilId=untilId, note_id=note_id ) - return [Note(note, self._client) for note in notes] @cache(group="get_note_children", override=True) async def fetch_children( @@ -146,9 +138,17 @@ async def fetch_children( list[Note] Children of the note """ - return await self.get_children( - limit=limit, since_id=since_id, untilId=untilId, note_id=note_id + data = { + "noteId": note_id, + "limit": limit, + "sinceId": since_id, + "untilId": untilId, + } + + notes: list[INote] = await self._session.request( + Route("POST", "/api/notes/children"), json=data ) + return [Note(note, self._client) for note in notes] async def get_all_children( self, @@ -417,11 +417,7 @@ async def get_state(self, *, note_id: str) -> NoteState: NoteState Note state """ - data = {"noteId": note_id} - res: INoteState = await self._session.request( - Route("POST", "/api/notes/state"), auth=True, json=data - ) - return NoteState(res) + return await self.fetch_state(note_id=note_id) @cache(group="get_note_state", override=True) async def fetch_state(self, *, note_id: str) -> NoteState: @@ -441,7 +437,12 @@ async def fetch_state(self, *, note_id: str) -> NoteState: NoteState Note state """ - return await self.get_state(note_id=note_id) + data = {"noteId": note_id} + res: INoteState = await self._session.request( + Route("POST", "/api/notes/state"), auth=True, json=data + ) + return NoteState(res) + async def add_clips(self, clip_id: str, *, note_id: str) -> bool: """Add a note to the clip diff --git a/mipac/actions/reaction.py b/mipac/actions/reaction.py index 8f5e9484..3fd923f8 100644 --- a/mipac/actions/reaction.py +++ b/mipac/actions/reaction.py @@ -71,6 +71,20 @@ async def get_reactions( until_id: str | None = None, *, note_id: str, + ) -> list[NoteReaction]: + return await self.fetch_reactions( + type=type, note_id=note_id, limit=limit, since_id=since_id, until_id=until_id + ) + + @cache(group="get_note_reaction", override=True) + async def fetch_reactions( + self, + type: str | None = None, + limit: int = 10, + since_id: str | None = None, + until_id: str | None = None, + *, + note_id: str, ) -> list[NoteReaction]: data = remove_dict_empty( { @@ -89,20 +103,6 @@ async def get_reactions( ) return [NoteReaction(i, client=self._client) for i in res] - @cache(group="get_note_reaction", override=True) - async def fetch_reactions( - self, - type: str | None = None, - limit: int = 10, - since_id: str | None = None, - until_id: str | None = None, - *, - note_id: str, - ) -> list[NoteReaction]: - return await self.get_reactions( - type=type, note_id=note_id, limit=limit, since_id=since_id, until_id=until_id - ) - class ClientReactionActions(SharedReactionActions): def __init__(self, note_id: str, *, session: HTTPClient, client: ClientManager) -> None: diff --git a/mipac/actions/user.py b/mipac/actions/user.py index 9da15fca..08176f31 100644 --- a/mipac/actions/user.py +++ b/mipac/actions/user.py @@ -850,7 +850,6 @@ async def get( user_ids: list[str] | None = None, username: str | None = None, host: str | None = None, - **kwargs, ) -> UserDetailedNotMe | MeDetailed: """ Retrieve user information from the user ID using the cache. @@ -868,14 +867,11 @@ async def get( host : str, default=None Hosts with target users """ - field = remove_dict_empty( - {"userId": user_id, "username": username, "host": host, "userIds": user_ids} - ) - data: IUser = await self._session.request( - Route("POST", "/api/users/show"), json=field, auth=True, lower=True + return await self.fetch( + user_id=user_id, username=username, host=host, user_ids=user_ids ) - return packed_user(data, client=self._client) + @cache(group="get_user", override=True) async def fetch( self, user_id: str | None = None, @@ -900,9 +896,13 @@ async def fetch( host : str, default=None Hosts with target users """ - return await self.get( - user_id=user_id, username=username, host=host, user_ids=user_ids, cache_override=True + field = remove_dict_empty( + {"userId": user_id, "username": username, "host": host, "userIds": user_ids} + ) + data: IUser = await self._session.request( + Route("POST", "/api/users/show"), json=field, auth=True, lower=True ) + return packed_user(data, client=self._client) @deprecated def get_mention(self, user: PartialUser) -> str: