def process_entity_post(entity, profile, receiving_profile=None): """Process an entity of type Post.""" guid = safe_text(entity.guid) if not validate_against_old_content(guid, entity, profile): return values = { "text": safe_text_for_markdown(entity.raw_content), "author": profile, "visibility": Visibility.PUBLIC if entity.public else Visibility.LIMITED, "remote_created": safe_make_aware(entity.created_at, "UTC"), "service_label": safe_text(entity.provider_display_name) or "", } values["text"] = _embed_entity_images_to_post(entity._children, values["text"]) content, created = Content.objects.update_or_create(guid=guid, defaults=values) _process_mentions(content, entity) if created: logger.info("Saved Content: %s", content) else: logger.info("Updated Content: %s", content) if content.visibility != Visibility.PUBLIC and receiving_profile: content.limited_visibilities.add(receiving_profile) logger.info("Added visibility to Post %s to %s", content.guid, receiving_profile.guid)
def process_entity_share(entity, profile): """Process an entity of type Share.""" if not entity.entity_type == "Post": # TODO: enable shares of replies too logger.warning("Ignoring share entity type that is not of type Post") return try: target_content = Content.objects.get(guid=entity.target_guid, share_of__isnull=True) except Content.DoesNotExist: # Try fetching. If found, process and then try again remote_target = retrieve_remote_content( entity.target_id, sender_key_fetcher=sender_key_fetcher) if remote_target: process_entities([remote_target]) try: target_content = Content.objects.get(guid=entity.target_guid, share_of__isnull=True) except Content.DoesNotExist: logger.warning( "Share target was fetched from remote, but it is still missing locally! Share: %s", entity) return else: logger.warning( "No target found for share even after fetching from remote: %s", entity) return if not target_content.author.handle == entity.target_handle: logger.warning( "Share target handle is different from the author of locally known shared content!" ) return values = { "text": safe_text_for_markdown(entity.raw_content), "author": profile, # TODO: ensure visibility constraints depending on shared content? "visibility": Visibility.PUBLIC if entity.public else Visibility.LIMITED, "remote_created": safe_make_aware(entity.created_at, "UTC"), "service_label": safe_text(entity.provider_display_name) or "", } values["text"] = _embed_entity_images_to_post(entity._children, values["text"]) guid = safe_text(entity.guid) content, created = Content.objects.update_or_create( guid=guid, share_of=target_content, defaults=values) _process_mentions(content, entity) if created: logger.info("Saved share: %s", content) else: logger.info("Updated share: %s", content) # TODO: send participation to the share from the author, if local # We probably want that to happen even though our shares are not separate in the stream? if target_content.local: # We should relay this share entity to participants we know of from socialhome.federate.tasks import forward_entity django_rq.enqueue(forward_entity, entity, target_content.id)
def process_entity_post(entity, profile): """Process an entity of type Post.""" values = { "text": safe_text_for_markdown(entity.raw_content), "author": profile, "visibility": Visibility.PUBLIC if entity.public else Visibility.LIMITED, "remote_created": safe_make_aware(entity.created_at, "UTC"), "service_label": safe_text(entity.provider_display_name) or "", } values["text"] = _embed_entity_images_to_post(entity._children, values["text"]) content, created = Content.objects.update_or_create(guid=safe_text( entity.guid), defaults=values) if created: logger.info("Saved Content: %s", content) else: logger.info("Updated Content: %s", content)
def process_entity_share(entity, profile): """Process an entity of type Share.""" if not entity.entity_type == "Post": # TODO: enable shares of replies too logger.warning("Ignoring share entity type that is not of type Post") return try: target_content = Content.objects.get(guid=entity.target_guid, share_of__isnull=True) except Content.DoesNotExist: # Try fetching # TODO federation library fetch util, for now just return logger.warning( "No target found for share even after fetching from remote: %s", entity) return if not target_content.author.handle == entity.target_handle: logger.warning( "Share target handle is different from the author of locally known shared content!" ) return values = { "text": safe_text_for_markdown(entity.raw_content), "author": profile, # TODO: ensure visibility constraints depending on shared content? "visibility": Visibility.PUBLIC if entity.public else Visibility.LIMITED, "remote_created": safe_make_aware(entity.created_at, "UTC"), "service_label": safe_text(entity.provider_display_name) or "", } values["text"] = _embed_entity_images_to_post(entity._children, values["text"]) guid = safe_text(entity.guid) content, created = Content.objects.update_or_create( guid=guid, share_of=target_content, defaults=values) if created: logger.info("Saved share: %s", content) else: logger.info("Updated share: %s", content)
def process_entity_post(entity, profile): """Process an entity of type Post.""" guid = safe_text(entity.guid) if Content.objects.filter(guid=guid, author__user__isnull=False).exists(): logger.warning("Remote sent content with guid %s is local! Skipping.", guid) return values = { "text": safe_text_for_markdown(entity.raw_content), "author": profile, "visibility": Visibility.PUBLIC if entity.public else Visibility.LIMITED, "remote_created": safe_make_aware(entity.created_at, "UTC"), "service_label": safe_text(entity.provider_display_name) or "", } values["text"] = _embed_entity_images_to_post(entity._children, values["text"]) content, created = Content.objects.update_or_create(guid=guid, defaults=values) if created: logger.info("Saved Content: %s", content) else: logger.info("Updated Content: %s", content)