Exemplo n.º 1
0
async def save(client, dbFileName, message):
    accounts = utilities.unpackAccounts(message["accounts"])
    packages = utilities.unpackPackages(message["packages"])

    database.save(dbFileName, accounts, packages)

    successful = [
        entity["entity"] for entity in packages
        if entity["status"] == "success"
    ]
    print("successful               ", successful)

    await messages.respond(
        client, message, {
            "packages": [{
                "entity":
                utilities.packPackages([entity["entity"]])[0],
                **(utilities.packEntities([entity])[0])
            } for entity in packages]
        })

    changedUsernames = set([package["username"] for package in successful])
    clients2usernames = connections.getClients(changedUsernames)
    for otherClient, usernames in clients2usernames.items():
        usernames = list(usernames)
        await messages.send(otherClient, 'packages changed',
                            {'usernames': usernames})
Exemplo n.º 2
0
async def save(client, dbFileName, message):
    accounts = utilities.unpackAccounts(message["accounts"])
    packages = utilities.unpackPackages(message["packages"])

    print("packages before          ", message["packages"])
    print("packages after         ", packages)
    successList, failedList = database.save(dbFileName, accounts, packages)

    print("successList           ", successList)
    await messages.respond(
        client, message, {
            "successful": utilities.packPackages(successList, set(["data"])),
            "failed": utilities.packPackages(failedList, set(["data"]))
        })

    changedAccountIds = set([package["accountId"] for package in successList])
    print("changedAccountIds1       ", changedAccountIds)
    print("activeClients       ", connections.activeClients())
    clients2accountIds = connections.getClients(changedAccountIds)
    print("changedAccountIds2.5     ", clients2accountIds)
    clients2accountIds.pop(client, None)
    print("changedAccountIds2       ", clients2accountIds)
    for otherClient, accountIds in clients2accountIds.items():
        accountIds = list(accountIds)
        print("accountIds           ", accountIds)
        await messages.send(otherClient, 'packages changed',
                            {'accountIds': utilities.packBlobs(accountIds)})
Exemplo n.º 3
0
async def save(client, dbFileName, message):
    accounts = message["accounts"]
    packages = message["packages"]
    timestamp = message["timestamp"]
    
    changes = database.save(dbFileName, accounts, packages, timestamp) 
    print(changes)
    if changes != False and len(changes) != 0:
        client2changedAccountIds = {}
        for accountId in changes:
            otherClients = connections.getClients(accountId)

            for otherClient in otherClients:
                if otherClient != client:
                    try: 
                        accountIds = client2changedAccountIds[otherClient]
                    except:
                        accountIds = set()
                    accountIds.add(accountId)
                    client2changedAccountIds[otherClient] = accountIds

        for client, accountIds in client2changedAccountIds.items():
            accountIds = list(accountIds)
            await messages.send(otherClient, 'packages changed', {
                'accountIds': accountIds
            })
Exemplo n.º 4
0
async def save(client, dbFileName, message):
    account = message["account"]
    packages = message["packages"]
    if database.save(client, account, packages):
        otherClients = connections.getClients(account["id"])

        for otherClient in otherClients:
            await messages.send(otherClient, 'packages changed')
Exemplo n.º 5
0
async def save(client, dbFileName, message):
    accounts = utilities.unpackAccounts(message["accounts"])
    packages = utilities.unpackPackages(message["packages"])
    
    successList, failedList = database.save(dbFileName, accounts, packages) 

    await messages.respond(client, message, {
        "successful" : utilities.packPackages(successList, set(["data"])),
        "failed" : utilities.packPackages(failedList, set(["data"]))
    })

    changedAccountIds = set([package["accountId"] for package in successList])
    clients2accountIds = connections.getClients(changedAccountIds)
    for otherClient, accountIds in clients2accountIds.items():
        accountIds = list(accountIds)
        await messages.send(otherClient, 'packages changed', {
            'accountIds': utilities.packBlobs(accountIds)
        })
Exemplo n.º 6
0
async def save(client, dbFileName, message):
    accounts = utilities.unpackAccounts(message["accounts"])
    packages = utilities.unpackPackages(message["packages"])

    packageWrappers = database.savePackages(dbFileName, accounts, packages)

    await messages.respond(
        client, message, {
            "packages":
            utilities.packStatusWrappers(packageWrappers,
                                         utilities.packPackage)
        })

    successful = [
        wrapper["entity"] for wrapper in packageWrappers
        if wrapper["status"] == "success"
    ]
    changedUsernames = set([package["username"] for package in successful])
    clients2usernames = connections.getClients(changedUsernames)
    for otherClient, usernames in clients2usernames.items():
        usernames = list(usernames)
        await messages.send(otherClient, 'packages changed',
                            {'usernames': usernames})