Пример #1
0
def create(data, notifData=None):
    """
    Create an event document.
    Parameters:
        data - a dictionary of the event data.
        notifData - a dictionary of data to be sent in the notifications.
    Returns:
        an event document.
    """
    db = core.connect()
    theTime = utils.utctime()
    data["created"] = theTime
    data["modified"] = theTime
    # create notification events
    notifications = stream.notifications(data["streamId"])
    for userId in notifications:
        create({
                "createdBy": data.get("createdBy"),
                "displayString": data.get("displayString"),
                "streamId": user.messageStream(userId),
                "unread": True,
                "content": data.get("content")
                })
    newEvent = schema.event()
    newEvent.update(data)
    newEvent["type"] = "event"
    return db.create(newEvent)
Пример #2
0
def invite(id, adminId, userId):
    """
    Give a user join permission.
    Parameters:
        id - a stream id.
        adminId - a user id, this user should be a stream admin.
        userId - a user id.
    """
    db = core.connect()
    permission.create({"streamId": id, "createdBy": adminId, "userId": userId, "level": 0})
    event.create(
        {
            "createdBy": userId,
            "streamId": user.messageStream(userId),
            "displayString": "%s has invited you to the %s %s" % (user.nameForId(adminId), meta(id), displayName(id)),
            "unread": True,
        }
    )