Example #1
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()
Example #2
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()
Example #3
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}
Example #4
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)
Example #5
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()
Example #6
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()
Example #7
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)
Example #8
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()
Example #9
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()
Example #10
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()
Example #11
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)
Example #13
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(',')}