Exemplo n.º 1
0
 def dialogs_get():
     get_data = dict(request.args)
     if 'uid' in get_data and get_data['uid'].isnumeric():
         interlocutor_id = get_data['uid']
         messages_model = Messages()
         my_data, interlocutor_data = messages_model.get_data(
             interlocutor_id)
         messages = messages_model.get_messages(interlocutor_id)
         return render_template('chat.html',
                                my_data=my_data,
                                interlocutor_data=interlocutor_data,
                                messages=messages)
     return redirect(url_for('dialogs'))
Exemplo n.º 2
0
class MessageNumApi(Resource):
    def __init__(self):
        self.message_model = Messages()

    def get(self):
        result = self.message_model.check_all_new_message(session['id'])
        if result:
            return {'num_message': result[0]['count']}, 200
        else:
            return {}, 204
Exemplo n.º 3
0
class LastMessageApi(Resource):
    def __init__(self):
        self.message_model = Messages()

    def get(self, you_id):
        result = self.message_model.get_last_message(session['id'], you_id)
        if result:
            result['message_date'] = str(result['message_date'])
            return {'new_messages': result}, 200
        else:
            return {}, 204
Exemplo n.º 4
0
class MessageApi(Resource):
    def __init__(self):
        self.message_model = Messages()

    def get(self, you_id):
        result = self.message_model.check_new_messages(session['id'],
                                                       you_id,
                                                       checker=True)
        if result:
            for r in result:
                r['message_date'] = str(r['message_date'])
            return {'new_messages': result}, 200
        else:
            return {}, 204

    def post(self, you_id):
        result = self.message_model.add_new_message(session['id'], you_id,
                                                    request.form['message'])
        if result:
            return {'id': session['id'], 'message_date': result}, 201
        else:
            return {}, 204
Exemplo n.º 5
0
class MessageNonCheckApi(Resource):
    def __init__(self):
        self.message_model = Messages()

    def get(self, you_id):
        result = self.message_model.check_new_messages(session['id'],
                                                       you_id,
                                                       checker=False)
        if result:
            for r in result:
                r['message_date'] = str(r['message_date'])
            return {'new_messages': result}, 200
        else:
            return {}, 204
Exemplo n.º 6
0
 def __init__(self):
     self.message_model = Messages()