Stub out more API, implement preferences and peers (#533)
This commit is contained in:
parent
6f4abd5aae
commit
3bd01b2b3d
|
@ -273,6 +273,14 @@ class Tag(Schema):
|
||||||
return cls(**hashtag.to_mastodon_json())
|
return cls(**hashtag.to_mastodon_json())
|
||||||
|
|
||||||
|
|
||||||
|
class FeaturedTag(Schema):
|
||||||
|
id: str
|
||||||
|
name: str
|
||||||
|
url: str
|
||||||
|
statuses_count: int
|
||||||
|
last_status_at: str
|
||||||
|
|
||||||
|
|
||||||
class Search(Schema):
|
class Search(Schema):
|
||||||
accounts: list[Account]
|
accounts: list[Account]
|
||||||
statuses: list[Status]
|
statuses: list[Status]
|
||||||
|
@ -337,3 +345,54 @@ class Announcement(Schema):
|
||||||
user: users_models.User,
|
user: users_models.User,
|
||||||
) -> "Announcement":
|
) -> "Announcement":
|
||||||
return cls(**announcement.to_mastodon_json(user=user))
|
return cls(**announcement.to_mastodon_json(user=user))
|
||||||
|
|
||||||
|
|
||||||
|
class List(Schema):
|
||||||
|
id: str
|
||||||
|
title: str
|
||||||
|
replies_policy: Literal[
|
||||||
|
"followed",
|
||||||
|
"list",
|
||||||
|
"none",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Preferences(Schema):
|
||||||
|
posting_default_visibility: Literal[
|
||||||
|
"public",
|
||||||
|
"unlisted",
|
||||||
|
"private",
|
||||||
|
"direct",
|
||||||
|
] = Field(alias="posting:default:visibility")
|
||||||
|
posting_default_sensitive: bool = Field(alias="posting:default:sensitive")
|
||||||
|
posting_default_language: str | None = Field(alias="posting:default:language")
|
||||||
|
reading_expand_media: Literal[
|
||||||
|
"default",
|
||||||
|
"show_all",
|
||||||
|
"hide_all",
|
||||||
|
] = Field(alias="reading:expand:media")
|
||||||
|
reading_expand_spoilers: bool = Field(alias="reading:expand:spoilers")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_identity(
|
||||||
|
cls,
|
||||||
|
identity: users_models.Identity,
|
||||||
|
) -> "Preferences":
|
||||||
|
visibility_mapping = {
|
||||||
|
activities_models.Post.Visibilities.public: "public",
|
||||||
|
activities_models.Post.Visibilities.unlisted: "unlisted",
|
||||||
|
activities_models.Post.Visibilities.followers: "private",
|
||||||
|
activities_models.Post.Visibilities.mentioned: "direct",
|
||||||
|
activities_models.Post.Visibilities.local_only: "public",
|
||||||
|
}
|
||||||
|
return cls.parse_obj(
|
||||||
|
{
|
||||||
|
"posting:default:visibility": visibility_mapping[
|
||||||
|
identity.config_identity.default_post_visibility
|
||||||
|
],
|
||||||
|
"posting:default:sensitive": False,
|
||||||
|
"posting:default:language": None,
|
||||||
|
"reading:expand:media": "default",
|
||||||
|
"reading:expand:spoilers": identity.config_identity.expand_linked_cws,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
17
api/urls.py
17
api/urls.py
|
@ -5,14 +5,19 @@ from api.views import (
|
||||||
accounts,
|
accounts,
|
||||||
announcements,
|
announcements,
|
||||||
apps,
|
apps,
|
||||||
|
bookmarks,
|
||||||
emoji,
|
emoji,
|
||||||
filters,
|
filters,
|
||||||
|
follow_requests,
|
||||||
instance,
|
instance,
|
||||||
|
lists,
|
||||||
media,
|
media,
|
||||||
notifications,
|
notifications,
|
||||||
polls,
|
polls,
|
||||||
|
preferences,
|
||||||
search,
|
search,
|
||||||
statuses,
|
statuses,
|
||||||
|
tags,
|
||||||
timelines,
|
timelines,
|
||||||
trends,
|
trends,
|
||||||
)
|
)
|
||||||
|
@ -35,19 +40,27 @@ urlpatterns = [
|
||||||
path("v1/accounts/<id>/unmute", accounts.account_unmute),
|
path("v1/accounts/<id>/unmute", accounts.account_unmute),
|
||||||
path("v1/accounts/<id>/following", accounts.account_following),
|
path("v1/accounts/<id>/following", accounts.account_following),
|
||||||
path("v1/accounts/<id>/followers", accounts.account_followers),
|
path("v1/accounts/<id>/followers", accounts.account_followers),
|
||||||
|
path("v1/accounts/<id>/featured_tags", accounts.account_featured_tags),
|
||||||
# Announcements
|
# Announcements
|
||||||
path("v1/announcements", announcements.announcement_list),
|
path("v1/announcements", announcements.announcement_list),
|
||||||
path("v1/announcements/<pk>/dismiss", announcements.announcement_dismiss),
|
path("v1/announcements/<pk>/dismiss", announcements.announcement_dismiss),
|
||||||
# Apps
|
# Apps
|
||||||
path("v1/apps", apps.add_app),
|
path("v1/apps", apps.add_app),
|
||||||
|
# Bookmarks
|
||||||
|
path("v1/bookmarks", bookmarks.bookmarks),
|
||||||
# Emoji
|
# Emoji
|
||||||
path("v1/custom_emojis", emoji.emojis),
|
path("v1/custom_emojis", emoji.emojis),
|
||||||
# Filters
|
# Filters
|
||||||
path("v2/filters", filters.list_filters),
|
path("v2/filters", filters.list_filters),
|
||||||
path("v1/filters", filters.list_filters),
|
path("v1/filters", filters.list_filters),
|
||||||
|
# Follow requests
|
||||||
|
path("v1/follow_requests", follow_requests.follow_requests),
|
||||||
# Instance
|
# Instance
|
||||||
path("v1/instance", instance.instance_info_v1),
|
path("v1/instance", instance.instance_info_v1),
|
||||||
|
path("v1/instance/peers", instance.peers),
|
||||||
path("v2/instance", instance.instance_info_v2),
|
path("v2/instance", instance.instance_info_v2),
|
||||||
|
# Lists
|
||||||
|
path("v1/lists", lists.get_lists),
|
||||||
# Media
|
# Media
|
||||||
path("v1/media", media.upload_media),
|
path("v1/media", media.upload_media),
|
||||||
path("v2/media", media.upload_media),
|
path("v2/media", media.upload_media),
|
||||||
|
@ -66,6 +79,8 @@ urlpatterns = [
|
||||||
# Polls
|
# Polls
|
||||||
path("v1/polls/<id>", polls.get_poll),
|
path("v1/polls/<id>", polls.get_poll),
|
||||||
path("v1/polls/<id>/votes", polls.vote_poll),
|
path("v1/polls/<id>/votes", polls.vote_poll),
|
||||||
|
# Preferences
|
||||||
|
path("v1/preferences", preferences.preferences),
|
||||||
# Search
|
# Search
|
||||||
path("v2/search", search.search),
|
path("v2/search", search.search),
|
||||||
# Statuses
|
# Statuses
|
||||||
|
@ -76,6 +91,8 @@ urlpatterns = [
|
||||||
path("v1/statuses/<id>/favourited_by", statuses.favourited_by),
|
path("v1/statuses/<id>/favourited_by", statuses.favourited_by),
|
||||||
path("v1/statuses/<id>/reblog", statuses.reblog_status),
|
path("v1/statuses/<id>/reblog", statuses.reblog_status),
|
||||||
path("v1/statuses/<id>/unreblog", statuses.unreblog_status),
|
path("v1/statuses/<id>/unreblog", statuses.unreblog_status),
|
||||||
|
# Tags
|
||||||
|
path("v1/followed_tags", tags.followed_tags),
|
||||||
# Timelines
|
# Timelines
|
||||||
path("v1/timelines/home", timelines.home),
|
path("v1/timelines/home", timelines.home),
|
||||||
path("v1/timelines/public", timelines.public),
|
path("v1/timelines/public", timelines.public),
|
||||||
|
|
|
@ -349,3 +349,9 @@ def account_followers(
|
||||||
request=request,
|
request=request,
|
||||||
include_params=["limit"],
|
include_params=["limit"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@api_view.get
|
||||||
|
def account_featured_tags(request: HttpRequest, id: str) -> list[schemas.FeaturedTag]:
|
||||||
|
# Not implemented yet
|
||||||
|
return []
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
from django.http import HttpRequest
|
||||||
|
from hatchway import api_view
|
||||||
|
|
||||||
|
from api import schemas
|
||||||
|
from api.decorators import scope_required
|
||||||
|
|
||||||
|
|
||||||
|
@scope_required("read:bookmarks")
|
||||||
|
@api_view.get
|
||||||
|
def bookmarks(
|
||||||
|
request: HttpRequest,
|
||||||
|
max_id: str | None = None,
|
||||||
|
since_id: str | None = None,
|
||||||
|
min_id: str | None = None,
|
||||||
|
limit: int = 20,
|
||||||
|
) -> list[schemas.Status]:
|
||||||
|
# We don't implement this yet
|
||||||
|
return []
|
|
@ -0,0 +1,18 @@
|
||||||
|
from django.http import HttpRequest
|
||||||
|
from hatchway import api_view
|
||||||
|
|
||||||
|
from api import schemas
|
||||||
|
from api.decorators import scope_required
|
||||||
|
|
||||||
|
|
||||||
|
@scope_required("read:follows")
|
||||||
|
@api_view.get
|
||||||
|
def follow_requests(
|
||||||
|
request: HttpRequest,
|
||||||
|
max_id: str | None = None,
|
||||||
|
since_id: str | None = None,
|
||||||
|
min_id: str | None = None,
|
||||||
|
limit: int = 40,
|
||||||
|
) -> list[schemas.Account]:
|
||||||
|
# We don't implement this yet
|
||||||
|
return []
|
|
@ -130,3 +130,12 @@ def instance_info_v2(request) -> dict:
|
||||||
},
|
},
|
||||||
"rules": [],
|
"rules": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@api_view.get
|
||||||
|
def peers(request) -> list[str]:
|
||||||
|
return list(
|
||||||
|
Domain.objects.filter(local=False, blocked=False).values_list(
|
||||||
|
"domain", flat=True
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
from django.http import HttpRequest
|
||||||
|
from hatchway import api_view
|
||||||
|
|
||||||
|
from api import schemas
|
||||||
|
from api.decorators import scope_required
|
||||||
|
|
||||||
|
|
||||||
|
@scope_required("read:lists")
|
||||||
|
@api_view.get
|
||||||
|
def get_lists(request: HttpRequest) -> list[schemas.List]:
|
||||||
|
# We don't implement this yet
|
||||||
|
return []
|
|
@ -0,0 +1,13 @@
|
||||||
|
from django.http import HttpRequest
|
||||||
|
from hatchway import api_view
|
||||||
|
|
||||||
|
from api import schemas
|
||||||
|
from api.decorators import scope_required
|
||||||
|
|
||||||
|
|
||||||
|
@scope_required("read:accounts")
|
||||||
|
@api_view.get
|
||||||
|
def preferences(request: HttpRequest) -> dict:
|
||||||
|
# Ideally this should just return Preferences; maybe hatchway needs a way to
|
||||||
|
# indicate response models should be serialized by alias?
|
||||||
|
return schemas.Preferences.from_identity(request.identity).dict(by_alias=True)
|
|
@ -0,0 +1,18 @@
|
||||||
|
from django.http import HttpRequest
|
||||||
|
from hatchway import api_view
|
||||||
|
|
||||||
|
from api import schemas
|
||||||
|
from api.decorators import scope_required
|
||||||
|
|
||||||
|
|
||||||
|
@scope_required("read:follows")
|
||||||
|
@api_view.get
|
||||||
|
def followed_tags(
|
||||||
|
request: HttpRequest,
|
||||||
|
max_id: str | None = None,
|
||||||
|
since_id: str | None = None,
|
||||||
|
min_id: str | None = None,
|
||||||
|
limit: int = 100,
|
||||||
|
) -> list[schemas.Tag]:
|
||||||
|
# We don't implement this yet
|
||||||
|
return []
|
Loading…
Reference in New Issue