Recognise 'service' type as bots

This commit is contained in:
freamon 2024-03-20 11:34:25 +00:00
parent 82a092eec8
commit 0966ce4346
3 changed files with 4 additions and 3 deletions

View file

@ -195,7 +195,7 @@ def user_profile(actor):
if is_activitypub_request():
server = current_app.config['SERVER_NAME']
actor_data = { "@context": default_context(),
"type": "Person",
"type": "Person" if not user.bot else "Service",
"id": f"https://{server}/u/{actor}",
"preferredUsername": actor,
"name": user.title if user.title else user.user_name,

View file

@ -488,7 +488,7 @@ def refresh_community_profile_task(community_id):
def actor_json_to_model(activity_json, address, server):
if activity_json['type'] == 'Person':
if activity_json['type'] == 'Person' or activity_json['type'] == 'Service':
try:
user = User(user_name=activity_json['preferredUsername'],
title=activity_json['name'] if 'name' in activity_json else None,
@ -508,6 +508,7 @@ def actor_json_to_model(activity_json, address, server):
ap_fetched_at=utcnow(),
ap_domain=server,
public_key=activity_json['publicKey']['publicKeyPem'],
bot=True if activity_json['type'] == 'Service' else False,
instance_id=find_instance_id(server)
# language=community_json['language'][0]['identifier'] # todo: language
)

View file

@ -149,7 +149,7 @@ def search_for_user(address: str):
if user_data.status_code == 200:
user_json = user_data.json()
user_data.close()
if user_json['type'] == 'Person':
if user_json['type'] == 'Person' or user_json['type'] == 'Service':
user = actor_json_to_model(user_json, name, server)
return user
return None