Skip to content

Commit

Permalink
feat: Reaction型を新しく #10
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Aug 29, 2022
1 parent 8835faa commit aeb6e6d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 54 deletions.
3 changes: 2 additions & 1 deletion mipac/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from .drive import File, Folder, Properties
from .emoji import Emoji
from .instance import Instance, InstanceMeta
from .note import Follow, Header, Note, NoteReaction, Poll, Reaction, Renote
from .note import Follow, Header, Note, NoteReaction, Poll, Renote
from .user import Followee, FollowRequest, User
from .notification import Reaction

__all__ = (
'Chat',
Expand Down
58 changes: 5 additions & 53 deletions mipac/models/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@
from typing import TYPE_CHECKING, Literal, Optional, Union
from typing_extensions import Self

from mipac.core.models.note import RawReaction, RawRenote
from mipac.core.models.note import RawRenote
from mipac.core.models.poll import RawPoll
from mipac.exception import NotExistRequiredData
from mipac.models.lite.user import UserLite
from mipac.types.drive import IDriveFile
from mipac.types.emoji import ICustomEmojiLite
from mipac.types.note import INote, INoteReaction, IPoll
from mipac.exception import NotExistRequiredData

if TYPE_CHECKING:
from mipac.actions.note import NoteActions
from mipac.manager.client import ClientActions
from mipac.manager.reaction import ReactionManager
from mipac.models.user import User
from mipac.types.drive import IDriveFile
from mipac.types.emoji import ICustomEmojiLite
from mipac.types.note import INote, INoteReaction, IPoll

__all__ = (
'Note',
'Poll',
'Reaction',
'Follow',
'Header',
'Renote',
Expand Down Expand Up @@ -179,52 +177,6 @@ async def delete(self) -> bool:
return await self.__client.note.action.delete(self.__raw_data.id)


class Reaction:
def __init__(self, raw_data: RawReaction, *, client: ClientActions):
self.__raw_data: RawReaction = raw_data
self.__client: ClientActions = client

@property
def id(self) -> Optional[str]:
return self.__raw_data.id

@property
def created_at(self) -> Optional[datetime]:
return self.__raw_data.created_at

@property
def type(self) -> Optional[str]:
return self.__raw_data.type

@property
def is_read(self) -> bool:
return self.__raw_data.is_read

@property
def user(self) -> Optional[User]:
return (
self.__client._modeler.create_user_instance(self.__raw_data.user)
if self.__raw_data.user
else None
)

@property
def note(self) -> Optional[Note]:
return (
Note(self.__raw_data.note, client=self.__client)
if self.__raw_data.note
else None
)

@property
def reaction(self) -> str:
return self.__raw_data.reaction

@property # TODO: 修正
def action(self) -> ReactionManager:
return self.__client.reaction


class NoteReaction:
"""
Attributes
Expand Down
52 changes: 52 additions & 0 deletions mipac/models/notification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from __future__ import annotations
from datetime import datetime
from typing import TYPE_CHECKING
from mipac.manager.client import ClientActions
from mipac.manager.reaction import ReactionManager
from mipac.models.lite.user import UserLite
from mipac.models.note import Note

if TYPE_CHECKING:
from mipac.types.notification import IReactionNf


class Reaction:
def __init__(
self, reaction: IReactionNf, *, client: ClientActions
) -> None:
self.__reaction: IReactionNf = reaction
self.__client: ClientActions = client

@property
def id(self) -> str:
return self.__reaction['id']

@property
def created_at(self) -> datetime:
return datetime.strptime(
self.__reaction['created_at'], '%Y-%m-%dT%H:%M:%S.%fZ'
)

@property
def type(self) -> str:
return self.__reaction['type']

@property
def is_read(self) -> bool:
return self.__reaction['is_read']

@property
def user(self) -> UserLite:
return UserLite(self.__reaction['user'])

@property
def note(self) -> Note:
return Note(self.__reaction['note'], client=self.__client)

@property
def reaction(self) -> str:
return self.__reaction['reaction']

@property
def action(self) -> ReactionManager:
return self.__client.reaction

0 comments on commit aeb6e6d

Please sign in to comment.