Source

openju / openju / bl / message.py

#!/usr/bin/python
# -*- coding: utf-8 -*-

from openju.model import *

def post_message(user, body):
    message = (
        Message(
            user=user,
            body=body))
    message.save()
    return message

def get_last_messages(skip=None, limit=10):
    return Message.objects(reply_to__exists=False)[skip:limit]

def get_message(message_id):
    return Message.objects.get(id=message_id)

def get_replies(message_id):
    return Message.objects(reply_to=message_id)

def post_reply(message, user, body):
    """ Returns newly created message """
    reply = Message(
        user=user,
        body=body,
        reply_to=message,
        )
    reply.save()
    return reply