2022-12-24 16:34:24 +00:00
|
|
|
"""app.bsky.feed.* XRPC methods."""
|
2022-12-28 17:27:42 +00:00
|
|
|
import logging
|
|
|
|
|
2022-12-25 05:08:12 +00:00
|
|
|
from app import xrpc_server
|
|
|
|
|
2022-12-28 17:27:42 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2022-12-25 05:08:12 +00:00
|
|
|
@xrpc_server.method('app.bsky.feed.getAuthorFeed')
|
2022-12-29 01:30:22 +00:00
|
|
|
def getAuthorFeed(input, author=None, limit=None, before=None):
|
2022-12-25 05:08:12 +00:00
|
|
|
"""
|
2022-12-29 01:30:22 +00:00
|
|
|
lexicons/app/bsky/feed/getAuthorFeed.json, feedViewPost.json
|
2022-12-25 05:08:12 +00:00
|
|
|
"""
|
2022-12-29 01:30:22 +00:00
|
|
|
if not re.match(util.DOMAIN_RE, author):
|
|
|
|
raise ValueError(f'{actor} is not a domain')
|
|
|
|
|
|
|
|
url = f'https://{actor}/'
|
|
|
|
mf2 = util.fetch_mf2(url, gateway=True)
|
|
|
|
hcard = mf2util.representative_hcard(mf2, mf2['url'])
|
|
|
|
if not hcard:
|
|
|
|
raise ValueError(f"Couldn't find a representative h-card (http://microformats.org/wiki/representative-hcard-parsing) on {mf2['url']}")
|
|
|
|
|
|
|
|
logger.info(f'Representative h-card: {json.dumps(hcard, indent=2)}')
|
|
|
|
|
|
|
|
actor = microformats2.json_to_object(hcard)
|
|
|
|
logger.info(f'AS1 actor: {json.dumps(actor, indent=2)}')
|
|
|
|
|
|
|
|
profile = {
|
|
|
|
**bluesky.from_as1(actor, from_url=url),
|
|
|
|
'myState': {
|
|
|
|
# ?
|
|
|
|
'follow': 'TODO',
|
|
|
|
'member': 'TODO',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
logger.info(f'Bluesky profile: {json.dumps(profile, indent=2)}')
|
|
|
|
return profile
|
|
|
|
|
2022-12-25 05:08:12 +00:00
|
|
|
|
|
|
|
@xrpc_server.method('app.bsky.feed.getPostThread')
|
2022-12-28 17:27:42 +00:00
|
|
|
def getPostThread(input):
|
2022-12-25 05:08:12 +00:00
|
|
|
"""
|
|
|
|
lexicons/app/bsky/feed/getPostThread.json
|
|
|
|
"""
|
|
|
|
|
|
|
|
@xrpc_server.method('app.bsky.feed.getRepostedBy')
|
2022-12-28 17:27:42 +00:00
|
|
|
def getRepostedBy(input):
|
2022-12-25 05:08:12 +00:00
|
|
|
"""
|
|
|
|
lexicons/app/bsky/feed/getRepostedBy.json
|
|
|
|
"""
|
|
|
|
|
|
|
|
@xrpc_server.method('app.bsky.feed.getTimeline')
|
2022-12-28 17:27:42 +00:00
|
|
|
def getTimeline(input):
|
2022-12-25 05:08:12 +00:00
|
|
|
"""
|
|
|
|
lexicons/app/bsky/feed/getTimeline.json
|
|
|
|
"""
|
|
|
|
|
|
|
|
@xrpc_server.method('app.bsky.feed.getVotes')
|
2022-12-28 17:27:42 +00:00
|
|
|
def getVotes(input):
|
2022-12-25 05:08:12 +00:00
|
|
|
"""
|
|
|
|
lexicons/app/bsky/feed/getVotes.json
|
|
|
|
"""
|
|
|
|
|
|
|
|
@xrpc_server.method('app.bsky.feed.setVote')
|
2022-12-28 17:27:42 +00:00
|
|
|
def setVote(input):
|
2022-12-25 05:08:12 +00:00
|
|
|
"""
|
|
|
|
lexicons/app/bsky/feed/setVote.json
|
|
|
|
"""
|