Exemple #1
0
 def addRoomAndAddressBook(room_uuid, focused_user_id, be_focused_user_id):
     roomData = {
         'room_uuid': room_uuid,
         'last_msg': '',
         'user_id': focused_user_id,
         'type': 0
     }
     Room.insertRoomData(roomData)
     addressBook = AddressBook(
         focused_user_id=focused_user_id,
         be_focused_user_id=be_focused_user_id,
         room_uuid=room_uuid,
         unread_number=0,
         is_alert=1,
         type=0,
     )
     dBSession.add(addressBook)
     addressBook = AddressBook(
         focused_user_id=be_focused_user_id,
         be_focused_user_id=focused_user_id,
         room_uuid=room_uuid,
         unread_number=0,
         is_alert=1,
         type=0,
     )
     dBSession.add(addressBook)
     return True
Exemple #2
0
 def adminAddRoomAndAddressBook(room_uuid, admin_user_info,
                                be_focused_user_id):
     roomData = {
         'room_uuid': room_uuid,
         'last_msg': '',
         'user_id': admin_user_info['id'],
         'type': CONST['ROOM']['ADMIN']['value'],
         'name': '系统管理-' + admin_user_info['nick_name']
     }
     Room.insertAdminRoomData(roomData)
     addressBook = AddressBook(focused_user_id=admin_user_info['uuid'],
                               be_focused_user_id=be_focused_user_id,
                               room_uuid=room_uuid,
                               unread_number=0,
                               is_alert=1,
                               save_action=CONST['SAVE']['CLOUD']['value'],
                               type=CONST['ADDRESSBOOK']['ADMIN']['value'])
     dBSession.add(addressBook)
     addressBook = AddressBook(focused_user_id=be_focused_user_id,
                               be_focused_user_id=admin_user_info['uuid'],
                               room_uuid=room_uuid,
                               unread_number=0,
                               is_alert=1,
                               save_action=CONST['SAVE']['CLOUD']['value'],
                               type=CONST['ADDRESSBOOK']['ADMIN']['value'])
     dBSession.add(addressBook)
     return True
Exemple #3
0
def roomDel(user_info, params):
    filters = {
        Room.room_uuid == params['room_uuid']
    }
    roomData = Room().getOne(filters)
    if roomData['type'] == 0:
        filters = {
            AddressBook.room_uuid == params['room_uuid']
        }
        AddressBook().delete(filters)
        filters = {
            Room.room_uuid == params['room_uuid']
        }
        Room().delete(filters)
    else:
        filters = {
            UserRoomRelation.room_uuid == params['room_uuid'],
            UserRoomRelation.user_id == params['user_id']
        }
        data = UserRoomRelation().delete(filters)
        filters = {
            Room.room_uuid == params['room_uuid'],
            Room.user_id == params['user_id']
        }
        Room().delete(filters)

    return BaseController().successData()
Exemple #4
0
def adminRoomList(*args, **kwargs):
    """ 获取房间列表 """
    params = kwargs['params']
    filters = {Room.name.like('%' + params['keyword'] + '%')}
    data = Room().getList(filters, Room.updated_at.desc(), (),
                          params['page_no'], params['per_page'])
    return BaseController().successData(data)
Exemple #5
0
 def updateSaveAction(params, user_info):
     """ 更新是否云端保存 """
     filters = {
         Room.room_uuid == params['room_uuid']
     }
     roomData = Room().getOne(filters)
     if roomData['type'] == CONST['ROOM']['ALONE']['value']:
         filters = {
             AddressBook.room_uuid == params['room_uuid'],
             AddressBook.be_focused_user_id == user_info['data']['id']
         }
         data = {
             'save_action': params['save_action']
         }
         status = AddressBook().edit(data, filters)
     else:
         filters = {
             UserRoomRelation.room_uuid == params['room_uuid'],
             UserRoomRelation.user_id == user_info['data']['id']
         }
         data = {
             'save_action': params['save_action']
         }
         status = UserRoomRelation().edit(data, filters)
     if status:
         return Utils.formatBody()
Exemple #6
0
 def updateAlert(params, user_info):
     """ 更新对否提醒 """
     filters = {
         Room.room_uuid == params['room_uuid']
     }
     roomData = Room().getOne(filters)
     if roomData['type'] == 0:
         filters = {
             AddressBook.room_uuid == params['room_uuid'],
             AddressBook.be_focused_user_id == user_info['data']['id']
         }
         data = {
             'is_alert': params['is_alert']
         }
         status = AddressBook().edit(data, filters)
     else:
         filters = {
             UserRoomRelation.room_uuid == params['room_uuid'],
             UserRoomRelation.user_id == user_info['data']['id']
         }
         data = {
             'is_alert': params['is_alert']
         }
         status = UserRoomRelation().edit(data, filters)
     if status:
         return Utils.formatBody()
Exemple #7
0
    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)
Exemple #8
0
 def groupChatCreate(self, user_info, params):
     """ 
         创建聊天群组
         @Param dict userInfo
         @param dict params
         @return bool
     """
     room_uuid = Utils.unique_id()
     name = ''
     now_item = int(time.time())
     for id in params['ids']:
         user_data = Users().getOne({Users.id == id})
         name = name + ',' + user_data['nick_name']
         userRoomRelationData = {
             'user_id': id,
             'room_uuid': room_uuid,
             'is_alert': 0,
             'unread_number': 0,
             'updated_at': now_item,
             'created_at': now_item
         }
         UserRoomRelation().add(userRoomRelationData)
     room_data = {
         'room_uuid': room_uuid,
         'last_msg': '',
         'type': 1,
         'updated_at': now_item,
         'created_at': now_item,
         'name': name.strip(','),
         'user_id': user_info['data']['id']
     }
     room = Room().addByClass(room_data)
     return {'room_uuid': room_uuid}
Exemple #9
0
 def getByRoomUuid(params, user_info):
     """ 获取群组或单聊信息 """
     filters = {
         Room.room_uuid == params['room_uuid']
     }
     roomData = Room().getOne(filters)
     if roomData['type'] == 0:
         filters = {
             AddressBook.room_uuid == params['room_uuid']
         }
         data = AddressBook().getList( filters, AddressBook.updated_at.desc())
         filters.add(
             AddressBook.be_focused_user_id == user_info['data']['id']
         )
         data['room'] = AddressBook().getOne( filters)
     else:
         filters = {
             UserRoomRelation.room_uuid == params['room_uuid']
         }
         data = UserRoomRelation().getList( filters, UserRoomRelation.updated_at.desc())
         filters.add(
             UserRoomRelation.user_id == user_info['data']['id']
         )
         data['room'] = UserRoomRelation().getOne( filters)
     return Utils.formatBody(data)
Exemple #10
0
 def addRoomAndAddressBook(room_uuid, focused_user_id, be_focused_user_id):
     roomData = {
         'room_uuid': room_uuid,
         'last_msg': '',
         'user_id': focused_user_id
     }
     room = Room.insertRoomData(roomData)
     addressBook = AddressBook(
         focused_user_id=focused_user_id,
         be_focused_user_id=be_focused_user_id,
         room_uuid=room_uuid,
         unread_number=0,
         is_alert=1,
         created_at=time.time(),
         updated_at=time.time()
     )
     dBSession.add(addressBook)
     addressBook = AddressBook(
         focused_user_id=be_focused_user_id,
         be_focused_user_id=focused_user_id,
         room_uuid=room_uuid,
         unread_number=0,
         is_alert=1,
         created_at=time.time(),
         updated_at=time.time()
     )
     dBSession.add(addressBook)
     return True
Exemple #11
0
def userRoomRelationUpdateSaveAction(params, user_info):
    """ 更新是否云端保存 """
    filters = {
        Room.room_uuid == params['room_uuid']
    }
    roomData = Room().getOne(filters)
    if roomData['type'] == 0:
        filters = {
            AddressBook.room_uuid == params['room_uuid'],
            AddressBook.be_focused_user_id == user_info['data']['id']
        }
        data = {
            'save_action': params['save_action']
        }
        status = AddressBook().edit(data, filters)
    else:
        filters = {
            UserRoomRelation.room_uuid == params['room_uuid'],
            UserRoomRelation.user_id == user_info['data']['id']
        }
        data = {
            'save_action': params['save_action']
        }
        status = UserRoomRelation().edit(data, filters)
    if status:
        return BaseController().successData()
Exemple #12
0
def adminRoomDelete(*args, **kwargs):
    """ 删除房间 """
    params = kwargs['params']
    filters = {Room.room_uuid == params['room_uuid']}
    Room().delete(filters)
    filters = {UserRoomRelation.room_uuid == params['room_uuid']}
    UserRoomRelation().delete(filters)
    return BaseController().successData()
Exemple #13
0
 def delete(params, user_info):
     filters = {Room.room_uuid == params['room_uuid']}
     roomData = Room().getOne(filters)
     if roomData['type'] == 0:
         address_book_data = Utils.db_l_to_d(
             AddressBook.get(params['room_uuid']))
         filters = {AddressBook.room_uuid == params['room_uuid']}
         AddressBook().delete(filters)
         filters = {Room.room_uuid == params['room_uuid']}
         Room().delete(filters)
         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']))
             roomList = AddressBook.getRoomList(
                 item['focused_user_id'])['data']
             socketio.emit('room',
                           Utils.formatBody(roomList),
                           namespace="/room",
                           room='@broadcast.' +
                           str(item['focused_user_id']))
     else:
         user_room_relation_data = Utils.db_l_to_d(
             UserRoomRelation.get(params['room_uuid']))
         filters = {
             UserRoomRelation.room_uuid == params['room_uuid'],
             UserRoomRelation.user_id == user_info['data']['id']
         }
         data = UserRoomRelation().delete(filters)
         filters = {Room.room_uuid == params['room_uuid']}
         Room().delete(filters)
         filters = {UserRoomRelation.room_uuid == params['room_uuid']}
         UserRoomRelation().delete(filters)
         for item in user_room_relation_data:
             roomList = UserRoomRelation.getRoomList(
                 item['user_id'])['data']
             socketio.emit('groupRoom',
                           Utils.formatBody(roomList),
                           namespace='/room',
                           room='@broadcast.' + str(item['user_id']))
     return Utils.formatBody()
Exemple #14
0
    def load_rooms():
        room_files_location = DataManager.data_location + 'rooms/*'
        room_files = glob(room_files_location)
        print("INFO: found %d rooms to load in folder '%s'." %
              (len(room_files), room_files_location))

        for room_file in room_files:
            with open(room_file) as room_handler:
                room_json = json.load(room_handler)

                room_object = Room(**room_json)
                DataManager.rooms[room_json['id']] = room_object
        print()
Exemple #15
0
def adminIndex(user_info):
    #获取管理用户总数
    admins = Admin().getCount({})
    #获取注册用户总数
    users = Users().getCount({})
    #获取房间总数
    rooms = Room().getCount({})
    #一周管理用户注册数量
    weekAdminData = Admin().getWeekData()
    #一周注册用户注册数量
    weekUsersData = Users().getWeekData()
    #一周房间总数
    weekRoomData = Room().getWeekData()
    data = {
        'panelGroupData': {
            'adminCount': admins,
            'usersCount': users,
            'roomCount': rooms
        },
        'weekAdminData': weekAdminData,
        'weekUsersData': weekUsersData,
        'weekRoomData': weekRoomData
    }
    return BaseController().successData(data)
def userRoomRelationGetByRoomUuid(params, user_info):
    """ 获取群组或单聊信息 """
    filters = {Room.room_uuid == params['room_uuid']}
    roomData = Room().getOne(filters)
    if roomData['type'] == 0:
        filters = {AddressBook.room_uuid == params['room_uuid']}
        data = AddressBook().getList(filters, 'updated_at desc')
        filters.add(AddressBook.be_focused_user_id == user_info['data']['id'])
        data['room'] = AddressBook().getOne(filters)
    else:
        filters = {UserRoomRelation.room_uuid == params['room_uuid']}
        data = UserRoomRelation().getList(filters, 'updated_at desc')
        filters.add(UserRoomRelation.user_id == user_info['data']['id'])
        data['room'] = UserRoomRelation().getOne(filters)
    return BaseController().successData(data)
Exemple #17
0
 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)
Exemple #18
0
 def groupChatCreate(params, user_info):
     """ 
         创建聊天群组,userInfo.id是群主
         @Param dict userInfo
         @param dict params
         @return bool
     """
     room_uuid = Utils.unique_id()
     name = ''
     userRoomRelationData = {
             'user_id': user_info['data']['id'],
             'room_uuid': room_uuid,
             'is_alert': 0,
             'unread_number': 0,
             'type':CONST['GROUP']['MASTER']['value']
         }
     UserRoomRelation().add(userRoomRelationData)
     for id in params['ids']:
         user_data = Users().getOne({Users.id == id})
         name = name + ',' + user_data['nick_name']
         userRoomRelationData = {
             'user_id': id,
             'room_uuid': room_uuid,
             'is_alert': 0,
             'unread_number': 0
         }
         UserRoomRelation().add(userRoomRelationData)
     room_data = {
         'room_uuid': room_uuid,
         'last_msg': '',
         'type': CONST['CHAT']['TEXT']['value'],
         'name': name.strip(','),
         'user_id': user_info['data']['id']
     }
     Room().addByClass(room_data)
     return {'room_uuid': room_uuid, 'name': name.strip(',')}
Exemple #19
0
 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"})
Exemple #20
0
 def sendChatMessage(msg, room_uuid, Type, room_data, room_type, created_at, save_action, user_data, user_type=0):
     data = {
         '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,
         'read_status': 0,
         'user_type': user_type
         }
     if room_data != None and room_type == CONST['ROOM']['ADMIN']['value']:
         address_book_data = AddressBook.get(room_uuid)
         # 发送消息
         socketio.emit('chat',  Utils.formatBody(data),
                       namespace='/api', room=room_uuid)
         # 视频消息则直接返回
         if Type ==  CONST['CHAT']['VIDEO']['value']:
             return
         # 如果是云端存储则记录,这边判断不判断都存储
         # if save_action == CONST['SAVE']['CLOUD']['value']:
         res = Msg().getOne({Msg.room_uuid == room_uuid, Msg.created_at ==
                             created_at, Msg.user_id == user_data['id']})
         if res == None:
             copy_data = data.copy()
             copy_data['msg'] = json.dumps(msg)
             copy_data['send_status'] = CONST['STATUS']['SUCCESS']['value']
             Msg().add(copy_data)
         else:
             copy_data = data.copy()
             copy_data['msg'] = json.dumps(msg)
             copy_data['send_status'] = CONST['STATUS']['SUCCESS']['value']
             filters = {
                 Msg.name == copy_data['name'],
                 Msg.created_at == copy_data['created_at'],
                 Msg.room_uuid == room_uuid
             }
             Msg().edit(copy_data, filters)
         # 聊天时同步房间信息
         Room.updateLastMsgRoom(room_uuid, data, created_at)
         # 更新聊天提示数字
         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)
             socketio.emit('room', Utils.formatBody(
                 roomList), namespace='/api', room='@broadcast.'+str(item.be_focused_user_id))
     if room_data != None and room_type == CONST['ROOM']['ALONE']['value']:
         address_book_data = AddressBook.get(room_uuid)
         # 视频消息则直接返回
         if Type ==  CONST['CHAT']['VIDEO']['value']:
             videoData = data
             videoData["room_type"] = room_type
             # 发送消息
             for item in address_book_data:
                 if item['be_focused_user_id'] != user_data['id']:
                     emit('video',  Utils.formatBody(videoData), room='@broadcast.'+str(item.be_focused_user_id))
             return 
         # 发送消息
         emit('chat',  Utils.formatBody(data), room=room_uuid)
         # 如果是云端存储则记录,这边判断不判断都存储
         # if save_action == CONST['SAVE']['CLOUD']['value']:
         res = Msg().getOne({Msg.room_uuid == room_uuid, Msg.created_at ==
                             created_at, Msg.user_id == user_data['id']})
         if res == None:
             copy_data = data.copy()
             copy_data['msg'] = json.dumps(msg)
             copy_data['send_status'] = CONST['STATUS']['SUCCESS']['value']
             Msg().add(copy_data)
         else:
             copy_data = data.copy()
             copy_data['msg'] = json.dumps(msg)
             copy_data['send_status'] = CONST['STATUS']['SUCCESS']['value']
             filters = {
                 Msg.name == copy_data['name'],
                 Msg.created_at == copy_data['created_at'],
                 Msg.room_uuid == room_uuid
             }
             Msg().edit(copy_data, filters)
         # 聊天时同步房间信息
         Room.updateLastMsgRoom(room_uuid, data, created_at)
         # 更新聊天提示数字
         AddressBook.updateUnreadNumber(room_uuid, user_data['id'])
         AddressBook.cleanUnreadNumber(room_uuid, user_data['id'])
         # 更新客户端房间信息
         for item in address_book_data:
             print(AddressBook,item)
             roomList = AddressBook.getRoomList(item.be_focused_user_id)
             socketio.emit('room', Utils.formatBody(
                 roomList), namespace='/api', room='@broadcast.'+str(item.be_focused_user_id))
     elif room_data != None and room_type == CONST['ROOM']['GROUP']['value']:
         # 获取用户的权限,如果禁言状态返回错误
         filters = {
             UserRoomRelation.user_id == user_data['id'],
             UserRoomRelation.room_uuid == room_uuid
         }
         selfUserRoomRelationData = UserRoomRelation().getOne(filters)
         if selfUserRoomRelationData['status'] == CONST['GROUP']['BLOCK']['value']:
             return Utils.formatError(CONST['CODE']['ERROR']['value'], '禁言中')
         # 获取群组内用户
         user_room_relation_data = UserRoomRelation.get(room_uuid)
         # 发送消息
         emit('chat', Utils.formatBody(data), room=room_uuid)
         # 如果是云端存储则记录
         # if save_action == CONST['SAVE']['CLOUD']['value']:
         res = Msg().getOne({Msg.room_uuid == room_uuid, Msg.created_at ==
                             created_at, Msg.user_id == user_data['id']})
         if res == None:
             copy_data = data.copy()
             copy_data['msg'] = json.dumps(msg)
             copy_data['send_status'] = CONST['STATUS']['SUCCESS']['value']
             Msg().add(copy_data)
         else:
             copy_data = data.copy()
             copy_data['msg'] = json.dumps(msg)
             copy_data['send_status'] = CONST['STATUS']['SUCCESS']['value']
             filters = {
                 Msg.name == copy_data['name'],
                 Msg.created_at == copy_data['created_at'],
                 Msg.room_uuid == room_uuid
             }
             Msg().edit(copy_data, filters)
         # 聊天时同步房间信息
         Room.updateLastMsgRoom(room_uuid, data, created_at)
         # 更新聊天提示数字
         UserRoomRelation.updateUnreadNumber(room_uuid, user_data['id'])
         UserRoomRelation.cleanUnreadNumber(room_uuid, user_data['id'])
         # 更新客户端房间信息
         for item in user_room_relation_data:
             roomList = UserRoomRelation.getRoomList(item.user_id)
             socketio.emit('groupRoom', Utils.formatBody(
                 roomList), namespace='/api', room='@broadcast.'+str(item.user_id))
     return Utils.formatBody({'action': "chat", "data": data})