epicyon/outbox.py

671 lines
28 KiB
Python
Raw Normal View History

2020-04-03 17:15:33 +00:00
__filename__ = "outbox.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
2021-01-26 10:07:42 +00:00
__version__ = "1.2.0"
2020-04-03 17:15:33 +00:00
__maintainer__ = "Bob Mottram"
2021-09-10 16:14:50 +00:00
__email__ = "bob@libreserver.org"
2020-04-03 17:15:33 +00:00
__status__ = "Production"
2021-06-15 15:08:12 +00:00
__module_group__ = "Timeline"
2020-01-13 10:35:17 +00:00
import os
from shutil import copyfile
2021-12-28 16:56:57 +00:00
from session import create_session
2021-12-28 21:36:27 +00:00
from auth import create_password
from posts import isImageMedia
2021-12-28 19:33:29 +00:00
from posts import outbox_message_create_wrap
2021-12-28 18:13:52 +00:00
from posts import save_post_to_box
2020-01-13 10:35:17 +00:00
from posts import sendToFollowersThread
2021-10-20 20:00:09 +00:00
from posts import sendToNamedAddressesThread
2021-12-26 17:12:07 +00:00
from utils import has_object_stringType
2021-12-26 11:29:40 +00:00
from utils import get_base_content_from_post
2021-12-26 10:57:03 +00:00
from utils import has_object_dict
2021-12-27 20:43:15 +00:00
from utils import get_local_network_addresses
2021-12-26 12:45:03 +00:00
from utils import get_full_domain
2021-12-27 11:20:57 +00:00
from utils import remove_id_ending
2021-12-27 19:05:25 +00:00
from utils import get_domain_from_actor
2021-12-27 21:42:08 +00:00
from utils import dangerous_markup
2021-12-26 12:07:40 +00:00
from utils import is_featured_writer
2021-12-26 15:13:34 +00:00
from utils import load_json
2021-12-26 14:47:21 +00:00
from utils import save_json
2021-12-26 12:02:29 +00:00
from utils import acct_dir
2021-12-26 10:19:59 +00:00
from utils import local_actor_url
2021-12-26 17:15:04 +00:00
from utils import has_actor
2020-01-13 10:35:17 +00:00
from blocking import isBlockedDomain
from blocking import outboxBlock
from blocking import outboxUndoBlock
2021-03-20 21:20:41 +00:00
from blocking import outboxMute
from blocking import outboxUndoMute
2021-12-28 21:36:27 +00:00
from media import replace_you_tube
from media import replace_twitter
2020-01-13 10:35:17 +00:00
from media import getMediaPath
from media import createMediaDirs
from inbox import inboxUpdateIndex
from announce import outboxAnnounce
from announce import outboxUndoAnnounce
2020-01-13 10:35:17 +00:00
from follow import outboxUndoFollow
2021-12-28 20:32:11 +00:00
from follow import follower_approval_active
2020-01-13 10:35:17 +00:00
from skills import outboxSkills
from availability import outboxAvailability
from like import outboxLike
from like import outboxUndoLike
2021-11-10 12:16:03 +00:00
from reaction import outboxReaction
from reaction import outboxUndoReaction
2020-01-13 10:35:17 +00:00
from bookmarks import outboxBookmark
from bookmarks import outboxUndoBookmark
from delete import outboxDelete
from shares import outboxShareUpload
from shares import outboxUndoShareUpload
from webapp_post import individualPostAsHtml
2020-01-13 10:35:17 +00:00
2020-04-03 17:15:33 +00:00
2021-12-26 20:01:37 +00:00
def _outboxPersonReceiveUpdate(recent_posts_cache: {},
2021-12-25 17:09:22 +00:00
base_dir: str, http_prefix: str,
2021-03-17 20:18:00 +00:00
nickname: str, domain: str, port: int,
2021-12-25 23:51:19 +00:00
message_json: {}, debug: bool) -> None:
2021-03-17 20:18:00 +00:00
""" Receive an actor update from c2s
For example, setting the PGP key from the desktop client
"""
# these attachments are updatable via c2s
updatableAttachments = ('PGP', 'OpenPGP', 'Email')
2021-12-25 23:51:19 +00:00
if not message_json.get('type'):
2021-03-17 20:18:00 +00:00
return
2021-12-25 23:51:19 +00:00
if not isinstance(message_json['type'], str):
2021-07-19 08:59:30 +00:00
if debug:
print('DEBUG: c2s actor update type is not a string')
return
2021-12-25 23:51:19 +00:00
if message_json['type'] != 'Update':
2021-03-17 20:18:00 +00:00
return
2021-12-26 17:12:07 +00:00
if not has_object_stringType(message_json, debug):
2021-03-17 20:18:00 +00:00
return
2021-12-25 23:51:19 +00:00
if not isinstance(message_json['object']['type'], str):
2021-07-19 08:59:30 +00:00
if debug:
print('DEBUG: c2s actor update object type is not a string')
return
2021-12-25 23:51:19 +00:00
if message_json['object']['type'] != 'Person':
2021-03-17 20:18:00 +00:00
if debug:
print('DEBUG: not a c2s actor update')
return
2021-12-25 23:51:19 +00:00
if not message_json.get('to'):
2021-03-17 20:18:00 +00:00
if debug:
print('DEBUG: c2s actor update has no "to" field')
return
2021-12-26 17:15:04 +00:00
if not has_actor(message_json, debug):
2021-03-17 20:18:00 +00:00
return
2021-12-25 23:51:19 +00:00
if not message_json.get('id'):
2021-03-17 20:18:00 +00:00
if debug:
print('DEBUG: c2s actor update has no id field')
return
2021-12-25 23:51:19 +00:00
if not isinstance(message_json['id'], str):
2021-07-19 08:59:30 +00:00
if debug:
print('DEBUG: c2s actor update id is not a string')
return
2021-12-26 12:45:03 +00:00
domain_full = get_full_domain(domain, port)
2021-12-26 10:19:59 +00:00
actor = local_actor_url(http_prefix, nickname, domain_full)
2021-12-25 23:51:19 +00:00
if len(message_json['to']) != 1:
2021-03-17 20:18:00 +00:00
if debug:
print('DEBUG: c2s actor update - to does not contain one actor ' +
2021-12-25 23:51:19 +00:00
str(message_json['to']))
2021-03-17 20:18:00 +00:00
return
2021-12-25 23:51:19 +00:00
if message_json['to'][0] != actor:
2021-03-17 20:18:00 +00:00
if debug:
print('DEBUG: c2s actor update - to does not contain actor ' +
2021-12-25 23:51:19 +00:00
str(message_json['to']) + ' ' + actor)
2021-03-17 20:18:00 +00:00
return
2021-12-25 23:51:19 +00:00
if not message_json['id'].startswith(actor + '#updates/'):
2021-03-17 20:18:00 +00:00
if debug:
print('DEBUG: c2s actor update - unexpected id ' +
2021-12-25 23:51:19 +00:00
message_json['id'])
2021-03-17 20:18:00 +00:00
return
2021-12-25 23:51:19 +00:00
updatedActorJson = message_json['object']
2021-03-17 20:18:00 +00:00
# load actor from file
2021-12-26 12:02:29 +00:00
actorFilename = acct_dir(base_dir, nickname, domain) + '.json'
2021-03-17 20:18:00 +00:00
if not os.path.isfile(actorFilename):
print('actorFilename not found: ' + actorFilename)
return
2021-12-26 15:13:34 +00:00
actor_json = load_json(actorFilename)
2021-12-26 10:29:52 +00:00
if not actor_json:
2021-03-17 20:18:00 +00:00
return
actorChanged = False
# update fields within actor
if 'attachment' in updatedActorJson:
for newPropertyValue in updatedActorJson['attachment']:
if not newPropertyValue.get('name'):
continue
if newPropertyValue['name'] not in updatableAttachments:
continue
if not newPropertyValue.get('type'):
continue
if not newPropertyValue.get('value'):
continue
if newPropertyValue['type'] != 'PropertyValue':
continue
2021-12-26 10:29:52 +00:00
if 'attachment' not in actor_json:
2021-07-13 21:59:53 +00:00
continue
found = False
2021-12-26 10:29:52 +00:00
for attachIdx in range(len(actor_json['attachment'])):
if actor_json['attachment'][attachIdx]['type'] != \
2021-07-13 21:59:53 +00:00
'PropertyValue':
continue
2021-12-26 10:29:52 +00:00
if actor_json['attachment'][attachIdx]['name'] != \
2021-07-13 21:59:53 +00:00
newPropertyValue['name']:
continue
else:
2021-12-26 10:29:52 +00:00
if actor_json['attachment'][attachIdx]['value'] != \
2021-07-13 21:59:53 +00:00
newPropertyValue['value']:
2021-12-26 10:29:52 +00:00
actor_json['attachment'][attachIdx]['value'] = \
2021-07-13 21:59:53 +00:00
newPropertyValue['value']
actorChanged = True
found = True
break
if not found:
2021-12-26 10:29:52 +00:00
actor_json['attachment'].append({
2021-07-13 21:59:53 +00:00
"name": newPropertyValue['name'],
"type": "PropertyValue",
"value": newPropertyValue['value']
})
actorChanged = True
2021-03-17 20:18:00 +00:00
# save actor to file
if actorChanged:
2021-12-26 14:47:21 +00:00
save_json(actor_json, actorFilename)
2021-03-17 20:18:00 +00:00
if debug:
print('actor saved: ' + actorFilename)
if debug:
2021-12-26 10:29:52 +00:00
print('New attachment: ' + str(actor_json['attachment']))
message_json['object'] = actor_json
2021-03-17 20:18:00 +00:00
if debug:
print('DEBUG: actor update via c2s - ' + nickname + '@' + domain)
def postMessageToOutbox(session, translate: {},
2021-12-25 23:51:19 +00:00
message_json: {}, postToNickname: str,
2021-12-25 17:09:22 +00:00
server, base_dir: str, http_prefix: str,
2021-12-26 10:00:46 +00:00
domain: str, domain_full: str,
2021-12-25 20:50:24 +00:00
onion_domain: str, i2p_domain: str, port: int,
2021-12-26 20:01:37 +00:00
recent_posts_cache: {}, followers_threads: [],
2021-12-25 23:45:30 +00:00
federation_list: [], send_threads: [],
2021-12-25 22:28:18 +00:00
postLog: [], cached_webfingers: {},
2021-12-25 22:17:49 +00:00
person_cache: {}, allow_deletion: bool,
2021-12-25 21:09:22 +00:00
proxy_type: str, version: str, debug: bool,
2021-12-25 17:15:52 +00:00
yt_replace_domain: str,
2021-12-25 20:55:47 +00:00
twitter_replacement_domain: str,
2021-12-25 20:06:27 +00:00
show_published_date_only: bool,
2021-12-25 18:54:50 +00:00
allow_local_network_access: bool,
2021-12-25 23:03:28 +00:00
city: str, system_language: str,
2021-12-25 18:05:01 +00:00
shared_items_federated_domains: [],
2021-08-13 20:18:36 +00:00
sharedItemFederationTokens: {},
2021-12-25 18:20:56 +00:00
low_bandwidth: bool,
2021-12-25 23:03:28 +00:00
signing_priv_key_pem: str,
2021-12-25 23:38:53 +00:00
peertube_instances: str, theme: str,
2021-12-25 18:23:12 +00:00
max_like_count: int,
2021-12-25 23:26:38 +00:00
max_recent_posts: int, cw_lists: {},
2021-12-25 18:12:13 +00:00
lists_enabled: str,
2021-12-25 17:13:38 +00:00
content_license_url: str) -> bool:
2020-01-13 10:35:17 +00:00
"""post is received by the outbox
Client to server message post
https://www.w3.org/TR/activitypub/#client-to-server-outbox-delivery
"""
2021-12-25 23:51:19 +00:00
if not message_json.get('type'):
2020-01-13 10:35:17 +00:00
if debug:
print('DEBUG: POST to outbox has no "type" parameter')
return False
2021-12-25 23:51:19 +00:00
if not message_json.get('object') and message_json.get('content'):
if message_json['type'] != 'Create':
2020-01-13 10:35:17 +00:00
# https://www.w3.org/TR/activitypub/#object-without-create
if debug:
print('DEBUG: POST to outbox - adding Create wrapper')
2021-12-25 23:51:19 +00:00
message_json = \
2021-12-28 19:33:29 +00:00
outbox_message_create_wrap(http_prefix,
postToNickname,
domain, port,
message_json)
# check that the outgoing post doesn't contain any markup
# which can be used to implement exploits
2021-12-26 10:57:03 +00:00
if has_object_dict(message_json):
2021-12-26 11:29:40 +00:00
contentStr = get_base_content_from_post(message_json, system_language)
if contentStr:
2021-12-27 21:42:08 +00:00
if dangerous_markup(contentStr, allow_local_network_access):
print('POST to outbox contains dangerous markup: ' +
2021-12-25 23:51:19 +00:00
str(message_json))
return False
2021-12-25 23:51:19 +00:00
if message_json['type'] == 'Create':
if not (message_json.get('id') and
message_json.get('type') and
message_json.get('actor') and
message_json.get('object') and
message_json.get('to')):
if not message_json.get('id'):
2020-01-13 12:45:27 +00:00
if debug:
2020-04-03 17:15:33 +00:00
print('DEBUG: POST to outbox - ' +
'Create does not have the id parameter ' +
2021-12-25 23:51:19 +00:00
str(message_json))
elif not message_json.get('id'):
2020-01-13 12:45:27 +00:00
if debug:
2020-04-03 17:15:33 +00:00
print('DEBUG: POST to outbox - ' +
'Create does not have the type parameter ' +
2021-12-25 23:51:19 +00:00
str(message_json))
elif not message_json.get('id'):
2020-01-13 12:45:27 +00:00
if debug:
2020-04-03 17:15:33 +00:00
print('DEBUG: POST to outbox - ' +
'Create does not have the actor parameter ' +
2021-12-25 23:51:19 +00:00
str(message_json))
elif not message_json.get('id'):
2020-01-13 12:45:27 +00:00
if debug:
2020-04-03 17:15:33 +00:00
print('DEBUG: POST to outbox - ' +
'Create does not have the object parameter ' +
2021-12-25 23:51:19 +00:00
str(message_json))
2020-01-13 12:45:27 +00:00
else:
if debug:
2020-04-03 17:15:33 +00:00
print('DEBUG: POST to outbox - ' +
'Create does not have the "to" parameter ' +
2021-12-25 23:51:19 +00:00
str(message_json))
2020-01-13 10:35:17 +00:00
return False
2021-02-15 10:06:49 +00:00
# actor should be a string
2021-12-25 23:51:19 +00:00
if not isinstance(message_json['actor'], str):
2021-02-15 10:06:49 +00:00
return False
# actor should look like a url
2021-12-25 23:51:19 +00:00
if '://' not in message_json['actor'] or \
'.' not in message_json['actor']:
2021-02-15 10:06:49 +00:00
return False
# sent by an actor on a local network address?
2021-12-25 18:54:50 +00:00
if not allow_local_network_access:
2021-12-27 20:43:15 +00:00
localNetworkPatternList = get_local_network_addresses()
2021-02-15 10:06:49 +00:00
for localNetworkPattern in localNetworkPatternList:
2021-12-25 23:51:19 +00:00
if localNetworkPattern in message_json['actor']:
2021-02-15 10:06:49 +00:00
return False
2021-12-27 19:05:25 +00:00
testDomain, testPort = get_domain_from_actor(message_json['actor'])
2021-12-26 12:45:03 +00:00
testDomain = get_full_domain(testDomain, testPort)
2021-12-25 16:17:53 +00:00
if isBlockedDomain(base_dir, testDomain):
2020-01-13 10:35:17 +00:00
if debug:
2021-12-25 23:51:19 +00:00
print('DEBUG: domain is blocked: ' + message_json['actor'])
2020-01-13 10:35:17 +00:00
return False
2020-01-15 11:06:40 +00:00
# replace youtube, so that google gets less tracking data
2021-12-28 21:36:27 +00:00
replace_you_tube(message_json, yt_replace_domain, system_language)
2021-09-18 17:08:14 +00:00
# replace twitter, so that twitter posts can be shown without
# having a twitter account
2021-12-28 21:36:27 +00:00
replace_twitter(message_json, twitter_replacement_domain,
system_language)
2020-01-13 10:35:17 +00:00
# https://www.w3.org/TR/activitypub/#create-activity-outbox
2021-12-25 23:51:19 +00:00
message_json['object']['attributedTo'] = message_json['actor']
if message_json['object'].get('attachment'):
2020-04-03 17:15:33 +00:00
attachmentIndex = 0
2021-12-25 23:51:19 +00:00
attach = message_json['object']['attachment'][attachmentIndex]
2020-04-03 17:15:33 +00:00
if attach.get('mediaType'):
fileExtension = 'png'
mediaTypeStr = \
attach['mediaType']
2020-11-28 20:52:13 +00:00
extensions = {
"jpeg": "jpg",
"gif": "gif",
2021-01-11 22:27:57 +00:00
"svg": "svg",
2020-11-28 20:52:13 +00:00
"webp": "webp",
"avif": "avif",
"audio/mpeg": "mp3",
"ogg": "ogg",
"mp4": "mp4",
"webm": "webm",
"ogv": "ogv"
}
for matchExt, ext in extensions.items():
if mediaTypeStr.endswith(matchExt):
fileExtension = ext
break
2020-04-03 17:15:33 +00:00
mediaDir = \
2021-12-25 16:17:53 +00:00
base_dir + '/accounts/' + \
2020-04-03 17:15:33 +00:00
postToNickname + '@' + domain
uploadMediaFilename = mediaDir + '/upload.' + fileExtension
2020-01-13 10:35:17 +00:00
if not os.path.isfile(uploadMediaFilename):
2021-12-25 23:51:19 +00:00
del message_json['object']['attachment']
2020-01-13 10:35:17 +00:00
else:
# generate a path for the uploaded image
2020-04-03 17:15:33 +00:00
mPath = getMediaPath()
mediaPath = mPath + '/' + \
2021-12-28 21:36:27 +00:00
create_password(16).lower() + '.' + fileExtension
2021-12-25 16:17:53 +00:00
createMediaDirs(base_dir, mPath)
mediaFilename = base_dir + '/' + mediaPath
2020-01-13 10:35:17 +00:00
# move the uploaded image to its new path
2020-04-03 17:15:33 +00:00
os.rename(uploadMediaFilename, mediaFilename)
2020-01-13 10:35:17 +00:00
# change the url of the attachment
2020-04-03 17:15:33 +00:00
attach['url'] = \
2021-12-26 10:00:46 +00:00
http_prefix + '://' + domain_full + '/' + mediaPath
2021-10-12 18:20:40 +00:00
attach['url'] = \
attach['url'].replace('/media/',
'/system/' +
'media_attachments/files/')
2020-01-13 10:35:17 +00:00
2021-11-10 12:16:03 +00:00
permittedOutboxTypes = (
'Create', 'Announce', 'Like', 'EmojiReact', 'Follow', 'Undo',
'Update', 'Add', 'Remove', 'Block', 'Delete', 'Skill', 'Ignore'
)
2021-12-25 23:51:19 +00:00
if message_json['type'] not in permittedOutboxTypes:
2020-01-13 10:35:17 +00:00
if debug:
2021-12-25 23:51:19 +00:00
print('DEBUG: POST to outbox - ' + message_json['type'] +
2020-01-13 10:35:17 +00:00
' is not a permitted activity type')
return False
2021-12-25 23:51:19 +00:00
if message_json.get('id'):
2021-12-27 11:20:57 +00:00
post_id = remove_id_ending(message_json['id'])
2020-01-13 10:35:17 +00:00
if debug:
print('DEBUG: id attribute exists within POST to outbox')
else:
if debug:
print('DEBUG: No id attribute within POST to outbox')
2021-12-26 19:47:06 +00:00
post_id = None
2020-01-13 10:35:17 +00:00
if debug:
2021-12-28 18:13:52 +00:00
print('DEBUG: save_post_to_box')
2021-12-25 23:51:19 +00:00
if message_json['type'] != 'Upgrade':
2020-04-03 17:15:33 +00:00
outboxName = 'outbox'
2020-02-24 22:50:55 +00:00
2020-08-23 11:13:35 +00:00
# if this is a blog post or an event then save to its own box
2021-12-25 23:51:19 +00:00
if message_json['type'] == 'Create':
2021-12-26 10:57:03 +00:00
if has_object_dict(message_json):
2021-12-25 23:51:19 +00:00
if message_json['object'].get('type'):
if message_json['object']['type'] == 'Article':
outboxName = 'tlblogs'
2020-04-03 17:15:33 +00:00
savedFilename = \
2021-12-28 18:13:52 +00:00
save_post_to_box(base_dir,
http_prefix,
post_id,
postToNickname, domain_full,
message_json, outboxName)
2020-08-25 20:20:56 +00:00
if not savedFilename:
print('WARN: post not saved to outbox ' + outboxName)
return False
# save all instance blogs to the news actor
if postToNickname != 'news' and outboxName == 'tlblogs':
2020-11-28 12:13:04 +00:00
if '/' in savedFilename:
2021-12-26 12:07:40 +00:00
if is_featured_writer(base_dir, postToNickname, domain):
2021-02-13 11:37:02 +00:00
savedPostId = savedFilename.split('/')[-1]
blogsDir = \
2021-12-25 16:17:53 +00:00
base_dir + '/accounts/news@' + domain + '/tlblogs'
2021-02-13 11:37:02 +00:00
if not os.path.isdir(blogsDir):
os.mkdir(blogsDir)
copyfile(savedFilename, blogsDir + '/' + savedPostId)
2021-12-25 16:17:53 +00:00
inboxUpdateIndex('tlblogs', base_dir,
2021-02-13 11:37:02 +00:00
'news@' + domain,
savedFilename, debug)
2020-11-28 12:13:04 +00:00
# clear the citations file if it exists
citationsFilename = \
2021-12-25 16:17:53 +00:00
base_dir + '/accounts/' + \
2020-11-28 12:13:04 +00:00
postToNickname + '@' + domain + '/.citations.txt'
if os.path.isfile(citationsFilename):
try:
os.remove(citationsFilename)
2021-11-25 18:42:38 +00:00
except OSError:
2021-10-29 18:48:15 +00:00
print('EX: postMessageToOutbox unable to delete ' +
citationsFilename)
2021-07-04 11:11:15 +00:00
# The following activity types get added to the index files
indexedActivities = (
'Create', 'Question', 'Note', 'EncryptedMessage', 'Article',
'Patch', 'Announce'
)
2021-12-25 23:51:19 +00:00
if message_json['type'] in indexedActivities:
2020-04-03 17:15:33 +00:00
indexes = [outboxName, "inbox"]
2020-08-25 17:28:29 +00:00
selfActor = \
2021-12-26 10:19:59 +00:00
local_actor_url(http_prefix, postToNickname, domain_full)
for boxNameIndex in indexes:
2020-08-25 20:20:56 +00:00
if not boxNameIndex:
continue
# should this also go to the media timeline?
if boxNameIndex == 'inbox':
2021-12-25 17:09:22 +00:00
if isImageMedia(session, base_dir, http_prefix,
postToNickname, domain,
2021-12-25 23:51:19 +00:00
message_json,
2021-09-18 17:08:14 +00:00
translate,
2021-12-25 17:15:52 +00:00
yt_replace_domain,
2021-12-25 20:55:47 +00:00
twitter_replacement_domain,
2021-12-25 18:54:50 +00:00
allow_local_network_access,
2021-12-26 20:01:37 +00:00
recent_posts_cache, debug, system_language,
2021-12-26 10:00:46 +00:00
domain_full, person_cache,
2021-12-25 23:03:28 +00:00
signing_priv_key_pem):
2021-12-25 16:17:53 +00:00
inboxUpdateIndex('tlmedia', base_dir,
postToNickname + '@' + domain,
savedFilename, debug)
2020-08-25 14:43:13 +00:00
if boxNameIndex == 'inbox' and outboxName == 'tlblogs':
continue
2021-06-22 20:30:27 +00:00
# avoid duplicates of the message if already going
# back to the inbox of the same account
2021-12-25 23:51:19 +00:00
if selfActor not in message_json['to']:
# show sent post within the inbox,
# as is the typical convention
2021-12-25 16:17:53 +00:00
inboxUpdateIndex(boxNameIndex, base_dir,
postToNickname + '@' + domain,
savedFilename, debug)
# regenerate the html
useCacheOnly = False
pageNumber = 1
showIndividualPostIcons = True
manuallyApproveFollowers = \
2021-12-28 20:32:11 +00:00
follower_approval_active(base_dir,
postToNickname, domain)
2021-12-25 23:03:28 +00:00
individualPostAsHtml(signing_priv_key_pem,
2021-12-26 20:01:37 +00:00
False, recent_posts_cache,
2021-12-25 20:28:06 +00:00
max_recent_posts,
translate, pageNumber,
2021-12-25 16:17:53 +00:00
base_dir, session,
2021-12-25 22:28:18 +00:00
cached_webfingers,
2021-12-25 22:17:49 +00:00
person_cache,
postToNickname, domain, port,
2021-12-25 23:51:19 +00:00
message_json, None, True,
2021-12-25 21:29:53 +00:00
allow_deletion,
2021-12-25 17:09:22 +00:00
http_prefix, __version__,
boxNameIndex,
2021-12-25 17:15:52 +00:00
yt_replace_domain,
2021-12-25 20:55:47 +00:00
twitter_replacement_domain,
2021-12-25 20:06:27 +00:00
show_published_date_only,
2021-12-25 23:38:53 +00:00
peertube_instances,
2021-12-25 18:54:50 +00:00
allow_local_network_access,
2021-12-25 23:03:28 +00:00
theme, system_language,
2021-12-25 18:23:12 +00:00
max_like_count,
boxNameIndex != 'dm',
showIndividualPostIcons,
manuallyApproveFollowers,
2021-10-21 13:08:21 +00:00
False, True, useCacheOnly,
2021-12-25 23:26:38 +00:00
cw_lists, lists_enabled)
2021-12-26 20:01:37 +00:00
if outboxAnnounce(recent_posts_cache,
2021-12-25 23:51:19 +00:00
base_dir, message_json, debug):
2020-01-13 10:35:17 +00:00
if debug:
2020-04-03 17:15:33 +00:00
print('DEBUG: Updated announcements (shares) collection ' +
'for the post associated with the Announce activity')
2020-01-13 10:35:17 +00:00
if not server.session:
2020-06-24 09:04:58 +00:00
print('DEBUG: creating new session for c2s')
2021-12-28 16:56:57 +00:00
server.session = create_session(proxy_type)
if not server.session:
print('ERROR: Failed to create session for postMessageToOutbox')
return False
2020-01-13 10:35:17 +00:00
if debug:
print('DEBUG: sending c2s post to followers')
# remove inactive threads
2020-04-03 17:15:33 +00:00
inactiveFollowerThreads = []
2021-12-25 22:48:08 +00:00
for th in followers_threads:
2020-01-13 10:35:17 +00:00
if not th.is_alive():
inactiveFollowerThreads.append(th)
for th in inactiveFollowerThreads:
2021-12-25 22:48:08 +00:00
followers_threads.remove(th)
2020-01-13 10:35:17 +00:00
if debug:
2021-12-25 22:48:08 +00:00
print('DEBUG: ' + str(len(followers_threads)) +
2020-04-03 17:15:33 +00:00
' followers threads active')
2020-01-20 12:43:34 +00:00
# retain up to 200 threads
2021-12-25 22:48:08 +00:00
if len(followers_threads) > 200:
2020-01-13 10:35:17 +00:00
# kill the thread if it is still alive
2021-12-25 22:48:08 +00:00
if followers_threads[0].is_alive():
followers_threads[0].kill()
2020-01-13 10:35:17 +00:00
# remove it from the list
2021-12-25 22:48:08 +00:00
followers_threads.pop(0)
2020-01-13 10:35:17 +00:00
# create a thread to send the post to followers
2020-04-03 17:15:33 +00:00
followersThread = \
sendToFollowersThread(server.session,
2021-12-25 16:17:53 +00:00
base_dir,
2020-04-03 17:15:33 +00:00
postToNickname,
2021-12-25 20:50:24 +00:00
domain, onion_domain, i2p_domain,
2021-12-25 17:09:22 +00:00
port, http_prefix,
2021-12-25 23:45:30 +00:00
federation_list,
2021-12-25 21:37:41 +00:00
send_threads,
2020-04-03 17:15:33 +00:00
postLog,
2021-12-25 22:28:18 +00:00
cached_webfingers,
2021-12-25 22:17:49 +00:00
person_cache,
2021-12-25 23:51:19 +00:00
message_json, debug,
version,
2021-12-25 18:05:01 +00:00
shared_items_federated_domains,
sharedItemFederationTokens,
2021-12-25 23:03:28 +00:00
signing_priv_key_pem)
2021-12-25 22:48:08 +00:00
followers_threads.append(followersThread)
2020-02-04 20:11:19 +00:00
2020-01-13 10:35:17 +00:00
if debug:
print('DEBUG: handle any unfollow requests')
2021-12-25 23:51:19 +00:00
outboxUndoFollow(base_dir, message_json, debug)
2020-02-04 20:11:19 +00:00
2020-01-13 10:35:17 +00:00
if debug:
print('DEBUG: handle skills changes requests')
2021-12-25 23:51:19 +00:00
outboxSkills(base_dir, postToNickname, message_json, debug)
2020-02-04 20:11:19 +00:00
2020-01-13 10:35:17 +00:00
if debug:
print('DEBUG: handle availability changes requests')
2021-12-25 23:51:19 +00:00
outboxAvailability(base_dir, postToNickname, message_json, debug)
2020-01-13 10:35:17 +00:00
if debug:
print('DEBUG: handle any like requests')
2021-12-26 20:01:37 +00:00
outboxLike(recent_posts_cache,
2021-12-25 17:09:22 +00:00
base_dir, http_prefix,
2020-04-03 17:15:33 +00:00
postToNickname, domain, port,
2021-12-25 23:51:19 +00:00
message_json, debug)
2020-01-13 10:35:17 +00:00
if debug:
print('DEBUG: handle any undo like requests')
2021-12-26 20:01:37 +00:00
outboxUndoLike(recent_posts_cache,
2021-12-25 17:09:22 +00:00
base_dir, http_prefix,
2020-04-03 17:15:33 +00:00
postToNickname, domain, port,
2021-12-25 23:51:19 +00:00
message_json, debug)
2021-11-10 12:16:03 +00:00
if debug:
print('DEBUG: handle any emoji reaction requests')
2021-12-26 20:01:37 +00:00
outboxReaction(recent_posts_cache,
2021-12-25 17:09:22 +00:00
base_dir, http_prefix,
2021-11-10 12:16:03 +00:00
postToNickname, domain, port,
2021-12-25 23:51:19 +00:00
message_json, debug)
2021-11-10 12:16:03 +00:00
if debug:
print('DEBUG: handle any undo emoji reaction requests')
2021-12-26 20:01:37 +00:00
outboxUndoReaction(recent_posts_cache,
2021-12-25 17:09:22 +00:00
base_dir, http_prefix,
2021-11-10 12:16:03 +00:00
postToNickname, domain, port,
2021-12-25 23:51:19 +00:00
message_json, debug)
2021-11-10 12:16:03 +00:00
if debug:
print('DEBUG: handle any undo announce requests')
2021-12-26 20:01:37 +00:00
outboxUndoAnnounce(recent_posts_cache,
2021-12-25 17:09:22 +00:00
base_dir, http_prefix,
postToNickname, domain, port,
2021-12-25 23:51:19 +00:00
message_json, debug)
2020-01-13 10:35:17 +00:00
if debug:
print('DEBUG: handle any bookmark requests')
2021-12-26 20:01:37 +00:00
outboxBookmark(recent_posts_cache,
2021-12-25 17:09:22 +00:00
base_dir, http_prefix,
2020-04-03 17:15:33 +00:00
postToNickname, domain, port,
2021-12-25 23:51:19 +00:00
message_json, debug)
2020-01-13 10:35:17 +00:00
if debug:
print('DEBUG: handle any undo bookmark requests')
2021-12-26 20:01:37 +00:00
outboxUndoBookmark(recent_posts_cache,
2021-12-25 17:09:22 +00:00
base_dir, http_prefix,
2020-04-03 17:15:33 +00:00
postToNickname, domain, port,
2021-12-25 23:51:19 +00:00
message_json, debug)
2020-01-13 10:35:17 +00:00
if debug:
2020-03-22 21:16:02 +00:00
print('DEBUG: handle delete requests')
2021-12-25 17:09:22 +00:00
outboxDelete(base_dir, http_prefix,
2020-04-03 17:15:33 +00:00
postToNickname, domain,
2021-12-25 23:51:19 +00:00
message_json, debug,
2021-12-25 21:29:53 +00:00
allow_deletion,
2021-12-26 20:01:37 +00:00
recent_posts_cache)
2020-02-04 20:11:19 +00:00
2020-01-13 10:35:17 +00:00
if debug:
print('DEBUG: handle block requests')
2021-12-25 17:09:22 +00:00
outboxBlock(base_dir, http_prefix,
2020-04-03 17:15:33 +00:00
postToNickname, domain,
2020-01-13 10:35:17 +00:00
port,
2021-12-25 23:51:19 +00:00
message_json, debug)
2020-02-04 20:11:19 +00:00
2020-01-13 10:35:17 +00:00
if debug:
print('DEBUG: handle undo block requests')
2021-12-25 17:09:22 +00:00
outboxUndoBlock(base_dir, http_prefix,
2020-04-03 17:15:33 +00:00
postToNickname, domain,
2021-12-25 23:51:19 +00:00
port, message_json, debug)
2020-02-04 20:11:19 +00:00
2021-03-20 21:20:41 +00:00
if debug:
print('DEBUG: handle mute requests')
2021-12-25 17:09:22 +00:00
outboxMute(base_dir, http_prefix,
2021-03-20 21:20:41 +00:00
postToNickname, domain,
port,
2021-12-25 23:51:19 +00:00
message_json, debug,
2021-12-26 20:01:37 +00:00
recent_posts_cache)
2021-03-20 21:20:41 +00:00
if debug:
print('DEBUG: handle undo mute requests')
2021-12-25 17:09:22 +00:00
outboxUndoMute(base_dir, http_prefix,
2021-03-20 21:20:41 +00:00
postToNickname, domain,
port,
2021-12-25 23:51:19 +00:00
message_json, debug,
2021-12-26 20:01:37 +00:00
recent_posts_cache)
2021-03-20 21:20:41 +00:00
2020-01-13 10:35:17 +00:00
if debug:
print('DEBUG: handle share uploads')
2021-12-25 17:09:22 +00:00
outboxShareUpload(base_dir, http_prefix, postToNickname, domain,
2021-12-25 23:51:19 +00:00
port, message_json, debug, city,
2021-12-25 23:03:28 +00:00
system_language, translate, low_bandwidth,
2021-12-25 17:13:38 +00:00
content_license_url)
2020-02-04 20:11:19 +00:00
2020-01-13 10:35:17 +00:00
if debug:
print('DEBUG: handle undo share uploads')
2021-12-25 17:09:22 +00:00
outboxUndoShareUpload(base_dir, http_prefix,
2020-04-03 17:15:33 +00:00
postToNickname, domain,
2021-12-25 23:51:19 +00:00
port, message_json, debug)
2020-02-04 20:11:19 +00:00
2021-03-17 20:18:00 +00:00
if debug:
print('DEBUG: handle actor updates from c2s')
2021-12-26 20:01:37 +00:00
_outboxPersonReceiveUpdate(recent_posts_cache,
2021-12-25 17:09:22 +00:00
base_dir, http_prefix,
2021-03-17 20:18:00 +00:00
postToNickname, domain, port,
2021-12-25 23:51:19 +00:00
message_json, debug)
2021-03-17 20:18:00 +00:00
2020-01-13 10:35:17 +00:00
if debug:
print('DEBUG: sending c2s post to named addresses')
2021-12-25 23:51:19 +00:00
if message_json.get('to'):
2020-04-03 17:15:33 +00:00
print('c2s sender: ' +
postToNickname + '@' + domain + ':' + str(port) +
2021-12-25 23:51:19 +00:00
' recipient: ' + str(message_json['to']))
2020-02-04 20:11:19 +00:00
else:
2020-04-03 17:15:33 +00:00
print('c2s sender: ' +
postToNickname + '@' + domain + ':' + str(port))
2021-10-20 20:00:09 +00:00
namedAddressesThread = \
2021-12-25 16:17:53 +00:00
sendToNamedAddressesThread(server.session, base_dir,
2021-10-20 20:00:09 +00:00
postToNickname,
2021-12-25 20:50:24 +00:00
domain, onion_domain, i2p_domain, port,
2021-12-25 17:09:22 +00:00
http_prefix,
2021-12-25 23:45:30 +00:00
federation_list,
2021-12-25 21:37:41 +00:00
send_threads,
2021-10-20 20:00:09 +00:00
postLog,
2021-12-25 22:28:18 +00:00
cached_webfingers,
2021-12-25 22:17:49 +00:00
person_cache,
2021-12-25 23:51:19 +00:00
message_json, debug,
2021-10-20 20:00:09 +00:00
version,
2021-12-25 18:05:01 +00:00
shared_items_federated_domains,
2021-10-20 20:00:09 +00:00
sharedItemFederationTokens,
2021-12-25 23:03:28 +00:00
signing_priv_key_pem)
2021-12-25 22:48:08 +00:00
followers_threads.append(namedAddressesThread)
2020-01-13 10:35:17 +00:00
return True