def test_get_msg_list_uid(): # print_b(MessageLib.get_msg_list(0, 10000000)) assert isinstance(MessageLib.get_msg_list(0, 10000000), list) # private msg res = MessageLib.get_msg_list(0, 10000000) last_msg_id = res[len(res) - 1]['id'] # print_b(MessageLib.get_msg_list(last_msg_id, 10000000)) assert isinstance(MessageLib.get_msg_list(last_msg_id, 10000000), list) # private msg
async def message_list(request, last_msg_id: types.number, os_type: types.text, app_version: types.text, channel: types.text, package_name: types.text = 'com.test.package', uid: types.number = -1, ticket: types.text = ''): """ """ if uid <= 0: return tools.response(MessageLib.get_msg_list(last_msg_id)) res = await UserLib.check_ticket(ticket, uid) if res['data']: return tools.response(MessageLib.get_msg_list(last_msg_id, uid)) return tools.response(code=err_code._ERR_TICKET_ERR, message="身份验证失败")
def get(self): uid = self.post_data.get('uid', '') password = self.post_data.get('password', '') last_msg_id = self.post_data.get('last_msg_id', '') res = yield UserLib.check_user(uid, password) if res: message_history = yield MessageLib.get_message_history(uid, last_msg_id) self.writeS({"data": message_history, "code": 0}) else: self.writeS({"data": "Error login info !!", "code": 1}) return
def on_message(self, message): try: pkg = json.loads(message) except: self.write_message(self.create_error_pkg(u'Format error')) return if pkg['TYPE'] == JOIN: self.client_name = pkg['USER_NAME'] self.uid = pkg['UID'] self.join_completed = True NAMED_CONNECTED_CLIENTS[pkg['UID']] = self CONNECTED_CLIENTS.remove(self) self.broadcast(self.create_join_pkg()) message_pkg = yield self.create_userlist_pkg() self.broadcast(message_pkg) # self.write_message(self.create_userlist_pkg()) elif pkg['TYPE'] == PRIVATE_MESSAGE: self.send_private_message( pkg['TO'], self.create_private_message_pkg(pkg['MESSAGE'])) pkg['FROM_UID'] = self.uid pkg['FROM'] = self.client_name pkg['MESSAGE_TYPE'] = PRIVATE_MESSAGE yield MessageLib.save_message(pkg) elif pkg['TYPE'] == MESSAGE: self.broadcast(self.create_message_pkg(pkg['MESSAGE'])) pkg['FROM_UID'] = self.uid pkg['FROM'] = self.client_name pkg['TO'] = '' pkg['MESSAGE_TYPE'] = MESSAGE yield MessageLib.save_message(pkg) elif pkg['TYPE'] == USERLIST: message_pkg = yield self.create_userlist_pkg() self.write_message(message_pkg) elif pkg['TYPE'] == NAMECHANGE: old_name = self.client_name self.client_name = pkg['NEWNAME'] self.broadcast(self.create_name_change_pkg(old_name)) else: self.write_message(self.create_error_pkg('unknown message type'))
def on_message(self, message): try: pkg = json.loads(message) except: self.write_message(self.create_error_pkg(u'Format error')) return if pkg['TYPE'] == JOIN: self.client_name = pkg['USER_NAME'] self.uid = pkg['UID'] self.join_completed = True NAMED_CONNECTED_CLIENTS[pkg['UID']] = self CONNECTED_CLIENTS.remove(self) self.broadcast(self.create_join_pkg()) message_pkg = yield self.create_userlist_pkg() self.broadcast(message_pkg) # self.write_message(self.create_userlist_pkg()) elif pkg['TYPE'] == PRIVATE_MESSAGE: self.send_private_message(pkg['TO'], self.create_private_message_pkg(pkg['MESSAGE'])) pkg['FROM_UID'] = self.uid pkg['FROM'] = self.client_name pkg['MESSAGE_TYPE'] = PRIVATE_MESSAGE yield MessageLib.save_message(pkg) elif pkg['TYPE'] == MESSAGE: self.broadcast(self.create_message_pkg(pkg['MESSAGE'])) pkg['FROM_UID'] = self.uid pkg['FROM'] = self.client_name pkg['TO'] = '' pkg['MESSAGE_TYPE'] = MESSAGE yield MessageLib.save_message(pkg) elif pkg['TYPE'] == USERLIST: message_pkg = yield self.create_userlist_pkg() self.write_message(message_pkg) elif pkg['TYPE'] == NAMECHANGE: old_name = self.client_name self.client_name = pkg['NEWNAME'] self.broadcast(self.create_name_change_pkg(old_name)) else: self.write_message(self.create_error_pkg('unknown message type'))
def get(self): uid = self.post_data.get('uid', '') password = self.post_data.get('password', '') last_msg_id = self.post_data.get('last_msg_id', '') res = yield UserLib.check_user(uid, password) if res: message_history = yield MessageLib.get_message_history( uid, last_msg_id) self.writeS({"data": message_history, "code": 0}) else: self.writeS({"data": "Error login info !!", "code": 1}) return
def test_get_msg_list(): # print_b(MessageLib.get_msg_list(0, -1)) assert isinstance(MessageLib.get_msg_list(0, -1), list) # public msg