def post(self, request): if request.user.is_authenticated: data = json.loads(request.body.decode('utf-8')) user_2_id = str(data['user_2_id']) database = Database() id_room = database.check_box_chat(request.user.id, user_2_id) # lưu tin nhắn if data['content'] != '': Mess = Message() Mess.from_user = MyUser.objects.get(id=request.user.id) Mess.conversation = Conversation.objects.get(c_id=id_room) Mess.content = data['content'] Mess.save() return HttpResponse('Gửi thành công rồi nhé Lalal') else: return redirect('home:home')
def send_comment_message(comment=(), su=User(), mu=User()): # tid:团队id,su:发表评论的用户,mu:文档的拥有者 # 我存的数据库原始id,使用msg/info给我发消息时请加密 # 这里没有写完,注释的地方需要完善 m = Message() m.owner = mu m.sender = su m.title = su.name + " 评论了您的文档:" # + comment.doc.title m.content = comment.content m.portrait = su.portrait m.related_id = comment.id m.type = 'doc' try: m.save() except: return False return True