65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
from izzylib import DotDict, ap_date
|
|
from urllib.parse import urlparse
|
|
from uuid import uuid4
|
|
|
|
from .config import config
|
|
|
|
|
|
def accept(followid, instance):
|
|
message = DotDict({
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
'type': 'Accept',
|
|
'to': [instance.actor],
|
|
'actor': f'https://{config.host}/actor',
|
|
|
|
'object': {
|
|
'type': 'Follow',
|
|
'id': followid,
|
|
'object': f'https://{config.host}/actor',
|
|
'actor': instance.actor
|
|
},
|
|
|
|
'id': f'https://{config.host}/activities/{str(uuid4())}',
|
|
})
|
|
|
|
return message
|
|
|
|
|
|
def announce(object_id, inbox):
|
|
data = DotDict({
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
'type': 'Announce',
|
|
'to': [f'https://{config.host}/followers'],
|
|
'actor': f'https://{config.host}/actor',
|
|
'object': object_id,
|
|
'id': f'https://{config.host}/activities/{str(uuid4())}'
|
|
})
|
|
|
|
return data
|
|
|
|
|
|
def note(user_handle, user_inbox, user_actor, actor, message):
|
|
actor_domain = urlparse(actor).netloc
|
|
user_domain = urlparse(user_inbox).netloc
|
|
data = DotDict({
|
|
"@context": "https://www.w3.org/ns/activitystreams",
|
|
"id": f"https://{config.host}/activities/{str(uuid4())}",
|
|
"type": "Create",
|
|
"actor": f"https://{config.host}/actor",
|
|
"object": {
|
|
"id": f"https://{config.host}/activities/{str(uuid4())}",
|
|
"type": "Note",
|
|
"published": ap_date(),
|
|
"attributedTo": f"https://{config.host}/actor",
|
|
"content": message,
|
|
'to': [user_inbox],
|
|
'tag': [{
|
|
'type': 'Mention',
|
|
'href': user_actor,
|
|
'name': f'@{user_handle}@{user_domain}'
|
|
}],
|
|
}
|
|
})
|
|
|
|
return data
|