Esempio n. 1
0
def reply_message():

    message = ""
    from_user_id = 0
    message_thread_id = ""
    name = ""
    response = {}

    if "message_thread_id" in request.form :
        message_thread_id = request.form["message_thread_id"]
        if message_thread_id == "" or message_thread_id is None:
            response = {
                "data": "not found",
                "message": "thread_id harus diisi!",
                "status_code": 203,
                "paginate": ""
            }
            return response


    if "from_user_id" in request.form :
        from_user_id = int(request.form["from_user_id"])

    if "message" in request.form :
        message = request.form["message"]

    data = Message()

    data.message_thread_id = message_thread_id
    data.user_id = from_user_id
    data.message = message
    data.created_at = datetime.datetime.now()
    data.updated_at = datetime.datetime.now()

    db.session.add(data)
    db.session.commit()

    check_user = User.query.filter_by(deleted_at=None).filter_by(id=data.user_id).first()
    db.session.commit()

    if check_user is not None:
        name = check_user.firstname + " " + check_user.lastname

    hasil = {
        "created_at" : data.created_at.strftime('%Y-%m-%d %H:%M:%S'),
        "name" : name,
        "user_id" : data.user_id,
        "message" : data.message
    }

    response = {
        "data": hasil,
        "message": "created message!",
        "status_code": 200,
        "paginate": ""
    }

    return response
Esempio n. 2
0
def create_message():
    subject = ""
    message_type = ""
    message = ""
    from_user_id = 0
    to_user_id = 0
    response = {}

    print (request.form)

    if "subject" in request.form :
        subject = request.form["subject"]

    if "from_user_id" in request.form :
        from_user_id = int(request.form["from_user_id"])

    if "to_user_id" in request.form :
        to_user_id = int(request.form["to_user_id"])

    if "message_type" in request.form :
        message_type = request.form["message_type"]

    if "message" in request.form :
        message = request.form["message"]

    thread = MessageThread()

    thread.subject = subject
    thread.message_type = message_type
    thread.message = message
    thread.from_user_id = from_user_id
    thread.to_user_id = to_user_id
    thread.created_at = datetime.datetime.now()
    thread.updated_at = datetime.datetime.now()

    db.session.add(thread)
    db.session.commit()

    data = Message()

    data.message_thread_id = thread.id
    data.user_id = from_user_id
    data.message = message
    data.created_at = datetime.datetime.now()
    data.updated_at = datetime.datetime.now()

    db.session.add(data)
    db.session.commit()

    response = {
        "data": "berhasil",
        "message": "created message!",
        "status_code": 200,
        "paginate": ""
    }

    return response
Esempio n. 3
0
def up():
    for item in seed:
        message = Message(**item["init"])

        minutes = item["created_at_minutes"]
        message.created_at = datetime.fromisoformat(
            f"2021-10-10T12:{minutes}:00.000000")

        db.session.add(message)

    db.session.commit()
Esempio n. 4
0
    def on_message(self, message):
        message = Message(**json.loads(message))
        message.author = self.current_user
        message.created_at = datetime.utcnow()
        message.conversation = self.conversation

        self.db.add(message)
        self.db.commit()

        for user in self.conversation.connected_users:
            user.write_message(json.dumps(message.as_json()))