Skip to content

Commit

Permalink
fix: fetchとgetメソッドの責務が逆になっている close #149
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Oct 10, 2024
1 parent dcd1269 commit f4220ac
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
37 changes: 19 additions & 18 deletions mipac/actions/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
28 changes: 14 additions & 14 deletions mipac/actions/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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:
Expand Down
18 changes: 9 additions & 9 deletions mipac/actions/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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:
Expand Down

0 comments on commit f4220ac

Please sign in to comment.