Created method to send private messages
This commit is contained in:
parent
afe3395d48
commit
fc5100c515
1 changed files with 10 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
from pymongo import MongoClient
|
||||
from bson.objectid import ObjectId
|
||||
from backend import accounts
|
||||
import datetime
|
||||
|
||||
client = MongoClient()
|
||||
db = client.tweeder
|
||||
|
@ -13,16 +14,23 @@ def send_message(msg_from, msg_to, msg_content):
|
|||
from_id = accounts.get_profile(msg_from)['_id']
|
||||
elif type(msg_from) == ObjectId:
|
||||
from_id = msg_from
|
||||
msg_from = accounts_db.find_one({'_id': from_id})['displayname']
|
||||
|
||||
if type(msg_to) == str:
|
||||
to_id = accounts.get_profile(msg_to)['_id']
|
||||
elif type(msg_to) == ObjectId:
|
||||
to_id = msg_to
|
||||
msg_to = accounts_db.find_one({'_id': to_id})['displayname']
|
||||
|
||||
currentTimeDate = datetime.datetime.now()
|
||||
|
||||
message = {
|
||||
'from': from_id,
|
||||
'to': to_id,
|
||||
'content': msg_content
|
||||
'fromName': msg_from,
|
||||
'toName': msg_to,
|
||||
'content': msg_content,
|
||||
'timeSent': currentTimeDate
|
||||
}
|
||||
|
||||
messages_db.insert_one(message)
|
Loading…
Add table
Reference in a new issue