mirror of
https://github.com/Sneed-Group/pypush-plus-plus
synced 2025-01-09 17:33:47 +00:00
make publishing client_data optional
This commit is contained in:
parent
3500879256
commit
56e0c6098c
2 changed files with 12 additions and 12 deletions
20
demo.py
20
demo.py
|
@ -57,6 +57,13 @@ async def main(args: argparse.Namespace):
|
|||
|
||||
push_creds = apns.PushCredentials(
|
||||
CONFIG.get("push", {}).get("key", ""), CONFIG.get("push", {}).get("cert", ""), token)
|
||||
|
||||
def register(conn, users):
|
||||
import emulated.nac
|
||||
vd = emulated.nac.generate_validation_data()
|
||||
vd = b64encode(vd).decode()
|
||||
users = ids.register(conn, users, vd, args.client_data)
|
||||
return users
|
||||
|
||||
async with apns.APNSConnection.start(push_creds) as conn:
|
||||
# Save the push credentials to the config
|
||||
|
@ -112,12 +119,7 @@ async def main(args: argparse.Namespace):
|
|||
|
||||
users.append(ids.IDSAppleUser.authenticate(conn, username, password))
|
||||
|
||||
import emulated.nac
|
||||
|
||||
vd = emulated.nac.generate_validation_data()
|
||||
vd = b64encode(vd).decode()
|
||||
|
||||
users = ids.register(conn, users, vd)
|
||||
users = register(conn, users)
|
||||
|
||||
CONFIG["users"] = []
|
||||
for user in users:
|
||||
|
@ -134,10 +136,7 @@ async def main(args: argparse.Namespace):
|
|||
|
||||
if args.reregister:
|
||||
print("Re-registering...")
|
||||
import emulated.nac
|
||||
vd = emulated.nac.generate_validation_data()
|
||||
vd = b64encode(vd).decode()
|
||||
users = ids.register(conn, users, vd)
|
||||
users = register(conn, users)
|
||||
|
||||
|
||||
# You CANNOT turn around and re-register like this:
|
||||
|
@ -271,5 +270,6 @@ async def output_task(im: imessage.iMessageUser):
|
|||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--reregister", action="store_true", help="Force re-registration")
|
||||
parser.add_argument("--client-data", action="store_true", help="Publish client data (only necessary for actually sending/receiving messages)")
|
||||
args = parser.parse_args()
|
||||
trio.run(main, args)
|
|
@ -106,7 +106,7 @@ DEFAULT_CLIENT_DATA = {
|
|||
|
||||
import uuid
|
||||
|
||||
def register(push_connection: apns.APNSConnection, users: list[IDSUser], validation_data: str):
|
||||
def register(push_connection: apns.APNSConnection, users: list[IDSUser], validation_data: str, publish_client_data: bool = True):
|
||||
signing_users = [(user.user_id, user.auth_keypair) for user in users]
|
||||
|
||||
# Create new encryption identity for each user
|
||||
|
@ -125,7 +125,7 @@ def register(push_connection: apns.APNSConnection, users: list[IDSUser], validat
|
|||
else:
|
||||
special_data = DEFAULT_CLIENT_DATA
|
||||
user_payloads.append({
|
||||
"client-data": special_data,
|
||||
"client-data": special_data if publish_client_data else None,
|
||||
"tag": "SIM" if user.user_id.startswith("P:") else None,
|
||||
"uris": [{"uri": handle} for handle in user.handles],
|
||||
"user-id": user.user_id,
|
||||
|
|
Loading…
Reference in a new issue