Skip to content

Commit 88d1e8e

Browse files
committed
add hacky fix for KNOWN_TOPICS issue
1 parent c22904a commit 88d1e8e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pypush/apns/lifecycle.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ async def _update_filter(self):
205205
@asynccontextmanager
206206
async def _filter(self, topics: list[str]):
207207
for topic in topics:
208+
protocol.ADD_KNOWN_TOPIC(topic)
208209
self._filters[topic] = self._filters.get(topic, 0) + 1
209210
await self._update_filter()
210211
yield
@@ -215,6 +216,7 @@ async def _filter(self, topics: list[str]):
215216
await self._update_filter()
216217

217218
async def mint_scoped_token(self, topic: str) -> bytes:
219+
protocol.ADD_KNOWN_TOPIC(topic)
218220
topic_hash = sha1(topic.encode()).digest()
219221
await self._send(
220222
protocol.ScopedTokenCommand(token=await self.base_token, topic=topic_hash)

pypush/apns/protocol.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
KNOWN_TOPICS_LOOKUP = {sha1(topic.encode()).digest():topic for topic in KNOWN_TOPICS}
1313
# fmt: on
1414

15+
def ADD_KNOWN_TOPIC(topic: str):
16+
# Add a topic and hash to the known topics and lookup
17+
if topic not in KNOWN_TOPICS:
18+
KNOWN_TOPICS.add(topic)
19+
topic_hash = sha1(topic.encode()).digest()
20+
KNOWN_TOPICS_LOOKUP[topic_hash] = topic
1521

1622
@dataclass
1723
class Command:
@@ -177,6 +183,9 @@ def __post_init__(self):
177183
and self.outgoing is not None
178184
) and not (self._token_topic_1 is not None and self._token_topic_2 is not None):
179185
raise ValueError("topic, token, and outgoing must be set.")
186+
187+
if self.topic is not None and isinstance(self.topic, str):
188+
ADD_KNOWN_TOPIC(self.topic)
180189

181190
if self.outgoing is True:
182191
assert self.topic and self.token

0 commit comments

Comments
 (0)