Beispiel #1
0
def get_messages():
    chat_id = request.form['chat_id']
    if not chat_model.can_write(chat_id):
        abort(400)
    try:
        last_msg_id = int(request.form['letter_id'])
    except ValueError:
        abort(400)

    letters = sorted(chat_model.get_messages(chat_id),
                     key=lambda x: x.create_time)
    ans = [{
        'id': msg.id,
        'text': msg.text,
        'is_business': msg.is_business
    } for msg in letters if msg.id > last_msg_id]
    chat_model.see_all(chat_id,
                       is_business=(not bool(session.get('id', False))))
    return jsonify(new_messages=ans)
Beispiel #2
0
def post_message():
    chat_id = request.form['chat_id']

    if not chat_model.can_write(chat_id):
        abort(400)

    msg = str(request.form['letter_id'])
    is_business = bool(session.get('id', False))

    regexp = re.compile('\<[^>]*\>')
    if len(re.findall(regexp, msg)) > 0:
        msg = '&#9731;' + msg

    msg = msg.replace('<', '&lt;')
    msg = msg.replace('>', '&gt;')

    letter = Letter(int(chat_id), msg, is_business)
    letter.save()

    return jsonify(id=letter.id)