Return an instance of :class:`.Message` or :class:`.SubredditMessage` from ``data``. :param data: The structured data. :param reddit: An instance of :class:`.Reddit`.
(cls, data: dict[str, Any], reddit: praw.Reddit)
| 43 | |
| 44 | @classmethod |
| 45 | def parse(cls, data: dict[str, Any], reddit: praw.Reddit) -> Message | SubredditMessage: |
| 46 | """Return an instance of :class:`.Message` or :class:`.SubredditMessage` from ``data``. |
| 47 | |
| 48 | :param data: The structured data. |
| 49 | :param reddit: An instance of :class:`.Reddit`. |
| 50 | |
| 51 | """ |
| 52 | if data["author"]: |
| 53 | data["author"] = Redditor(reddit, data["author"]) |
| 54 | |
| 55 | if data["dest"].startswith("#"): |
| 56 | data["dest"] = Subreddit(reddit, data["dest"][1:]) |
| 57 | else: |
| 58 | data["dest"] = Redditor(reddit, data["dest"]) |
| 59 | |
| 60 | if data["replies"]: |
| 61 | replies = data["replies"] |
| 62 | data["replies"] = reddit._objector.objectify(data=replies["data"]["children"]) |
| 63 | else: |
| 64 | data["replies"] = [] |
| 65 | |
| 66 | if data["subreddit"]: |
| 67 | data["subreddit"] = Subreddit(reddit, data["subreddit"]) |
| 68 | return SubredditMessage(reddit, _data=data) |
| 69 | |
| 70 | return cls(reddit, _data=data) |
| 71 | |
| 72 | @property |
| 73 | def _kind(self) -> str: |
nothing calls this directly
no test coverage detected