コード例 #1
0
 def beg(params, user_info):
     if user_info['data']['id'] == params['be_focused_user_id']:
         return Utils.formatError(CONST['CODE']['BAD_REQUEST']['value'],
                                  '无法添加自己为新朋友')
     addressBookdata = AddressBook.getAdddressBookByFocusedUserId(
         user_info['data']['id'], params['be_focused_user_id'])
     if addressBookdata != None:
         return Utils.formatError(CONST['CODE']['BAD_REQUEST']['value'],
                                  '已添加')
     msg_uuid = Utils.unique_id()
     userData = Users().getOne({Users.id == user_info['data']['id']})
     data = {
         'data': userData,
         'action': 'beg_add',
         'msg_uuid': msg_uuid,
         'be_focused_user_id': params['be_focused_user_id'],
         'focused_user_id': user_info['data']['id']
     }
     socketio.emit('beg',
                   Utils.formatBody(data),
                   namespace='/api',
                   room='@broadcast.' +
                   str(params['be_focused_user_id']))  #,callback=success)
     #只缓存最新的一条
     cache.set('@broadcast.beg' + str(params['be_focused_user_id']), data)
     return Utils.formatBody({}, msg='发送成功')
コード例 #2
0
def addressBookBeg(params):
    if params['focused_user_id'] == params['be_focused_user_id']:
        return BaseController().error(msg='无法添加自己为新朋友')
    addressBookdata = AddressBook.getAdddressBookByFocusedUserId(params['focused_user_id'], params['be_focused_user_id'])
    if addressBookdata != None:
        return BaseController().error(msg='已添加')
    msg_uuid = Utils.unique_id()
    userData = Users().getOne({Users.id == params['focused_user_id']})
    socketio.emit('beg', Utils.formatBody({
        'data':userData, 
        'action':'beg_add', 
        'msg_uuid': msg_uuid, 
        'be_focused_user_id': params['be_focused_user_id']
    }), namespace='/room', room='@broadcast.'+str(params['be_focused_user_id']), callback=success)
    return BaseController().successData(msg='发送成功')