async def forward_to_followers(self, activity): recipients = await self.followers_get() try: recipients.remove(activity["actor"]) except ValueError: pass asyncio.ensure_future(deliver(self.key, activity, recipients))
async def inbox_post(request, user): # TODO implement shared inbox # TODO https://www.w3.org/TR/activitypub/#inbox-forwarding activity = request.json.copy() verified = await verify_request( request.method, request.path, request.headers, request.body ) if not verified: if request.app.config.DEBUG: logger.info("signature incorrect") else: return response.json({"zrada": "signature incorrect"}, status=401) # TODO skip blocked # if Outbox.find_one( # { # "activity.type": "Block", # "user_id": user_id, # "meta.undo": False, # }): # return response.json({"zrada": "actor is blocked"}, status=403) if activity["type"] == "Follow": saved = await Inbox.save(user, activity) if saved: deliverance = { "type": "Accept", "object": activity } deliverance = Activity(user, deliverance) await deliverance.save() asyncio.ensure_future(deliver(user.key, deliverance.render, [activity["actor"]])) elif activity["type"] in ["Announce", "Like", "Create"]: # TODO validate if local object of reaction exists in outbox saved = await Inbox.save(user, activity) local = check_origin(activity["object"], user.uri) if local and saved: await user.forward_to_followers(activity) elif activity["type"] == "Undo": deleted = await Inbox.delete(activity["object"]["id"]) undo_obj = activity["object"].get("object", "") if undo_obj.startswith(user.uri) and deleted: if activity["object"]["type"] == "Follow": await Outbox.delete(activity["object"]["id"]) elif activity["object"]["type"] in ["Announce", "Like"]: await user.forward_to_followers(activity) elif activity["type"] == "Delete": await Inbox.delete(activity["object"]["id"]) # TODO handle(forward) delete of reply to local user post else: await Inbox.save(user, activity) return response.json({'peremoga': 'yep'}, status=202)
async def inbox_post(request, user): # TODO implement shared inbox # TODO https://www.w3.org/TR/activitypub/#inbox-forwarding activity = request.json.copy() # TODO The receiver must verify the notification by fetching its source from the origin server. verified = await verify_request(request) if not verified: if getattr(request.app.config, 'DEBUG_INBOX', False): logger.info("signature incorrect") else: return response.json({"error": "signature incorrect"}, status=401) # TODO skip blocked # if Outbox.find_one( # { # "activity.type": "Block", # "user_id": user_id, # "meta.undo": False, # }): # return response.json({"zrada": "actor is blocked"}, status=403) if activity["type"] == "Follow": saved = await Inbox.save(user, activity) if saved: deliverance = {"type": "Accept", "object": activity} deliverance = Activity(user, deliverance) await deliverance.save() asyncio.ensure_future( deliver(user.key, deliverance.render, [activity["actor"]])) elif activity["type"] in ["Announce", "Like", "Create"]: # TODO validate if local object of reaction exists in outbox saved = await Inbox.save(user, activity) local_user = check_origin(activity["object"], user.uri) if saved: if local_user: await user.forward_to_followers(activity) elif activity["type"] in ["Announce", "Like"]: if not check_origin(activity["object"], request.app.base_url): await ensure_cached(activity['object']) elif activity["type"] == "Undo": deleted = await Inbox.delete(activity["object"]["id"]) undo_obj = activity["object"].get("object", "") if undo_obj.startswith(user.uri) and deleted: if activity["object"]["type"] == "Follow": await Outbox.delete(activity["object"]["id"]) elif activity["object"]["type"] in ["Announce", "Like"]: await user.forward_to_followers(activity) elif activity["type"] == "Delete": await Inbox.delete(activity["object"]["id"]) # TODO handle(forward) delete of reply to local user post else: await Inbox.save(user, activity) return response.json({'Created': 'success'}, status=202)
async def deliver(self, debug=False): recipients = await self.recipients() asyncio.ensure_future( deliver(self.user.key, self.render, recipients, debug=debug))
async def deliver(self): recipients = await self.recipients() asyncio.ensure_future(deliver(self.user.key, self.render, recipients))