|
13 | 13 | from ._session import NcSessionApp, NcSessionBasic |
14 | 14 |
|
15 | 15 |
|
16 | | -@dataclasses.dataclass |
17 | | -class NotificationInfo: |
18 | | - """Extra Notification attributes from Nextcloud.""" |
19 | | - |
20 | | - app_name: str |
21 | | - """Application name that generated notification.""" |
22 | | - user_id: str |
23 | | - """User name for which this notification is.""" |
24 | | - time: datetime.datetime |
25 | | - """Time when the notification was created.""" |
26 | | - subject: str |
27 | | - """Subject of the notification.""" |
28 | | - message: str |
29 | | - """Message of the notification.""" |
30 | | - link: str |
31 | | - """Link which will be opened when user clicks on notification.""" |
32 | | - icon: str |
33 | | - """Relative to instance url of the icon image.""" |
34 | | - |
35 | | - def __init__(self, raw_info: dict): |
36 | | - self.app_name = raw_info["app"] |
37 | | - self.user_id = raw_info["user"] |
38 | | - self.time = nc_iso_time_to_datetime(raw_info["datetime"]) |
39 | | - self.subject = raw_info["subject"] |
40 | | - self.message = raw_info["message"] |
41 | | - self.link = raw_info.get("link", "") |
42 | | - self.icon = raw_info.get("icon", "") |
43 | | - |
44 | | - |
45 | 16 | @dataclasses.dataclass |
46 | 17 | class Notification: |
47 | 18 | """Class representing information about Nextcloud notification.""" |
48 | 19 |
|
49 | | - notification_id: int |
50 | | - """ID of the notification.""" |
51 | | - object_id: str |
52 | | - """Randomly generated unique object ID""" |
53 | | - object_type: str |
54 | | - """Currently not used.""" |
55 | | - info: NotificationInfo |
56 | | - """Additional extra information for the object""" |
57 | | - |
58 | | - def __init__(self, raw_info: dict): |
59 | | - self.notification_id = raw_info["notification_id"] |
60 | | - self.object_id = raw_info["object_id"] |
61 | | - self.object_type = raw_info["object_type"] |
62 | | - self.info = NotificationInfo(raw_info) |
| 20 | + def __init__(self, raw_data: dict): |
| 21 | + self._raw_data = raw_data |
| 22 | + |
| 23 | + @property |
| 24 | + def notification_id(self) -> int: |
| 25 | + """ID of the notification.""" |
| 26 | + return self._raw_data["notification_id"] |
| 27 | + |
| 28 | + @property |
| 29 | + def object_id(self) -> str: |
| 30 | + """Randomly generated unique object ID.""" |
| 31 | + return self._raw_data["object_id"] |
| 32 | + |
| 33 | + @property |
| 34 | + def object_type(self) -> str: |
| 35 | + """Currently not used.""" |
| 36 | + return self._raw_data["object_type"] |
| 37 | + |
| 38 | + @property |
| 39 | + def app_name(self) -> str: |
| 40 | + """Application name that generated notification.""" |
| 41 | + return self._raw_data["app"] |
| 42 | + |
| 43 | + @property |
| 44 | + def user_id(self) -> str: |
| 45 | + """User ID of user for which this notification is.""" |
| 46 | + return self._raw_data["user"] |
| 47 | + |
| 48 | + @property |
| 49 | + def subject(self) -> str: |
| 50 | + """Subject of the notification.""" |
| 51 | + return self._raw_data["subject"] |
| 52 | + |
| 53 | + @property |
| 54 | + def message(self) -> str: |
| 55 | + """Message of the notification.""" |
| 56 | + return self._raw_data["message"] |
| 57 | + |
| 58 | + @property |
| 59 | + def time(self) -> datetime.datetime: |
| 60 | + """Time when the notification was created.""" |
| 61 | + return nc_iso_time_to_datetime(self._raw_data["datetime"]) |
| 62 | + |
| 63 | + @property |
| 64 | + def link(self) -> str: |
| 65 | + """Link, which will be opened when user clicks on notification.""" |
| 66 | + return self._raw_data.get("link", "") |
| 67 | + |
| 68 | + @property |
| 69 | + def icon(self) -> str: |
| 70 | + """Relative to instance url of the icon image.""" |
| 71 | + return self._raw_data.get("icon", "") |
| 72 | + |
| 73 | + def __repr__(self): |
| 74 | + return ( |
| 75 | + f"<{self.__class__.__name__} id={self.notification_id}, app_name={self.app_name}, user_id={self.user_id}," |
| 76 | + f" time={self.time}>" |
| 77 | + ) |
63 | 78 |
|
64 | 79 |
|
65 | 80 | class _NotificationsAPI: |
|
0 commit comments