예제 #1
0
파일: messages.py 프로젝트: bibliotechie/h
def _generate_annotation_event(session, request, message, resource):
    """
    Get message about annotation event `message` to be sent to `socket`.

    Inspects the embedded annotation event and decides whether or not the
    passed socket should receive notification of the event.

    Returns None if the socket should not receive any message about this
    annotation event, otherwise a dict containing information about the event.
    """

    if message["action"] == "delete":
        payload = {"id": message["annotation_id"]}
    else:
        user_service = request.find_service(name="user")
        formatters = [AnnotationUserInfoFormatter(session, user_service)]
        payload = presenters.AnnotationJSONPresenter(
            resource, formatters=formatters).asdict()

    return {
        "type": "annotation-notification",
        "options": {
            "action": message["action"]
        },
        "payload": [payload],
    }
예제 #2
0
def handle_annotation_event(message, sockets, settings, session):
    id_ = message["annotation_id"]
    annotation = storage.fetch_annotation(session, id_)

    if annotation is None:
        log.warning("received annotation event for missing annotation: %s",
                    id_)
        return

    # Find connected clients which are interested in this annotation.
    matching_sockets = SocketFilter.matching(sockets, annotation)

    try:
        # Check to see if the generator has any items
        first_socket = next(matching_sockets)
    except StopIteration:
        # Nothing matched
        return

    # Create a generator which has the first socket back again
    matching_sockets = chain((first_socket, ), matching_sockets)

    nipsa_service = NipsaService(session)
    user_nipsad = nipsa_service.is_flagged(annotation.userid)

    authority = settings.get("h.authority", "localhost")
    group_service = GroupfinderService(session, authority)
    user_service = UserService(authority, session)
    formatters = [AnnotationUserInfoFormatter(session, user_service)]

    for socket in matching_sockets:
        reply = _generate_annotation_event(message, socket, annotation,
                                           user_nipsad, group_service,
                                           formatters)
        if reply is None:
            continue
        socket.send_json(reply)
예제 #3
0
파일: messages.py 프로젝트: julien-cheng/h
def handle_annotation_event(message, sockets, settings, session):
    id_ = message["annotation_id"]
    annotation = storage.fetch_annotation(session, id_)

    if annotation is None:
        log.warning("received annotation event for missing annotation: %s",
                    id_)
        return

    nipsa_service = NipsaService(session)
    user_nipsad = nipsa_service.is_flagged(annotation.userid)

    authority = text_type(settings.get("h.authority", "localhost"))
    group_service = GroupfinderService(session, authority)
    user_service = UserService(authority, session)
    formatters = [AnnotationUserInfoFormatter(session, user_service)]

    for socket in sockets:
        reply = _generate_annotation_event(message, socket, annotation,
                                           user_nipsad, group_service,
                                           formatters)
        if reply is None:
            continue
        socket.send_json(reply)