Created messages.py with basic send_message function

This commit is contained in:
SecretlyTaco 2018-03-17 01:40:28 +00:00
parent 8ada8b853f
commit afe3395d48

28
backend/messages.py Normal file
View file

@ -0,0 +1,28 @@
from pymongo import MongoClient
from bson.objectid import ObjectId
from backend import accounts
client = MongoClient()
db = client.tweeder
accounts_db = db.accounts
messages_db = db.messages
def send_message(msg_from, msg_to, msg_content):
if type(msg_from) == str:
from_id = accounts.get_profile(msg_from)['_id']
elif type(msg_from) == ObjectId:
from_id = msg_from
if type(msg_to) == str:
to_id = accounts.get_profile(msg_to)['_id']
elif type(msg_to) == ObjectId:
to_id = msg_to
message = {
'from': from_id,
'to': to_id,
'content': msg_content
}
messages_db.insert_one(message)