Пример #1
0
def getOfflineMessages(request, connectionSocket):
    database = lite.connect('user.db')
    cursor = database.cursor()

    request = request.strip("\r\n")
    request = request.split("\t")

    user = OverView.findUserBySocket(connectionSocket)
    userID = user.id
    roomID = request[1]

    loadmessages = cursor.execute(
        "select messages.* from messages join user on user.id = messages.userID and messages.roomID = ?",
        [roomID])
    loadmessages = loadmessages.fetchall()
    messages = []
    for i in range(len(loadmessages)):
        user = OverView.findUserByID(loadmessages[i][1])
        messages.append({
            'User': user.name,
            'Message': loadmessages[i][2],
            'Time': loadmessages[i][3],
            'RoomID': loadmessages[i][4]
        })
    print("getOfflineMessages")
    messages = messages.__str__()
    connectionSocket.send(
        ("getOfflineMessages\t" + messages + "\r\n").encode())
Пример #2
0
def printFriendsList(request, connectionSocket):
    print("printFriendsList")

    database = lite.connect('user.db')
    cursor = database.cursor()
    user = OverView.findUserBySocket(connectionSocket)
    if user != None:
        users = cursor.execute(
            "select distinct * from friends as f1, friends as f2 where f1.secondFriendID = f2.firstFriendID and f1.firstFriendID = f2.secondFriendID and (f1.firstFriendID = ?)",
            [user.id])
        users = users.fetchall()

        friends = []
        for i in range(len(users)):
            secondPerson = OverView.findUserByID(users[i][1])
            id = users[i][1]
            friends.append({
                "Name": secondPerson.name,
                "Status": secondPerson.status,
                "ID": id
            })

        friends = friends.__str__()
        connectionSocket.send(("FriendsList\t" + friends + "\r\n").encode())
    else:
        connectionSocket.send(("FriendsList").encode())
Пример #3
0
def sendPrivateMessage(request, connectionSocket):
    database = lite.connect('user.db')
    cursor = database.cursor()
    print("sendPrivateMessage")
    request = request.strip("\r\n")
    request = request.split("\t")
    sender = OverView.findUserBySocket(connectionSocket)
    receiverID = int(request[1])
    receiver = OverView.findUserByID(receiverID)
    message = request[2]
    timeStamp = time.time()
    receiver = OverView.findUserByID(receiverID)
    insert = cursor.execute(
        "insert into privateMessages(toUser, fromUser, message, timeStamp) values(?, ?, ?, ? )",
        [receiverID, sender.id, message, timeStamp])
    database.commit()
    connectionSocket.send(("SendPrivateMessage\tSuccess").encode())
Пример #4
0
def getFriendStatus(request, connectionSocket):
    print("getFriendStatus")
    request = request.strip("\r\n")
    request = request.split("\t")
    friendID = request[1]

    friend = OverView.findUserByID(friendID)

    connectionSocket.send(
        ("FriendStatus\tSuccess\t" + friend.status + "\r\n").encode())
    return 1