Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/NorCz/MessageApp
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekuskus committed Feb 27, 2024
2 parents 30b0e6b + 761631f commit f1bc132
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
59 changes: 57 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def send_message(user_id):
400
)
params = request.json

u_id = current_user.get_id()
if "content" not in params:
return make_response(
jsonify(
Expand All @@ -415,14 +415,18 @@ def send_message(user_id):

with app.app_context():
message = PrivateMessage(
from_id=current_user.get_id(),
from_id=u_id,
to_id=user_id,
content=params.get("content"),
)
if 'attachment' in params:
message.attachment = params.get("attachment")
db.session.add(message)
db.session.commit()
u_id = current_user.get_id()
m = PrivateMessagesRead.query.filter_by(from_user_id=u_id).filter_by(to_user_id=user_id).first()
m.readTill = int(time.time() * 1000) + 1
db.session.commit()
return jsonify(
response=True
)
Expand Down Expand Up @@ -823,6 +827,40 @@ def send_group_message(chat_id):
)


@app.route('/api/chats', methods=["GET"])
@login_required
def get_info_about_chat(chat_id):
chat = GroupChat.query.all()
json_of_users = {}
for i in chat:
json_of_users.update({"id": i.id, "name": i.name})
return json.dumps(json_of_users)


@app.route('/api/group_chats/read_till/<chat_id>', methods=["POST"])
@login_required
def gr_read_till(chat_id):
if request.json:
data = request.json
if "date" in data:
u_id = current_user.get_id()
chat_member = ChatMember.query.filter_by(user_id=u_id).filter_by(groupchat_id=chat_id).first()
chat_member.readtill = data["date"]
db.session.commit()
return make_response(jsonify(response=True), 200)
else:
return make_response(
jsonify(
response=False
), 404
)
return make_response(
jsonify(
response=False
), 404
)


@app.route('/api/chat/<chat_id>')
@login_required
def get_chat_member(chat_id):
Expand All @@ -839,6 +877,23 @@ def get_chat_member(chat_id):
), 404)


@app.route("/api/chat/get_chat_member/<chat_id>/<user_id>", methods=["GET"])
def get_mem(chat_id, user_id):
member = ChatMember.query.filter((ChatMember.groupchat_id == chat_id) & (ChatMember.user_id == user_id)).first()
if member is not None:
return jsonify(
id=member.id,
user_id=member.user_id,
readtill=member.readtill,
isAdmin=member.isAdmin,
isRemove=member.isRemoved,
groupchat_id=member.groupchat_id
)
else:
return make_response(jsonify(
response=False
), 404)


@app.route('/api/chats/<chat_id>/<page>', methods=["GET"])
@login_required
Expand Down
2 changes: 1 addition & 1 deletion models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class GroupMessage(db.Model):
content = db.Column(db.String, unique=False, nullable=False)
isDeleted = db.Column(db.Boolean, unique=False, nullable=False, default=False)
timestamp = db.Column(db.DateTime, unique=False, nullable=False, default=datetime.now)
attachment = db.Column(db.LargeBinary, unique=False, nullable=True)
attachment = db.Column(db.String, unique=False, nullable=True)

member = db.relationship('ChatMember')
groupchat = db.relationship('GroupChat')
Expand Down
1 change: 1 addition & 0 deletions send_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

load_dotenv('/app/backend/.env', verbose=True, override=True)


def send_email(destination_email, code):
asyncio.run(send_generic_email(destination_email, "Hi there", f"Your code is {code}"))

Expand Down

0 comments on commit f1bc132

Please sign in to comment.