示例#1
0
 def test_follower_added_sends_a_notification(self, mock_enqueue):
     process_entity_follow(
         base.Follow(target_handle=self.profile.handle, following=True),
         self.remote_profile)
     mock_enqueue.assert_called_once_with(send_follow_notification,
                                          self.remote_profile.id,
                                          self.profile.id)
示例#2
0
 def test_follower_added_on_following_true(self):
     process_entity_follow(
         base.Follow(target_handle=self.profile.handle, following=True),
         self.remote_profile)
     self.assertEqual(self.remote_profile.following.count(), 1)
     self.assertEqual(self.remote_profile.following.first().handle,
                      self.profile.handle)
示例#3
0
def send_follow_change(profile_id, followed_id, follow):
    """Handle sending of a local follow of a remote profile."""
    try:
        profile = Profile.objects.get(id=profile_id, user__isnull=False)
    except Profile.DoesNotExist:
        logger.warning(
            "send_follow_change - No local profile %s found to send follow with",
            profile_id)
        return
    try:
        remote_profile = Profile.objects.get(id=followed_id, user__isnull=True)
    except Profile.DoesNotExist:
        logger.warning(
            "send_follow_change - No remote profile %s found to send follow for",
            followed_id)
        return
    if settings.DEBUG:
        # Don't send in development mode
        return
    entity = base.Follow(
        actor_id=profile.fid,
        target_id=remote_profile.fid,
        following=follow,
        handle=profile.handle,
        target_handle=remote_profile.handle,
    )
    recipients = [
        # TODO fid or handle?
        (remote_profile.handle, remote_profile.key, remote_profile.guid),
    ]
    logger.debug("send_follow_change - sending to recipients: %s", recipients)
    handle_send(entity, profile.federable, recipients)
    # Also trigger a profile send
    # TODO fid or handle?
    send_profile(profile_id, recipients=[remote_profile.handle])
示例#4
0
def send_follow_change(profile_id, followed_id, follow):
    """Handle sending of a local follow of a remote profile."""
    try:
        profile = Profile.objects.get(id=profile_id, user__isnull=False)
    except Profile.DoesNotExist:
        logger.warning(
            "send_follow_change - No local profile %s found to send follow with",
            profile_id)
        return
    try:
        remote_profile = Profile.objects.get(id=followed_id, user__isnull=True)
    except Profile.DoesNotExist:
        logger.warning(
            "send_follow_change - No remote profile %s found to send follow for",
            followed_id)
        return
    if settings.DEBUG:
        # Don't send in development mode
        return
    entity = base.Follow(handle=profile.handle,
                         target_handle=remote_profile.handle,
                         following=follow)
    # TODO: add high level method support to federation for private payload delivery
    payload = handle_create_payload(entity, profile, to_user=remote_profile)
    url = "https://%s/receive/users/%s" % (
        remote_profile.handle.split("@")[1],
        remote_profile.guid,
    )
    send_document(url, payload)
    # Also trigger a profile send
    send_profile(profile_id, recipients=[(remote_profile.handle, None)])
示例#5
0
def send_follow_change(profile_id, followed_id, follow):
    """Handle sending of a local follow of a remote profile."""
    try:
        profile = Profile.objects.get(id=profile_id, user__isnull=False)
    except Profile.DoesNotExist:
        logger.warning("send_follow_change - No local profile %s found to send follow with", profile_id)
        return
    try:
        remote_profile = Profile.objects.get(id=followed_id, user__isnull=True)
    except Profile.DoesNotExist:
        logger.warning("send_follow_change - No remote profile %s found to send follow for", followed_id)
        return
    if settings.DEBUG:
        # Don't send in development mode
        return
    entity = base.Follow(
        activity_id=f'{profile.fid}#follow-{uuid4()}',
        actor_id=profile.fid,
        target_id=remote_profile.fid,
        following=follow,
        handle=profile.handle,
        target_handle=remote_profile.handle,
    )
    # Explicitly use limited visibility to force private endpoint
    recipients = [remote_profile.get_recipient_for_visibility(Visibility.LIMITED)]
    logger.debug("send_follow_change - sending to recipients: %s", recipients)
    handle_send(entity, profile.federable, recipients)
    # Also trigger a profile send
    send_profile(profile_id, recipients=recipients)
示例#6
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.post = entities.PostFactory()
     cls.comment = base.Comment()
     cls.retraction = base.Retraction()
     cls.relationship = base.Relationship()
     cls.follow = base.Follow()
示例#7
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.post = entities.PostFactory()
     cls.comment = base.Comment()
     cls.retraction = base.Retraction()
     cls.follow = base.Follow()
     cls.profile = BaseProfileFactory()
     cls.share = BaseShareFactory()
     cls.receiving_user = UserFactory()
     cls.receiving_profile = cls.receiving_user.profile
示例#8
0
 def test_follower_removed_on_following_false(self):
     self.remote_profile.following.add(self.profile)
     process_entity_follow(
         base.Follow(target_handle=self.profile.handle, following=False),
         self.remote_profile)
     self.assertEqual(self.remote_profile.following.count(), 0)