Add packet_hash to bot kwargs. Closes #268.

This commit is contained in:
Jack Kingsman
2026-06-01 18:50:19 -07:00
parent 50af30f3bb
commit bea51b894d
9 changed files with 95 additions and 39 deletions
+6 -1
View File
@@ -154,6 +154,7 @@ async def _store_direct_message(
update_last_contacted_key: str | None,
best_effort_content_dedup: bool,
linked_packet_dedup: bool,
packet_hash: str | None = None,
message_repository=MessageRepository,
contact_repository=ContactRepository,
raw_packet_repository=RawPacketRepository,
@@ -248,7 +249,9 @@ async def _store_direct_message(
sender_name=sender_name,
packet_id=packet_id,
)
broadcast_message(message=message, broadcast_fn=broadcast_fn, realtime=realtime)
broadcast_message(
message=message, broadcast_fn=broadcast_fn, realtime=realtime, packet_hash=packet_hash
)
if update_last_contacted_key:
await contact_repository.update_last_contacted(update_last_contacted_key, received_at)
@@ -279,6 +282,7 @@ async def ingest_decrypted_direct_message(
outgoing: bool = False,
realtime: bool = True,
broadcast_fn: BroadcastFn,
packet_hash: str | None = None,
contact_repository=ContactRepository,
) -> Message | None:
conversation_key = their_public_key.lower()
@@ -338,6 +342,7 @@ async def ingest_decrypted_direct_message(
update_last_contacted_key=conversation_key,
best_effort_content_dedup=outgoing,
linked_packet_dedup=True,
packet_hash=packet_hash,
)
if message is None:
return None
+7
View File
@@ -95,9 +95,12 @@ def broadcast_message(
message: Message,
broadcast_fn: BroadcastFn,
realtime: bool | None = None,
packet_hash: str | None = None,
) -> None:
"""Broadcast a message payload, preserving the caller's broadcast signature."""
payload = message.model_dump()
if packet_hash is not None:
payload["packet_hash"] = packet_hash
if realtime is None:
broadcast_fn("message", payload)
else:
@@ -272,6 +275,7 @@ async def create_message_from_decrypted(
channel_name: str | None = None,
realtime: bool = True,
broadcast_fn: BroadcastFn,
packet_hash: str | None = None,
) -> int | None:
"""Store and broadcast a decrypted channel message."""
received = received_at or int(time.time())
@@ -340,6 +344,7 @@ async def create_message_from_decrypted(
),
broadcast_fn=broadcast_fn,
realtime=realtime,
packet_hash=packet_hash,
)
return msg_id
@@ -359,6 +364,7 @@ async def create_dm_message_from_decrypted(
outgoing: bool = False,
realtime: bool = True,
broadcast_fn: BroadcastFn,
packet_hash: str | None = None,
) -> int | None:
"""Store and broadcast a decrypted direct message."""
from app.services.dm_ingest import ingest_decrypted_direct_message
@@ -375,6 +381,7 @@ async def create_dm_message_from_decrypted(
outgoing=outgoing,
realtime=realtime,
broadcast_fn=broadcast_fn,
packet_hash=packet_hash,
)
return message.id if message is not None else None