mirror of https://gitlab.com/bashrc2/epicyon
Getting follow requests collection via c2s
parent
0f70a98ed4
commit
76fba0e5dd
11
daemon.py
11
daemon.py
|
@ -10616,6 +10616,17 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.followingItemsPerPage,
|
||||
self.server.debug, 'followers')
|
||||
return
|
||||
elif '/followrequests?page=' in self.path:
|
||||
self._getFollowingJson(self.server.baseDir,
|
||||
self.path,
|
||||
callingDomain,
|
||||
self.server.httpPrefix,
|
||||
self.server.domain,
|
||||
self.server.port,
|
||||
self.server.followingItemsPerPage,
|
||||
self.server.debug,
|
||||
'followrequests')
|
||||
return
|
||||
|
||||
# authorized endpoint used for TTS of posts
|
||||
# arriving in your inbox
|
||||
|
|
35
epicyon.py
35
epicyon.py
|
@ -46,6 +46,7 @@ from filters import addFilter
|
|||
from filters import removeFilter
|
||||
from pprint import pprint
|
||||
from daemon import runDaemon
|
||||
from follow import getFollowRequestsViaServer
|
||||
from follow import getFollowingViaServer
|
||||
from follow import getFollowersViaServer
|
||||
from follow import clearFollows
|
||||
|
@ -262,6 +263,12 @@ parser.add_argument("--followersList",
|
|||
const=True, default=False,
|
||||
help="Get the followers list. Use nickname and " +
|
||||
"domain options to specify the account")
|
||||
parser.add_argument("--followRequestsList",
|
||||
dest='followRequestsList',
|
||||
type=str2bool, nargs='?',
|
||||
const=True, default=False,
|
||||
help="Get the follow requests list. Use nickname and " +
|
||||
"domain options to specify the account")
|
||||
parser.add_argument("--repliesEnabled", "--commentsEnabled",
|
||||
dest='commentsEnabled',
|
||||
type=str2bool, nargs='?',
|
||||
|
@ -1554,6 +1561,34 @@ if args.followersList:
|
|||
pprint(followersJson)
|
||||
sys.exit()
|
||||
|
||||
if args.followRequestsList:
|
||||
# follow requests list via c2s protocol
|
||||
if not args.nickname:
|
||||
print('Please specify the nickname for the account with --nickname')
|
||||
sys.exit()
|
||||
if not args.password:
|
||||
args.password = getpass.getpass('Password: ')
|
||||
if not args.password:
|
||||
print('Specify a password with the --password option')
|
||||
sys.exit()
|
||||
args.password = args.password.replace('\n', '')
|
||||
|
||||
session = createSession(proxyType)
|
||||
personCache = {}
|
||||
cachedWebfingers = {}
|
||||
followHttpPrefix = httpPrefix
|
||||
|
||||
followRequestsJson = \
|
||||
getFollowRequestsViaServer(baseDir, session,
|
||||
args.nickname, args.password,
|
||||
domain, port,
|
||||
httpPrefix, args.pageNumber,
|
||||
cachedWebfingers, personCache,
|
||||
debug, __version__)
|
||||
if followRequestsJson:
|
||||
pprint(followRequestsJson)
|
||||
sys.exit()
|
||||
|
||||
nickname = 'admin'
|
||||
if args.domain:
|
||||
domain = args.domain
|
||||
|
|
76
follow.py
76
follow.py
|
@ -1281,6 +1281,82 @@ def getFollowersViaServer(baseDir: str, session,
|
|||
return followersJson
|
||||
|
||||
|
||||
def getFollowRequestsViaServer(baseDir: str, session,
|
||||
nickname: str, password: str,
|
||||
domain: str, port: int,
|
||||
httpPrefix: str, pageNumber: int,
|
||||
cachedWebfingers: {}, personCache: {},
|
||||
debug: bool, projectVersion: str) -> {}:
|
||||
"""Gets a page from the follow requests collection as json
|
||||
"""
|
||||
if not session:
|
||||
print('WARN: No session for getFollowRequestsViaServer')
|
||||
return 6
|
||||
|
||||
domainFull = getFullDomain(domain, port)
|
||||
|
||||
followActor = httpPrefix + '://' + domainFull + '/users/' + nickname
|
||||
handle = httpPrefix + '://' + domainFull + '/@' + nickname
|
||||
|
||||
# lookup the inbox for the To handle
|
||||
wfRequest = \
|
||||
webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
|
||||
domain, projectVersion, debug)
|
||||
if not wfRequest:
|
||||
if debug:
|
||||
print('DEBUG: follow requests list webfinger failed for ' +
|
||||
handle)
|
||||
return 1
|
||||
if not isinstance(wfRequest, dict):
|
||||
print('WARN: follow requests list Webfinger for ' + handle +
|
||||
' did not return a dict. ' + str(wfRequest))
|
||||
return 1
|
||||
|
||||
postToBox = 'outbox'
|
||||
|
||||
# get the actor inbox for the To handle
|
||||
(inboxUrl, pubKeyId, pubKey,
|
||||
fromPersonId, sharedInbox, avatarUrl,
|
||||
displayName) = getPersonBox(baseDir, session, wfRequest, personCache,
|
||||
projectVersion, httpPrefix, nickname,
|
||||
domain, postToBox, 42759)
|
||||
|
||||
if not inboxUrl:
|
||||
if debug:
|
||||
print('DEBUG: follow requests list no ' + postToBox +
|
||||
' was found for ' + handle)
|
||||
return 3
|
||||
if not fromPersonId:
|
||||
if debug:
|
||||
print('DEBUG: follow requests list no actor was found for ' +
|
||||
handle)
|
||||
return 4
|
||||
|
||||
authHeader = createBasicAuthHeader(nickname, password)
|
||||
|
||||
headers = {
|
||||
'host': domain,
|
||||
'Content-type': 'application/json',
|
||||
'Authorization': authHeader
|
||||
}
|
||||
|
||||
if pageNumber < 1:
|
||||
pageNumber = 1
|
||||
url = followActor + '/followrequests?page=' + str(pageNumber)
|
||||
followersJson = \
|
||||
getJson(session, url, headers, {}, debug,
|
||||
__version__, httpPrefix, domain, 10, True)
|
||||
if not followersJson:
|
||||
if debug:
|
||||
print('DEBUG: GET follow requests list failed for c2s to ' + url)
|
||||
return 5
|
||||
|
||||
if debug:
|
||||
print('DEBUG: c2s GET follow requests list request success')
|
||||
|
||||
return followersJson
|
||||
|
||||
|
||||
def getFollowersOfActor(baseDir: str, actor: str, debug: bool) -> {}:
|
||||
"""In a shared inbox if we receive a post we know who it's from
|
||||
and if it's addressed to followers then we need to get a list of those.
|
||||
|
|
Loading…
Reference in New Issue