def adminChat(message: dict) -> dict: admin_user_info = UsersAuthJWT().adminIdentify( message['Authorization']) if isinstance(admin_user_info, str): return Utils.formatError(CONST['CODE']['ERROR_AUTH_CHECK_TOKEN_FAIL']['value'], admin_user_info) # 整合数据信息 filters = { Admin.id == admin_user_info['data']['id'], } admin_user_info = Admin().getOne(filters) default_img_data = Config().getOne( {Config.type == 'img', Config.code == 'default.img', Config.status == 1}) if default_img_data == None: default_img = 'static/img/about/python.jpg' else: default_img = default_img_data['config'] admin_user_info['nick_name'] = '系统管理-'+admin_user_info['nick_name'] admin_user_info['head_img'] = default_img # 这里后期改成配置的 # 使用0作为系统id msg = message['data']['msg'] room_uuid = message['data']['room_uuid'] Type = message['data']['type'] room_data = Room.get(room_uuid) if room_data == None: return Utils.formatError(CONST['CODE']['ROOM_NO_EXIST']['value'], "房间不存在") room_type = room_data.type created_at = int(time.time()) save_action = message['data']['save_action'] return ChatService.sendChatMessage(msg, room_uuid, Type, room_data, room_type, created_at, save_action, admin_user_info, 1)
def chat(message, user_info): """ @param dict message @param dict user_info @return dict """ msg = message['data']['msg'] room_uuid = message['data']['room_uuid'] Type = message['data']['type'] room_data = Room.get(room_uuid) if room_data == None: return Utils.formatError(CONST['CODE']['ROOM_NO_EXIST']['value'], "房间不存在") room_type = room_data.type created_at = message['data']['created_at'] save_action = message['data']['save_action'] user_data = Users().getOne({Users.id == user_info['data']['id']}) return ChatService.sendChatMessage(msg, room_uuid, Type, room_data, room_type, created_at, save_action, user_data)
def chat(self, message, user_info): """ @param dict message @param dict user_info @return dict """ msg = message['data']['msg'] room_uuid = message['data']['room_uuid'] Type = message['data']['type'] room_data = Room.get(room_uuid) room_type = room_data.type created_at = message['data']['created_at'] user_data = Users().getOne({Users.id == user_info['data']['id']}) if room_data != None and room_type == 0: address_book_data = AddressBook.get(room_uuid) #发送消息 emit('chat', Utils.formatBody({ 'msg': msg, 'name': user_data['nick_name'], 'user_id': user_data['id'], 'type': Type, 'head_img': user_data['head_img'], 'room_uuid': room_uuid, 'created_at': created_at }), room=room_uuid) #聊天时同步房间信息 Room.updateLastMsgRoom(room_uuid, msg) #更新聊天提示数字 AddressBook.updateUnreadNumber(room_uuid, user_data['id']) AddressBook.cleanUnreadNumber(room_uuid, user_data['id']) #更新客户端房间信息 for item in address_book_data: roomList = AddressBook.getRoomList( item.be_focused_user_id)['data'] socketio.emit('room', Utils.formatBody(roomList), namespace='/room', room='@broadcast.' + str(item.be_focused_user_id)) elif room_data != None and room_type == 1: user_room_relation_data = UserRoomRelation.get(room_uuid) #发送消息 emit('chat', Utils.formatBody({ 'msg': msg, 'name': user_data['nick_name'], 'user_id': user_data['id'], 'type': Type, 'head_img': user_data['head_img'], 'room_uuid': room_uuid, 'created_at': created_at }), room=room_uuid) #聊天时同步房间信息 Room.updateLastMsgRoom(room_uuid, msg) #更新聊天提示数字 UserRoomRelation.updateUnreadNumber(room_uuid, user_data['id']) UserRoomRelation.cleanUnreadNumber(room_uuid, user_data['id']) #更新客户端房间信息 for item in user_room_relation_data: #if item.user_id != user_id: roomList = UserRoomRelation.getRoomList(item.user_id)['data'] socketio.emit('groupRoom', Utils.formatBody(roomList), namespace='/room', room='@broadcast.' + str(item.user_id)) return Utils.formatBody({'action': "chat"})