From 84d7e7c3945da3d3cd7fa1ad5f9da8f9e525fd4c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 29 Mar 2020 18:42:34 -0700 Subject: [PATCH] Simplifies incoming activity handler --- fedireads/incoming.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/fedireads/incoming.py b/fedireads/incoming.py index 9f9fedba8..12649f433 100644 --- a/fedireads/incoming.py +++ b/fedireads/incoming.py @@ -38,23 +38,23 @@ def shared_inbox(request): 'Reject': handle_follow_reject, 'Create': handle_create, 'Like': handle_favorite, - 'Add': handle_add, + 'Add': { + 'Tag': handle_add, + }, + 'Undo': { + 'Follow': handle_unfollow, + 'Like': handle_unfavorite, + }, + 'Update': { + 'Person': None,# TODO: handle_update_user + 'Document': None# TODO: handle_update_book + }, } activity_type = activity['type'] - handler = None - if activity_type in handlers: - handler = handlers[activity_type] - elif activity_type == 'Undo' and 'object' in activity: - if activity['object']['type'] == 'Follow': - handler = handle_unfollow - elif activity['object']['type'] == 'Like': - handler = handle_unfavorite - elif activity_type == 'Update' and 'object' in activity: - if activity['object']['type'] == 'Person': - handler = None# TODO: handle_update_user - elif activity_type['object']['type'] == 'Book': - handler = None# TODO: handle_update_book + handler = handlers.get(activity_type, None) + if isinstance(handler, dict): + handler = handler.get(activity['object']['type'], None) if handler: return handler(activity)