kopia lustrzana https://github.com/tsileo/little-boxes
Add get_hashtags helper
rodzic
30b9a40bc8
commit
df8b9a5280
|
@ -109,6 +109,7 @@ class ActivityType(Enum):
|
||||||
|
|
||||||
# Others
|
# Others
|
||||||
MENTION = "Mention"
|
MENTION = "Mention"
|
||||||
|
HASHTAG = "Hashtag"
|
||||||
|
|
||||||
# Mastodon specific?
|
# Mastodon specific?
|
||||||
QUESTION = "Question"
|
QUESTION = "Question"
|
||||||
|
@ -616,6 +617,15 @@ class Mention(BaseActivity):
|
||||||
ACTOR_REQUIRED = False
|
ACTOR_REQUIRED = False
|
||||||
|
|
||||||
|
|
||||||
|
class Hashtag(BaseActivity):
|
||||||
|
ACTIVITY_TYPE = ActivityType.HASHTAG
|
||||||
|
OBJECT_REQUIRED = False
|
||||||
|
ACTOR_REQUIRED = False
|
||||||
|
|
||||||
|
def get_value(self) -> str:
|
||||||
|
return self.name[1:]
|
||||||
|
|
||||||
|
|
||||||
class Person(BaseActivity):
|
class Person(BaseActivity):
|
||||||
ACTIVITY_TYPE = ActivityType.PERSON
|
ACTIVITY_TYPE = ActivityType.PERSON
|
||||||
OBJECT_REQUIRED = False
|
OBJECT_REQUIRED = False
|
||||||
|
@ -929,6 +939,21 @@ class Note(BaseActivity):
|
||||||
|
|
||||||
return mentions
|
return mentions
|
||||||
|
|
||||||
|
def get_hashtags(self) -> List["Hashtag"]:
|
||||||
|
if self.tag is None:
|
||||||
|
return []
|
||||||
|
|
||||||
|
hashtags = []
|
||||||
|
for tag in self.tag:
|
||||||
|
# Some AP implemention return "type"less tag for links
|
||||||
|
if "type" not in tag:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if _has_type(tag["type"], ActivityType.HASHTAG):
|
||||||
|
hashtags.append(Hashtag(**tag))
|
||||||
|
|
||||||
|
return hashtags
|
||||||
|
|
||||||
def get_in_reply_to(self) -> Optional[str]:
|
def get_in_reply_to(self) -> Optional[str]:
|
||||||
return _get_id(self.inReplyTo)
|
return _get_id(self.inReplyTo)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue