Added chat list endpoint
Returns all chats that are associated with a user
This commit is contained in:
20
main.py
20
main.py
@@ -1,6 +1,7 @@
|
|||||||
from flask import Flask, jsonify, request, render_template
|
from flask import Flask, jsonify, request, render_template
|
||||||
from pymongo import MongoClient
|
from pymongo import MongoClient
|
||||||
from bson.objectid import ObjectId
|
from bson.objectid import ObjectId
|
||||||
|
from bson.json_util import dumps, loads
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from argon2 import PasswordHasher
|
from argon2 import PasswordHasher
|
||||||
import random
|
import random
|
||||||
@@ -80,6 +81,25 @@ def checkChatPermission(token, chatId, permission):
|
|||||||
else:
|
else:
|
||||||
return False, "Invalid Token"
|
return False, "Invalid Token"
|
||||||
|
|
||||||
|
# Chat List Endpoint:
|
||||||
|
# Get all the chats associated with a user
|
||||||
|
# Arguments: token (required)
|
||||||
|
@app.route('/api/user/chats', methods = ['GET'])
|
||||||
|
def getUserChats():
|
||||||
|
# Get user auth token
|
||||||
|
token = request.json['token']
|
||||||
|
a, userId = checkUserPermission(token, True)
|
||||||
|
if (a == True):
|
||||||
|
returnedChats = list(chatCollection.find({'permissions.' + userId : "view"}))
|
||||||
|
chats = []
|
||||||
|
for doc in returnedChats:
|
||||||
|
if '_id' in doc and isinstance(doc['_id'], ObjectId):
|
||||||
|
doc['_id'] = str(doc['_id'])
|
||||||
|
chats.append(doc)
|
||||||
|
|
||||||
|
jsonChats = json.dumps(chats, indent=2)
|
||||||
|
return jsonChats
|
||||||
|
|
||||||
# Chat Details Endpoint:
|
# Chat Details Endpoint:
|
||||||
# Get or change details about a chat using the chatId
|
# Get or change details about a chat using the chatId
|
||||||
# Arguments: token (required), details (required), model, name
|
# Arguments: token (required), details (required), model, name
|
||||||
|
|||||||
Reference in New Issue
Block a user