2020-04-01 19:11:39 +00:00
|
|
|
__filename__ = "announce.py"
|
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
2021-01-26 10:07:42 +00:00
|
|
|
__version__ = "1.2.0"
|
2020-04-01 19:11:39 +00:00
|
|
|
__maintainer__ = "Bob Mottram"
|
2021-09-10 16:14:50 +00:00
|
|
|
__email__ = "bob@libreserver.org"
|
2020-04-01 19:11:39 +00:00
|
|
|
__status__ = "Production"
|
2021-06-15 15:08:12 +00:00
|
|
|
__module_group__ = "ActivityPub"
|
2019-07-02 09:25:29 +00:00
|
|
|
|
2021-12-26 15:54:46 +00:00
|
|
|
from utils import has_object_string_object
|
2021-12-26 17:53:07 +00:00
|
|
|
from utils import has_group_type
|
2021-12-26 18:17:37 +00:00
|
|
|
from utils import remove_domain_port
|
2021-12-27 11:20:57 +00:00
|
|
|
from utils import remove_id_ending
|
2021-12-26 12:19:00 +00:00
|
|
|
from utils import has_users_path
|
2021-12-26 12:45:03 +00:00
|
|
|
from utils import get_full_domain
|
2021-12-27 17:42:35 +00:00
|
|
|
from utils import get_status_number
|
2021-12-27 17:57:27 +00:00
|
|
|
from utils import create_outbox_dir
|
2021-12-27 20:47:05 +00:00
|
|
|
from utils import url_permitted
|
2021-12-27 22:19:18 +00:00
|
|
|
from utils import get_nickname_from_actor
|
2021-12-27 19:05:25 +00:00
|
|
|
from utils import get_domain_from_actor
|
2021-12-26 20:36:08 +00:00
|
|
|
from utils import locate_post
|
2021-12-26 14:47:21 +00:00
|
|
|
from utils import save_json
|
2021-12-27 10:55:48 +00:00
|
|
|
from utils import undo_announce_collection_entry
|
2021-12-26 23:41:34 +00:00
|
|
|
from utils import update_announce_collection
|
2021-12-26 10:19:59 +00:00
|
|
|
from utils import local_actor_url
|
2021-12-26 17:21:37 +00:00
|
|
|
from utils import replace_users_with_at
|
2021-12-26 17:15:04 +00:00
|
|
|
from utils import has_actor
|
2021-12-26 17:12:07 +00:00
|
|
|
from utils import has_object_stringType
|
2021-12-29 21:55:09 +00:00
|
|
|
from posts import send_signed_json
|
|
|
|
from posts import get_person_box
|
|
|
|
from session import post_json
|
|
|
|
from webfinger import webfinger_handle
|
2021-12-28 21:36:27 +00:00
|
|
|
from auth import create_basic_auth_header
|
2019-07-02 09:25:29 +00:00
|
|
|
|
2020-04-01 19:11:39 +00:00
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
def is_self_announce(post_json_object: {}) -> bool:
|
2021-06-22 19:43:03 +00:00
|
|
|
"""Is the given post a self announce?
|
|
|
|
"""
|
2021-12-25 22:09:19 +00:00
|
|
|
if not post_json_object.get('actor'):
|
2021-06-22 19:43:03 +00:00
|
|
|
return False
|
2021-12-25 22:09:19 +00:00
|
|
|
if not post_json_object.get('type'):
|
2021-06-22 19:43:03 +00:00
|
|
|
return False
|
2021-12-25 22:09:19 +00:00
|
|
|
if post_json_object['type'] != 'Announce':
|
2021-06-22 19:43:03 +00:00
|
|
|
return False
|
2021-12-25 22:09:19 +00:00
|
|
|
if not post_json_object.get('object'):
|
2021-06-22 19:43:03 +00:00
|
|
|
return False
|
2021-12-25 22:09:19 +00:00
|
|
|
if not isinstance(post_json_object['actor'], str):
|
2021-06-22 19:43:03 +00:00
|
|
|
return False
|
2021-12-25 22:09:19 +00:00
|
|
|
if not isinstance(post_json_object['object'], str):
|
2021-06-22 19:43:03 +00:00
|
|
|
return False
|
2021-12-25 22:09:19 +00:00
|
|
|
return post_json_object['actor'] in post_json_object['object']
|
2021-06-22 19:43:03 +00:00
|
|
|
|
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
def outbox_announce(recent_posts_cache: {},
|
|
|
|
base_dir: str, message_json: {}, debug: bool) -> bool:
|
2019-08-01 11:43:22 +00:00
|
|
|
""" Adds or removes announce entries from the shares collection
|
|
|
|
within a given post
|
|
|
|
"""
|
2021-12-26 17:15:04 +00:00
|
|
|
if not has_actor(message_json, debug):
|
2019-08-01 11:43:22 +00:00
|
|
|
return False
|
2021-12-25 23:51:19 +00:00
|
|
|
if not isinstance(message_json['actor'], str):
|
2021-06-03 08:33:50 +00:00
|
|
|
return False
|
2021-12-25 23:51:19 +00:00
|
|
|
if not message_json.get('type'):
|
2019-08-01 11:43:22 +00:00
|
|
|
return False
|
2021-12-25 23:51:19 +00:00
|
|
|
if not message_json.get('object'):
|
2019-08-01 11:43:22 +00:00
|
|
|
return False
|
2021-12-25 23:51:19 +00:00
|
|
|
if message_json['type'] == 'Announce':
|
|
|
|
if not isinstance(message_json['object'], str):
|
2019-09-02 09:43:43 +00:00
|
|
|
return False
|
2021-12-29 21:55:09 +00:00
|
|
|
if is_self_announce(message_json):
|
2021-06-03 08:33:50 +00:00
|
|
|
return False
|
2021-12-27 22:19:18 +00:00
|
|
|
nickname = get_nickname_from_actor(message_json['actor'])
|
2019-09-02 09:43:43 +00:00
|
|
|
if not nickname:
|
2021-12-25 23:51:19 +00:00
|
|
|
print('WARN: no nickname found in ' + message_json['actor'])
|
2019-09-02 09:43:43 +00:00
|
|
|
return False
|
2021-12-27 19:05:25 +00:00
|
|
|
domain, _ = get_domain_from_actor(message_json['actor'])
|
2021-12-26 23:41:34 +00:00
|
|
|
post_filename = locate_post(base_dir, nickname, domain,
|
|
|
|
message_json['object'])
|
|
|
|
if post_filename:
|
|
|
|
update_announce_collection(recent_posts_cache,
|
|
|
|
base_dir, post_filename,
|
|
|
|
message_json['actor'],
|
|
|
|
nickname, domain, debug)
|
2019-08-01 11:43:22 +00:00
|
|
|
return True
|
2021-12-25 23:51:19 +00:00
|
|
|
elif message_json['type'] == 'Undo':
|
2021-12-26 17:12:07 +00:00
|
|
|
if not has_object_stringType(message_json, debug):
|
2019-08-01 11:43:22 +00:00
|
|
|
return False
|
2021-12-25 23:51:19 +00:00
|
|
|
if message_json['object']['type'] == 'Announce':
|
|
|
|
if not isinstance(message_json['object']['object'], str):
|
2019-09-02 09:43:43 +00:00
|
|
|
return False
|
2021-12-27 22:19:18 +00:00
|
|
|
nickname = get_nickname_from_actor(message_json['actor'])
|
2019-09-02 09:43:43 +00:00
|
|
|
if not nickname:
|
2021-12-25 23:51:19 +00:00
|
|
|
print('WARN: no nickname found in ' + message_json['actor'])
|
2019-09-02 09:43:43 +00:00
|
|
|
return False
|
2021-12-27 19:05:25 +00:00
|
|
|
domain, _ = get_domain_from_actor(message_json['actor'])
|
2021-12-26 23:41:34 +00:00
|
|
|
post_filename = locate_post(base_dir, nickname, domain,
|
|
|
|
message_json['object']['object'])
|
|
|
|
if post_filename:
|
2021-12-27 10:55:48 +00:00
|
|
|
undo_announce_collection_entry(recent_posts_cache,
|
|
|
|
base_dir, post_filename,
|
|
|
|
message_json['actor'],
|
|
|
|
domain, debug)
|
2019-08-01 11:43:22 +00:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2020-04-01 19:11:39 +00:00
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
def announced_by_person(isAnnounced: bool, postActor: str,
|
|
|
|
nickname: str, domain_full: str) -> bool:
|
2019-08-01 09:31:38 +00:00
|
|
|
"""Returns True if the given post is announced by the given person
|
|
|
|
"""
|
2021-05-07 22:49:04 +00:00
|
|
|
if not postActor:
|
2021-05-07 13:26:00 +00:00
|
|
|
return False
|
2021-05-07 21:10:55 +00:00
|
|
|
if isAnnounced and \
|
2021-12-26 10:00:46 +00:00
|
|
|
postActor.endswith(domain_full + '/users/' + nickname):
|
2021-05-07 21:10:55 +00:00
|
|
|
return True
|
2019-08-01 09:31:38 +00:00
|
|
|
return False
|
|
|
|
|
2020-04-01 19:11:39 +00:00
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
def create_announce(session, base_dir: str, federation_list: [],
|
|
|
|
nickname: str, domain: str, port: int,
|
|
|
|
toUrl: str, ccUrl: str, http_prefix: str,
|
|
|
|
objectUrl: str, saveToFile: bool,
|
|
|
|
client_to_server: bool,
|
|
|
|
send_threads: [], postLog: [],
|
|
|
|
person_cache: {}, cached_webfingers: {},
|
|
|
|
debug: bool, project_version: str,
|
|
|
|
signing_priv_key_pem: str) -> {}:
|
2019-07-02 09:25:29 +00:00
|
|
|
"""Creates an announce message
|
|
|
|
Typically toUrl will be https://www.w3.org/ns/activitystreams#Public
|
2019-07-06 17:00:22 +00:00
|
|
|
and ccUrl might be a specific person favorited or repeated and the
|
|
|
|
followers url objectUrl is typically the url of the message,
|
|
|
|
corresponding to url or atomUri in createPostBase
|
2019-07-02 09:25:29 +00:00
|
|
|
"""
|
2021-12-27 20:47:05 +00:00
|
|
|
if not url_permitted(objectUrl, federation_list):
|
2019-07-02 10:43:54 +00:00
|
|
|
return None
|
|
|
|
|
2021-12-26 18:17:37 +00:00
|
|
|
domain = remove_domain_port(domain)
|
2021-12-26 12:45:03 +00:00
|
|
|
fullDomain = get_full_domain(domain, port)
|
2020-04-01 19:11:39 +00:00
|
|
|
|
2021-12-27 17:42:35 +00:00
|
|
|
statusNumber, published = get_status_number()
|
2021-12-25 17:09:22 +00:00
|
|
|
newAnnounceId = http_prefix + '://' + fullDomain + \
|
2020-04-01 19:11:39 +00:00
|
|
|
'/users/' + nickname + '/statuses/' + statusNumber
|
2021-12-26 10:19:59 +00:00
|
|
|
atomUriStr = local_actor_url(http_prefix, nickname, fullDomain) + \
|
2020-04-01 19:11:39 +00:00
|
|
|
'/statuses/' + statusNumber
|
|
|
|
newAnnounce = {
|
2019-08-18 11:07:06 +00:00
|
|
|
"@context": "https://www.w3.org/ns/activitystreams",
|
2021-12-26 10:19:59 +00:00
|
|
|
'actor': local_actor_url(http_prefix, nickname, fullDomain),
|
2020-04-01 19:11:39 +00:00
|
|
|
'atomUri': atomUriStr,
|
2019-07-02 09:25:29 +00:00
|
|
|
'cc': [],
|
2020-08-23 11:13:35 +00:00
|
|
|
'id': newAnnounceId + '/activity',
|
2019-07-02 09:25:29 +00:00
|
|
|
'object': objectUrl,
|
|
|
|
'published': published,
|
|
|
|
'to': [toUrl],
|
|
|
|
'type': 'Announce'
|
|
|
|
}
|
|
|
|
if ccUrl:
|
2020-04-01 19:11:39 +00:00
|
|
|
if len(ccUrl) > 0:
|
|
|
|
newAnnounce['cc'] = [ccUrl]
|
2019-07-02 09:25:29 +00:00
|
|
|
if saveToFile:
|
2021-12-27 17:57:27 +00:00
|
|
|
outboxDir = create_outbox_dir(nickname, domain, base_dir)
|
2020-04-01 19:11:39 +00:00
|
|
|
filename = outboxDir + '/' + newAnnounceId.replace('/', '#') + '.json'
|
2021-12-26 14:47:21 +00:00
|
|
|
save_json(newAnnounce, filename)
|
2019-07-11 17:55:10 +00:00
|
|
|
|
2020-04-01 19:11:39 +00:00
|
|
|
announceNickname = None
|
|
|
|
announceDomain = None
|
|
|
|
announcePort = None
|
2021-12-26 00:07:44 +00:00
|
|
|
group_account = False
|
2021-12-26 12:19:00 +00:00
|
|
|
if has_users_path(objectUrl):
|
2021-12-27 22:19:18 +00:00
|
|
|
announceNickname = get_nickname_from_actor(objectUrl)
|
2021-12-27 19:05:25 +00:00
|
|
|
announceDomain, announcePort = get_domain_from_actor(objectUrl)
|
2021-07-31 13:19:45 +00:00
|
|
|
if '/' + str(announceNickname) + '/' in objectUrl:
|
|
|
|
announceActor = \
|
|
|
|
objectUrl.split('/' + announceNickname + '/')[0] + \
|
|
|
|
'/' + announceNickname
|
2021-12-26 17:53:07 +00:00
|
|
|
if has_group_type(base_dir, announceActor, person_cache):
|
2021-12-26 00:07:44 +00:00
|
|
|
group_account = True
|
2019-07-11 17:55:10 +00:00
|
|
|
|
|
|
|
if announceNickname and announceDomain:
|
2021-12-29 21:55:09 +00:00
|
|
|
send_signed_json(newAnnounce, session, base_dir,
|
|
|
|
nickname, domain, port,
|
|
|
|
announceNickname, announceDomain, announcePort, None,
|
|
|
|
http_prefix, True, client_to_server, federation_list,
|
|
|
|
send_threads, postLog, cached_webfingers,
|
|
|
|
person_cache,
|
|
|
|
debug, project_version, None, group_account,
|
|
|
|
signing_priv_key_pem, 639633)
|
2020-03-22 21:16:02 +00:00
|
|
|
|
2019-07-02 09:25:29 +00:00
|
|
|
return newAnnounce
|
|
|
|
|
2020-04-01 19:11:39 +00:00
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
def announce_public(session, base_dir: str, federation_list: [],
|
|
|
|
nickname: str, domain: str, port: int, http_prefix: str,
|
|
|
|
objectUrl: str, client_to_server: bool,
|
|
|
|
send_threads: [], postLog: [],
|
|
|
|
person_cache: {}, cached_webfingers: {},
|
|
|
|
debug: bool, project_version: str,
|
|
|
|
signing_priv_key_pem: str) -> {}:
|
2019-07-02 09:25:29 +00:00
|
|
|
"""Makes a public announcement
|
|
|
|
"""
|
2021-12-26 12:45:03 +00:00
|
|
|
fromDomain = get_full_domain(domain, port)
|
2020-04-01 19:11:39 +00:00
|
|
|
|
|
|
|
toUrl = 'https://www.w3.org/ns/activitystreams#Public'
|
2021-12-26 10:19:59 +00:00
|
|
|
ccUrl = local_actor_url(http_prefix, nickname, fromDomain) + '/followers'
|
2021-12-29 21:55:09 +00:00
|
|
|
return create_announce(session, base_dir, federation_list,
|
|
|
|
nickname, domain, port,
|
|
|
|
toUrl, ccUrl, http_prefix,
|
|
|
|
objectUrl, True, client_to_server,
|
|
|
|
send_threads, postLog,
|
|
|
|
person_cache, cached_webfingers,
|
|
|
|
debug, project_version,
|
|
|
|
signing_priv_key_pem)
|
|
|
|
|
|
|
|
|
|
|
|
def send_announce_via_server(base_dir: str, session,
|
|
|
|
fromNickname: str, password: str,
|
|
|
|
fromDomain: str, fromPort: int,
|
|
|
|
http_prefix: str, repeatObjectUrl: str,
|
|
|
|
cached_webfingers: {}, person_cache: {},
|
|
|
|
debug: bool, project_version: str,
|
|
|
|
signing_priv_key_pem: str) -> {}:
|
2019-07-16 19:07:45 +00:00
|
|
|
"""Creates an announce message via c2s
|
|
|
|
"""
|
|
|
|
if not session:
|
2021-12-29 21:55:09 +00:00
|
|
|
print('WARN: No session for send_announce_via_server')
|
2019-07-16 19:07:45 +00:00
|
|
|
return 6
|
|
|
|
|
2021-12-26 12:45:03 +00:00
|
|
|
fromDomainFull = get_full_domain(fromDomain, fromPort)
|
2019-07-16 19:07:45 +00:00
|
|
|
|
2020-04-01 19:11:39 +00:00
|
|
|
toUrl = 'https://www.w3.org/ns/activitystreams#Public'
|
2021-12-26 10:19:59 +00:00
|
|
|
actorStr = local_actor_url(http_prefix, fromNickname, fromDomainFull)
|
2021-08-14 11:13:39 +00:00
|
|
|
ccUrl = actorStr + '/followers'
|
2019-07-16 19:07:45 +00:00
|
|
|
|
2021-12-27 17:42:35 +00:00
|
|
|
statusNumber, published = get_status_number()
|
2021-08-14 11:13:39 +00:00
|
|
|
newAnnounceId = actorStr + '/statuses/' + statusNumber
|
2020-04-01 19:11:39 +00:00
|
|
|
newAnnounceJson = {
|
2019-08-18 11:07:06 +00:00
|
|
|
"@context": "https://www.w3.org/ns/activitystreams",
|
2021-06-22 12:42:52 +00:00
|
|
|
'actor': actorStr,
|
2019-07-16 19:07:45 +00:00
|
|
|
'atomUri': newAnnounceId,
|
|
|
|
'cc': [ccUrl],
|
2020-08-23 11:13:35 +00:00
|
|
|
'id': newAnnounceId + '/activity',
|
2019-07-16 19:07:45 +00:00
|
|
|
'object': repeatObjectUrl,
|
|
|
|
'published': published,
|
|
|
|
'to': [toUrl],
|
|
|
|
'type': 'Announce'
|
|
|
|
}
|
|
|
|
|
2021-12-25 17:09:22 +00:00
|
|
|
handle = http_prefix + '://' + fromDomainFull + '/@' + fromNickname
|
2019-07-16 19:07:45 +00:00
|
|
|
|
|
|
|
# lookup the inbox for the To handle
|
2021-12-29 21:55:09 +00:00
|
|
|
wfRequest = webfinger_handle(session, handle, http_prefix,
|
|
|
|
cached_webfingers,
|
|
|
|
fromDomain, project_version, debug, False,
|
|
|
|
signing_priv_key_pem)
|
2019-07-16 19:07:45 +00:00
|
|
|
if not wfRequest:
|
|
|
|
if debug:
|
2020-04-01 19:11:39 +00:00
|
|
|
print('DEBUG: announce webfinger failed for ' + handle)
|
2019-07-16 19:07:45 +00:00
|
|
|
return 1
|
2020-06-23 10:41:12 +00:00
|
|
|
if not isinstance(wfRequest, dict):
|
2021-03-18 10:01:01 +00:00
|
|
|
print('WARN: announce webfinger for ' + handle +
|
|
|
|
' did not return a dict. ' + str(wfRequest))
|
2020-06-23 10:41:12 +00:00
|
|
|
return 1
|
2019-07-16 19:07:45 +00:00
|
|
|
|
2020-04-01 19:11:39 +00:00
|
|
|
postToBox = 'outbox'
|
2019-07-16 19:07:45 +00:00
|
|
|
|
|
|
|
# get the actor inbox for the To handle
|
2021-09-15 14:05:08 +00:00
|
|
|
originDomain = fromDomain
|
2020-04-01 19:11:39 +00:00
|
|
|
(inboxUrl, pubKeyId, pubKey, fromPersonId,
|
2020-09-27 19:27:24 +00:00
|
|
|
sharedInbox, avatarUrl,
|
2021-12-29 21:55:09 +00:00
|
|
|
displayName, _) = get_person_box(signing_priv_key_pem,
|
|
|
|
originDomain,
|
|
|
|
base_dir, session, wfRequest,
|
|
|
|
person_cache,
|
|
|
|
project_version, http_prefix,
|
|
|
|
fromNickname, fromDomain,
|
|
|
|
postToBox, 73528)
|
2020-03-22 21:16:02 +00:00
|
|
|
|
2019-07-16 19:07:45 +00:00
|
|
|
if not inboxUrl:
|
|
|
|
if debug:
|
2021-03-18 10:01:01 +00:00
|
|
|
print('DEBUG: announce no ' + postToBox +
|
|
|
|
' was found for ' + handle)
|
2019-07-16 19:07:45 +00:00
|
|
|
return 3
|
|
|
|
if not fromPersonId:
|
|
|
|
if debug:
|
2021-03-18 10:01:01 +00:00
|
|
|
print('DEBUG: announce no actor was found for ' + handle)
|
2019-07-16 19:07:45 +00:00
|
|
|
return 4
|
2020-03-22 21:16:02 +00:00
|
|
|
|
2021-12-28 21:36:27 +00:00
|
|
|
authHeader = create_basic_auth_header(fromNickname, password)
|
2020-03-22 21:16:02 +00:00
|
|
|
|
2020-04-01 19:11:39 +00:00
|
|
|
headers = {
|
|
|
|
'host': fromDomain,
|
|
|
|
'Content-type': 'application/json',
|
2020-03-22 20:36:19 +00:00
|
|
|
'Authorization': authHeader
|
|
|
|
}
|
2021-12-29 21:55:09 +00:00
|
|
|
postResult = post_json(http_prefix, fromDomainFull,
|
|
|
|
session, newAnnounceJson, [], inboxUrl,
|
|
|
|
headers, 3, True)
|
2020-04-01 19:11:39 +00:00
|
|
|
if not postResult:
|
2021-03-18 10:01:01 +00:00
|
|
|
print('WARN: announce not posted')
|
2019-07-16 19:07:45 +00:00
|
|
|
|
|
|
|
if debug:
|
|
|
|
print('DEBUG: c2s POST announce success')
|
|
|
|
|
|
|
|
return newAnnounceJson
|
2021-03-18 20:56:08 +00:00
|
|
|
|
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
def send_undo_announce_via_server(base_dir: str, session,
|
|
|
|
undoPostJsonObject: {},
|
|
|
|
nickname: str, password: str,
|
|
|
|
domain: str, port: int,
|
|
|
|
http_prefix: str, repeatObjectUrl: str,
|
|
|
|
cached_webfingers: {}, person_cache: {},
|
|
|
|
debug: bool, project_version: str,
|
|
|
|
signing_priv_key_pem: str) -> {}:
|
2021-03-18 20:56:08 +00:00
|
|
|
"""Undo an announce message via c2s
|
|
|
|
"""
|
|
|
|
if not session:
|
2021-12-29 21:55:09 +00:00
|
|
|
print('WARN: No session for send_undo_announce_via_server')
|
2021-03-18 20:56:08 +00:00
|
|
|
return 6
|
|
|
|
|
2021-12-26 12:45:03 +00:00
|
|
|
domain_full = get_full_domain(domain, port)
|
2021-03-18 20:56:08 +00:00
|
|
|
|
2021-12-26 10:19:59 +00:00
|
|
|
actor = local_actor_url(http_prefix, nickname, domain_full)
|
2021-12-26 17:21:37 +00:00
|
|
|
handle = replace_users_with_at(actor)
|
2021-03-18 20:56:08 +00:00
|
|
|
|
2021-12-27 17:42:35 +00:00
|
|
|
statusNumber, published = get_status_number()
|
2021-03-18 20:56:08 +00:00
|
|
|
unAnnounceJson = {
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
'id': actor + '/statuses/' + str(statusNumber) + '/undo',
|
|
|
|
'type': 'Undo',
|
|
|
|
'actor': actor,
|
|
|
|
'object': undoPostJsonObject['object']
|
|
|
|
}
|
|
|
|
|
|
|
|
# lookup the inbox for the To handle
|
2021-12-29 21:55:09 +00:00
|
|
|
wfRequest = webfinger_handle(session, handle, http_prefix,
|
|
|
|
cached_webfingers,
|
|
|
|
domain, project_version, debug, False,
|
|
|
|
signing_priv_key_pem)
|
2021-03-18 20:56:08 +00:00
|
|
|
if not wfRequest:
|
|
|
|
if debug:
|
|
|
|
print('DEBUG: undo announce webfinger failed for ' + handle)
|
|
|
|
return 1
|
|
|
|
if not isinstance(wfRequest, dict):
|
|
|
|
print('WARN: undo announce webfinger for ' + handle +
|
|
|
|
' did not return a dict. ' + str(wfRequest))
|
|
|
|
return 1
|
|
|
|
|
|
|
|
postToBox = 'outbox'
|
|
|
|
|
|
|
|
# get the actor inbox for the To handle
|
2021-09-15 14:05:08 +00:00
|
|
|
originDomain = domain
|
2021-03-18 20:56:08 +00:00
|
|
|
(inboxUrl, pubKeyId, pubKey, fromPersonId,
|
|
|
|
sharedInbox, avatarUrl,
|
2021-12-29 21:55:09 +00:00
|
|
|
displayName, _) = get_person_box(signing_priv_key_pem,
|
|
|
|
originDomain,
|
|
|
|
base_dir, session, wfRequest,
|
|
|
|
person_cache,
|
|
|
|
project_version, http_prefix,
|
|
|
|
nickname, domain,
|
|
|
|
postToBox, 73528)
|
2021-03-18 20:56:08 +00:00
|
|
|
|
|
|
|
if not inboxUrl:
|
|
|
|
if debug:
|
|
|
|
print('DEBUG: undo announce no ' + postToBox +
|
|
|
|
' was found for ' + handle)
|
|
|
|
return 3
|
|
|
|
if not fromPersonId:
|
|
|
|
if debug:
|
|
|
|
print('DEBUG: undo announce no actor was found for ' + handle)
|
|
|
|
return 4
|
|
|
|
|
2021-12-28 21:36:27 +00:00
|
|
|
authHeader = create_basic_auth_header(nickname, password)
|
2021-03-18 20:56:08 +00:00
|
|
|
|
|
|
|
headers = {
|
|
|
|
'host': domain,
|
|
|
|
'Content-type': 'application/json',
|
|
|
|
'Authorization': authHeader
|
|
|
|
}
|
2021-12-29 21:55:09 +00:00
|
|
|
postResult = post_json(http_prefix, domain_full,
|
|
|
|
session, unAnnounceJson, [], inboxUrl,
|
|
|
|
headers, 3, True)
|
2021-03-18 20:56:08 +00:00
|
|
|
if not postResult:
|
|
|
|
print('WARN: undo announce not posted')
|
|
|
|
|
|
|
|
if debug:
|
|
|
|
print('DEBUG: c2s POST undo announce success')
|
|
|
|
|
|
|
|
return unAnnounceJson
|
2021-05-08 13:14:52 +00:00
|
|
|
|
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
def outbox_undo_announce(recent_posts_cache: {},
|
|
|
|
base_dir: str, http_prefix: str,
|
|
|
|
nickname: str, domain: str, port: int,
|
|
|
|
message_json: {}, debug: bool) -> None:
|
2021-05-08 13:14:52 +00:00
|
|
|
""" When an undo announce is received by the outbox from c2s
|
|
|
|
"""
|
2021-12-25 23:51:19 +00:00
|
|
|
if not message_json.get('type'):
|
2021-05-08 13:14:52 +00:00
|
|
|
return
|
2021-12-25 23:51:19 +00:00
|
|
|
if not message_json['type'] == 'Undo':
|
2021-05-08 13:14:52 +00:00
|
|
|
return
|
2021-12-26 17:12:07 +00:00
|
|
|
if not has_object_stringType(message_json, debug):
|
2021-05-08 13:14:52 +00:00
|
|
|
return
|
2021-12-25 23:51:19 +00:00
|
|
|
if not message_json['object']['type'] == 'Announce':
|
2021-05-08 13:14:52 +00:00
|
|
|
if debug:
|
|
|
|
print('DEBUG: not a undo announce')
|
|
|
|
return
|
2021-12-26 15:54:46 +00:00
|
|
|
if not has_object_string_object(message_json, debug):
|
2021-05-08 13:14:52 +00:00
|
|
|
return
|
|
|
|
if debug:
|
|
|
|
print('DEBUG: c2s undo announce request arrived in outbox')
|
|
|
|
|
2021-12-27 11:20:57 +00:00
|
|
|
messageId = remove_id_ending(message_json['object']['object'])
|
2021-12-26 18:17:37 +00:00
|
|
|
domain = remove_domain_port(domain)
|
2021-12-26 23:41:34 +00:00
|
|
|
post_filename = locate_post(base_dir, nickname, domain, messageId)
|
|
|
|
if not post_filename:
|
2021-05-08 13:14:52 +00:00
|
|
|
if debug:
|
|
|
|
print('DEBUG: c2s undo announce post not found in inbox or outbox')
|
|
|
|
print(messageId)
|
|
|
|
return True
|
2021-12-27 10:55:48 +00:00
|
|
|
undo_announce_collection_entry(recent_posts_cache, base_dir, post_filename,
|
|
|
|
message_json['actor'], domain, debug)
|
2021-05-08 13:14:52 +00:00
|
|
|
if debug:
|
2021-12-26 23:41:34 +00:00
|
|
|
print('DEBUG: post undo announce via c2s - ' + post_filename)
|