def handle_create(activity): PUBLIC_CONTEXT = "https://www.w3.org/ns/activitystreams#Public" # Confirm that the status has images on it. At least one attachments = activity.object.attachment valid_atachments = [] for attachment in attachments: if 'image' in attachment.type: valid_atachments.append(attachment) # If not end the job if not len(valid_atachments): return # Check who is the actor ap_id = "" if isinstance(activity.actor, activities.Actor): ap_id = activity.actor.id elif isinstance(activity.actor, str): ap_id = activity.actor # Get the profile of the creator actor = ActivityPubId(ap_id).get_or_create_remote_user() # Get the targets of the status targets = [ x for x in activity.get("to", []) + activity.get("cc", []) + activity.get('bcc', []) ] is_public = PUBLIC_CONTEXT in targets followers_of = [ ActivityPubId(x.replace('/followers', '')).get_or_create_remote_user() for x in targets ] directs = [ x.split('/')[-1] for x in targets if urlparse(x).hostname == DOMAIN ] # Data for the new status note = activity.object data = { "caption": note.content, "visibility": is_public, "user": actor, "sensitive": False, "remote": True, "story": False, "ap_id": note.id, "identifier": note.id.split('/')[-1] } try: status = Status.create(**data) spread_status(status, [], False) except: return
def upload_image(user, message, description, ident ,sensitive, dimensions, filename): return Status.create(title=filename, user=user, message = message or '', description = description or '', sensitive = sensitive or '', width = dimensions[0], height=dimensions[1], media_name=ident, )
def create(self, user, caption, sensitive, public, spoiler=None, remote=False, story=False, media_ids): """ user: UserProfile - User creating the status caption: str - Image caption sensitive: bool - Content has something sensitive. spoiler: str - Content spoiler text public: bool - True if yes media_ids: list - A list with the media related to the status Returns the created status """ status = Status.create(caption=caption, is_public=public, user=user, sensitive=sensitive, spoiler_text=spoiler, remote=remote, is_story=story) for image in req.get_param('media_ids').split(','): m = Media.get_or_none(media_name=image) m.status = status m.save() UserProfile.update({ UserProfile.statuses_count: UserProfile.statuses_count + 1 }).where(UserProfile.id == status.user.id).execute() spread_status(status)