chore: 未消化のTODOを消化

pull/109/head
yupix 7 months ago
parent a7963e8039
commit 5b6f52b56b
No known key found for this signature in database
GPG Key ID: 2FF705F5C56D9C06

@ -24,10 +24,25 @@ class SharedClipActions(AbstractAction):
limit: int = 10,
since_id: str | None = None,
until_id: str | None = None,
get_all: bool = False,
*,
clip_id: str | None = None,
) -> AsyncGenerator[Note, None]: # TODO: 作り直し
clip_id: str,
) -> list[Note]:
body = {"clipId": clip_id, "limit": limit, "sinceId": since_id, "untilId": until_id}
raw_notes: list[INote] = await self._session.request(
Route("POST", "/api/clips/notes"), json=body
)
return [Note(raw_note=raw_note, client=self._client) for raw_note in raw_notes]
async def get_all_notes(
self,
limit: int = 10,
since_id: str | None = None,
until_id: str | None = None,
*,
clip_id: str,
) -> AsyncGenerator[Note, None]:
"""Get notes from a clip
Parameters
----------
@ -39,34 +54,23 @@ class SharedClipActions(AbstractAction):
The note id to get notes after
until_id : str | None, optional, by default None
The note id to get notes before
get_all : bool, optional, by default False
Whether to get all notes
Yields
------
AsyncGenerator[Note, None]
The notes
"""
if limit > 100:
raise ValueError("limit must be less than 100")
if get_all:
limit = 100
body = {"clipId": clip_id, "limit": limit, "sinceId": since_id, "untilId": until_id}
pagination = Pagination[INote](
self._session, Route("POST", "/api/clips/notes"), json=body, auth=True
)
while True:
clips = await pagination.next()
for raw_clip in clips:
while pagination.is_final is False:
raw_clips = await pagination.next()
for raw_clip in raw_clips:
yield Note(raw_clip, client=self._client)
if get_all is False or pagination.is_final:
break
async def add_note(self, note_id: str, *, clip_id: str) -> bool:
"""Add a note to a clip
@ -162,7 +166,7 @@ class SharedClipActions(AbstractAction):
return Clip(result, client=self._client)
class ClientClipActions(SharedClipActions): # TODO: 使うようにする
class ClientClipActions(SharedClipActions):
def __init__(self, clip_id: str, *, session: HTTPClient, client: ClientManager):
super().__init__(session=session, client=client)
self._clip_id = clip_id
@ -176,6 +180,21 @@ class ClientClipActions(SharedClipActions): # TODO: 使うようにする
get_all: bool = False,
*,
clip_id: str | None = None,
) -> list[Note]:
clip_id = clip_id or self._clip_id
return await super().get_notes(
limit=limit, since_id=since_id, until_id=until_id, clip_id=clip_id
)
@override
async def get_all_notes(
self,
limit: int = 10,
since_id: str | None = None,
until_id: str | None = None,
*,
clip_id: str | None = None,
) -> AsyncGenerator[Note, None]:
"""Get notes from a clip
Parameters
@ -199,8 +218,8 @@ class ClientClipActions(SharedClipActions): # TODO: 使うようにする
clip_id = clip_id or self._clip_id
async for note in super().get_notes(
limit=limit, since_id=since_id, until_id=until_id, get_all=get_all, clip_id=clip_id
async for note in super().get_all_notes(
limit=limit, since_id=since_id, until_id=until_id, clip_id=clip_id
):
yield note

@ -29,8 +29,7 @@ class FederationActions(AbstractAction):
async def show_ap(
self, host: str, since_id: str | None = None, until_id: str | None = None, limit: int = 10
) -> FederationInstance:
# TODO: これ本当にuntilId必要なのか確認する
) -> FederationInstance: # TODO: 存在するのか確認する
body = {"host": host, "sinceId": since_id, "untilId": until_id, "limit": limit}
res: FederationInstance = await self.__session.request(

@ -152,11 +152,12 @@ class SharedNoteActions(AbstractAction):
async def get_all_children(
self,
limit: int = 10,
since_id: str | None = None,
untilId: str | None = None,
*,
note_id: str,
) -> AsyncGenerator[Note, None]: # TODO: limitをサポートする
) -> AsyncGenerator[Note, None]:
"""Get all children of the note
Endpoint: `/api/notes/children`
@ -175,8 +176,6 @@ class SharedNoteActions(AbstractAction):
AsyncGenerator[Note, None]
Children of the note
"""
limit = 100
data = {
"noteId": note_id,
"limit": limit,
@ -369,6 +368,7 @@ class SharedNoteActions(AbstractAction):
self,
since_id: str | None = None,
until_id: str | None = None,
limit: int = 10,
*,
note_id: str,
) -> AsyncGenerator[Note, None]:
@ -390,23 +390,17 @@ class SharedNoteActions(AbstractAction):
AsyncGenerator[Note, None]
replies
"""
limit = 100
body = {"noteId": note_id, "sinceId": since_id, "untilId": until_id, "limit": limit}
pagination = Pagination[INote](
self._session, Route("POST", "/api/notes/replies"), json=body
)
while True:
while pagination.is_final is False:
res_notes = await pagination.next()
for res_note in res_notes:
yield Note(res_note, client=self._client)
if pagination.is_final:
break
@cache(group="get_note_state")
async def get_state(self, *, note_id: str) -> NoteState:
"""Get the state of the note
@ -789,11 +783,12 @@ class ClientNoteActions(SharedNoteActions):
@override
async def get_all_children(
self,
limit: int = 10,
since_id: str | None = None,
untilId: str | None = None,
*,
note_id: str | None = None,
) -> AsyncGenerator[Note, None]: # TODO: limitをサポート
) -> AsyncGenerator[Note, None]:
"""Get all children of the note
Endpoint: `/api/notes/children`
@ -815,7 +810,7 @@ class ClientNoteActions(SharedNoteActions):
note_id = note_id or self._note_id
async for i in super().get_all_children(
since_id=since_id, untilId=untilId, note_id=note_id
limit=limit, since_id=since_id, untilId=untilId, note_id=note_id
):
yield i
@ -1000,9 +995,10 @@ class ClientNoteActions(SharedNoteActions):
self,
since_id: str | None = None,
until_id: str | None = None,
limit: int = 10,
*,
note_id: str | None = None,
) -> AsyncGenerator[Note, None]: # TODO: limitをサポート
) -> AsyncGenerator[Note, None]:
"""Get replies to the note
Endpoint: `/api/notes/replies`
@ -1024,7 +1020,7 @@ class ClientNoteActions(SharedNoteActions):
note_id = note_id or self._note_id
async for i in super().get_all_replies(
since_id=since_id, until_id=until_id, note_id=note_id
since_id=since_id, until_id=until_id, limit=limit, note_id=note_id
):
yield i
@ -1756,12 +1752,10 @@ class NoteActions(SharedNoteActions):
self._session, Route("POST", "/api/notes"), json=body, limit=limit
)
while True:
res_notes = await pagination.next()
for note in res_notes:
yield Note(note, client=self._client)
if get_all is False or pagination.is_final:
break
while pagination.is_final is False:
raw_notes = await pagination.next()
for raw_note in raw_notes:
yield Note(raw_note=raw_note, client=self._client)
async def get_time_line(
self,

@ -83,6 +83,7 @@ class SharedUserActions(AbstractAction):
self,
with_replies: bool = False,
with_renotes: bool = True,
limit: int = 10,
since_id: str | None = None,
until_id: str | None = None,
since_data: int | None = None,
@ -98,7 +99,7 @@ class SharedUserActions(AbstractAction):
"userId": user_id,
"withReplies": with_replies,
"withRenotes": with_renotes,
"limit": 100,
"limit": limit,
"sinceId": since_id,
"untilId": until_id,
"sinceDate": since_data,
@ -538,6 +539,7 @@ class ClientUserActions(SharedUserActions):
self,
with_replies: bool = False,
with_renotes: bool = True,
limit: int = 10,
since_id: str | None = None,
until_id: str | None = None,
since_data: int | None = None,
@ -548,12 +550,13 @@ class ClientUserActions(SharedUserActions):
exclude_nsfw: bool = False,
*,
user_id: str | None = None,
) -> AsyncGenerator[Note, None]: # TODO: limitを指定できるように
) -> AsyncGenerator[Note, None]:
user_id = user_id or self.__user.id
async for i in super().get_all_notes(
with_replies=with_replies,
with_renotes=with_renotes,
limit=limit,
since_id=since_id,
until_id=until_id,
since_data=since_data,
@ -883,14 +886,13 @@ class UserActions(SharedUserActions):
):
super().__init__(session=session, client=client)
async def get_me(self) -> MeDetailed: # TODO: トークンが無い場合は例外返すようにする
async def get_me(self) -> MeDetailed:
"""
ログインしているユーザーの情報を取得します
"""
res: IMeDetailedSchema = await self._session.request(
Route("POST", "/api/i"),
auth=True,
lower=True,
)
return MeDetailed(res, client=self._client)

@ -1,9 +1,11 @@
from __future__ import annotations
from datetime import datetime
from typing import TYPE_CHECKING, Any
from mipac.models.lite.user import PartialUser
from mipac.types.drive import IDriveStatus
from mipac.utils.format import str_to_datetime
if TYPE_CHECKING:
from mipac.manager.client import ClientManager
@ -96,8 +98,8 @@ class Folder:
return self.__raw_folder["id"]
@property
def created_at(self) -> str: # TODO: 型
return self.__raw_folder["created_at"]
def created_at(self) -> datetime:
return str_to_datetime(self.__raw_folder["created_at"])
@property
def name(self) -> str:
@ -155,8 +157,8 @@ class File:
return self.__raw_file["id"]
@property
def created_at(self):
return self.__raw_file["created_at"]
def created_at(self) -> datetime:
return str_to_datetime(self.__raw_file["created_at"])
@property
def name(self) -> str:

@ -214,7 +214,7 @@ class UserDetailedNotMeOnly:
return self._raw_user["location"]
@property
def birthday(self) -> str | None: # TODO: datetimeにする必要があるか確認する
def birthday(self) -> str | None:
return self._raw_user["birthday"]
@property

Loading…
Cancel
Save