Exemple #1
0
def send(user, message):
    """
    Sends a message to all of a user's registered listeners
    """
    listeners = NotificationRegister.find({u"user": user})

    results = list()
    for listener in listeners:
        results.append(notifiers[listener[u"client_type"]].send(user, listener[u"client_id"], message))
    # this return is mainly to make all this testable
    return results
    def get(self):
        """
        Fetch the most recent notifications, and clears the queue.
        """

        # We require that the client id be sent, and that it belongs to this
        # user.  No eavesdropping allowed!
        client_id = self.get_argument(u"client_id", None)
        if not client_id or not NotificationRegister.get(
            {u"client_id": client_id, u"user": self.get_session()[u"username"]}
        ):
            raise HTTPError(403)

        # output to the client
        notifications = GenericPollNotifications.pop(client_id) or []
        self.output({u"notifications": notifications})