2019-08-24 11:43:41 +00:00
|
|
|
from collections import namedtuple
|
|
|
|
|
2019-08-27 12:34:51 +00:00
|
|
|
from .utils import parse_datetime
|
|
|
|
|
2019-08-24 11:43:41 +00:00
|
|
|
|
|
|
|
Author = namedtuple("Author", ["account", "display_name"])
|
|
|
|
|
|
|
|
|
2019-08-24 09:20:31 +00:00
|
|
|
class Status:
|
|
|
|
"""
|
|
|
|
A wrapper around the Status entity data fetched from Mastodon.
|
|
|
|
|
|
|
|
https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#status
|
|
|
|
"""
|
2019-09-04 14:16:16 +00:00
|
|
|
def __init__(self, data, is_mine, default_instance):
|
2019-08-24 09:20:31 +00:00
|
|
|
self.data = data
|
2019-09-04 14:16:16 +00:00
|
|
|
self.is_mine = is_mine
|
|
|
|
self.default_instance = default_instance
|
2019-08-24 09:20:31 +00:00
|
|
|
|
2019-08-29 12:01:26 +00:00
|
|
|
# This can be toggled by the user
|
|
|
|
self.show_sensitive = False
|
|
|
|
|
2019-08-26 11:28:37 +00:00
|
|
|
# TODO: make Status immutable?
|
|
|
|
|
2019-08-24 09:20:31 +00:00
|
|
|
self.id = self.data["id"]
|
2019-08-24 10:53:55 +00:00
|
|
|
self.display_name = self.data["account"]["display_name"]
|
2019-08-24 09:20:31 +00:00
|
|
|
self.account = self.get_account()
|
|
|
|
self.created_at = parse_datetime(data["created_at"])
|
2019-09-04 14:16:16 +00:00
|
|
|
self.author = self.get_author()
|
2019-08-24 10:53:55 +00:00
|
|
|
self.favourited = data.get("favourited", False)
|
|
|
|
self.reblogged = data.get("reblogged", False)
|
2019-08-31 13:24:03 +00:00
|
|
|
self.in_reply_to = data.get("in_reply_to_id")
|
2019-08-24 10:53:55 +00:00
|
|
|
|
2019-09-04 14:16:16 +00:00
|
|
|
def get_author(self):
|
|
|
|
# Show the author, not the persopn who reblogged
|
|
|
|
data = self.data["reblog"] or self.data
|
|
|
|
acct = data['account']['acct']
|
|
|
|
acct = acct if "@" in acct else "{}@{}".format(acct, self.default_instance)
|
|
|
|
return Author(acct, data['account']['display_name'])
|
|
|
|
|
2019-08-24 09:20:31 +00:00
|
|
|
def get_account(self):
|
|
|
|
acct = self.data['account']['acct']
|
2019-09-04 14:16:16 +00:00
|
|
|
return acct if "@" in acct else "{}@{}".format(acct, self.default_instance)
|
2019-08-26 11:28:37 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "<Status id={}>".format(self.id)
|