~fabrixxm/activist

5bc616f0e1b7ea3025163d75ba01033d89d095ba — fabrixxm 10 months ago ed9d068
Handle Undo activity (maybe)
1 files changed, 25 insertions(+), 0 deletions(-)

M activist/activitypub.py
M activist/activitypub.py => activist/activitypub.py +25 -0
@@ 184,6 184,28 @@ def handle_follow(activity:dict, actor:dict) -> bool:
    return True


def handle_undo(activity:dict, actor:dict) -> bool:
    logging.debug("handle_incoming: something has been undone..")
    try:
        obj = stored_object(activity['object'])
    except store.ObjectNotFound:
        logger.warning("handle_incoming Undone object %r not found, ignore", activity['object'])
        return False
    
    if obj['type'] == "Follow":
        followed_actor_id = obj['object']  # our activityes have always object id as object...
        if followed_actor_id == settings.USER_URL:
            logger.debug("handle_reject: %r has undone Follow us", actor['id'])

            # delete object from store, delete actor from followed
            store.rm(obj['id'])
            store.list_rm('followers', actor['id'])
        else:
            logger.info("%r sent an Undo to a Follow for %r . ignore!", actor['id'], followed_actor_id)
            return False

    return True


def handle_incoming(activity:dict):
    # TODO: check request signature


@@ 205,6 227,9 @@ def handle_incoming(activity:dict):
    elif acttype == "Follow":
        can_store = handle_follow(activity, actor)

    elif acttype == "Undo":
        can_store = handle_undo(activity, actor)


    if can_store:
        # store activity