def message(self, msg): '''收到Ejabberd服务器发来的信息, 判断后发到browser端''' if msg['type'] == 'chat': # 只有上线后才能收到信息 ChatMessageDocument.get_collection(True).update( {'_id': ObjectId(str(msg['subject']))}, {'$set': {'received': True}}) BrowserClientManager.new_message(msg)
def message(self, msg): '''收到Ejabberd服务器发来的信息, 判断后发到browser端''' if msg['type'] == 'chat': # 只有上线后才能收到信息 ChatMessageDocument.get_collection(True).update( {'_id': ObjectId(str(msg['subject']))}, {'$set': { 'received': True }}) BrowserClientManager.new_message(msg)
def new_message(self, msg): '''新消息: Ejabberd服务器 => XMPPClient => Broswer => Here(callback)''' if self.request.connection.stream.closed(): return message = ChatMessageDocument.get_collection(pymongo=True).find_one( {'_id': ObjectId(str(msg['subject']))} ) BrowserClientManager.remove(self.current_user_id, self.chat_with_id) self.render('chat/template/message-others.html', message=message)
def post(self): form = MessageUpdateForm(self.request.arguments) if not form.validate(): raise HTTPError(404) self.chat_with_id = form.chat_with.data self.current_user_id = str(self.current_user['_id']) if self.current_user_id == self.chat_with_id: raise HTTPError(404) BrowserClientManager.add( self.current_user_id, self.chat_with_id, self.new_message)
def on_connection_close(self): BrowserClientManager.remove(self.current_user_id, self.chat_with_id)