-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from __future__ import annotations | ||
from datetime import datetime | ||
|
||
from typing import TYPE_CHECKING | ||
from mipac.models.drive import File | ||
from mipac.models.lite.user import PartialUser | ||
|
||
from mipac.types.gallery import IGalleryPost | ||
from mipac.utils.format import str_to_datetime | ||
|
||
if TYPE_CHECKING: | ||
from mipac.manager.client import ClientManager | ||
|
||
|
||
class GalleryPost: | ||
def __init__(self, raw_gallery: IGalleryPost, *, client: ClientManager) -> None: | ||
self._raw_gallery: IGalleryPost = raw_gallery | ||
self.__client: ClientManager = client | ||
|
||
@property | ||
def id(self) -> str: | ||
return self._raw_gallery["id"] | ||
|
||
@property | ||
def created_at(self) -> datetime: | ||
return str_to_datetime(self._raw_gallery["created_at"]) | ||
|
||
@property | ||
def updated_at(self) -> datetime: | ||
return str_to_datetime(self._raw_gallery["updated_at"]) | ||
|
||
@property | ||
def user_id(self) -> str: | ||
return self._raw_gallery["user_id"] | ||
|
||
@property | ||
def user(self) -> PartialUser: | ||
return PartialUser(self._raw_gallery["user"], client=self.__client) | ||
|
||
@property | ||
def title(self) -> str: | ||
return self._raw_gallery["title"] | ||
|
||
@property | ||
def description(self) -> str | None: | ||
return self._raw_gallery["description"] | ||
|
||
@property | ||
def file_ids(self) -> list[str]: | ||
return self._raw_gallery["file_ids"] | ||
|
||
@property | ||
def files(self) -> list[File]: | ||
return [File(file, client=self.__client) for file in self._raw_gallery["files"]] | ||
|
||
@property | ||
def tags(self) -> list[str] | None: | ||
return self._raw_gallery.get("tags") | ||
|
||
@property | ||
def is_sensitive(self) -> bool: | ||
return self._raw_gallery["is_sensitive"] | ||
|
||
@property | ||
def liked_count(self) -> int: | ||
return self._raw_gallery["liked_count"] | ||
|
||
@property | ||
def is_liked(self) -> bool | None: | ||
return self._raw_gallery.get("is_liked") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from typing import NotRequired, TypedDict | ||
|
||
from mipac.types.user import IPartialUser | ||
from mipac.types.drive import IFile | ||
|
||
|
||
class IGalleryPost(TypedDict): | ||
id: str | ||
created_at: str | ||
updated_at: str # 更新が一度もない場合は created_atとほぼ同じものが入ってる | ||
user_id: str | ||
user: IPartialUser | ||
title: str | ||
description: str | None | ||
file_ids: list[str] | ||
files: list[IFile] | ||
tags: NotRequired[list[str]] # Misskeyの今の実装では常に存在しない? | ||
is_sensitive: bool | ||
liked_count: int | ||
is_liked: NotRequired[bool] |