Beispiel #1
0
def chat_message(user):
    res = SendMessage.objects.filter(to_user_id=user['id'], is_read=0, msg__status=1).all().values('id', 'msg__msg')
    ids = []
    for msg in list(res):
        ids.append(msg['id'])
        user['socket'].send(msg['msg__msg'])
    if len(ids):
        theadDB(updateSendMessage, ids)
Beispiel #2
0
def friend_remove(params, user):
    content = user['username'] + ' 已经将您删除'
    tid = int(params['id'])
    if channels.get(tid, None) is not None:
        data = chat_output(CHAT, content)
        channels[tid]['socket'].send(json.dumps({
                'type': 'sendMessage',
                'data': data
            }))
    theadDB(removeFriend, user['id'], tid, content)
Beispiel #3
0
def friend_update(params, user):
    _type = 1 if params['type'] == 1 else 2
    tid = int(params['id'])
    msg = ' 已经同意好友申请' if _type == 1 else ' 拒绝了你的好友申请'
    content = user['username'] + msg
    if channels.get(tid, None) is not None:
        data = chat_output(CHAT, content)
        channels[tid]['socket'].send(json.dumps({
                'type': 'sendMessage',
                'data': data
            }))
    theadDB(updateFriend, user['id'], int(params['id']), _type, content)
Beispiel #4
0
def friend_chat(params, user):
    tid = int(params['id'])
    data = chat_output(user, params['content'], 'friend')
    data = json.dumps({
            'type': 'chatMessage',
            'data': data
        })
    if channels.get(tid, None) is not None:
        channels[tid]['socket'].send(data)
    else:
        # 玩家离线
        theadDB(sendMessage, user['id'], [tid], data, 0)
Beispiel #5
0
def friend_add(params, user):
    print('friend_add', params)
    tid = int(params['id'])
    if channels.get(int(params['id']), None) is not None:
        channels[tid]['socket'].send(json.dumps({
                'type': 'sendMessage',
                'data': {
                    'username': user['username'],
                    'avatar': user['avatar'],
                    'id': user['id'],
                    'type': 'system',
                    'content': params['content']
                }
            }))
    theadDB(addFriend, user['id'], tid, int(params['group']), params['content'])
Beispiel #6
0
def group_chat(params, user):
    gid = int(params['id'])
    g = groups.get(gid)
    # print('g----', g)
    if g is not None:
        data = chat_output(user, params['content'], 'group')
        data['id'] = gid
        data = json.dumps({
            'type': 'chatMessage',
            'data': data
        })
        for uid1 in g['online']:
            if uid1 == user['id']:
                continue
            if channels.get(uid1, None) is not None:
                channels[uid1]['socket'].send(data)
        if len(g['offline']):
            theadDB(sendMessage, user['id'], g['offline'], data, gid)
Beispiel #7
0
def send_group_message(gid, data, user_id=0):
    """
    发送消息
    :param user_id: user_id = 0 为系统消息
    :param gid:
    :param data:
    :return:
    """
    if user_id == 0:
        g = groups.get(gid, None)
        if g is not None:
            # 消息给离线者
            theadDB(sendMessage, user_id, g['offline'], data, gid)
            # 消息发送给在线者
            for uid in g['online']:
                if channels.get(uid, None) is not None:
                    channels[uid]['socket'].send(data)
    else:
        # 系统通知,如上下线通知
        for uid in channels:
            channels[uid]['socket'].send(data)