2019-08-24 13:43:41 +02:00
|
|
|
from collections import namedtuple
|
|
|
|
|
2019-08-27 14:34:51 +02:00
|
|
|
from .utils import parse_datetime
|
|
|
|
|
2019-08-24 13:43:41 +02:00
|
|
|
|
|
|
|
Author = namedtuple("Author", ["account", "display_name"])
|
|
|
|
|
|
|
|
|
|
|
|
def get_author(data, instance):
|
|
|
|
# Show the author, not the persopn who reblogged
|
|
|
|
status = data["reblog"] or data
|
|
|
|
acct = status['account']['acct']
|
|
|
|
acct = acct if "@" in acct else "{}@{}".format(acct, instance)
|
|
|
|
return Author(acct, status['account']['display_name'])
|
2019-08-24 11:20:31 +02: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
|
|
|
|
"""
|
|
|
|
def __init__(self, data, instance):
|
|
|
|
self.data = data
|
|
|
|
self.instance = instance
|
|
|
|
|
2019-08-29 14:01:26 +02:00
|
|
|
# This can be toggled by the user
|
|
|
|
self.show_sensitive = False
|
|
|
|
|
2019-08-26 13:28:37 +02:00
|
|
|
# TODO: make Status immutable?
|
|
|
|
|
2019-08-24 11:20:31 +02:00
|
|
|
self.id = self.data["id"]
|
2019-08-24 12:53:55 +02:00
|
|
|
self.display_name = self.data["account"]["display_name"]
|
2019-08-24 11:20:31 +02:00
|
|
|
self.account = self.get_account()
|
|
|
|
self.created_at = parse_datetime(data["created_at"])
|
2019-08-24 13:43:41 +02:00
|
|
|
self.author = get_author(data, instance)
|
2019-08-24 12:53:55 +02:00
|
|
|
self.favourited = data.get("favourited", False)
|
|
|
|
self.reblogged = data.get("reblogged", False)
|
2019-08-31 15:24:03 +02:00
|
|
|
self.in_reply_to = data.get("in_reply_to_id")
|
2019-08-24 12:53:55 +02:00
|
|
|
|
2019-08-24 11:20:31 +02:00
|
|
|
def get_account(self):
|
|
|
|
acct = self.data['account']['acct']
|
|
|
|
return acct if "@" in acct else "{}@{}".format(acct, self.instance)
|
2019-08-26 13:28:37 +02:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "<Status id={}>".format(self.id)
|