Skip to content

Commit

Permalink
feat: /api/notes/user-list-timelineをサポート
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Dec 29, 2023
1 parent 081f50e commit 44ccd07
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 0 deletions.
100 changes: 100 additions & 0 deletions mipac/actions/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,3 +1008,103 @@ async def get_mentions(
)

return [Note(note, client=self._client) for note in res]

async def get_time_line(
self,
list_id: str,
limit: int = 10,
since_id: str | None = None,
until_id: str | None = None,
since_date: int | None = None,
until_date: int | None = None,
include_renote_my_notes: bool = True,
include_local_renotes: bool = True,
with_renotes: bool = True,
with_files: bool = True,
) -> list[Note]:
"""
Get the timeline of the specified list
Endpoint: `/api/notes/user-list-timeline`
Parameters
----------
list_id : str
List ID
limit : int, default=10
limit
since_id : str | None, default=None
Since ID
until_id : str | None, default=None
Until ID
since_date : int | None, default=None
Since date
until_date : int | None, default=None
Until date
include_renote_my_notes : bool, default=True
Whether to include your own renote
include_local_renotes : bool, default=True
Whether to include local renote
with_renotes : bool, default=True
Whether to include renote
with_files : bool, default=True
Whether to include files
Returns
-------
list[Note]
Notes
"""
data = {
"limit": limit,
"listId": list_id,
"includeRenoteMyNotes": include_renote_my_notes,
"includeLocalRenotes": include_local_renotes,
"withRenotes": with_renotes,
"withFiles": with_files,
"sinceId": since_id,
"untilId": until_id,
"sinceDate": since_date,
"untilDate": until_date,
}

raw_notes: list[INote] = await self._session.request(
Route("POST", "/api/notes/user-list-timeline"), json=data, auth=True
)

return [Note(raw_note, client=self._client) for raw_note in raw_notes]

async def get_all_time_line(
self,
list_id: str,
limit: int = 10,
since_id: str | None = None,
until_id: str | None = None,
since_date: int | None = None,
until_date: int | None = None,
include_renote_my_notes: bool = True,
include_local_renotes: bool = True,
with_renotes: bool = True,
with_files: bool = True,
):
data = {
"limit": limit,
"listId": list_id,
"includeRenoteMyNotes": include_renote_my_notes,
"includeLocalRenotes": include_local_renotes,
"withRenotes": with_renotes,
"withFiles": with_files,
"sinceId": since_id,
"untilId": until_id,
"sinceDate": since_date,
"untilDate": until_date,
}

pagination = Pagination[INote](
self._session, Route("POST", "/api/notes/user-list-timeline"), json=data, auth=True
)

while pagination.is_final is False:
raw_notes: list[INote] = await pagination.next()
for raw_note in raw_notes:
yield Note(raw_note, client=self._client)
121 changes: 121 additions & 0 deletions mipac/actions/users/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from mipac.abstract.action import AbstractAction
from mipac.errors.base import ParameterError
from mipac.http import HTTPClient, Route
from mipac.models.note import Note
from mipac.models.user import UserList
from mipac.types.user import IUserList

Expand Down Expand Up @@ -236,6 +237,71 @@ async def unfavorite(self, *, list_id: str | None = None) -> bool:
)
return res

async def get_time_line(
self,
limit: int = 10,
since_id: str | None = None,
until_id: str | None = None,
since_date: int | None = None,
until_date: int | None = None,
include_renote_my_notes: bool = True,
include_local_renotes: bool = True,
with_renotes: bool = True,
with_files: bool = True,
*,
list_id: str | None = None,
) -> list[Note]:
list_id = list_id or self.__list_id

if list_id is None:
raise ParameterError("required parameter list_id is missing")

return await self._client.note.action.get_time_line(
list_id=list_id,
limit=limit,
since_id=since_id,
until_id=until_id,
since_date=since_date,
until_date=until_date,
include_renote_my_notes=include_renote_my_notes,
include_local_renotes=include_local_renotes,
with_renotes=with_renotes,
with_files=with_files,
)

async def get_all_time_line(
self,
limit: int = 10,
since_id: str | None = None,
until_id: str | None = None,
since_date: int | None = None,
until_date: int | None = None,
include_renote_my_notes: bool = True,
include_local_renotes: bool = True,
with_renotes: bool = True,
with_files: bool = True,
*,
list_id: str | None = None,
):
list_id = list_id or self.__list_id

if list_id is None:
raise ParameterError("required parameter list_id is missing")

async for i in self._client.note.action.get_all_time_line(
list_id=list_id,
limit=limit,
since_id=since_id,
until_id=until_id,
since_date=since_date,
until_date=until_date,
include_renote_my_notes=include_renote_my_notes,
include_local_renotes=include_local_renotes,
with_renotes=with_renotes,
with_files=with_files,
):
yield i


class UserListActions(ClientUserListActions):
def __init__(self, *, session: HTTPClient, client: ClientManager):
Expand Down Expand Up @@ -284,3 +350,58 @@ async def favorite(self, list_id: str) -> bool:
@override
async def unfavorite(self, list_id: str) -> bool:
return await super().unfavorite(list_id=list_id)

@override
async def get_time_line(
self,
list_id: str,
limit: int = 10,
since_id: str | None = None,
until_id: str | None = None,
since_date: int | None = None,
until_date: int | None = None,
include_renote_my_notes: bool = True,
include_local_renotes: bool = True,
with_renotes: bool = True,
with_files: bool = True,
) -> list[Note]:
return await self._client.note.action.get_time_line(
list_id=list_id,
limit=limit,
since_id=since_id,
until_id=until_id,
since_date=since_date,
until_date=until_date,
include_renote_my_notes=include_renote_my_notes,
include_local_renotes=include_local_renotes,
with_renotes=with_renotes,
with_files=with_files,
)

@override
async def get_all_time_line(
self,
list_id: str,
limit: int = 10,
since_id: str | None = None,
until_id: str | None = None,
since_date: int | None = None,
until_date: int | None = None,
include_renote_my_notes: bool = True,
include_local_renotes: bool = True,
with_renotes: bool = True,
with_files: bool = True,
):
async for i in self._client.note.action.get_all_time_line(
list_id=list_id,
limit=limit,
since_id=since_id,
until_id=until_id,
since_date=since_date,
until_date=until_date,
include_renote_my_notes=include_renote_my_notes,
include_local_renotes=include_local_renotes,
with_renotes=with_renotes,
with_files=with_files,
):
yield i

0 comments on commit 44ccd07

Please sign in to comment.