added some notification classes

pull/27/head
xtaodada 2 years ago
parent bda30fe0de
commit f558161b2f
No known key found for this signature in database
GPG Key ID: 4CBB3F4FA8C85659

@ -18,6 +18,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- ✨ added `MuteActions` class.
- ✨ added `MuteUser` class.
- ✨ added `IMuteUser` class.
- ✨ added some notification classes.
- `Notification`
- `NotificationFollow`
- `NotificationFollowRequest`
- `NotificationNote`
- `NotificationPollEnd`
- `NotificationReaction`
- `IUserNf`
- `INoteNf`
- `IPollEndNf`
## Removed

@ -8,46 +8,163 @@ from mipac.models.note import Note
if TYPE_CHECKING:
from mipac.manager.client import ClientActions
from mipac.manager.follow import FollowManager, FollowRequestManager
from mipac.manager.note import NoteManager
from mipac.manager.reaction import ReactionManager
from mipac.types.notification import IReactionNf
from mipac.types.notification import INotification, IUserNf, \
INoteNf, IPollEndNf, IReactionNf
class NotificationReaction:
class Notification:
def __init__(
self, reaction: IReactionNf, *, client: ClientActions
self,
notification: INotification,
*,
client: ClientActions,
) -> None:
self.__reaction: IReactionNf = reaction
self.__notification: INotification = notification
self.__client: ClientActions = client
@property
def id(self) -> str:
return self.__reaction['id']
return self.__notification['id']
@property
def type(self) -> str:
return self.__notification['type']
@property
def created_at(self) -> datetime:
return datetime.strptime(
self.__reaction['created_at'], '%Y-%m-%dT%H:%M:%S.%fZ'
self.__notification['created_at'], '%Y-%m-%dT%H:%M:%S.%fZ'
)
@property
def type(self) -> str:
return self.__reaction['type']
def is_read(self) -> bool:
return self.__notification['is_read']
class NotificationFollow(Notification):
def __init__(
self,
notification: IUserNf,
*,
client: ClientActions,
) -> None:
super().__init__(notification, client=client)
self.__notification: IUserNf = notification
self.__client: ClientActions = client
@property
def is_read(self) -> bool:
return self.__reaction['is_read']
def user(self) -> LiteUser:
return LiteUser(
self.__notification['user'], client=self.__client,
)
@property
def user_id(self) -> str:
return self.__notification['user_id']
@property
def api(self) -> FollowManager:
return self.__client.follow
class NotificationFollowRequest(Notification):
def __init__(
self,
notification: IUserNf,
*,
client: ClientActions,
) -> None:
super().__init__(notification, client=client)
self.__notification: IUserNf = notification
self.__client: ClientActions = client
@property
def user(self) -> LiteUser:
return LiteUser(
self.__notification['user'], client=self.__client,
)
@property
def user_id(self) -> str:
return self.__notification['user_id']
@property
def api(self) -> FollowRequestManager:
return self.__client.follow_request
class NotificationNote(Notification):
def __init__(
self,
notification: INoteNf,
*,
client: ClientActions,
) -> None:
super().__init__(notification, client=client)
self.__notification: INoteNf = notification
self.__client: ClientActions = client
@property
def user(self) -> LiteUser:
return LiteUser(
self.__notification['user'], client=self.__client,
)
@property
def user_id(self) -> str:
return self.__notification['user_id']
@property
def note(self) -> Note:
return Note(
self.__notification['note'], client=self.__client,
)
@property
def api(self) -> NoteManager:
return self.__client.note
class NotificationPollEnd(Notification):
def __init__(
self,
notification: IPollEndNf,
*,
client: ClientActions,
) -> None:
super().__init__(notification, client=client)
self.__notification: IPollEndNf = notification
self.__client: ClientActions = client
@property
def note(self) -> Note:
return Note(
self.__notification['note'], client=self.__client,
)
class NotificationReaction(Notification):
def __init__(
self, reaction: IReactionNf, *, client: ClientActions
) -> None:
super().__init__(reaction, client=client)
self.__notification: IReactionNf = reaction
self.__client: ClientActions = client
@property
def user(self) -> LiteUser:
return LiteUser(self.__reaction['user'], client=self.__client)
return LiteUser(self.__notification['user'], client=self.__client)
@property
def note(self) -> Note:
return Note(self.__reaction['note'], client=self.__client)
return Note(self.__notification['note'], client=self.__client)
@property
def reaction(self) -> str:
return self.__reaction['reaction']
return self.__notification['reaction']
@property
def api(self) -> ReactionManager:

@ -13,14 +13,29 @@ if TYPE_CHECKING:
from mipac.types.user import ILiteUser
class Notification(TypedDict):
class INotification(TypedDict):
id: str
type: str
created_at: str
is_read: bool
class IReactionNf(Notification):
type: str
class IUserNf(INotification):
user: ILiteUser
user_id: str
class INoteNf(INotification):
user: ILiteUser
user_id: str
note: INote
class IPollEndNf(INotification):
note: INote
class IReactionNf(INotification):
reaction: str
user: ILiteUser
user_id: str

Loading…
Cancel
Save