mirror of
https://github.com/Sneed-Group/pypush-plus-plus
synced 2024-12-23 19:32:29 -06:00
squash more bugs
This commit is contained in:
parent
931bb00caa
commit
9822d6f66f
4 changed files with 14 additions and 12 deletions
9
apns.py
9
apns.py
|
@ -100,7 +100,11 @@ class APNSConnection:
|
|||
# Check if anything currently in the queue matches the id
|
||||
for payload in self._incoming_queue:
|
||||
if payload.id == id:
|
||||
return payload
|
||||
if filter is not None:
|
||||
if filter(payload):
|
||||
return payload
|
||||
else:
|
||||
return payload
|
||||
while True:
|
||||
await self._queue_park.wait() # Wait for a new payload to be added to the queue
|
||||
logger.debug(f"Woken by event, checking for {id}")
|
||||
|
@ -256,6 +260,7 @@ class APNSConnection:
|
|||
|
||||
async def send_notification(self, topic: str, payload: bytes, id=None):
|
||||
"""Sends a notification to the APNs server"""
|
||||
logger.debug(f"Sending notification to topic {topic}")
|
||||
if id is None:
|
||||
id = random.randbytes(4)
|
||||
|
||||
|
@ -280,7 +285,7 @@ class APNSConnection:
|
|||
"""Waits for a notification to be received, and acks it"""
|
||||
|
||||
def f(payload: APNSPayload):
|
||||
if payload.fields_with_id(1)[0].value != sha1(topic.encode()).digest():
|
||||
if payload.fields_with_id(2)[0].value != sha1(topic.encode()).digest():
|
||||
return False
|
||||
if filter is not None:
|
||||
return filter(payload)
|
||||
|
|
6
demo.py
6
demo.py
|
@ -23,15 +23,15 @@ logging.getLogger("py.warnings").setLevel(logging.ERROR) # Ignore warnings from
|
|||
logging.getLogger("asyncio").setLevel(logging.WARNING)
|
||||
logging.getLogger("jelly").setLevel(logging.INFO)
|
||||
logging.getLogger("nac").setLevel(logging.INFO)
|
||||
logging.getLogger("apns").setLevel(logging.DEBUG)
|
||||
logging.getLogger("apns").setLevel(logging.INFO)
|
||||
logging.getLogger("albert").setLevel(logging.INFO)
|
||||
logging.getLogger("ids").setLevel(logging.DEBUG)
|
||||
logging.getLogger("bags").setLevel(logging.INFO)
|
||||
logging.getLogger("imessage").setLevel(logging.DEBUG)
|
||||
logging.getLogger("imessage").setLevel(logging.INFO)
|
||||
|
||||
logging.captureWarnings(True)
|
||||
|
||||
process = Popen(["git", "rev-parse", "HEAD"], stdout=PIPE)
|
||||
process = Popen(["git", "rev-parse", "HEAD"], stdout=PIPE) # type: ignore
|
||||
(commit_hash, err) = process.communicate()
|
||||
exit_code = process.wait()
|
||||
commit_hash = commit_hash.decode().strip()
|
||||
|
|
|
@ -55,7 +55,6 @@ async def lookup(
|
|||
if body is None:
|
||||
return False
|
||||
body = plistlib.loads(body)
|
||||
logging.warning(body.get('U'))
|
||||
return body.get('U') == msg_id
|
||||
|
||||
payload = await conn.expect_notification(topic, check)
|
||||
|
|
10
imessage.py
10
imessage.py
|
@ -626,21 +626,19 @@ class iMessageUser:
|
|||
|
||||
await self.connection.send_notification(topic, body, message_id)
|
||||
|
||||
async def _receive_raw(self, c: int, topic: str) -> dict | None:
|
||||
async def _receive_raw(self, c: int, topic: str) -> dict:
|
||||
def check(payload: apns.APNSPayload):
|
||||
# Check if the "c" key matches
|
||||
body = payload.fields_with_id(3)[0].value
|
||||
if body is None:
|
||||
return False
|
||||
body = plistlib.loads(body)
|
||||
if not "c" in body or "c" != c:
|
||||
if not "c" in body or body["c"] != c:
|
||||
return False
|
||||
return True
|
||||
|
||||
payload = await self.connection.expect_notification(topic, check)
|
||||
|
||||
if payload is None:
|
||||
return None
|
||||
body = payload.fields_with_id(3)[0].value
|
||||
body = plistlib.loads(body)
|
||||
return body
|
||||
|
@ -713,8 +711,8 @@ class iMessageUser:
|
|||
|
||||
while count < total and time.time() - start < 2:
|
||||
resp = await self._receive_raw(255, topic)
|
||||
if resp is None:
|
||||
continue
|
||||
#if resp is None:
|
||||
# continue
|
||||
count += 1
|
||||
|
||||
logger.debug(f"Received response : {resp}")
|
||||
|
|
Loading…
Reference in a new issue